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

fix: correctly handle viper env var overrides for slice fields #143

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

obs-gh-mattcotter
Copy link
Collaborator

@obs-gh-mattcotter obs-gh-mattcotter commented Dec 11, 2024

Description

OB-40043: Correctly handle viper env var overrides for slice fields. We need this to specify host log overrides via env vars. This example works now but errored prior to this change:

$ env HOST_MONITORING::LOGS::INCLUDE='/test/file.txt,/file.log' ./observe-agent config
# ======== computed agent config
cloud_resource_detectors:
    - ec2
self_monitoring:
    enabled: true
host_monitoring:
    enabled: true
    logs:
        enabled: true
        include:
            - /test/file.txt
            - /file.log
    metrics:
        host:
            enabled: true

Checklist

  • Created tests which fail without the change (if possible)
  • Extended the README / documentation, if necessary

}

type HostMonitoringMetricsConfig struct {
Host HostMonitoringHostMetricsConfig `yaml:"host,omitempty"`
Process HostMonitoringProcessMetricsConfig `yaml:"process,omitempty"`
Host HostMonitoringHostMetricsConfig `yaml:"host,omitempty" mapstructure:"host"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does the mapstructure flag do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This tag is what viper checks for serialization. I found it through googling the exact problem we were hitting. We couldn't do direct viper (de)serialization without it because it would expect keys matching the variable name by default, which is why I did the yaml workaround that ultimately failed.

@obs-gh-mattcotter obs-gh-mattcotter merged commit 780ec50 into main Dec 17, 2024
8 checks passed
@obs-gh-mattcotter obs-gh-mattcotter deleted the mc/viper-str-slice-fix branch December 17, 2024 16:27
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