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

Add option to merge SNMP configs (custom with embedded) #2633

Merged
merged 20 commits into from
Feb 14, 2025

Conversation

v-zhuravlev
Copy link
Contributor

@v-zhuravlev v-zhuravlev commented Feb 6, 2025

PR Description

This PR adds config_merge_strategy in prometheus.exporter.snmp to optionally merge custom snmp config with embedded config instead of replacing. Useful for providing SNMP auths.

Which issue(s) this PR fixes

Fixes #2493

Notes to the Reviewer

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

Copy link
Contributor

github-actions bot commented Feb 6, 2025

💻 Deploy preview deleted.

@v-zhuravlev v-zhuravlev marked this pull request as ready for review February 6, 2025 13:56
@v-zhuravlev v-zhuravlev requested review from clayton-cornell and a team as code owners February 6, 2025 13:56
@v-zhuravlev v-zhuravlev changed the title Add option to merge SNMP configs Add option to merge SNMP configs (custom with embedded) Feb 6, 2025
internal/component/prometheus/exporter/snmp/snmp.go Outdated Show resolved Hide resolved
@@ -218,6 +220,10 @@ func (a *Arguments) UnmarshalAlloy(f func(interface{}) error) error {
return errors.New("config and config_file are mutually exclusive")
}

if a.ConfigMergeStategy != "replace" && a.ConfigMergeStategy != "merge" {
return errors.New("config_merge_strategy must be `replace` or `merge`")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would recommend a switch instead of an if here where the case "replace", "merge" does nothing and the default case returns the error. It avoids repeating the a.ConfigMergeStategy != for every case which makes it scale better with the number of values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

you did not change it to a switch here (if you want to keep it as an if that's also ok for me, just a nit)

@v-zhuravlev v-zhuravlev requested a review from wildum February 7, 2025 10:18
@@ -218,6 +220,10 @@ func (a *Arguments) UnmarshalAlloy(f func(interface{}) error) error {
return errors.New("config and config_file are mutually exclusive")
}

if a.ConfigMergeStategy != "replace" && a.ConfigMergeStategy != "merge" {
return errors.New("config_merge_strategy must be `replace` or `merge`")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you did not change it to a switch here (if you want to keep it as an if that's also ok for me, just a nit)

@wildum
Copy link
Contributor

wildum commented Feb 7, 2025

@clayton-cornell over to you for a review of the small doc changes

Copy link
Contributor

@clayton-cornell clayton-cornell left a comment

Choose a reason for hiding this comment

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

Minor doc tweak

@clayton-cornell clayton-cornell added the type/docs Docs Squad label across all Grafana Labs repos label Feb 14, 2025
@v-zhuravlev
Copy link
Contributor Author

thanks fro the reviews! Anything else we need to merge it?

@wildum wildum merged commit 4d6e96f into main Feb 14, 2025
33 checks passed
@wildum wildum deleted the vzhuravlev/multiple-configs branch February 14, 2025 14:52
@wildum
Copy link
Contributor

wildum commented Feb 14, 2025

sorry I thought I merged it already, merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/docs Docs Squad label across all Grafana Labs repos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support defining snmp authentification params without overriding whole snmp.yml config.
3 participants