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

[Fleet] Add source information to configuration settings #20591

Merged
merged 15 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions cmd/agent/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/DataDog/datadog-agent/cmd/agent/common/path"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/model"
"github.com/DataDog/datadog-agent/pkg/config/settings"
"github.com/DataDog/datadog-agent/pkg/util/log"

Expand Down Expand Up @@ -86,19 +87,19 @@ func SelectedCheckMatcherBuilder(checkNames []string, minInstances uint) func(co
// SetupInternalProfiling is a common helper to configure runtime settings for internal profiling.
func SetupInternalProfiling(cfg config.Reader, configPrefix string) {
if v := cfg.GetInt(configPrefix + "internal_profiling.block_profile_rate"); v > 0 {
if err := settings.SetRuntimeSetting("runtime_block_profile_rate", v, settings.SourceConfig); err != nil {
if err := settings.SetRuntimeSetting("runtime_block_profile_rate", v, model.SourceAgentRuntime); err != nil {
log.Errorf("Error setting block profile rate: %v", err)
}
}

if v := cfg.GetInt(configPrefix + "internal_profiling.mutex_profile_fraction"); v > 0 {
if err := settings.SetRuntimeSetting("runtime_mutex_profile_fraction", v, settings.SourceConfig); err != nil {
if err := settings.SetRuntimeSetting("runtime_mutex_profile_fraction", v, model.SourceAgentRuntime); err != nil {
log.Errorf("Error mutex profile fraction: %v", err)
}
}

if cfg.GetBool(configPrefix + "internal_profiling.enabled") {
err := settings.SetRuntimeSetting("internal_profiling", true, settings.SourceConfig)
err := settings.SetRuntimeSetting("internal_profiling", true, model.SourceAgentRuntime)
if err != nil {
log.Errorf("Error starting profiler: %v", err)
}
Expand Down
28 changes: 14 additions & 14 deletions cmd/agent/subcommands/flare/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ func TestReadProfileData(t *testing.T) {
port := u.Port()

mockConfig := config.Mock(t)
mockConfig.Set("expvar_port", port)
mockConfig.Set("apm_config.enabled", true)
mockConfig.Set("apm_config.debug.port", port)
mockConfig.Set("apm_config.receiver_timeout", "10")
mockConfig.Set("process_config.expvar_port", port)
mockConfig.Set("security_agent.expvar_port", port)
mockConfig.Set("system_probe_config.debug_port", port)
mockConfig.SetWithoutSource("expvar_port", port)
mockConfig.SetWithoutSource("apm_config.enabled", true)
mockConfig.SetWithoutSource("apm_config.debug.port", port)
mockConfig.SetWithoutSource("apm_config.receiver_timeout", "10")
mockConfig.SetWithoutSource("process_config.expvar_port", port)
mockConfig.SetWithoutSource("security_agent.expvar_port", port)
mockConfig.SetWithoutSource("system_probe_config.debug_port", port)

data, err := readProfileData(10)
require.NoError(t, err)
Expand Down Expand Up @@ -103,12 +103,12 @@ func TestReadProfileDataNoTraceAgent(t *testing.T) {

// We're not setting "apm_config.debug.port" on purpose
mockConfig := config.Mock(t)
mockConfig.Set("expvar_port", port)
mockConfig.Set("apm_config.enabled", true)
mockConfig.Set("apm_config.receiver_timeout", "10")
mockConfig.Set("process_config.expvar_port", port)
mockConfig.Set("security_agent.expvar_port", port)
mockConfig.Set("system_probe_config.debug_port", port)
mockConfig.SetWithoutSource("expvar_port", port)
mockConfig.SetWithoutSource("apm_config.enabled", true)
mockConfig.SetWithoutSource("apm_config.receiver_timeout", "10")
mockConfig.SetWithoutSource("process_config.expvar_port", port)
mockConfig.SetWithoutSource("security_agent.expvar_port", port)
mockConfig.SetWithoutSource("system_probe_config.debug_port", port)

data, err := readProfileData(10)
require.Error(t, err)
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestReadProfileDataNoTraceAgent(t *testing.T) {
func TestReadProfileDataErrors(t *testing.T) {
// We're not setting "apm_config.debug.port" on purpose
mockConfig := config.Mock(t)
mockConfig.Set("apm_config.enabled", true)
mockConfig.SetWithoutSource("apm_config.enabled", true)

data, err := readProfileData(10)
require.Error(t, err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/agent/subcommands/jmx/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/DataDog/datadog-agent/pkg/cli/standalone"
"github.com/DataDog/datadog-agent/pkg/collector"
pkgconfig "github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/model"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

Expand Down Expand Up @@ -230,7 +231,7 @@ func runJmxCommandConsole(config config.Component, cliParams *cliParams, diagnos
// This prevents log-spam from "pkg/workloadmeta/collectors/internal/remote/process_collector/process_collector.go"
// It appears that this collector creates some contention in AD.
// Disabling it is both more efficient and gets rid of this log spam
pkgconfig.Datadog.Set("language_detection.enabled", "false")
pkgconfig.Datadog.Set("language_detection.enabled", "false", model.SourceAgentRuntime)

err := pkgconfig.SetupJMXLogger(cliParams.logFile, "", false, true, false)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import (
"fmt"
"time"

pkgsettings "github.com/DataDog/datadog-agent/pkg/config/settings"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/model"
)

// DsdCaptureDurationRuntimeSetting wraps operations to change the duration, in seconds, of traffic captures
type DsdCaptureDurationRuntimeSetting struct {
value string
source pkgsettings.Source
value string
}

func NewDsdCaptureDurationRuntimeSetting(value string) *DsdCaptureDurationRuntimeSetting {
return &DsdCaptureDurationRuntimeSetting{
value: value,
source: pkgsettings.SourceDefault,
value: value,
}
}

Expand All @@ -47,7 +46,7 @@ func (l *DsdCaptureDurationRuntimeSetting) Get() (interface{}, error) {
}

// Set changes the value of the runtime setting
func (l *DsdCaptureDurationRuntimeSetting) Set(v interface{}, source pkgsettings.Source) error {
func (l *DsdCaptureDurationRuntimeSetting) Set(v interface{}, source model.Source) error {
var err error

s, ok := v.(string)
Expand All @@ -62,10 +61,6 @@ func (l *DsdCaptureDurationRuntimeSetting) Set(v interface{}, source pkgsettings

// TODO
// common.DSD.Capture.SetDuration(d)
l.source = source
config.Datadog.Set(l.value, s, source)
return nil
}

func (l *DsdCaptureDurationRuntimeSetting) GetSource() pkgsettings.Source {
return l.source
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import (

dogstatsddebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/model"
"github.com/DataDog/datadog-agent/pkg/config/settings"
)

// DsdStatsRuntimeSetting wraps operations to change the collection of dogstatsd stats at runtime.
type DsdStatsRuntimeSetting struct {
ServerDebug dogstatsddebug.Component
source settings.Source
}

// NewDsdStatsRuntimeSetting creates a new instance of DsdStatsRuntimeSetting
func NewDsdStatsRuntimeSetting(serverDebug dogstatsddebug.Component) *DsdStatsRuntimeSetting {
return &DsdStatsRuntimeSetting{
ServerDebug: serverDebug,
source: settings.SourceDefault,
}
}

Expand All @@ -48,7 +47,7 @@ func (s *DsdStatsRuntimeSetting) Get() (interface{}, error) {
}

// Set changes the value of the runtime setting
func (s *DsdStatsRuntimeSetting) Set(v interface{}, source settings.Source) error {
func (s *DsdStatsRuntimeSetting) Set(v interface{}, source model.Source) error {
var newValue bool
var err error

Expand All @@ -58,11 +57,6 @@ func (s *DsdStatsRuntimeSetting) Set(v interface{}, source settings.Source) erro

s.ServerDebug.SetMetricStatsEnabled(newValue)

config.Datadog.Set("dogstatsd_metrics_stats_enable", newValue)
s.source = source
config.Datadog.Set("dogstatsd_metrics_stats_enable", newValue, source)
return nil
}

func (s *DsdStatsRuntimeSetting) GetSource() settings.Source {
return s.source
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"go.uber.org/fx"

"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/config/settings"
"github.com/DataDog/datadog-agent/pkg/config/model"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
)

Expand Down Expand Up @@ -62,7 +62,7 @@ func TestDogstatsdMetricsStats(t *testing.T) {

// true string

err = s.Set("true", settings.SourceDefault)
err = s.Set("true", model.SourceDefault)
assert.Nil(err)
assert.Equal(deps.Debug.IsDebugEnabled(), true)
v, err := s.Get()
Expand All @@ -71,7 +71,7 @@ func TestDogstatsdMetricsStats(t *testing.T) {

// false string

err = s.Set("false", settings.SourceDefault)
err = s.Set("false", model.SourceDefault)
assert.Nil(err)
assert.Equal(deps.Debug.IsDebugEnabled(), false)
v, err = s.Get()
Expand All @@ -80,7 +80,7 @@ func TestDogstatsdMetricsStats(t *testing.T) {

// true boolean

err = s.Set(true, settings.SourceDefault)
err = s.Set(true, model.SourceDefault)
assert.Nil(err)
assert.Equal(deps.Debug.IsDebugEnabled(), true)
v, err = s.Get()
Expand All @@ -89,7 +89,7 @@ func TestDogstatsdMetricsStats(t *testing.T) {

// false boolean

err = s.Set(false, settings.SourceDefault)
err = s.Set(false, model.SourceDefault)
assert.Nil(err)
assert.Equal(deps.Debug.IsDebugEnabled(), false)
v, err = s.Get()
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster-agent/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func TestValidateTokenMiddleware(t *testing.T) {
mockConfig := config.Mock(t)
mockConfig.Set("cluster_agent.auth_token", "abc123")
mockConfig.SetWithoutSource("cluster_agent.auth_token", "abc123")
util.InitDCAAuthToken()

tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/process-agent/subcommands/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestStatus(t *testing.T) {
func TestNotRunning(t *testing.T) {
// Use different ports in case the host is running a real agent
cfg := config.Mock(t)
cfg.Set("process_config.cmd_port", 8082)
cfg.SetWithoutSource("process_config.cmd_port", 8082)

addressPort, err := config.GetProcessAPIAddressPort()
require.NoError(t, err)
Expand All @@ -87,7 +87,7 @@ func TestNotRunning(t *testing.T) {
// a connection error
func TestError(t *testing.T) {
cfg := config.Mock(t)
cfg.Set("ipc_address", "8.8.8.8") // Non-local ip address will cause error in `GetIPCAddress`
cfg.SetWithoutSource("ipc_address", "8.8.8.8") // Non-local ip address will cause error in `GetIPCAddress`
_, ipcError := config.GetIPCAddress()

var errText, expectedErrText strings.Builder
Expand Down
3 changes: 2 additions & 1 deletion cmd/security-agent/subcommands/start/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder"
"github.com/DataDog/datadog-agent/pkg/aggregator"
pkgconfig "github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/model"
"github.com/DataDog/datadog-agent/pkg/config/settings"
"github.com/DataDog/datadog-agent/pkg/pidfile"
"github.com/DataDog/datadog-agent/pkg/security/utils"
Expand Down Expand Up @@ -198,7 +199,7 @@ func RunAgent(ctx context.Context, log log.Component, config config.Component, s

// Setup expvar server
port := config.GetString("security_agent.expvar_port")
pkgconfig.Datadog.Set("expvar_port", port)
pkgconfig.Datadog.Set("expvar_port", port, model.SourceAgentRuntime)
if config.GetBool("telemetry.enabled") {
http.Handle("/telemetry", telemetry.Handler())
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/serverless-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/DataDog/datadog-agent/cmd/serverless-init/tag"
logsAgent "github.com/DataDog/datadog-agent/comp/logs/agent"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/model"
configUtils "github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/datadog-agent/pkg/serverless/metrics"
"github.com/DataDog/datadog-agent/pkg/serverless/otlp"
Expand Down Expand Up @@ -112,7 +113,7 @@ func setupTraceAgent(traceAgent *trace.ServerlessTraceAgent, tags map[string]str
}

func setupMetricAgent(tags map[string]string) *metrics.ServerlessMetricAgent {
config.Datadog.Set("use_v2_api.series", false)
config.Datadog.Set("use_v2_api.series", false, model.SourceAgentRuntime)
metricAgent := &metrics.ServerlessMetricAgent{
SketchesBucketOffset: time.Second * 0,
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

logConfig "github.com/DataDog/datadog-agent/comp/logs/agent/config"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/model"
configUtils "github.com/DataDog/datadog-agent/pkg/config/utils"
pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
"github.com/DataDog/datadog-agent/pkg/serverless"
Expand Down Expand Up @@ -70,7 +71,7 @@ const (

func main() {
flavor.SetFlavor(flavor.ServerlessAgent)
config.Datadog.Set("use_v2_api.series", false)
config.Datadog.Set("use_v2_api.series", false, model.SourceAgentRuntime)
stopCh := make(chan struct{})

// Disable remote configuration for now as it just spams the debug logs
Expand Down
Loading