include db for gitea build
This commit is contained in:
1 parent
8de4a2e010
commit
645f923175
33 files changed
+1490
-150
No files matched your search
@@ -98,3 +98,26 @@ func TestDetectSpikesWarmupGuard(t *testing.T) {
|
||||
t.Fatalf("guard should be off when DataSince is zero")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectSpikesSkipsDuplicateHopsAndCountsClients(t *testing.T) {
|
||||
at := time.Date(2026, 9, 19, 12, 0, 0, 0, time.UTC)
|
||||
cfg := SpikeConfig{Window: 5 * time.Minute, BaselineWindows: 12}
|
||||
var events []Event
|
||||
for i := 0; i < 8; i++ {
|
||||
ts := at.Add(-time.Minute).Add(time.Duration(i) * time.Second)
|
||||
client := "203.0.113." + string(rune('1'+i%2))
|
||||
events = append(events,
|
||||
Event{Timestamp: ts, Service: "nginx", IsError: true, PatternSignature: "p", ClientIP: client},
|
||||
// two more hops of the same request must not count
|
||||
Event{Timestamp: ts, Service: "nginx", IsError: true, PatternSignature: "p", ClientIP: client, IsDuplicate: true},
|
||||
Event{Timestamp: ts, Service: "nginx", IsError: true, PatternSignature: "p", ClientIP: client, IsDuplicate: true},
|
||||
)
|
||||
}
|
||||
got := DetectSpikes(events, at, cfg)
|
||||
if len(got) != 1 || got[0].ErrorCount != 8 || got[0].Patterns[0].Count != 8 {
|
||||
t.Fatalf("duplicates were counted: %+v", got)
|
||||
}
|
||||
if got[0].Patterns[0].Clients != 2 {
|
||||
t.Fatalf("clients = %d, want 2", got[0].Patterns[0].Clients)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user