-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/bosun: (wip) link previous incidents and next incident #2323
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package sched | |
import ( | ||
"fmt" | ||
"math" | ||
"sort" | ||
"time" | ||
|
||
"bosun.org/cmd/bosun/cache" | ||
|
@@ -244,10 +245,34 @@ func (s *Schedule) runHistory(r *RunHistory, ak models.AlertKey, event *models.E | |
if a.Log || silencedOrIgnored(a, event, si) { | ||
//a log or silenced/ignored alert will not need to be saved | ||
} else { | ||
incident.Id, err = s.DataAccess.State().UpdateIncidentState(incident) | ||
daState := s.DataAccess.State() | ||
incident.Id, err = daState.UpdateIncidentState(incident) | ||
if err != nil { | ||
return | ||
} | ||
previousIds := []int64{} | ||
previousIds, err = daState.GetAllIncidentIdsByAlertKey(ak) | ||
if err != nil { | ||
return | ||
} | ||
for _, id := range previousIds { | ||
if incident.Id > id { | ||
incident.PreviousIds = append(incident.PreviousIds, id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, we're storing all previous alert keys on every alert? Gross. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @captncraig To make it easier to either:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also to clarify not the previous alert keys, just an array of incident id numbers (int64) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another Also :P alert keys are the alert name plus the tagset (not all alerts under the name, unless the tagset is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I'm just uncomfortable anytime I see potentially large, and also redundant, and also repetitive collections or lists. I guess though I'd rather a template could show them all without having to recursively traverse the chain, which was gonna be the alternative I suggested. So ok. |
||
} | ||
} | ||
sort.Slice(incident.PreviousIds, func(i, j int) bool { | ||
return incident.PreviousIds[i] > incident.PreviousIds[j] | ||
}) | ||
_, err = daState.UpdateIncidentState(incident) | ||
if err != nil { | ||
return | ||
} | ||
if len(incident.PreviousIds) > 0 { | ||
err = daState.SetIncidentNext(incident.PreviousIds[0], incident.Id) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly collect Alert Keys up front, and run inner loop once per alert key, not once per incident.