-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[procmgr] Config gates for processes.d auto-start #54732
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
Changes from all commits
ad366fa
1be8013
7fa9099
cab3925
68248ee
77dd1d3
5f09b32
23fe8c1
3653da7
c37e26e
87f7761
33081af
bc63e90
478fd15
fe05fbd
5d0282a
0696322
67c4161
28ab29f
5cd9278
3133f49
3675484
3b57713
a0066b5
10e542e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,10 @@ func unsetProxyEnvForTest(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // testFleetPoliciesDir is a fixed path used in YAML round-trip tests so fleet_policies_dir | ||
| // is deterministic across platforms (env is read during InitConfig; FleetConfigOverride skips when set). | ||
| const testFleetPoliciesDir = `C:\testdata\fleet\policies` | ||
|
|
||
| func TestDefaults(t *testing.T) { | ||
| config := newTestConf(t) | ||
|
|
||
|
|
@@ -1394,6 +1398,7 @@ process_config: | |
| `) | ||
|
|
||
| func TestConfigAssignAtPath(t *testing.T) { | ||
| t.Setenv("DD_FLEET_POLICIES_DIR", testFleetPoliciesDir) | ||
|
|
||
| config := newTestConf(t) | ||
| config.SetInTest("use_proxy_for_cloud_metadata", true) | ||
|
|
@@ -1420,6 +1425,7 @@ func TestConfigAssignAtPath(t *testing.T) { | |
| - changed | ||
| https://url2.eu: | ||
| - third | ||
| fleet_policies_dir: C:\testdata\fleet\policies | ||
| process_config: | ||
| additional_endpoints: | ||
| https://url1.com: | ||
|
|
@@ -1485,6 +1491,7 @@ secret_backend_arguments: | |
| `) | ||
|
|
||
| func TestConfigAssignAtPathSimple(t *testing.T) { | ||
| t.Setenv("DD_FLEET_POLICIES_DIR", testFleetPoliciesDir) | ||
|
|
||
| config := newTestConf(t) | ||
| config.SetInTest("use_proxy_for_cloud_metadata", true) | ||
|
|
@@ -1498,7 +1505,8 @@ func TestConfigAssignAtPathSimple(t *testing.T) { | |
| err = configAssignAtPath(config, []string{"secret_backend_arguments", "0"}, "password1") | ||
| assert.NoError(t, err) | ||
|
|
||
| expectedYaml := `secret_backend_arguments: | ||
| expectedYaml := `fleet_policies_dir: C:\testdata\fleet\policies | ||
| secret_backend_arguments: | ||
| - password1 | ||
| secret_backend_command: some command | ||
| use_proxy_for_cloud_metadata: true | ||
|
|
@@ -1510,6 +1518,7 @@ use_proxy_for_cloud_metadata: true | |
| } | ||
|
|
||
| func TestConfigMustMatchOrigin(t *testing.T) { | ||
| t.Setenv("DD_FLEET_POLICIES_DIR", testFleetPoliciesDir) | ||
|
|
||
| testMinimalConf := []byte(`apm_config: | ||
| apm_dd_url: ENC[some_url] | ||
|
|
@@ -1525,13 +1534,20 @@ use_proxy_for_cloud_metadata: true | |
|
|
||
| expectedYaml := `apm_config: | ||
| apm_dd_url: first_value | ||
| fleet_policies_dir: C:\testdata\fleet\policies | ||
| secret_backend_command: command | ||
| use_proxy_for_cloud_metadata: true | ||
| ` | ||
| expectedDiffYaml := `apm_config: | ||
| apm_dd_url: second_value | ||
| secret_backend_command: command | ||
| use_proxy_for_cloud_metadata: true | ||
| ` | ||
| expectedDiffConfigYaml := `apm_config: | ||
| apm_dd_url: second_value | ||
| fleet_policies_dir: C:\testdata\fleet\policies | ||
| secret_backend_command: command | ||
| use_proxy_for_cloud_metadata: true | ||
| ` | ||
|
|
||
| config := newTestConf(t) | ||
|
|
@@ -1573,7 +1589,7 @@ use_proxy_for_cloud_metadata: true | |
| // now the original config was modified because of the origin match | ||
| yamlConf, err = yaml.Marshal(config.AllSettingsWithoutDefault()) | ||
| assert.NoError(t, err) | ||
| assert.YAMLEq(t, expectedDiffYaml, string(yamlConf)) | ||
| assert.YAMLEq(t, expectedDiffConfigYaml, string(yamlConf)) | ||
| } | ||
|
|
||
| func TestConfigAssignAtPathForIntMapKeys(t *testing.T) { | ||
|
|
@@ -1604,9 +1620,15 @@ additional_endpoints: | |
| ) | ||
| } | ||
|
|
||
| func TestServerlessConfigNumComponents(t *testing.T) { | ||
| // Enforce the number of config "components" reachable by the serverless agent | ||
| // to avoid accidentally adding entire components if it's not needed | ||
| require.Len(t, commonConfigComponents, 24) | ||
| } | ||
|
|
||
| func TestServerlessConfigInit(t *testing.T) { | ||
| conf := newEmptyMockConf(t) | ||
| initCommonBase(conf) | ||
| initCommonConfigComponents(conf) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it defined anywhere? |
||
|
|
||
| // ensure some core configs are declared | ||
| assert.True(t, conf.IsKnown("api_key")) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,27 +6,59 @@ | |
| package setup | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
|
|
||
| pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model" | ||
| "github.com/DataDog/datadog-agent/pkg/util/winutil" | ||
| ) | ||
|
|
||
| // FleetConfigOverride sets the fleet_policies_dir config value to the value set in the registry. | ||
| // FleetConfigOverride sets fleet_policies_dir for every Windows agent binary that loads | ||
| // config through pkg/config/setup (registered in fixup_init; system-probe calls it directly). | ||
| // | ||
| // Resolution order (first non-empty wins): datadog.yaml / DD_FLEET_POLICIES_DIR, then the | ||
| // registry experiment path, then defaultStableFleetPoliciesDir. Mirrors dd-procmgr config | ||
| // gates in pkg/procmgr/rust/src/config_gate.rs. | ||
| // | ||
| // The stable ProgramData fallback is intentional global parity with procmgr-managed children | ||
| // (process-agent, PAR, DDOT): they no longer carry DD_FLEET_POLICIES_DIR in processes.d, so | ||
| // all Windows binaries must resolve the same managed policy directory without per-service env. | ||
| // | ||
| // This value tells the agent to load a config experiment from Fleet Automation. | ||
| // Standalone installs are unaffected: comp/core/config and system-probe call MergeFleetPolicy | ||
| // only after fleet_policies_dir is set, and MergeFleetPolicy no-ops when the policy YAML file | ||
| // is absent (pkg/config/nodetreemodel/config.go). On fleet-managed hosts between experiments | ||
| // (registry empty, stable managed datadog.yaml present), the stable layer now merges as | ||
| // SourceFleetPolicies — previously nothing merged in that window. | ||
| // | ||
| // Linux sets this option with an environment variable in the experiment's systemd unit file, | ||
| // so we need a different approach for Windows. After the viper migration is complete, we can | ||
| // consider replacing this override with a Windows Registry config source. | ||
| // Linux sets fleet_policies_dir via environment in experiment systemd units; after the viper | ||
| // migration we may replace this override with a Windows registry config source. | ||
| func FleetConfigOverride(config pkgconfigmodel.Config) { | ||
| // Prioritize the value set in the config file / env var | ||
| if config.IsConfigured("fleet_policies_dir") { | ||
| return | ||
| } | ||
|
|
||
| val := winutil.ReadFleetPoliciesDirFromRegistry() | ||
| if val == "" { | ||
| val = defaultStableFleetPoliciesDir() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So |
||
| } | ||
| if val == "" { | ||
| return | ||
| } | ||
|
|
||
| config.Set("fleet_policies_dir", val, pkgconfigmodel.SourceAgentRuntime) | ||
| } | ||
|
|
||
| // defaultStableFleetPoliciesDir returns the stable managed fleet policies directory under | ||
| // ProgramData. Matches pkg/fleet/installer/paths.FleetPoliciesDirForManagedProcess without | ||
| // importing fleet/installer (circular dependency with config/setup). | ||
| // | ||
| // Used as the global FleetConfigOverride fallback, not only for dd-procmgr: every Windows | ||
| // binary that merges fleet policy YAML must find the same stable directory when the registry | ||
| // experiment path is unset. | ||
| func defaultStableFleetPoliciesDir() string { | ||
| dataDir, err := winutil.GetProgramDataDirForProduct("Datadog Agent") | ||
| if err != nil || dataDir == "" { | ||
| return "" | ||
| } | ||
| return filepath.Join(dataDir, "Installer", "managed", "datadog-agent", "stable") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // 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. | ||
|
|
||
| //go:build windows && test | ||
|
|
||
| package setup | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| const expectedStableFleetPoliciesRel = "datadog-agent/stable" | ||
|
|
||
| func TestFleetConfigOverride_FallsBackToStableFleetPoliciesDirWhenUnset(t *testing.T) { | ||
| t.Setenv("DD_FLEET_POLICIES_DIR", "") | ||
|
|
||
| config := newTestConf(t) | ||
| FleetConfigOverride(config) | ||
|
|
||
| dir := config.GetString("fleet_policies_dir") | ||
| assert.NotEmpty(t, dir) | ||
| normalized := filepath.ToSlash(filepath.Clean(dir)) | ||
| assert.True(t, strings.HasSuffix(normalized, expectedStableFleetPoliciesRel), normalized) | ||
| } | ||
|
|
||
| func TestFleetConfigOverride_RespectsEnvOverride(t *testing.T) { | ||
| const customDir = `C:\custom\fleet\policies` | ||
| t.Setenv("DD_FLEET_POLICIES_DIR", customDir) | ||
|
|
||
| config := newTestConf(t) | ||
| FleetConfigOverride(config) | ||
|
|
||
| assert.Equal(t, customDir, config.GetString("fleet_policies_dir")) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
commonConfigComponentsdefined?