Calculate min/max timestamps and store those as globals, keep individual timestamps per instance

This commit is contained in:
Łukasz Mierzwa
2017-07-01 12:09:07 -07:00
parent 5bd03234a0
commit 01c89082dd
5 changed files with 26 additions and 4 deletions

View File

@@ -31,9 +31,22 @@ func DedupAlerts() []models.AlertGroup {
alertLFP := alert.LabelsFingerprint()
a, found := alerts[alertLFP]
if found {
// if we already have an alert with the same fp then just append
// alertmanager instances to it, this way we end up with all instances
// for each unique alert merged into a single alert with all
// alertmanager instances attached to it
for _, am := range alert.Alertmanager {
a.Alertmanager = append(a.Alertmanager, am)
}
// set startsAt to the earliest value we have
if alert.StartsAt.Before(a.StartsAt) {
a.StartsAt = alert.StartsAt
}
// set endsAt to the oldest value we have
if alert.EndsAt.After(a.EndsAt) {
a.EndsAt = alert.EndsAt
}
// update map
alerts[alertLFP] = a
} else {
alerts[alertLFP] = models.Alert(alert)

View File

@@ -153,6 +153,8 @@ func (am *Alertmanager) pullAlerts(version string) error {
models.AlertmanagerInstance{
Name: am.Name,
URI: am.URI,
StartsAt: alert.StartsAt,
EndsAt: alert.EndsAt,
Source: alert.GeneratorURL,
Silences: silences,
},

View File

@@ -37,9 +37,10 @@ type Alert struct {
State string `json:"state"`
// those are not exposed in JSON, Alertmanager specific value will be in kept
// in the Alertmanager slice
GeneratorURL string `json:"-"`
SilencedBy []string `json:"-"`
InhibitedBy []string `json:"-"`
// skip those when generating alert fingerprint too
GeneratorURL string `json:"-" hash:"-"`
SilencedBy []string `json:"-" hash:"-"`
InhibitedBy []string `json:"-" hash:"-"`
// unsee fields
Alertmanager []AlertmanagerInstance `json:"alertmanager"`
Receiver string `json:"receiver"`

View File

@@ -114,7 +114,7 @@ var agFPTests = []agFPTest{
},
StateCount: map[string]int{"default": 0},
},
fingerprint: "954a7283c2cda4179b63499465d82a313d21180f",
fingerprint: "87e79b3d507d26f21bc5e82b8db19f87ce46c1ad",
},
}

View File

@@ -1,10 +1,16 @@
package models
import "time"
// AlertmanagerInstance describes the Alertmanager instance alert was collected
// from
type AlertmanagerInstance struct {
Name string `json:"name"`
URI string `json:"uri"`
// timestamp collected from this instance, those on the alert itself
// will be calculated min/max values
StartsAt time.Time `json:"startsAt"`
EndsAt time.Time `json:"endsAt"`
// Source links to alert source for given alertmanager instance
Source string `json:"source"`
// all silences matching current alert in this upstream