Change to clearer alert time fields
This commit is contained in:
parent
c3b36790eb
commit
5ed89a72a5
13
api.go
13
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"},
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue