mirror of
https://github.com/prymitive/karma
synced 2026-08-23 11:56:20 +00:00
fix(api): ensure alert state is always correctly selected
This commit is contained in:
committed by
Łukasz Mierzwa
parent
35c4e9b237
commit
ebfe335750
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## [unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Overview modal could show incorrect counters for `@state` labels.
|
||||
|
||||
## v0.91
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -394,3 +394,21 @@ func filterAlerts(dedupedAlerts []models.AlertGroup, fl []filters.FilterT) (filt
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func newStateCount() map[string]int {
|
||||
stateCount := map[string]int{}
|
||||
for _, s := range models.AlertStateList {
|
||||
stateCount[s] = 0
|
||||
}
|
||||
return stateCount
|
||||
}
|
||||
|
||||
func stateFromStateCount(stateCount map[string]int) string {
|
||||
if stateCount[models.AlertStateActive] > 0 {
|
||||
return models.AlertStateActive
|
||||
} else if stateCount[models.AlertStateSuppressed] > 0 {
|
||||
return models.AlertStateSuppressed
|
||||
} else {
|
||||
return models.AlertStateUnprocessed
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -315,10 +315,7 @@ func alerts(w http.ResponseWriter, r *http.Request) {
|
||||
perGridAlertGroup[alertGridLabelValue] = agCopy
|
||||
}
|
||||
|
||||
stateCount := map[string]int{}
|
||||
for _, s := range models.AlertStateList {
|
||||
stateCount[s] = 0
|
||||
}
|
||||
stateCount := newStateCount()
|
||||
switch gridLabel {
|
||||
case "@alertmanager":
|
||||
ams := []models.AlertmanagerInstance{}
|
||||
@@ -344,13 +341,7 @@ func alerts(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if stateCount[models.AlertStateActive] > 0 {
|
||||
alert.State = models.AlertStateActive
|
||||
} else if stateCount[models.AlertStateSuppressed] > 0 {
|
||||
alert.State = models.AlertStateSuppressed
|
||||
} else {
|
||||
alert.State = models.AlertStateUnprocessed
|
||||
}
|
||||
alert.State = stateFromStateCount(stateCount)
|
||||
|
||||
agCopy.Alerts = append(agCopy.Alerts, alert)
|
||||
|
||||
@@ -800,6 +791,14 @@ func counters(w http.ResponseWriter, r *http.Request) {
|
||||
for _, ag := range filtered {
|
||||
total += len(ag.Alerts)
|
||||
for _, alert := range ag.Alerts {
|
||||
alert := alert
|
||||
|
||||
stateCount := newStateCount()
|
||||
for _, am := range alert.Alertmanager {
|
||||
stateCount[am.State]++
|
||||
}
|
||||
alert.State = stateFromStateCount(stateCount)
|
||||
|
||||
if len(upstreams.Clusters) > 1 {
|
||||
clusters := map[string]struct{}{}
|
||||
for _, am := range alert.Alertmanager {
|
||||
|
||||
Reference in New Issue
Block a user