8000 🐛 Fix E2E regressions from the core rebuild by abahmed · Pull Request #528 · abahmed/kwatch · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
05688d8
🐛 Fix E2E regressions: bootstrap-object blame, smoke script, stale tests
abahmed Oct 2, 2026
89dbcd4
🩹 Use name/resource syntax for kubectl auth can-i in the smoke script
abahmed Oct 3, 2026
eed6112
♻️ Add the Scenario helper and fix stale E2E assertions
abahmed Oct 3, 2026
a2b5cda
♻️ Simplify the E2E suite and run it in four parallel shards
abahmed Oct 3, 2026
7058e97
🐛 Fix the E2E failures found by the first sharded run
abahmed Oct 3, 2026
c49fd9d
🐛 Fix the heartbeat config and the smoke recovery race
abahmed Oct 3, 2026
b0051cd
🐛 Fix the crashing test workload and wait out the startup window
abahmed Oct 3, 2026
3270561
🐛 Fix the remaining E2E failures from the corrected workload run
abahmed Oct 3, 2026
47995b9
🩹 Let the restart scenario wait for Kwatch to become ready
abahmed Oct 3, 2026
60af9d8
🩹 Replace the Pods when the missing ConfigMap is created
abahmed Oct 3, 2026
0ea5603
♻️ Make the E2E scenarios read like plain steps
abahmed Oct 3, 2026
b7bf458
⚡️ Run independent E2E scenarios in parallel and balance shards by time
abahmed Oct 3, 2026
a75dfe7
🩹 Probe the current Lease holder after every smoke-test restart
abahmed Oct 3, 2026
ff1badc
🐛 Resolve E2E incidents by ID and keep failed scenarios' diagnostics
abahmed Oct 3, 2026
8f6871e
🐛 Count only announcements as an incident's root in E2E checks
abahmed Oct 3, 2026
6de7382
🙈 Skip two more scenarios that expose tracked Kwatch bugs
abahmed Oct 3, 2026
8f54c1d
🔍 Add debug logs for findings and incident members
abahmed Oct 3, 2026
58f5dc1
🐛 Fix four Kwatch bugs found by the real-cluster E2E suite
abahmed Oct 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ env:

jobs:
scenarios:
name: Kind regression scenarios
name: >-
Kind regression scenarios${{ matrix.shard != '' && format(' ({0})', matrix.shard) || '' }}
if: >-
(github.event_name != 'pull_request'
|| contains(github.event.pull_request.labels.*.name, 'e2e'))
Expand All @@ -108,6 +109,17 @@ jobs:
timeout-minutes: 150
permissions:
contents: read
# The full suite is split over four Kind clusters that run in parallel.
# A filtered or compare run keeps one cluster, since its own filter
# already picks the scenarios.
strategy:
fail-fast: false
matrix:
shard: >-
${{ fromJSON(
(inputs.scenario != '' || inputs.family != '' || inputs.shard != ''
|| inputs.compare_with_main) && '[""]'
|| '["1/4","2/4","3/4","4/4"]') }}
env:
SOURCE_REF: >-
${{ inputs.compare_with_main && 'main' || github.ref_name }}
Expand Down Expand Up @@ -172,8 +184,12 @@ jobs:
KEEP_CLUSTER: "${{ inputs.keep_cluster || false }}"
SCENARIO_REGEX: "${{ inputs.scenario }}"
SCENARIO_FAMILY: "${{ inputs.family }}"
SCENARIO_SHARD: "${{ inputs.shard }}"
SCENARIO_SHARD: "${{ inputs.shard || matrix.shard }}"
SUITE_TIMEOUT: "${{ inputs.suite_timeout || '60m' }}"
# A run filtered to some scenarios is a debugging run: log every
# finding and incident membership change.
KWATCH_VERBOSITY: "${{ inputs.scenario != '' && '4' || '' }}"
KWATCH_E2E_RUN_KNOWN_GAPS: "${{ inputs.scenario != '' }}"
REPORTED_REF: "${{ inputs.reported_ref }}"
REPORTED_VERSION: "${{ inputs.reported_version }}"
COMPARE_WITH_MAIN: "${{ inputs.compare_with_main || false }}"
Expand All @@ -189,7 +205,7 @@ jobs:
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: kwatch-e2e-${{ github.run_id }}
name: kwatch-e2e-${{ github.run_id }}-${{ strategy.job-index }}
path: |
${{ runner.temp }}/kwatch-e2e
${{ runner.temp }}/kwatch-source.txt
Expand Down
39 changes: 38 additions & 1 deletion internal/detection/detectors/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/abahmed/kwatch/internal/detection"
"github.com/abahmed/kwatch/internal/detection/reasons"
"github.com/abahmed/kwatch/internal/inventory"
"github.com/abahmed/kwatch/internal/inventory/kube"
)

// EventWindow is how recent a Warning event must be to count as current.
Expand Down Expand Up @@ -62,11 +63,14 @@ func (Event) Kinds() []inventory.Kind {
func (Event) Detect(
ctx detection.Context, e inventory.Entity,
) []detection.Finding {
if deleted(ctx, e) {
return nil
}
var order []string
byReason := map[string]*eventGroup{}
for _, note := range ctx.Model.Notes(e.ID, ctx.Now.Add(-EventWindow)) {
severity, failing := eventReasons[note.Reason]
if !note.Warning || !failing {
if !note.Warning || !failing || overcomeAtStart(e, note) {
continue
}
ctx.RecheckAfter(note.At.Add(EventWindow).Sub(ctx.Now))
Expand Down Expand Up @@ -136,3 +140,36 @@ func eventSummary(note inventory.Note) string {
return "Kubernetes reported " + note.Reason
}
}

// startReasons are events of a pod getting ready to run: its volumes,
// devices and network. The kubelet retries them, and a short failure while
// the token volume is prepared is common on a busy node.
var startReasons = map[string]bool{
"FailedMount": true,
"FailedAttachVolume": true,
"FailedCreatePodSandBox": true,
"NetworkNotReady": true,
reasons.FailedMapVolume: true,
reasons.FailedPrepareDynamicResources: true,
}

// overcomeAtStart reports whether note is a start-up failure of a pod that
// became ready after it: the retry worked, so the event is history, not a
// failure. A failure after the pod became ready still counts.
func overcomeAtStart(e inventory.Entity, note inventory.Note) bool {
if e.ID.Kind != kube.KindPod || !startReasons[note.Reason] ||
!flag(e, kube.AttrReady) {
return false
}
readySince := timestamp(e, kube.AttrReadySince)
return !readySince.IsZero() && !readySince.Before(note.At)
}

// deleted reports whether e was an object of a watched kind that is gone.
// Its events outlive it by up to EventWindow, but a deleted Pod no longer
// fails: keeping its findings would hold an incident open after the fix.
// Events about kinds kwatch does not watch have no object to check and
// still count.
func deleted(ctx detection.Context, e inventory.Entity) bool {
return ctx.Synced(e.ID.Kind) && !ctx.Model.Exists(e.ID)
}
62 changes: 62 additions & 0 deletions internal/detection/detectors/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,65 @@ func TestEventSourcesWithSameReasonFoldIntoOneFinding(t *testing.T) {
detection.Evidence{Label: "occurrences", Value: "5"})
assert.Equal(t, t0.Add(time.Minute), got[0].Since)
}

// A pod that hit a FailedMount while starting and then became ready has
// recovered: the event is history. A failure after it became ready counts.
func TestEventStartFailureOvercomeByReadyPod(t *testing.T) {
now := time.Date(2026, 10, 3, 16, 33, 0, 0, time.UTC)
mount := now.Add(-52 * time.Second)
for _, tc := range []struct {
name string
ready bool
readySince time.Time
want int
}{
{"ready after the event", true, mount.Add(time.Second), 0},
{"ready before the event", true, mount.Add(-time.Minute), 1},
{"never ready", false, time.Time{}, 1},
} {
t.Run(tc.name, func(t *testing.T) {
model := newTestModel()
id := inventory.CoreID(kube.KindPod, "ns", "tenant-0")
model.Apply(inventory.Observation{
Kind: inventory.Observed, Source: "test", At: mount,
Entity: id, Attributes: map[string]inventory.Value{
kube.AttrReady: inventory.Bool(tc.ready),
kube.AttrReadySince: inventory.Time(tc.readySince),
},
})
warn(model, id, mount, "FailedMount",
"MountVolume.SetUp failed for volume \"kube-api-access\"")
entity, _ := model.Entity(id)
found := Event{}.Detect(testDetectorContext(model, now), entity)
assert.Len(t, found, tc.want)
})
}
}

// A deleted Pod keeps its events for a while, but it no longer fails: its
// event findings must clear, or an incident stays open after the fix. An
// event about a kind kwatch does not watch still counts.
func TestEventFindingsClearWhenTheObjectIsDeleted(t *testing.T) {
now := time.Date(2026, 10, 3, 16, 52, 0, 0, time.UTC)
mount := now.Add(-90 * time.Second)
pod := inventory.CoreID(kube.KindPod, "ns", "recovery-old")
unwatched := inventory.EntityID{Kind: "widget", Namespace: "ns",
Name: "w"}
synced := func(kind inventory.Kind) bool { return kind == kube.KindPod }
model := newTestModel()
model.Apply(inventory.Observation{Kind: inventory.Observed,
Source: "test", At: mount, Entity: pod,
Attributes: map[string]inventory.Value{}})
warn(model, pod, mount, "FailedMount", "MountVolume.SetUp failed")
warn(model, unwatched, mount, "FailedMount", "MountVolume.SetUp failed")
registry := detection.NewRegistry(synced, Event{})

assert.Len(t, registry.Evaluate(model, now, pod).Findings, 1,
"a live pod with a recent failure still fails")
model.Apply(inventory.Observation{Kind: inventory.Gone,
Source: "test", At: now, Entity: pod})
assert.Empty(t, registry.Evaluate(model, now, pod).Findings,
"a deleted pod's events are history")
assert.Len(t, registry.Evaluate(model, now, unwatched).Findings, 1,
"events about unwatched kinds keep counting")
}
14 changes: 14 additions & 0 deletions internal/incident/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package incident
import (
"time"

"k8s.io/klog/v2"

"github.com/abahmed/kwatch/internal/detection"
"github.com/abahmed/kwatch/internal/inventory"
"github.com/abahmed/kwatch/internal/rootcause"
Expand Down Expand Up @@ -159,6 +161,7 @@ func (m *Manager) attach(
p.note(now, s.Summary+" ("+describe(s.Entity)+")")
}
p.Members[key] = s
logMember("added to", p, key)
p.SupersededBy = ""
if where.cause != nil {
p.Cause, p.CauseUnclear = where.cause, false
Expand Down Expand Up @@ -210,6 +213,7 @@ func (m *Manager) revise(
return false
}
delete(old.Members, key)
logMember("moved out of", old, key)
m.changed[old.ID] = true
old.note(now, "cause revised: "+describe(s.Entity)+
" is now explained by "+describe(root))
Expand Down Expand Up @@ -269,6 +273,7 @@ func (m *Manager) detach(now time.Time, s detection.Finding) {
delete(m.byMember, key)
if p := m.incidents[id]; p != nil {
delete(p.Members, key)
logMember("removed from", p, key)
p.note(now, "recovered: "+s.Summary+" ("+describe(s.Entity)+")")
}
}
Expand Down Expand Up @@ -322,3 +327,12 @@ func (m *Manager) recur(p, previous *Incident, now time.Time) {
// the predecessor would only grow memory with every blip.
m.forget(previous)
}

// logMember writes a debug line when a finding joins or leaves an incident.
// It is off by default; -v=4 shows which member keeps an incident open.
func logMember(change string, p *Incident, key detection.Key) {
klog.V(4).InfoS("incident: finding "+change+" incident",
"component", "incident", "incident", p.ID, "root", p.Root.String(),
"entity", key.Entity.String(), "reason", key.Reason,
"members", len(p.Members), "state", p.State.String())
}
3 changes: 3 additions & 0 deletions internal/incident/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ type Incident struct {
// impactPeak is the largest impact size seen. The fingerprint reads it,
// so impact that shrinks while failures churn is not news.
impactPeak int
// restored marks an incident loaded from the state file; only such
// incidents wait out the restore grace.
restored bool
// trafficLost records that a Service in the impact, routed to by an
// Ingress or route, has no ready backends or mostly failing ones.
// It is recomputed with the impact; the traffic-lost page reads it.
Expand Down
29 changes: 20 additions & 9 deletions internal/incident/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (m *Manager) deadline(p *Incident, now time.Time) (time.Time, bool) {
switch p.State {
case Settling:
if len(p.Members) == 0 {
return m.graceDeadline(now)
return m.graceDeadline(p, now)
}
settle := m.cfg.Settle
if p.Tier == Page {
Expand All @@ -111,29 +111,31 @@ func (m *Manager) deadline(p *Incident, now time.Time) (time.Time, bool) {
return p.Opened.Add(settle), true
case Open:
if len(p.Members) == 0 {
return m.graceDeadline(now)
return m.graceDeadline(p, now)
}
if p.revised {
return p.revisedAt.Add(m.cfg.ReviseSettle), true
}
case Recovering:
if len(p.Members) == 0 {
hold := m.cfg.hold(len(recent(p.Cycles, now, m.cfg.FlapWindow)))
return m.afterGrace(p.RecoveringSince.Add(hold), now), true
return m.afterGrace(p, p.RecoveringSince.Add(hold), now), true
}
case Flapping:
if len(p.Members) == 0 && !p.RecoveringSince.IsZero() {
due := p.RecoveringSince.Add(m.cfg.MaxHold)
return m.afterGrace(due, now), true
return m.afterGrace(p, due, now), true
}
case Resolved:
return p.Resolved.Add(m.cfg.Remember + time.Nanosecond), true
}
return time.Time{}, false
}

func (m *Manager) graceDeadline(now time.Time) (time.Time, bool) {
return m.restoreGrace, now.Before(m.restoreGrace)
func (m *Manager) graceDeadline(
p *Incident, now time.Time,
) (time.Time, bool) {
return m.restoreGrace, m.inGrace(p, now)
}

func (m *Manager) advance(p *Incident, now time.Time) (Decision, bool) {
Expand Down Expand Up @@ -312,7 +314,14 @@ func (m *Manager) awaitingEvidence(p *Incident, now time.Time) bool {
if len(p.Members) > 0 {
return false
}
return now.Before(m.restoreGrace) || !m.verifiable(p)
return m.inGrace(p, now) || !m.verifiable(p)
}

// inGrace reports whether p is a restored incident still inside the
// restore grace. Incidents opened after the restart have no stale
// model to wait for: their members come from this session's detectors.
func (m *Manager) inGrace(p *Incident, now time.Time) bool {
return p.restored && now.Before(m.restoreGrace)
}

// holdRecovery reports whether a recovering incident without members
Expand All @@ -332,8 +341,10 @@ func (m *Manager) holdRecovery(p *Incident, now time.Time) bool {

// afterGrace moves a deadline that falls inside the restore grace to the
// end of the grace, when recovery may first be decided.
func (m *Manager) afterGrace(at, now time.Time) time.Time {
if now.Before(m.restoreGrace) && at.Before(m.restoreGrace) {
func (m *Manager) afterGrace(
p *Incident, at, now time.Time,
) time.Time {
if m.inGrace(p, now) && at.Before(m.restoreGrace) {
return m.restoreGrace
}
return at
Expand Down
2 changes: 1 addition & 1 deletion internal/incident/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func restored(r Record) *Incident {
Members: make(map[detection.Key]detection.Finding),
impactPeak: r.ImpactPeak, revised: r.Revised,
revisedAt: r.RevisedAt, AlertKey: r.AlertKey,
sent: restoredMark(len(r.Timeline)),
sent: restoredMark(len(r.Timeline)), restored: true,
}
if p.AlertKey == "" && wasAnnounced(p) {
p.AlertKey = alertKey(p.Root, p.Mode)
Expand Down
27 changes: 27 additions & 0 deletions internal/incident/restore_grace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package incident

import (
"testing"
"time"
)

// An incident opened after a restart is not a restored one: when it
// recovers it resolves after the hold, not after the restore grace of the
// incidents loaded from the state file.
func TestManagerRestoreGraceSparesIncidentsOpenedAfterRestart(t *testing.T) {
old := newRig(t, Config{})
announced(t, old, podSig("old"))
fresh := newRig(t, Config{})
fresh.m.Restore(old.m.Export(), at(10*time.Minute))

web := podSig("web")
fresh.raise(at(time.Minute), web)
wantAction(t, fresh.tick(at(time.Minute+DefaultSettle)),
Announce, "settled")
fresh.clear(at(2*time.Minute), web)
wantNone(t, fresh.tick(at(2*time.Minute+time.Second)))

ds := fresh.tick(
at(2*time.Minute + time.Second + DefaultHold))
wantAction(t, ds, Resolve, "healthy for "+DefaultHold.String())
}
Loading
Loading
0