fix notifications
Build and Publish / Metadata (push) Successful in 10s
Build and Publish / BuildAndDeployAmd64 (push) Failing after 2m16s

This commit is contained in:
mats committed 2026-09-22 08:35:40 +02:00
1 parent e790c02d59
commit a0f558b43c
10 files changed
+277 -7

No files matched your search

+61
View File
@@ -279,3 +279,64 @@ func TestEdgeAlertShowsIngressBackends(t *testing.T) {
t.Fatalf("non-edge alert enriched")
}
}
type fakePodResolver struct {
got []struct{ namespace, deployment string }
}
func (f *fakePodResolver) PodLogs(ctx context.Context, namespace, deployment string, tail int) topology.PodLog {
f.got = append(f.got, struct{ namespace, deployment string }{namespace, deployment})
switch deployment {
case "orders-v2":
return topology.PodLog{Pod: "orders-v2-7d8f9-abcde", Found: true, Lines: []string{"line1", "line2", "line3"}}
default:
return topology.PodLog{} // scaled to 0
}
}
func TestAlertShowsPodLogsOrScaledToZero(t *testing.T) {
at := time.Date(2026, 9, 20, 12, 0, 0, 0, time.UTC)
ev := burst("bad-gw", 16, at.Add(-2*time.Minute), 502, "/api/order")
for i := range ev {
ev[i].Service, ev[i].Host = "nginx", "shop.example.com"
}
sp := DetectAlerts(ev, at, features.SpikeConfig{Window: 5 * time.Minute, BaselineWindows: 12, MinExcess: 5})
a := NewAlert(sp[0], at)
a.Enrich(&fakeResolver{})
pr := &fakePodResolver{}
a.EnrichPods(context.Background(), pr)
txt := a.Text("")
if !strings.Contains(txt, "orders-v2: pod orders-v2-7d8f9-abcde, last 3 log line(s):") {
t.Fatalf("missing pod logs in:\n%s", txt)
}
for _, want := range []string{"line1", "line2", "line3"} {
if !strings.Contains(txt, want) {
t.Fatalf("missing log line %q in:\n%s", want, txt)
}
}
if len(pr.got) != 1 || pr.got[0].namespace != "shop" || pr.got[0].deployment != "orders-v2" {
t.Fatalf("unexpected lookups: %+v", pr.got)
}
}
func TestPodLineNoPod(t *testing.T) {
got := podLine(PodStatus{Deployment: "orders-v2", Found: false})
if got != "orders-v2: no pod running (scaled to 0?)" {
t.Fatalf("got %q", got)
}
}
func TestDropMuted(t *testing.T) {
mk := func(id string, excess float64) features.PatternDelta {
return features.PatternDelta{Excess: excess, Example: features.Event{IssueFingerprint: id}}
}
spikes := []features.Spike{
{Excess: 10, Patterns: []features.PatternDelta{mk("ignored", 6), mk("live", 4)}},
{Excess: 5, Patterns: []features.PatternDelta{mk("ignored", 5)}},
}
got := DropMuted(spikes, func(id string) bool { return id == "ignored" })
if len(got) != 1 || len(got[0].Patterns) != 1 || got[0].Patterns[0].Example.IssueFingerprint != "live" || got[0].Excess != 4 {
t.Fatalf("unexpected result: %+v", got)
}
}