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 17 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 9 times, most recently from 001fe91 to a0a4de8 Compare January 20, 2025 15:42
mmorel-35 and others added 11 commits January 20, 2025 16:42
…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]>
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
2 participants