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

feat(cli): add grouping verification to routing test command #4208

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

heartwilltell
Copy link

@heartwilltell heartwilltell commented Jan 16, 2025

Closes: #3003

Add grouping verification to amtool config routes test

This PR adds the ability to verify alert grouping configuration when testing routes with amtool. The new functionality helps users ensure that alerts are not only routed to the correct receivers but are also grouped as expected.

Changes

Added a new flag --verify.receivers-grouping to amtool config routes test that allows users to specify both receivers and their expected grouping labels. The flag supports:

  1. Simple receiver verification (backward compatible):

amtool config routes test --verify.receivers-grouping="team-A-opsgenie,team-B-opsgenie"

  1. Receiver with grouping verification:

amtool config routes test --verify.receivers-grouping="team-A-opsgenie[cluster,severity]"

  1. Multiple grouping configurations for the same receiver:

amtool config routes test --verify.receivers-grouping="team-A-opsgenie[cluster,severity],team-A-opsgenie[cluster,severity,alertname]"

Example Usage

Test routing and grouping

amtool config routes test --config.file=alertmanager.yaml \ --verify.receivers-grouping="wire-team-opsgenie[env,cluster,priority]" \ team=wire

Output shows both the receiver and its grouping

wire-team-opsgenie[env,cluster,priority]

@heartwilltell heartwilltell force-pushed the alert-grouping-test branch 14 times, most recently from 1a4eb95 to a6fabf5 Compare January 20, 2025 22:29
@heartwilltell heartwilltell force-pushed the alert-grouping-test branch 3 times, most recently from 37ca328 to 2b33bb7 Compare January 28, 2025 13:49
SuperQ and others added 12 commits January 28, 2025 14:50
* [CHANGE] Templating errors in the SNS integration now return an error. prometheus#3531 prometheus#3879
* [CHANGE] Adopt log/slog, drop go-kit/log prometheus#4089
* [FEATURE] Add a new Microsoft Teams integration based on Flows prometheus#4024
* [FEATURE] Add a new Rocket.Chat integration prometheus#3600
* [FEATURE] Add a new Jira integration prometheus#3590 prometheus#3931
* [FEATURE] Add support for `GOMEMLIMIT`, enable it via the feature flag `--enable-feature=auto-gomemlimit`. prometheus#3895
* [FEATURE] Add support for `GOMAXPROCS`, enable it via the feature flag `--enable-feature=auto-gomaxprocs`. prometheus#3837
* [FEATURE] Add support for limits of silences including the maximum number of active and pending silences, and the maximum size per silence (in bytes). You can use the flags `--silences.max-silences` and `--silences.max-silence-size-bytes` to set them accordingly prometheus#3852 prometheus#3862 prometheus#3866 prometheus#3885 prometheus#3886 prometheus#3877
* [FEATURE] Muted alerts now show whether they are suppressed or not in both the `/api/v2/alerts` endpoint and the Alertmanager UI. prometheus#3793 prometheus#3797 prometheus#3792
* [ENHANCEMENT] Add support for `content`, `username` and `avatar_url` in the Discord integration. `content` and `username` also support templating. prometheus#4007
* [ENHANCEMENT] Only invalidate the silences cache if a new silence is created or an existing silence replaced - should improve latency on both `GET api/v2/alerts` and `POST api/v2/alerts` API endpoint. prometheus#3961
* [ENHANCEMENT] Add image source label to Dockerfile. To get changelogs shown when using Renovate prometheus#4062
* [ENHANCEMENT] Build using go 1.23 prometheus#4071
* [ENHANCEMENT] Support setting a global SMTP TLS configuration. prometheus#3732
* [ENHANCEMENT] The setting `room_id` in the WebEx integration can now be templated to allow for dynamic room IDs. prometheus#3801
* [ENHANCEMENT] Enable setting `message_thread_id` for the Telegram integration. prometheus#3638
* [ENHANCEMENT] Support the `since` and `humanizeDuration` functions to templates. This means users can now format time to more human-readable text. prometheus#3863
* [ENHANCEMENT] Support the `date` and `tz` functions to templates. This means users can now format time in a specified format and also change the timezone to their specific locale. prometheus#3812
* [ENHANCEMENT] Latency metrics now support native histograms. prometheus#3737
* [ENHANCEMENT] Add full width to adaptive card for msteamsv2 prometheus#4135
* [ENHANCEMENT] Add timeout option for webhook notifier. prometheus#4137
* [ENHANCEMENT] Update config to allow showing secret values when marshaled prometheus#4158
* [ENHANCEMENT] Enable templating for Jira project and issue_type prometheus#4159
* [BUGFIX] Fix the SMTP integration not correctly closing an SMTP submission, which may lead to unsuccessful dispatches being marked as successful. prometheus#4006
* [BUGFIX]  The `ParseMode` option is now set explicitly in the Telegram integration. If we don't HTML tags had not been parsed by default. prometheus#4027
* [BUGFIX] Fix a memory leak that was caused by updates silences continuously. prometheus#3930
* [BUGFIX] Fix hiding secret URLs when the URL is incorrect. prometheus#3887
* [BUGFIX] Fix a race condition in the alerts - it was more of a hypothetical race condition that could have occurred in the alert reception pipeline. prometheus#3648
* [BUGFIX] Fix a race condition in the alert delivery pipeline that would cause a firing alert that was delivered earlier to be deleted from the aggregation group when instead it should have been delivered again. prometheus#3826
* [BUGFIX] Fix version in APIv1 deprecation notice. prometheus#3815
* [BUGFIX] Fix crash errors when using `url_file` in the Webhook integration. prometheus#3800
* [BUGFIX] fix `Route.ID()` returns conflicting IDs. prometheus#3803
* [BUGFIX] Fix deadlock on the alerts memory store. prometheus#3715
* [BUGFIX] Fix `amtool template render` when using the default values. prometheus#3725
* [BUGFIX] Fix `webhook_url_file` for both the Discord and Microsoft Teams integrations. prometheus#3728 prometheus#3745
* [BUGFIX] Fix wechat api link prometheus#4084
* [BUGFIX] Fix build info metric prometheus#4166
* [BUGFIX] Fix UTF-8 not allowed in Equal field for inhibition rules prometheus#4177

Signed-off-by: SuperQ <[email protected]>
Signed-off-by: heartwilltell <[email protected]>
…0 and use `version.ComponentUserAgent`

Signed-off-by: Matthieu MOREL <[email protected]>
Signed-off-by: heartwilltell <[email protected]>
- Added `expectedReceiversGroup` field to `routingShow` struct for grouping verification.
- Updated command flags to include `--verify.receivers-grouping` for specifying receivers and their groupings.
- Implemented `parseReceiversWithGrouping` function to handle input parsing for receivers with optional groupings.
- Enhanced `routingTestAction` to validate both receivers and their groupings against resolved values.

This update improves the routing test command's ability to verify complex receiver configurations.

Signed-off-by: heartwilltell <[email protected]>
- Enhanced documentation for the receiversGrouping field in the routingShow struct to clarify its purpose.
- No functional changes were made; this update focuses on code readability and maintainability.

Signed-off-by: heartwilltell <[email protected]>
Signed-off-by: heartwilltell <[email protected]>
- Improved the `parseReceiversWithGrouping` function to correctly handle commas within square brackets, allowing for more complex receiver formats.
- Updated the grouping validation logic to ensure proper formatting and trimming of group names.
- Enhanced the `routingTestAction` method to provide clearer warnings when expected and actual receivers do not match, including detailed output of discrepancies.

This update increases the robustness of receiver parsing and validation in the routing test command.

Signed-off-by: heartwilltell <[email protected]>
…racket handling

- Updated the `parseReceiversWithGrouping` function to remove spaces around commas for cleaner input processing.
- Enhanced bracket handling to correctly manage nested groupings, ensuring proper parsing of receiver lists.
- Improved error messaging for invalid grouping formats to provide clearer feedback.

These changes enhance the robustness and usability of the receiver parsing functionality.

Signed-off-by: heartwilltell <[email protected]>
Signed-off-by: heartwilltell <[email protected]>
Signed-off-by: heartwilltell <[email protected]>
- Introduced `removeSpacesAroundCommas` function to streamline input processing by removing unnecessary spaces around commas.
- Improved `parseReceiversWithGrouping` to better handle nested groupings and enhance error messaging for invalid formats.
- Added `sortGroupLabels` function to return sorted group labels for improved consistency in output.
- Updated `verifyReceivers` and `verifyReceiversGrouping` functions to provide clearer error messages when expected and actual receivers do not match.
- Enhanced `formatOutput` to generate a more structured output of receivers and their groupings.

These changes improve the robustness and usability of the receiver parsing and validation functionality in the routing test command.

Signed-off-by: heartwilltell <[email protected]>
…thGrouping`

- Removed redundant variable declarations for `inBrackets` and `bracketCount` by initializing them directly in the variable declaration block.
- Simplified the conditional logic for handling commas outside of brackets, improving code readability and maintainability.

These changes enhance the clarity and efficiency of the receiver parsing functionality.

Signed-off-by: heartwilltell <[email protected]>
…iversGrouping`

- Introduced a new map to store expected groupings for base receivers, improving the logic for matching actual groups against expected ones.
- Simplified the matching process by eliminating unnecessary checks and enhancing error messaging for unmatched groupings.
- Improved clarity of warnings when no matching grouping is found, providing detailed output of expected groups.

These changes enhance the efficiency and readability of the receiver grouping verification process in the routing test command.

Signed-off-by: heartwilltell <[email protected]>
…ReceiversGrouping`

- Updated error messages in `parseLabelSet` to start with a capital letter for consistency.
- Enhanced the warning message in `verifyReceiversGrouping` to format the output more clearly, ensuring better readability of expected groupings when no match is found.

These changes improve the clarity and consistency of error handling in the routing test command.

Signed-off-by: heartwilltell <[email protected]>
…ing`

- Improved the logic for matching actual groupings against expected ones by sorting both expected and actual groups before comparison.
- Added comments for clarity, ensuring that the purpose of each step in the verification process is well-documented.
- This update enhances the accuracy and readability of the receiver grouping verification process in the routing test command.

Signed-off-by: heartwilltell <[email protected]>
- Enhanced `parseReceiversWithGrouping` to handle quoted receivers and nested brackets
- Added support for parsing receivers with quotes and complex grouping structures
- Improved parsing logic to correctly handle commas within quotes and brackets
- Simplified receiver name extraction and trimming

These changes make the receiver parsing more robust and flexible for complex input scenarios.

Signed-off-by: Serhii Mariiekha <[email protected]>
Signed-off-by: heartwilltell <[email protected]>
- Deleted the `removeSpacesAroundCommas` function as it is no longer needed
- Minor comment adjustment in `verifyReceiversGrouping` for consistency

This cleanup removes an unnecessary utility function and maintains code simplicity.

Signed-off-by: heartwilltell <[email protected]>
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.

Alert grouping test with amtool
3 participants