@@ -73,84 +73,26 @@ func TestBuildPreflightConfigCarriesOperatorSettings(t *testing.T) {
7373 requireEq (t , got , "proxy.https" , "http://proxy.internal:3128" )
7474}
7575
76- // TestBuildPreflightConfigCarriesOnlyOperatorSettings documents the choice to base the preflight
77- // config on AllSettingsWithoutDefault: everything the operator configured, and nothing they did
78- // not .
76+ // TestBuildPreflightConfigCarriesTheWholeAgentConfig documents the deliberate choice to base
77+ // the preflight config on AllSettings, defaults included, rather than only the settings the
78+ // operator touched .
7979//
80- // The point of the pre-flight is for ADP to see the configuration it would really run with, and a
81- // normally-supervised ADP is started with `--config /etc/datadog-agent/datadog.yaml` -- the
82- // operator's settings, with ADP's own defaults underneath. Passing the Agent's defaults instead
83- // would be a different configuration, not a more faithful one, and for dd_url it was an actively
84- // wrong one (see TestBuildPreflightConfigDropsUnsetDDURL).
85- //
86- // Passing the operator's settings through wholesale is safe because ADP ignores keys it does not
87- // recognise: verified against agent-data-plane 1.4.0 by running it with the full Core Agent
88- // config, including Core-Agent-only sections, with no resulting warning or error (see
89- // TestBuildPreflightConfigPassesThroughCoreAgentOnlySettings).
90- func TestBuildPreflightConfigCarriesOnlyOperatorSettings (t * testing.T ) {
91- cfg := configmock .New (t )
92- cfg .Set ("forwarder_timeout" , 42 , pkgconfigmodel .SourceFile )
93-
94- got := buildPreflightConfig (cfg , newListener (t .TempDir ()))
95-
96- // A setting the operator tuned reaches ADP, so it forwards the way the Agent would.
97- requireEq (t , got , "forwarder_timeout" , 42 )
98-
99- // One they never touched does not, so ADP applies its own default rather than the Agent's.
100- _ , present := get (t , got , "logs_config" )
101- assert .False (t , present , "a section the operator never configured should not reach ADP" )
102- }
103-
104- // TestBuildPreflightConfigCarriesEnvSourcedSettings is the case that matters most in a container,
105- // where the operator configures the Agent entirely through DD_ variables and datadog.yaml is
106- // close to empty.
107- //
108- // It is load-bearing for the pre-flight specifically: childEnv strips the whole DD_ namespace from
109- // the preflight process, so the generated file is the only channel these settings have. A dump
110- // that dropped them would leave ADP with no api_key and no site at all.
111- func TestBuildPreflightConfigCarriesEnvSourcedSettings (t * testing.T ) {
112- t .Setenv ("DD_API_KEY" , "0123456789abcdef0123456789abcdef" )
113- t .Setenv ("DD_SITE" , "datad0g.com" )
114-
115- cfg := configmock .New (t )
116- // The Agent resolves DD_PROXY_* into the config at startup rather than leaving it on the env
117- // layer, writing it back as config-post-init; mirror that here so the dump under test is the
118- // one the real preflight sees.
119- cfg .Set ("proxy.https" , "http://proxy.internal:3128" , pkgconfigmodel .SourceConfigPostInit )
120-
121- got := buildPreflightConfig (cfg , newListener (t .TempDir ()))
122-
123- requireEq (t , got , "api_key" , "0123456789abcdef0123456789abcdef" )
124- requireEq (t , got , "site" , "datad0g.com" )
125- requireEq (t , got , "proxy.https" , "http://proxy.internal:3128" )
126- }
127-
128- // TestBuildPreflightConfigDropsUnsetDDURL is the regression this policy exists for.
129- //
130- // dd_url's default is a non-empty https://app.datadoghq.com, and an explicit dd_url beats `site`
131- // in ADP just as it does in the Core Agent. Rendered as a default by AllSettings, it pointed the
132- // pre-flight -- metrics and API key both -- at US1 regardless of the configured site.
133- func TestBuildPreflightConfigDropsUnsetDDURL (t * testing.T ) {
134- cfg := configmock .New (t )
135- cfg .Set ("site" , "datad0g.com" , pkgconfigmodel .SourceFile )
136-
137- got := buildPreflightConfig (cfg , newListener (t .TempDir ()))
138-
139- _ , present := get (t , got , "dd_url" )
140- assert .False (t , present , "an unset dd_url must not reach ADP as though it were configured" )
141- requireEq (t , got , "site" , "datad0g.com" )
142- }
143-
144- // TestBuildPreflightConfigKeepsConfiguredDDURL is the other half: a dd_url the operator really set
145- // is part of the configuration ADP is meant to run against, and must survive.
146- func TestBuildPreflightConfigKeepsConfiguredDDURL (t * testing.T ) {
80+ // The point of the pre-flight is for ADP to see the configuration it would really run with,
81+ // and passing everything through is the closest approximation. It is safe because ADP
82+ // ignores keys it does not recognise: verified against agent-data-plane 1.4.0 by running it
83+ // with the full Core Agent config, including Core-Agent-only sections, with no resulting
84+ // warning or error (see TestBuildPreflightConfigPassesThroughCoreAgentOnlySettings).
85+ func TestBuildPreflightConfigCarriesTheWholeAgentConfig (t * testing.T ) {
14786 cfg := configmock .New (t )
148- cfg .Set ("site" , "datad0g.com" , pkgconfigmodel .SourceFile )
149- cfg .Set ("dd_url" , "https://app.datad0g.com" , pkgconfigmodel .SourceFile )
15087
15188 got := buildPreflightConfig (cfg , newListener (t .TempDir ()))
15289
153- requireEq (t , got , "dd_url" , "https://app.datad0g.com" )
90+ // Defaults ADP shares with the Agent come through, so it forwards the way the Agent
91+ // would.
92+ _ , present := get (t , got , "forwarder_timeout" )
93+ assert .True (t , present , "the Agent's forwarder settings should reach ADP" )
94+ _ , present = get (t , got , "site" )
95+ assert .True (t , present , "the Agent's site should reach ADP" )
15496}
15597
15698func TestBuildPreflightConfigOverrides (t * testing.T ) {
0 commit comments