Skip to content

fix: add defaults for agent config to fully support nested env var overriders #188

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

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

obs-gh-mattcotter
Copy link
Collaborator

Description

Add viper defaults for all agent config settings. Without this, nested env vars will be ignored unless the value is already set in the config. ex: env HOST_MONITORING::ENABLED=true ./observe-agent start will be ignored with an empty agent config.

Copy link

@orca-security-us orca-security-us bot left a comment

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

if err != nil {
panic(err)
}
var recursiveDfs func(prefix string, defaults map[string]any)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not just recursiveDfs := func(?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to declare it first since it's recursive, otherwise I can't reference it in the function body.

@@ -53,6 +54,11 @@ func InitConfig() {
}

viper.AutomaticEnv() // read in environment variables that match
// TODO add this into our next major release to improve our env var naming.
// viper.SetEnvKeyReplacer(strings.NewReplacer(`::`, `_`))
Copy link
Collaborator

Choose a reason for hiding this comment

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

we use _ in the actual field names as well, would this work with that? that's why we switched to :: to begin with

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, if the :: was to avoid ambiguity, then I will just delete this comment. I think that _ is easier to use (ie HOST_MONITORING_ENABLED=true observe-agent start vs env HOST_MONITORING::ENABLED=true observe-agent start), but if this was an intentional choice for clarity then let's keep it.

@obs-gh-mattcotter obs-gh-mattcotter merged commit 0cb5550 into main Apr 22, 2025
12 checks passed
@obs-gh-mattcotter obs-gh-mattcotter deleted the mc/config-defaults branch April 22, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants