Skip to content

Commit

Permalink
Adding check that default payloads is enabled (#30600)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosroman authored Nov 4, 2024
1 parent 953c6ba commit 9b44f30
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion comp/trace/config/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/setup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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" {
Expand Down
18 changes: 18 additions & 0 deletions pkg/config/utils/miscellaneous.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
66 changes: 66 additions & 0 deletions pkg/config/utils/miscellaneous_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}

0 comments on commit 9b44f30

Please sign in to comment.