diff --git a/cmd/serverless/main.go b/cmd/serverless/main.go index 68865f96aa14e..3d0fdc9a9104e 100644 --- a/cmd/serverless/main.go +++ b/cmd/serverless/main.go @@ -336,7 +336,8 @@ func startOtlpAgent(wg *sync.WaitGroup, metricAgent *metrics.ServerlessMetricAge func startTraceAgent(wg *sync.WaitGroup, lambdaSpanChan chan *pb.Span, coldStartSpanId uint64, serverlessDaemon *daemon.Daemon) { defer wg.Done() - traceAgent := trace.StartServerlessTraceAgent(pkgconfigsetup.Datadog().GetBool("apm_config.enabled"), &trace.LoadConfig{Path: datadogConfigPath}, lambdaSpanChan, coldStartSpanId) + apmEnabled := configUtils.IsDefaultPayloadsEnabled(pkgconfigsetup.Datadog()) && pkgconfigsetup.Datadog().GetBool("apm_config.enabled") + traceAgent := trace.StartServerlessTraceAgent(apmEnabled, &trace.LoadConfig{Path: datadogConfigPath}, lambdaSpanChan, coldStartSpanId) serverlessDaemon.SetTraceAgent(traceAgent) } diff --git a/comp/trace/config/setup.go b/comp/trace/config/setup.go index ab9361127c633..28ffcd0176dcb 100644 --- a/comp/trace/config/setup.go +++ b/comp/trace/config/setup.go @@ -196,7 +196,8 @@ func applyDatadogConfig(c *config.AgentConfig, core corecompcfg.Component) error c.SkipSSLValidation = core.GetBool("skip_ssl_validation") } if core.IsSet("apm_config.enabled") { - c.Enabled = core.GetBool("apm_config.enabled") + isAPMEnabled := core.GetBool("apm_config.enabled") && utils.IsDefaultPayloadsEnabled(core) + c.Enabled = isAPMEnabled } if pkgconfigsetup.Datadog().IsSet("apm_config.log_file") { c.LogFilePath = pkgconfigsetup.Datadog().GetString("apm_config.log_file") diff --git a/pkg/config/setup/config.go b/pkg/config/setup/config.go index 9c535190419da..5dcca17bc5604 100644 --- a/pkg/config/setup/config.go +++ b/pkg/config/setup/config.go @@ -1020,10 +1020,6 @@ func InitConfig(config pkgconfigmodel.Setup) { config.SetKnown("reverse_dns_enrichment.rate_limiter.throttle_error_threshold") config.SetKnown("reverse_dns_enrichment.rate_limiter.recovery_intervals") config.BindEnvAndSetDefault("reverse_dns_enrichment.rate_limiter.recovery_interval", time.Duration(0)) - - // Default payloads (disabled for Error Tracking Standalone, Logs Collection Only) - config.BindEnvAndSetDefault("default_payloads.enabled", true) - pkgconfigmodel.AddOverrideFunc(toggleDefaultPayloads) } func agent(config pkgconfigmodel.Setup) { @@ -1115,6 +1111,10 @@ func agent(config pkgconfigmodel.Setup) { config.SetKnown("proxy.http") config.SetKnown("proxy.https") config.SetKnown("proxy.no_proxy") + + // Default payloads (disabled for Error Tracking Standalone, Logs Collection Only) + config.BindEnvAndSetDefault("default_payloads.enabled", true) + pkgconfigmodel.AddOverrideFunc(toggleDefaultPayloads) } func fips(config pkgconfigmodel.Setup) { @@ -2578,7 +2578,7 @@ func GetRemoteConfigurationAllowedIntegrations(cfg pkgconfigmodel.Reader) map[st return allowMap } -// IsAgentTelemetryEnabled returns true if Agent Telemetry ise enabled +// IsAgentTelemetryEnabled returns true if Agent Telemetry is enabled func IsAgentTelemetryEnabled(cfg pkgconfigmodel.Reader) bool { // Disable Agent Telemetry for GovCloud if cfg.GetBool("fips.enabled") || cfg.GetString("site") == "ddog-gov.com" { diff --git a/pkg/config/utils/miscellaneous.go b/pkg/config/utils/miscellaneous.go index 18f87b9ade392..1a09260387b24 100644 --- a/pkg/config/utils/miscellaneous.go +++ b/pkg/config/utils/miscellaneous.go @@ -31,3 +31,21 @@ func SetLogLevel(level string, config pkgconfigmodel.Writer, source pkgconfigmod config.Set("log_level", seelogLogLevel, source) return nil } + +// IsDefaultPayloadsEnabled checks if the Agent is able to send the payloads it and other Agents need to function with +func IsDefaultPayloadsEnabled(cfg pkgconfigmodel.Reader) bool { + if !cfg.GetBool("default_payloads.enabled") { + return false + } + + // default_payloads.enabled can be true but the following payloads if set to false means + // default_payloads are disabled + if !cfg.GetBool("enable_payloads.events") && + !cfg.GetBool("enable_payloads.series") && + !cfg.GetBool("enable_payloads.service_checks") && + !cfg.GetBool("enable_payloads.sketches") { + return false + } + + return true +} diff --git a/pkg/config/utils/miscellaneous_test.go b/pkg/config/utils/miscellaneous_test.go new file mode 100644 index 0000000000000..7cd1dbff7fd43 --- /dev/null +++ b/pkg/config/utils/miscellaneous_test.go @@ -0,0 +1,66 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +package utils + +import ( + "github.com/stretchr/testify/assert" + "testing" + + configmock "github.com/DataDog/datadog-agent/pkg/config/mock" + "github.com/DataDog/datadog-agent/pkg/config/model" +) + +func TestIsDefaultPayloadsEnabled(t *testing.T) { + + tests := []struct { + name string + expected bool + setConfig func(m model.Config) + }{ + { + name: "default_payloads.enabled false", + expected: false, + setConfig: func(m model.Config) { + m.SetWithoutSource("default_payloads.enabled", false) + }, + }, + { + name: "All enable_payloads.enabled false", + expected: false, + setConfig: func(m model.Config) { + m.SetWithoutSource("enable_payloads.events", false) + m.SetWithoutSource("enable_payloads.series", false) + m.SetWithoutSource("enable_payloads.service_checks", false) + m.SetWithoutSource("enable_payloads.sketches", false) + }, + }, + { + name: "Some enable_payloads.enabled false", + expected: true, + setConfig: func(m model.Config) { + m.SetWithoutSource("enable_payloads.events", false) + m.SetWithoutSource("enable_payloads.series", true) + m.SetWithoutSource("enable_payloads.service_checks", false) + m.SetWithoutSource("enable_payloads.sketches", true) + }, + }, + { + name: "default values", + expected: true, + setConfig: func(_ model.Config) {}, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + mockConfig := configmock.New(t) + test.setConfig(mockConfig) + assert.Equal(t, + test.expected, IsDefaultPayloadsEnabled(mockConfig), + "Was expecting IsDefaultPayloadsEnabled to return", test.expected) + }) + } +}