Skip to content
Closed
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
14 changes: 14 additions & 0 deletions ddlambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,17 @@ func setupAppSec() {
}
}
}

// The extension forwards feature flag config requests with the API key it
// resolved (e.g. from DD_API_KEY_SECRET_ARN). Only use it when DD_API_KEY is
// unset: an extension without that route returns 404, and the tracer does not
// fall back to the default endpoint. This runs in init so that it happens
// before main creates a feature flag provider.
func init() { setFeatureFlagsBaseURL(ddExtensionFilePath) }

func setFeatureFlagsBaseURL(extensionPath string) {
const baseURL = "DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL"
if _, err := os.Stat(extensionPath); err == nil && os.Getenv("DD_API_KEY") == "" && os.Getenv(baseURL) == "" {
_ = os.Setenv(baseURL, "http://127.0.0.1:8126")
}
}
30 changes: 30 additions & 0 deletions ddlambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,33 @@ func TestCalculateFipsMode(t *testing.T) {
func boolPtr(b bool) *bool {
return &b
}

func TestSetFeatureFlagsBaseURL(t *testing.T) {
const baseURL = "DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL"
extension := t.TempDir() + "/datadog-agent"
assert.NoError(t, os.WriteFile(extension, nil, 0o600))

tests := []struct {
name string
extension string
env map[string]string
expected string
}{
{"no api key", extension, nil, "http://127.0.0.1:8126"},
{"secret arn only", extension, map[string]string{"DD_API_KEY_SECRET_ARN": "arn"}, "http://127.0.0.1:8126"},
{"api key set", extension, map[string]string{"DD_API_KEY": "key"}, ""},
{"base url set", extension, map[string]string{baseURL: "http://custom"}, "http://custom"},
{"no extension", extension + "-missing", nil, ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("DD_API_KEY", "")
t.Setenv(baseURL, "")
for k, v := range tt.env {
t.Setenv(k, v)
}
setFeatureFlagsBaseURL(tt.extension)
assert.Equal(t, tt.expected, os.Getenv(baseURL))
})
}
}
Loading