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

Add infra agent config option #30137

Merged
merged 15 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 2 additions & 1 deletion cmd/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ func startOtlpAgent(wg *sync.WaitGroup, metricAgent *metrics.ServerlessMetricAge

func startTraceAgent(wg *sync.WaitGroup, lambdaSpanChan chan *pb.Span, coldStartSpanId uint64, serverlessDaemon *daemon.Daemon, tagger tagger.Component) {
defer wg.Done()
apmEnabled := configUtils.IsCoreAgentEnabled(pkgconfigsetup.Datadog()) && pkgconfigsetup.Datadog().GetBool("apm_config.enabled")
traceAgent := trace.StartServerlessTraceAgent(trace.StartServerlessTraceAgentArgs{
Enabled: pkgconfigsetup.Datadog().GetBool("apm_config.enabled"),
Enabled: apmEnabled,
LoadConfig: &trace.LoadConfig{Path: datadogConfigPath, Tagger: tagger},
LambdaSpanChan: lambdaSpanChan,
ColdStartSpanID: coldStartSpanId,
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 @@ -194,7 +194,8 @@ func applyDatadogConfig(c *config.AgentConfig, core corecompcfg.Component) error
c.SkipSSLValidation = core.GetBool("skip_ssl_validation")
}
if core.IsSet("apm_config.enabled") {
pgimalac marked this conversation as resolved.
Show resolved Hide resolved
c.Enabled = core.GetBool("apm_config.enabled")
isAPMEnabled := core.GetBool("apm_config.enabled") && utils.IsCoreAgentEnabled(core)
c.Enabled = isAPMEnabled
ichinaski marked this conversation as resolved.
Show resolved Hide resolved
}
if pkgconfigsetup.Datadog().IsSet("apm_config.log_file") {
c.LogFilePath = pkgconfigsetup.Datadog().GetString("apm_config.log_file")
Expand Down
17 changes: 16 additions & 1 deletion pkg/config/setup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,10 @@ func agent(config pkgconfigmodel.Setup) {
config.SetKnown("proxy.http")
config.SetKnown("proxy.https")
config.SetKnown("proxy.no_proxy")

// Core agent (disabled for Error Tracking Standalone, Logs Collection Only)
config.BindEnvAndSetDefault("core_agent.enabled", true)
pkgconfigmodel.AddOverrideFunc(toggleDefaultPayloads)
}

func fips(config pkgconfigmodel.Setup) {
Expand Down Expand Up @@ -2357,6 +2361,17 @@ func sanitizeExternalMetricsProviderChunkSize(config pkgconfigmodel.Config) {
}
}

func toggleDefaultPayloads(config pkgconfigmodel.Config) {
// Disables metric data submission (including Custom Metrics) so that hosts stop showing up in Datadog.
// Used namely for Error Tracking Standalone where it is not needed.
if !config.GetBool("core_agent.enabled") {
config.BindEnvAndSetDefault("enable_payloads.events", false)
config.BindEnvAndSetDefault("enable_payloads.series", false)
config.BindEnvAndSetDefault("enable_payloads.service_checks", false)
config.BindEnvAndSetDefault("enable_payloads.sketches", false)
Guillaume-Barrier marked this conversation as resolved.
Show resolved Hide resolved
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if the customer has defined these settings manually?

Copy link
Member

@GianlucaBortoli GianlucaBortoli Nov 27, 2024

Choose a reason for hiding this comment

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

core_agent.enabled takes precedence if specified. As mentioned in this doc core_agent.enabled is just grouping all these existing flags into one for an easier setup.

}

func bindEnvAndSetLogsConfigKeys(config pkgconfigmodel.Setup, prefix string) {
config.BindEnv(prefix + "logs_dd_url") // Send the logs to a proxy. Must respect format '<HOST>:<PORT>' and '<PORT>' to be an integer
config.BindEnv(prefix + "dd_url")
Expand Down Expand Up @@ -2568,7 +2583,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
23 changes: 23 additions & 0 deletions pkg/config/setup/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,29 @@ func TestServerlessConfigInit(t *testing.T) {
assert.False(t, conf.IsKnown("inventories_enabled"))
}

func TestDisableCoreAgent(t *testing.T) {
pkgconfigmodel.CleanOverride(t)
conf := pkgconfigmodel.NewConfig("datadog", "DD", strings.NewReplacer(".", "_")) // nolint: forbidigo // legit use case
pkgconfigmodel.AddOverrideFunc(toggleDefaultPayloads)

InitConfig(conf)
assert.True(t, conf.GetBool("core_agent.enabled"))
pkgconfigmodel.ApplyOverrideFuncs(conf)
// ensure events default payloads are enabled
assert.True(t, conf.GetBool("enable_payloads.events"))
assert.True(t, conf.GetBool("enable_payloads.series"))
assert.True(t, conf.GetBool("enable_payloads.service_checks"))
assert.True(t, conf.GetBool("enable_payloads.sketches"))

conf.BindEnvAndSetDefault("core_agent.enabled", false)
pkgconfigmodel.ApplyOverrideFuncs(conf)
// ensure events default payloads are disabled
assert.False(t, conf.GetBool("enable_payloads.events"))
assert.False(t, conf.GetBool("enable_payloads.series"))
assert.False(t, conf.GetBool("enable_payloads.service_checks"))
assert.False(t, conf.GetBool("enable_payloads.sketches"))
}

func TestAgentConfigInit(t *testing.T) {
conf := newTestConf()

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
}

// IsCoreAgentEnabled checks if the Agent is able to send the payloads it and other Agents need to function with
func IsCoreAgentEnabled(cfg pkgconfigmodel.Reader) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: IMO this function name is bit deceptive, I would have expected only core_agent.enabled to be relevant for it's resolution

Copy link
Member

@GianlucaBortoli GianlucaBortoli Nov 27, 2024

Choose a reason for hiding this comment

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

I agree. However, as mentioned in this comment core_agent.enabled is an "alias" for other existing flags so we have to check for both in this section to make sure they're compatible in case all of them are set at the same time.

I don't have a better idea, but if you have I'm more than happy to change it :)

if !cfg.GetBool("core_agent.enabled") {
return false
}

// core_agent.enabled can be true but the following payloads if set to false means
// core_agent is 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 TestIsCoreAgentEnabled(t *testing.T) {

tests := []struct {
name string
expected bool
setConfig func(m model.Config)
}{
{
name: "core_agent.enabled false",
expected: false,
setConfig: func(m model.Config) {
m.SetWithoutSource("core_agent.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, IsCoreAgentEnabled(mockConfig),
"Was expecting IsCoreAgentEnabled to return", test.expected)
})
}
}
Loading