diff --git a/api.go b/api.go index 4a6285bc..8058bda6 100644 --- a/api.go +++ b/api.go @@ -81,14 +81,13 @@ func (api *API) addAlerts(w http.ResponseWriter, r *http.Request) { for _, alert := range alerts { now := time.Now() - if alert.Timestamp.IsZero() { - alert.Timestamp = now + alert.UpdatedAt = now + + if alert.StartsAt.IsZero() { + alert.StartsAt = now } - if alert.CreatedAt.IsZero() { - alert.CreatedAt = now - } - if alert.ResolvedAt.IsZero() { - alert.ResolvedAt = alert.CreatedAt.Add(ResolveTimeout) + if alert.EndsAt.IsZero() { + alert.EndsAt = alert.StartsAt.Add(ResolveTimeout) } } diff --git a/dispatch.go b/dispatch.go index 3d05c2cb..0fdeea7b 100644 --- a/dispatch.go +++ b/dispatch.go @@ -238,7 +238,7 @@ func (ag *aggrGroup) insert(alert *types.Alert) { // Immediately trigger a flush if the wait duration for this // alert is already over. - if !ag.hasSent && alert.Timestamp.Add(ag.opts.GroupWait).Before(time.Now()) { + if !ag.hasSent && alert.UpdatedAt.Add(ag.opts.GroupWait).Before(time.Now()) { ag.next.Reset(0) } } diff --git a/notify/notify_test.go b/notify/notify_test.go index b2fd9214..12c196df 100644 --- a/notify/notify_test.go +++ b/notify/notify_test.go @@ -52,16 +52,16 @@ func TestDedupingNotifier(t *testing.T) { Labels: model.LabelSet{"alertname": "2"}, }, { - Labels: model.LabelSet{"alertname": "3"}, - ResolvedAt: now.Add(-20 * time.Minute), + Labels: model.LabelSet{"alertname": "3"}, + EndsAt: now.Add(-20 * time.Minute), }, { - Labels: model.LabelSet{"alertname": "4"}, - ResolvedAt: now.Add(-10 * time.Minute), + Labels: model.LabelSet{"alertname": "4"}, + EndsAt: now.Add(-10 * time.Minute), }, { - Labels: model.LabelSet{"alertname": "5"}, - ResolvedAt: now.Add(-10 * time.Minute), + Labels: model.LabelSet{"alertname": "5"}, + EndsAt: now.Add(-10 * time.Minute), }, { Labels: model.LabelSet{"alertname": "6"}, diff --git a/types/types.go b/types/types.go index f24ac7e6..ae7ba5bb 100644 --- a/types/types.go +++ b/types/types.go @@ -34,11 +34,11 @@ type Alert struct { // Extra key/value information which does not define alert identity. Annotations Annotations `json:"annotations,omitempty"` - CreatedAt time.Time `json:"createdAt,omitempty"` - ResolvedAt time.Time `json:"resolvedAt,omitempty"` + StartsAt time.Time `json:"startsAt,omitempty"` + EndsAt time.Time `json:"endsAt,omitempty"` // The authoritative timestamp. - Timestamp time.Time `json:"timestamp"` + UpdatedAt time.Time `json:"timestamp"` } // Name returns the name of the alert. It is equivalent to the "alertname" label. @@ -78,17 +78,17 @@ func (a *Alert) String() string { } func (a *Alert) Resolved() bool { - if a.ResolvedAt.IsZero() { + if a.EndsAt.IsZero() { return false } - return !a.ResolvedAt.After(time.Now()) + return !a.EndsAt.After(time.Now()) } // alertTimeline is a list of alerts sorted by their timestamp. type alertTimeline []*Alert func (at alertTimeline) Len() int { return len(at) } -func (at alertTimeline) Less(i, j int) bool { return at[i].Timestamp.Before(at[j].Timestamp) } +func (at alertTimeline) Less(i, j int) bool { return at[i].UpdatedAt.Before(at[j].UpdatedAt) } func (at alertTimeline) Swap(i, j int) { at[i], at[j] = at[j], at[i] } // A Silencer determines whether a given label set is muted.