40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package alerts
|
|
|
|
import (
|
|
"git.tornberg.me/go-otel/internal/features"
|
|
"git.tornberg.me/go-otel/internal/triage"
|
|
)
|
|
|
|
// TriageOf classifies a pattern's example event with the deterministic rules.
|
|
func TriageOf(e features.Event) triage.Result {
|
|
return triage.Classify(triage.Input{Service: e.Service, Kind: e.Kind, Status: e.StatusCode, Route: e.Route, Title: e.SpanName, Message: e.Message,
|
|
IsTimeout: e.IsTimeout, IsCancellation: e.IsCancellation, IsRetry: e.IsRetry})
|
|
}
|
|
|
|
// FilterActionable keeps only patterns whose category should page a human
|
|
// (unless keepMuted), recomputing each spike's excess so a probe storm cannot
|
|
// alert by itself. muted, when non-nil, counts what was dropped per category.
|
|
func FilterActionable(spikes []features.Spike, keepMuted bool, muted map[triage.Category]int) []features.Spike {
|
|
var out []features.Spike
|
|
for _, sp := range spikes {
|
|
var kept []features.PatternDelta
|
|
sp.Excess = 0
|
|
for _, p := range sp.Patterns {
|
|
c := TriageOf(p.Example).Category
|
|
if !keepMuted && !c.Actionable() {
|
|
if muted != nil {
|
|
muted[c]++
|
|
}
|
|
continue
|
|
}
|
|
kept = append(kept, p)
|
|
sp.Excess += p.Excess
|
|
}
|
|
if len(kept) > 0 {
|
|
sp.Patterns = kept
|
|
out = append(out, sp)
|
|
}
|
|
}
|
|
return out
|
|
}
|