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
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0bc0c15
Release v0.28.0
SuperQ Dec 19, 2024
c21f7af
chore(deps): bump `github.com/prometheus/common` from 0.60.0 to 0.61.…
mmorel-35 Dec 5, 2024
e6e2283
feat(cli): add grouping verification to routing test command
heartwilltell Jan 16, 2025
6967cff
Rename groupingStr to groupingSlug
heartwilltell Jan 16, 2025
5c21da0
feat(cli): enhance routing test command with receiver grouping support
heartwilltell Jan 16, 2025
ca1b190
refactor(cli): improve comments in routingShow struct
heartwilltell Jan 16, 2025
41ef883
syntax fixes
heartwilltell Jan 16, 2025
988ee8b
feat(cli): enhance receiver parsing to support nested groupings
heartwilltell Jan 17, 2025
cc94e98
fix(cli): improve receiver parsing by trimming spaces and enhancing b…
heartwilltell Jan 20, 2025
eb735b4
Syntax fixes.
heartwilltell Jan 20, 2025
9eaeae8
Syntax fixes.
heartwilltell Jan 20, 2025
7fb1e0d
refactor(cli): enhance receiver parsing and validation
heartwilltell Jan 20, 2025
2fd5775
refactor(cli): streamline receiver parsing logic in `parseReceiversWi…
heartwilltell Jan 20, 2025
ff493d4
refactor(cli): optimize receiver grouping verification in `verifyRece…
heartwilltell Jan 20, 2025
ebd7b55
refactor(cli): improve error messaging in `parseLabelSet` and `verify…
heartwilltell Jan 20, 2025
6f1a243
refactor(cli): enhance grouping verification in `verifyReceiversGroup…
heartwilltell Jan 20, 2025
ebd1492
feat(cli): improve receiver parsing with quote and bracket handling
heartwilltell Jan 28, 2025
061d593
refactor(cli): remove unused `removeSpacesAroundCommas` function
heartwilltell Jan 28, 2025
77c7531
Merge branch 'main' into alert-grouping-test
heartwilltell Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(cli): improve receiver parsing by trimming spaces and enhancing b…
…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 <heartwilltell@gmail.com>
heartwilltell committed Jan 28, 2025
commit cc94e98cf2d73ddc352f67d4ad4353046fb38bd3
18 changes: 14 additions & 4 deletions cli/test_routing.go
Original file line number Diff line number Diff line change
@@ -75,6 +75,11 @@ func printMatchingTree(mainRoute *dispatch.Route, ls models.LabelSet) {

func parseReceiversWithGrouping(input string) (map[string][]string, error) {
result := make(map[string][][]string) // maps receiver to list of possible groupings

// Remove spaces around commas
input = strings.ReplaceAll(input, " ,", ",")
input = strings.ReplaceAll(input, ", ", ",")

// If no square brackets in input, treat it as simple receiver list
if !strings.Contains(input, "[") {
receivers := strings.Split(input, ",")
@@ -91,26 +96,31 @@ func parseReceiversWithGrouping(input string) (map[string][]string, error) {
var receivers []string
var currentReceiver strings.Builder
inBrackets := false
bracketCount := 0

for i := 0; i < len(input); i++ {
char := input[i]
if char == '[' {
inBrackets = true
bracketCount++
} else if char == ']' {
inBrackets = false
bracketCount--
if bracketCount == 0 {
inBrackets = false
}
}

if char == ',' && !inBrackets {
if currentReceiver.Len() > 0 {
receivers = append(receivers, currentReceiver.String())
receivers = append(receivers, strings.TrimSpace(currentReceiver.String()))
currentReceiver.Reset()
}
} else {
currentReceiver.WriteByte(char)
}
}
if currentReceiver.Len() > 0 {
receivers = append(receivers, currentReceiver.String())
receivers = append(receivers, strings.TrimSpace(currentReceiver.String()))
}

for _, r := range receivers {
@@ -133,7 +143,7 @@ func parseReceiversWithGrouping(input string) (map[string][]string, error) {

groupingPart := r[bracketIndex:]
if !strings.HasPrefix(groupingPart, "[") || !strings.HasSuffix(groupingPart, "]") {
return nil, fmt.Errorf("invalid grouping format in: %s", r)
return nil, fmt.Errorf("missing closing bracket in: %s", r)
}

grouping := strings.TrimSuffix(strings.TrimPrefix(groupingPart, "["), "]")