mirror of
https://github.com/prymitive/karma
synced 2026-08-28 11:17:28 +00:00
committed by
Łukasz Mierzwa
parent
2431d62841
commit
fc3f6baedf
+1
-1
@@ -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 (
|
||||
|
||||
+1
-1
@@ -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]
|
||||
|
||||
+16
-3
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user