mirror of
https://github.com/prymitive/karma
synced 2026-08-23 11:56:20 +00:00
fix(api): split alertmanager information in multi-grid
This commit is contained in:
committed by
Łukasz Mierzwa
parent
d07c56d3d8
commit
fb1f59426f
+45
-5
@@ -244,11 +244,6 @@ func alerts(c *gin.Context) {
|
||||
}
|
||||
if !validFilters || (slices.BoolInSlice(results, true) && !slices.BoolInSlice(results, false)) {
|
||||
matches++
|
||||
// we need to update fingerprints since we've modified some fields in dedup
|
||||
// and agCopy.ContentFingerprint() depends on per alert fingerprint
|
||||
// we update it here rather than in dedup since here we can apply it
|
||||
// only for alerts left after filtering
|
||||
alert.UpdateFingerprints()
|
||||
|
||||
alertGridLabelValues := map[string]bool{}
|
||||
switch gridLabel {
|
||||
@@ -267,6 +262,14 @@ func alerts(c *gin.Context) {
|
||||
}
|
||||
|
||||
for alertGridLabelValue, _ := range alertGridLabelValues {
|
||||
alert := models.Alert(alert)
|
||||
|
||||
// we need to update fingerprints since we've modified some fields in dedup
|
||||
// and agCopy.ContentFingerprint() depends on per alert fingerprint
|
||||
// we update it here rather than in dedup since here we can apply it
|
||||
// only for alerts left after filtering
|
||||
alert.UpdateFingerprints()
|
||||
|
||||
agCopy, found := perGridAlertGroup[alertGridLabelValue]
|
||||
if !found {
|
||||
agCopy = &models.AlertGroup{
|
||||
@@ -284,6 +287,43 @@ func alerts(c *gin.Context) {
|
||||
perGridAlertGroup[alertGridLabelValue] = agCopy
|
||||
}
|
||||
|
||||
stateCount := map[string]int{}
|
||||
for _, s := range models.AlertStateList {
|
||||
stateCount[s] = 0
|
||||
}
|
||||
switch gridLabel {
|
||||
case "@alertmanager":
|
||||
ams := []models.AlertmanagerInstance{}
|
||||
for _, am := range alert.Alertmanager {
|
||||
if am.Name == alertGridLabelValue {
|
||||
ams = append(ams, am)
|
||||
stateCount[am.State]++
|
||||
}
|
||||
}
|
||||
alert.Alertmanager = ams
|
||||
case "@cluster":
|
||||
ams := []models.AlertmanagerInstance{}
|
||||
for _, am := range alert.Alertmanager {
|
||||
if am.Cluster == alertGridLabelValue {
|
||||
ams = append(ams, am)
|
||||
stateCount[am.State]++
|
||||
}
|
||||
}
|
||||
alert.Alertmanager = ams
|
||||
default:
|
||||
for _, am := range alert.Alertmanager {
|
||||
stateCount[am.State]++
|
||||
}
|
||||
}
|
||||
|
||||
if stateCount[models.AlertStateActive] > 0 {
|
||||
alert.State = models.AlertStateActive
|
||||
} else if stateCount[models.AlertStateSuppressed] > 0 {
|
||||
alert.State = models.AlertStateSuppressed
|
||||
} else {
|
||||
alert.State = models.AlertStateUnprocessed
|
||||
}
|
||||
|
||||
agCopy.Alerts = append(agCopy.Alerts, alert)
|
||||
|
||||
countLabel(counters, "@state", alert.State)
|
||||
|
||||
Reference in New Issue
Block a user