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

Adding check that default payloads is enabled #30600

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
2 changes: 1 addition & 1 deletion pkg/config/setup/config.go
Original file line number Diff line number Diff line change
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)
})
}
}
Loading