mirror of
https://github.com/prymitive/karma
synced 2026-05-13 03:56:59 +00:00
feat(api): summarize alertmanager counts in group API
This commit is contained in:
@@ -33,12 +33,13 @@ func (a AlertList) Less(i, j int) bool {
|
||||
// There is a hash computed from all alerts, it's used by UI to quickly tell
|
||||
// if there was any change in a group and it needs to refresh it
|
||||
type AlertGroup struct {
|
||||
Receiver string `json:"receiver"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
Alerts AlertList `json:"alerts"`
|
||||
ID string `json:"id"`
|
||||
Hash string `json:"hash"`
|
||||
StateCount map[string]int `json:"stateCount"`
|
||||
Receiver string `json:"receiver"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
Alerts AlertList `json:"alerts"`
|
||||
ID string `json:"id"`
|
||||
Hash string `json:"hash"`
|
||||
AlertmanagerCount map[string]int `json:"alertmanagerCount"`
|
||||
StateCount map[string]int `json:"stateCount"`
|
||||
}
|
||||
|
||||
// LabelsFingerprint is a checksum of this AlertGroup labels and the receiver
|
||||
|
||||
19
views.go
19
views.go
@@ -84,11 +84,12 @@ func alerts(c *gin.Context) {
|
||||
var matches int
|
||||
for _, ag := range dedupedAlerts {
|
||||
agCopy := models.AlertGroup{
|
||||
ID: ag.ID,
|
||||
Receiver: ag.Receiver,
|
||||
Labels: ag.Labels,
|
||||
Alerts: []models.Alert{},
|
||||
StateCount: map[string]int{},
|
||||
ID: ag.ID,
|
||||
Receiver: ag.Receiver,
|
||||
Labels: ag.Labels,
|
||||
Alerts: []models.Alert{},
|
||||
AlertmanagerCount: map[string]int{},
|
||||
StateCount: map[string]int{},
|
||||
}
|
||||
for _, s := range models.AlertStateList {
|
||||
agCopy.StateCount[s] = 0
|
||||
@@ -127,6 +128,14 @@ func alerts(c *gin.Context) {
|
||||
|
||||
agCopy.StateCount[alert.State]++
|
||||
|
||||
for _, am := range alert.Alertmanager {
|
||||
if _, found := agCopy.AlertmanagerCount[am.Name]; !found {
|
||||
agCopy.AlertmanagerCount[am.Name] = 1
|
||||
} else {
|
||||
agCopy.AlertmanagerCount[am.Name]++
|
||||
}
|
||||
}
|
||||
|
||||
for key, value := range alert.Labels {
|
||||
if keyMap, foundKey := dedupedColors[key]; foundKey {
|
||||
if color, foundColor := keyMap[value]; foundColor {
|
||||
|
||||
Reference in New Issue
Block a user