Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RC4] Fix for datadog logs output #196

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions pkg/globals/application.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
package globals

import "os"

const (
DDServiceName = "kubehound"
DDEnv = "prod"
DDServiceName = "kubehound"
DefaultDDEnv = "dev"
DefaultComponent = "kubehound-ingestor"
)

func ProdEnv() bool {
return false
func GetDDEnv() string {
env := os.Getenv("DD_ENV")
if env == "" {
return DefaultDDEnv
}

return env
}

func IsDDFormat() bool {
_, isDDEnv := os.LookupEnv("DD_ENV")

return isDDEnv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of IsDDFormat here, what format is it? (I know it's for the logs because this PR says it, but it's a global func)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I just reuse what was in place. Did not like the ProdEnv() func. Will see if it is not too painful to add it to the config file instead.

}

const (
Expand Down
11 changes: 6 additions & 5 deletions pkg/ingestor/puller/mocks/mock_puller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions pkg/kubehound/graph/edge/mocks/edge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions pkg/telemetry/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ type LoggerConfig struct {
DD bool // Whether Datadog integration is enabled.
}

const (
DefaultComponent = "kubehound"
)

var globalConfig = LoggerConfig{
Tags: logrus.Fields{
globals.TagService: globals.DDServiceName,
globals.TagComponent: DefaultComponent,
globals.TagComponent: globals.DefaultComponent,
},
Mu: &sync.Mutex{},
DD: true,
Expand Down Expand Up @@ -59,7 +55,7 @@ func spanID(span tracer.Span) string {
// Base returns the base logger for the application.
func Base() *KubehoundLogger {
logger := logrus.WithFields(globalConfig.Tags)
if globals.ProdEnv() {
if globals.IsDDFormat() {
logger.Logger.SetFormatter(&logrus.JSONFormatter{})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Initialize(cfg *config.KubehoundConfig) {
opts := []profiler.Option{
profiler.WithService(globals.DDServiceName),
profiler.WithEnv(globals.DDEnv),
profiler.WithEnv(globals.GetDDEnv()),
profiler.WithVersion(config.BuildVersion),
profiler.WithProfileTypes(
profiler.CPUProfile,
Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func Initialize(cfg *config.KubehoundConfig) {
// Default options
opts := []tracer.StartOption{
tracer.WithEnv(globals.DDEnv),
tracer.WithEnv(globals.GetDDEnv()),
tracer.WithService(globals.DDServiceName),
tracer.WithServiceVersion(config.BuildVersion),
tracer.WithLogStartup(false),
Expand Down
Loading