Skip to content

Alertmanager configuration validate-only mode #3437 #3440

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 14 commits into from
Nov 17, 2022

Conversation

dannystaple
Copy link
Contributor

What this PR does

This introduces an additional flag for mimirtool alertmanager load to validate configuration only, without proceeding to upload it to server. This can be used to validate configuration, for example in PR CI pipelines before attempting to merge and deploy.

Which issue(s) this PR fixes or relates to

Fixes #3437

Checklist

  • Tests updated - no tests exist for mimirtool alertmanager load
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@dannystaple dannystaple requested review from a team as code owners November 11, 2022 16:57
@CLAassistant
Copy link

CLAassistant commented Nov 11, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@osg-grafana osg-grafana left a comment

Choose a reason for hiding this comment

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

A nit

…ger.md

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>
@Logiraptor
Copy link
Contributor

I liked the suggestion you had in the issue about mimirtool alertmanager verify (or maybe mimirtool alertmanager validate. Is there a reason that isn't an option? I think it would be preferable to have an explicit command to avoid the need to specify address and tenant when it's not used. What do you think?

@dannystaple
Copy link
Contributor Author

I liked the suggestion you had in the issue about mimirtool alertmanager verify (or maybe mimirtool alertmanager validate. Is there a reason that isn't an option? I think it would be preferable to have an explicit command to avoid the need to specify address and tenant when it's not used. What do you think?

Let me take a look at that. Certainly sounds reasonable as the id/address is a little ugly.

@dannystaple
Copy link
Contributor Author

Ok - committed mimirtool alertmanager verify.

Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Good job! I left few minor comments before merging. Thanks!

CHANGELOG.md Outdated
@@ -97,6 +97,7 @@

### Mimirtool

* [ENHANCEMENT] Added `mimirtool alertmanager verify` command to validate configuration without uploading. #3247
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] I think you can proudly call it a new feature ;) We're also used to reference the PR number, so #3440 in this case.

Suggested change
* [ENHANCEMENT] Added `mimirtool alertmanager verify` command to validate configuration without uploading. #3247
* [FEATURE] Added `mimirtool alertmanager verify` command to validate configuration without uploading. #3440

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. :)

@@ -92,6 +92,14 @@ mimirtool alertmanager load <config_file>
mimirtool alertmanager load <config_file> <template_files>...
```

### Validate Alertmanager configuration
Copy link
Collaborator

Choose a reason for hiding this comment

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

The ##### Example below is related to "Load Alertmanager configuration". I think you should:

  1. Move ### Validate Alertmanager configuration after the example below (right before #### Delete Alertmanager configuration)
  2. Change ### Validate Alertmanager configuration to #### Validate Alertmanager configuration (4 hashes) to keep formatting consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. Done.

Comment on lines 73 to 74
getAlertsCmd.Flag("address", "Address of the Grafana Mimir cluster; alternatively, set "+envVars.Address+".").Envar(envVars.Address).Required().StringVar(&a.ClientConfig.Address)
getAlertsCmd.Flag("id", "Grafana Mimir tenant ID; alternatively, set "+envVars.TenantID+".").Envar(envVars.TenantID).Required().StringVar(&a.ClientConfig.ID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] Since there's a bit of repetition here between getAlertsCmd, deleteCmd and loadalertCmd, what if we register these flags in a for loop, something like (pseudocode):

for _, cmd := range []*kingpin.CmdClause{getAlertsCmd, deleteCmd, loadalertCmd } {
   cmd.Flag("address", ...)
   cmd.Flag("id", ...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that - more DRY. Done.

@@ -104,27 +113,39 @@ func (a *AlertmanagerCommand) getConfig(k *kingpin.ParseContext) error {
return p.PrintAlertmanagerConfig(cfg, templates)
}

func (a *AlertmanagerCommand) loadConfig(k *kingpin.ParseContext) error {
func (a *AlertmanagerCommand) prepareAlertManagerConfig(k *kingpin.ParseContext) (error, string, map[string]string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] WDYT about calling it "read"? We're basically reading it from file.

Suggested change
func (a *AlertmanagerCommand) prepareAlertManagerConfig(k *kingpin.ParseContext) (error, string, map[string]string) {
func (a *AlertmanagerCommand) readAlertmanagerConfigFromFile(k *kingpin.ParseContext) (error, string, map[string]string) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. And done.

Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM (modulo a nit). Thanks!

cmd.Flag("id", "Grafana Mimir tenant ID; alternatively, set "+envVars.TenantID+".").Envar(envVars.TenantID).Required().StringVar(&a.ClientConfig.ID)
}

vertifyalertCmd := alertCmd.Command("verify", "Verify Alertmanager tenant configuration and template files.").Action(a.verifyAlertmanagerConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] Doh, there's a small typo here:

Suggested change
vertifyalertCmd := alertCmd.Command("verify", "Verify Alertmanager tenant configuration and template files.").Action(a.verifyAlertmanagerConfig)
verifyalertCmd := alertCmd.Command("verify", "Verify Alertmanager tenant configuration and template files.").Action(a.verifyAlertmanagerConfig)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok - fixed.

@pracucci pracucci enabled auto-merge (squash) November 17, 2022 13:28
auto-merge was automatically disabled November 17, 2022 14:02

Head branch was pushed to by a user without write access

@pracucci pracucci enabled auto-merge (squash) November 17, 2022 14:10
@pracucci pracucci merged commit cba8c18 into grafana:main Nov 17, 2022
@dannystaple dannystaple deleted the 3437-alertmanager-config-validation branch November 17, 2022 14:32
manohar-koukuntla added a commit to manohar-koukuntla/mimir that referenced this pull request Nov 17, 2022
Co-authored-by: Marco Pracucci <marco@pracucci.com>

Add scheme to DNS service discovery docs (grafana#3450)

* Add schema to DNS service discovery docs

The missing schema leads to errors like `improperly formatted alertmanager URL "alertmanager.mimir.svc.cluster.local:8080/alertmanager" (maybe the scheme is missing?)`.

* Update docs/sources/operators-guide/configure/about-dns-service-discovery.md

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

Alertmanager configuration validate-only mode grafana#3437 (grafana#3440)

* Alertmanager configuration validate-only mode grafana#3437

* Documentation update for alertmanager config validation

* Update changelog

* Update docs/sources/operators-guide/architecture/components/alertmanager.md

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

* Swap a command line flag for a verify subcommand.

* Update pkg/mimirtool/commands/alerts.go

Co-authored-by: Marco Pracucci <marco@pracucci.com>

* For loop to reduce repetition

* Use review suggestion.

* Make alertmanager verification docs more consistent.
Bump from enhancement to feature.

* fmt

* Fix the golint issue.

* Fix typo

* Make doc result (as specified by lint process)

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>

lint fix
pracucci pushed a commit that referenced this pull request Nov 17, 2022
* add runbook urls for alerts

Co-authored-by: Joshua Hesketh <josh@hesketh.net.au>

Update CHANGELOG.md

Co-authored-by: Joshua Hesketh <josh@hesketh.net.au>

* Update CHANGELOG.md

Co-authored-by: Marco Pracucci <marco@pracucci.com>

Add scheme to DNS service discovery docs (#3450)

* Add schema to DNS service discovery docs

The missing schema leads to errors like `improperly formatted alertmanager URL "alertmanager.mimir.svc.cluster.local:8080/alertmanager" (maybe the scheme is missing?)`.

* Update docs/sources/operators-guide/configure/about-dns-service-discovery.md

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

Alertmanager configuration validate-only mode #3437 (#3440)

* Alertmanager configuration validate-only mode #3437

* Documentation update for alertmanager config validation

* Update changelog

* Update docs/sources/operators-guide/architecture/components/alertmanager.md

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

* Swap a command line flag for a verify subcommand.

* Update pkg/mimirtool/commands/alerts.go

Co-authored-by: Marco Pracucci <marco@pracucci.com>

* For loop to reduce repetition

* Use review suggestion.

* Make alertmanager verification docs more consistent.
Bump from enhancement to feature.

* fmt

* Fix the golint issue.

* Fix typo

* Make doc result (as specified by lint process)

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>

lint fix

Co-authored-by: Joshua Hesketh <josh@hesketh.net.au>
masonmei pushed a commit to udmire/mimir that referenced this pull request Dec 16, 2022
)

* Alertmanager configuration validate-only mode grafana#3437

* Documentation update for alertmanager config validation

* Update changelog

* Update docs/sources/operators-guide/architecture/components/alertmanager.md

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

* Swap a command line flag for a verify subcommand.

* Update pkg/mimirtool/commands/alerts.go

Co-authored-by: Marco Pracucci <marco@pracucci.com>

* For loop to reduce repetition

* Use review suggestion.

* Make alertmanager verification docs more consistent.
Bump from enhancement to feature.

* fmt

* Fix the golint issue.

* Fix typo

* Make doc result (as specified by lint process)

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
masonmei pushed a commit to udmire/mimir that referenced this pull request Dec 16, 2022
* add runbook urls for alerts

Co-authored-by: Joshua Hesketh <josh@hesketh.net.au>

Update CHANGELOG.md

Co-authored-by: Joshua Hesketh <josh@hesketh.net.au>

* Update CHANGELOG.md

Co-authored-by: Marco Pracucci <marco@pracucci.com>

Add scheme to DNS service discovery docs (grafana#3450)

* Add schema to DNS service discovery docs

The missing schema leads to errors like `improperly formatted alertmanager URL "alertmanager.mimir.svc.cluster.local:8080/alertmanager" (maybe the scheme is missing?)`.

* Update docs/sources/operators-guide/configure/about-dns-service-discovery.md

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

Co-authored-by: Marco Pracucci <marco@pracucci.com>
Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

Alertmanager configuration validate-only mode grafana#3437 (grafana#3440)

* Alertmanager configuration validate-only mode grafana#3437

* Documentation update for alertmanager config validation

* Update changelog

* Update docs/sources/operators-guide/architecture/components/alertmanager.md

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>

* Swap a command line flag for a verify subcommand.

* Update pkg/mimirtool/commands/alerts.go

Co-authored-by: Marco Pracucci <marco@pracucci.com>

* For loop to reduce repetition

* Use review suggestion.

* Make alertmanager verification docs more consistent.
Bump from enhancement to feature.

* fmt

* Fix the golint issue.

* Fix typo

* Make doc result (as specified by lint process)

Co-authored-by: Ursula Kallio <ursula.kallio@grafana.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>

lint fix

Co-authored-by: Joshua Hesketh <josh@hesketh.net.au>
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.

Feature request: A command line mode be made to validate alertmanager configuration
6 participants