include db for gitea build
Build and Publish / Metadata (push) Successful in 10s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 2m16s

This commit is contained in:
mats committed 2026-09-20 11:01:56 +02:00
1 parent 8de4a2e010
commit 645f923175
33 files changed
+1490 -150

No files matched your search

+14 -3
View File
@@ -33,7 +33,8 @@ type PatternDelta struct {
Count int `json:"count"`
BaselineMean float64 `json:"baselineMean"`
Excess float64 `json:"excess"`
Novel bool `json:"novel"` // never seen in the baseline
Novel bool `json:"novel"` // never seen in the baseline
Clients int `json:"clients,omitempty"` // distinct resolved client IPs in the current window
Example Event `json:"example"`
}
@@ -84,6 +85,7 @@ func DetectSpikes(events []Event, at time.Time, cfg SpikeConfig) []Spike {
cur int
base []int // per baseline window
example Event
clients map[string]struct{}
}
type svc struct {
cur int
@@ -92,7 +94,10 @@ func DetectSpikes(events []Event, at time.Time, cfg SpikeConfig) []Spike {
}
services := map[string]*svc{}
for _, e := range events {
if !e.IsError {
// A duplicate is a later hop of a request whose outermost error is
// already counted; counting it again multiplies every failure by the
// number of services it crossed.
if !e.IsError || e.IsDuplicate {
continue
}
ts := e.Timestamp.UTC()
@@ -123,6 +128,12 @@ func DetectSpikes(events []Event, at time.Time, cfg SpikeConfig) []Spike {
s.cur++
p.cur++
p.example = e
if e.ClientIP != "" {
if p.clients == nil {
p.clients = map[string]struct{}{}
}
p.clients[e.ClientIP] = struct{}{}
}
} else {
idx := int(ts.Sub(baseStart) / cfg.Window)
if idx >= cfg.BaselineWindows {
@@ -154,7 +165,7 @@ func DetectSpikes(events []Event, at time.Time, cfg SpikeConfig) []Spike {
}
spike.Excess += excess
spike.Patterns = append(spike.Patterns, PatternDelta{
Signature: sig, Count: p.cur, BaselineMean: mean, Excess: excess, Novel: !seen, Example: p.example,
Signature: sig, Count: p.cur, BaselineMean: mean, Excess: excess, Novel: !seen, Example: p.example, Clients: len(p.clients),
})
}
if spike.Excess < float64(cfg.MinExcess) {