diff --git a/cmd/karma/main.go b/cmd/karma/main.go index 02fe8b4e3..7a82a80a9 100644 --- a/cmd/karma/main.go +++ b/cmd/karma/main.go @@ -25,7 +25,6 @@ import ( "github.com/prymitive/karma/internal/transform" "github.com/prymitive/karma/internal/uri" "github.com/prymitive/karma/ui" - "go.uber.org/automaxprocs/maxprocs" "github.com/getsentry/sentry-go" sentryhttp "github.com/getsentry/sentry-go/http" @@ -37,6 +36,7 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/pflag" + "go.uber.org/automaxprocs/maxprocs" ) var ( diff --git a/cmd/karma/views.go b/cmd/karma/views.go index 6e115898b..8dddd0d7a 100644 --- a/cmd/karma/views.go +++ b/cmd/karma/views.go @@ -417,7 +417,7 @@ func alerts(w http.ResponseWriter, r *http.Request) { ag.LatestStartsAt = ag.FindLatestStartsAt() ag.Hash = ag.ContentFingerprint() apiAG := models.APIAlertGroup{AlertGroup: *ag, TotalAlerts: len(ag.Alerts)} - apiAG.DedupSharedMaps() + apiAG.DedupSharedMaps([]string{gridLabel}) resp.TotalAlerts += len(ag.Alerts) alertLimit, found := request.GroupLimits[ag.ID] diff --git a/internal/models/api.go b/internal/models/api.go index 1feff94f9..8ea07e939 100644 --- a/internal/models/api.go +++ b/internal/models/api.go @@ -146,10 +146,23 @@ func (ag *APIAlertGroup) dedupLabels() { } -func (ag *APIAlertGroup) removeGroupingLabels() { +func (ag *APIAlertGroup) removeGroupingLabels(dropNames []string) { + newGroupLabels := map[string]string{} + for name, val := range ag.Labels { + if slices.StringInSlice(dropNames, name) { + continue + } + newGroupLabels[name] = val + } + ag.Labels = newGroupLabels + for i, alert := range ag.Alerts { newAlertLabels := map[string]string{} for name, val := range alert.Labels { + if slices.StringInSlice(dropNames, name) { + // skip all labels from the drop list + continue + } if _, found := ag.Labels[name]; found { // skip all labels that are used for grouping continue @@ -341,10 +354,10 @@ func (ag *APIAlertGroup) populateAllLabels() { // DedupSharedMaps will find all labels and annotations shared by all alerts // in this group and moved them to Shared namespace -func (ag *APIAlertGroup) DedupSharedMaps() { +func (ag *APIAlertGroup) DedupSharedMaps(ignoredLabels []string) { ag.populateAllLabels() // remove all labels that are used for grouping - ag.removeGroupingLabels() + ag.removeGroupingLabels(ignoredLabels) // don't dedup if we only have a single alert in this group if len(ag.Alerts) > 1 { ag.dedupLabels() diff --git a/internal/models/api_test.go b/internal/models/api_test.go index 34310c116..8230dccc2 100644 --- a/internal/models/api_test.go +++ b/internal/models/api_test.go @@ -78,7 +78,7 @@ func TestDedupSharedMaps(t *testing.T) { }, }, } - ag.DedupSharedMaps() + ag.DedupSharedMaps(nil) agJSON, _ := json.MarshalIndent(ag, "", " ") abide.AssertReader(t, "SharedMaps", bytes.NewReader(agJSON)) @@ -93,7 +93,7 @@ func TestDedupSharedMapsSingleGroup(t *testing.T) { }, }, } - ag.DedupSharedMaps() + ag.DedupSharedMaps(nil) if len(ag.Shared.Annotations) > 0 { t.Errorf("Expected empty shared annotations, got %v", ag.Shared.Annotations) } @@ -110,7 +110,7 @@ func TestDedupSharedMapsWithSingleAlert(t *testing.T) { }, }, } - ag.DedupSharedMaps() + ag.DedupSharedMaps(nil) if len(ag.Shared.Annotations) > 0 { t.Errorf("Expected empty shared annotations, got %v", ag.Shared.Annotations) } @@ -128,7 +128,7 @@ func TestDedupWithBadSource(t *testing.T) { }, }, } - ag.DedupSharedMaps() + ag.DedupSharedMaps(nil) if len(ag.Shared.Sources) > 0 { t.Errorf("Expected empty sources list, got %v", ag.Shared.Sources) }