FFFF ✨ smarter incidents and shared-error grouping by abahmed · Pull Request #532 · abahmed/kwatch · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
83 changes: 75 additions & 8 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,70 @@ on:
permissions:
contents: read

# A new push to a pull request cancels the older run of that push. Label
# events get their own group and never cancel anything: adding an unrelated
# label to a pull request must not kill an in-flight run.
concurrency:
group: e2e-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
group: e2e-${{ github.event_name }}-${{ github.event.action }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' && github.event.action != 'labeled' }}

env:
KIND_VERSION: v0.30.0

jobs:
# The images are built once here and loaded by every job below, instead of
# being rebuilt in each of them. Compare mode builds its own images from
# two different sources, so it does not use them.
build:
name: Build e2e images
if: >-
(github.event_name != 'pull_request'
|| contains(github.event.pull_request.labels.*.name, 'e2e'))
&& !inputs.compare_with_main
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false

- name: Build and save images
run: ./scripts/build-e2e-images.sh "${RUNNER_TEMP}/e2e-images.tar.gz"
10000
- name: Upload images
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: kwatch-e2e-images-${{ github.run_attempt }}
path: ${{ runner.temp }}/e2e-images.tar.gz
retention-days: 1
compression-level: 0
if-no-files-found: error

scenarios:
needs: build
name: >-
Kind regression scenarios${{ matrix.shard != '' && format(' ({0})', matrix.shard) || '' }}
if: >-
(github.event_name != 'pull_request'
!cancelled() && (needs.build.result == 'success'
|| inputs.compare_with_main)
&& (github.event_name != 'pull_request'
|| contains(github.event.pull_request.labels.*.name, 'e2e'))
&& (github.event_name != 'workflow_dispatch'
|| inputs.suite == 'all' || inputs.suite == 'scenarios')
runs-on: ubuntu-24.04
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
# The full suite is split over ten Kind clusters that run in parallel.
# The shard count is only this list: scenarios are dealt to shards by
# test/e2e/scenarios/sharding_test.go, so any count works. The slowest
# scenarios (the ten-minute PDB one and the cluster DNS outage) get a
# cluster each. Extra clusters are free on a public repository, but a
# run should stay under the 20 concurrent jobs GitHub allows. A
# filtered or compare run keeps one cluster, since its own filter
# already picks the scenarios.
strategy:
fail-fast: false
Expand All @@ -119,7 +161,7 @@ jobs:
${{ fromJSON(
(inputs.scenario != '' || inputs.family != '' || inputs.shard != ''
|| inputs.compare_with_main) && '[""]'
|| '["1/4","2/4","3/4","4/4"]') }}
|| '["1/10","2/10","3/10","4/10","5/10","6/10","7/10","8/10","9/10","10/10"]') }}
env:
SOURCE_REF: >-
${{ inputs.compare_with_main && 'main' || github.ref_name }}
Expand Down Expand Up @@ -177,8 +219,21 @@ jobs:
echo "resolved_sha=$SOURCE_SHA"
} > "${RUNNER_TEMP}/kwatch-source.txt"

- name: Download e2e images
if: ${{ !inputs.compare_with_main }}
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: kwatch-e2e-images-${{ github.run_attempt }}
path: ${{ runner.temp }}/e2e-images

- name: Run Kind scenarios
env:
KWATCH_PREBUILT_IMAGES: "${{ !inputs.compare_with_main }}"
# The script loads the images while the Kind cluster is created.
KWATCH_IMAGES_ARCHIVE: >-
${{ !inputs.compare_with_main
&& format('{0}/e2e-images/e2e-images.tar.gz', runner.temp)
|| '' }}
ARTIFACTS: "${{ runner.temp }}/kwatch-e2e"
KIND_CLUSTER_NAME: "kwatch-e2e-${{ github.run_id }}"
KEEP_CLUSTER: "${{ inputs.keep_cluster || false }}"
Expand Down Expand Up @@ -212,6 +267,7 @@ jobs:
if-no-files-found: warn

operational:
needs: build
name: Operational smoke (${{ matrix.rbac }}, secrets=${{ matrix.secrets }})
if: >-
(github.event_name != 'pull_request'
Expand Down Expand Up @@ -246,8 +302,19 @@ jobs:
with:
cluster_name: ${{ env.KIND_CLUSTER_NAME }}

- name: Build image
run: docker build --tag kwatch:ci .
# The scenarios' Kwatch image, which the smoke test only needs under
# another name.
- name: Download e2e images
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: kwatch-e2e-images-${{ github.run_attempt }}
path: ${{ runner.temp }}/e2e-images

- name: Tag image
run: |
set -euo pipefail
docker load --input "${RUNNER_TEMP}/e2e-images/e2e-images.tar.gz"
docker tag "kwatch:e2e-$(git rev-parse HEAD)" kwatch:ci

- name: Run production smoke test
env:
Expand Down
32 changes: 17 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -485,21 +485,6 @@ jobs:

echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

- name: Push the version bump to main
if: ${{ steps.bump.outputs.bumped == 'true' && inputs.target == '' }}
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
MAIN_SHA: ${{ steps.bump.outputs.main_sha }}
run: |
set -euo pipefail
basic=$(printf 'x-access-token:%s' "$RELEASE_TOKEN" | base64 -w0)
if ! git -c "http.https://github.com/.extraheader=AUTHORIZATION: basic $basic" \
push origin "$MAIN_SHA:refs/heads/main"; t 10000 hen
echo "::error::could not push the version bump to main. RELEASE_TOKEN must be a classic PAT with repo scope, allowed to bypass branch protection. Push it manually and re-run:"
echo "::error:: git push origin $MAIN_SHA:main"
exit 1
fi

- name: Verify release contents before tagging
if: ${{ !inputs.dry_run }}
env:
Expand Down Expand Up @@ -547,6 +532,23 @@ jobs:
git -c "http.https://github.com/.extraheader=AUTHORIZATION: basic $basic" \
push origin "refs/tags/$VERSION"

# Pushed only after the contents were verified and the tag exists, so a
# failed check never leaves main pinned to a version that was not cut.
- name: Push the version bump to main
if: ${{ steps.bump.outputs.bumped == 'true' && inputs.target == '' }}
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
MAIN_SHA: ${{ steps.bump.outputs.main_sha }}
run: |
set -euo pipefail
basic=$(printf 'x-access-token:%s' "$RELEASE_TOKEN" | base64 -w0)
if ! git -c "http.https://github.com/.extraheader=AUTHORIZATION: basic $basic" \
push origin "$MAIN_SHA:refs/heads/main"; then
echo "::error::could not push the version bump to main. RELEASE_TOKEN must be a classic PAT with repo scope, allowed to bypass branch protection. Push it manually and re-run:"
echo "::error:: git push origin $MAIN_SHA:main"
exit 1
fi

- name: Create GitHub release
if: ${{ !inputs.dry_run }}
env:
Expand Down
74 changes: 49 additions & 25 deletions AGENTS.md
< 10BC8 td class="blob-code blob-code-context js-file-line"> active session, drains delivery, closes the state file, and exits so
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Guidance for humans and AI agents making changes to this repository. For the
user-facing contribution process and published technical documentation, see
[kwatch.dev/docs](https://kwatch.dev/docs). New contributors should read
`docs/contributor-architecture.md` first: it explains the packages and import
rules in plain English before this file's rules. The root `CONTRIBUTING.md` is
rules in plain English before this file's rules. Anyone changing
`internal/incident` should also read `docs/incident-lifecycle.md`, the
one-page guide to the life of an incident and its timings. The root `CONTRIBUTING.md` is
a short repository entry point; it must not become a second public
documentation source.

Expand Down Expand Up @@ -50,10 +52,10 @@ true when extending the system:
write transaction verifies the claim, so a process whose claim was
superseded fails with a fenced error instead of overwriting newer state. A
failed save is logged and retried; it never stops delivery.
- The leader session ends in a fixed order: readiness is withdrawn at once,
- The active session ends in a fixed order: readiness is withdrawn at once,
components stop, delivery drains, thread IDs are saved, the session end is
recorded, and the file is closed. Delivery drains before the thread save
so the thread IDs of the last sends survive. After leadership is lost,
so the thread IDs of the last sends survive. After the state lock is lost,
delivery sends nothing more: queued jobs are dead-lettered.
- Every queued delivery is written to the persisted outbox when a provider
queue accepts it and removed when a provider (or its fallback) accepted it
Expand Down Expand Up @@ -268,6 +270,9 @@ enforces, are in `docs/contributor-architecture.md`.
| `internal/notification` | Provider-neutral message type, severity levels, and rendering helpers such as chunking and mention neutralizing (leaf) |
| `internal/scope` | Delivery scope over findings: namespaces, reasons, silences, and maintenance holds |
| `internal/pipeline` | Engine loop: observation queue, model update, detectors, incident manager, scope, investigation, downtime 10000 reconciliation, audit entries; the only producer of incident decisions |
| `internal/pipeline/announce` | Collecting steps: startup summary, digest, roll-up, namespace outage hold, listings; the pipeline wires it and it never imports the pipeline |
| `internal/pipeline/coverage` | Memory of the coverage backstop (failing workloads, hand-backs) and its timings |
| `internal/pipeline/investigate` | Evidence investigators (crash, node, scheduling, config, admission, registry) and the `Investigator` contract |
| `internal/delivery/*` | Delivery manager for notification messages: routing, retries, fallback, pacing, queue coalescing, transport, provider dispatch |
| `internal/delivery/api` | Neutral provider contract shared by delivery and the static catalog |
| `internal/alert/*` | Provider adapters; one subpackage per provider |
Expand All @@ -288,8 +293,8 @@ Application composition is split by responsibility:

- `internal/app/bootstrap.go` and `serve.go` own infrastructure, health, and
the serve loop.
- `internal/app/leader_election.go` and `election_lock.go` own the Lease lock.
- `internal/app/active.go` runs the leader session: state file, startup
- `internal/app/leader_election.go` and `election_lock.go` own the state lock.
- `internal/app/active.go` runs the active session: state file, startup
bookkeeping, and supervised components. `startup.go`,
`restart_classification.go`, and `startup_message.go` own the runtime
session, restart classification, and the startup message.
Expand Down Expand Up @@ -443,6 +448,25 @@ Step-by-step guides with real examples and test commands:
lifecycle with the injected clock, and update
`docs/kubernetes-coverage.md`.

### Message data flows (writers never read the model)

- `incident.Decision` carries data the pipeline adds before writing:
`Output`, `Evidence`, `Changes` (latest namespace changes, only for an
incident without a cause, from `incident.RecentChanges`) and `KindNames`
(declared spelling of custom kinds, from the `kube.AttrKindName` entity
attribute). Compose reads these; it never reads the model or a package
global.
- Fix attempts: `Incident.Attempt` is the latest rollout or config change
while open. It makes `ReasonFixAttempt` once per change and
`ReasonFixStillFailing` once, `FixWatch` later, only while `Revision` is at
most `maxAttemptRevision` (the message budget). It is in the fingerprint.
- Damping: `keepsMember` keeps a finding in its incident when it was told
about it and the new root is in the same workload chain
(`sameChainFlip`); a superseded non-page incident with the same failures
as a target created within `ReviseSettle` resolves quietly. `holdFor`
doubles the resolve hold once more for roots reopened more than
`ChronicReopens` times within `ChronicWindow`.

## Naming conventions

- `New*` constructors; `Detect`, `Explain`, `Apply`, `Tick`, `Write`,
Expand Down Expand Up @@ -487,7 +511,7 @@ Some quirks are load-bearing. Preserve them unless a change explicitly says othe
`Message.Carrier` set; delivery drops it, the replay keeps it apart from
delivered messages, and the audit entry says `delivery: digest`.
- Two or more announcements in one tick go as one roll-up
(`internal/pipeline/rollup.go`). A roll-up is a `Listing` like the startup
(`internal/pipeline/announce/rollup.go`). A roll-up is a `Listing` like the startup
summary: the first own message of a listed incident is written as an
announcement, and the roll-up resolves once every listed incident has.
Open roll-ups are persisted in the startup marker.
Expand Down Expand Up @@ -763,16 +787,16 @@ Kwatch runs as one replica with the `Recreate` strategy; there is no standby
and no self-failover. The Lease is a lock, not a failover mechanism: it stops
two processes from writing the state volume at once, for example during a
rollout. The epoch that fences the state file is a counter kept in the file
itself and claimed only by the Lease holder; it does not come from the Lease,
so a deleted or recreated Lease cannot fence the new leader. The volume must
be `ReadWriteOnce` block storage, because RWO attach exclusivity is what keeps
a partitioned node off the file. A restart resumes from the PVC, so incidents
are not re-announced and
changes made while kwatch was down are still found. This does not protect
against total cluster, node, API, volume, or network failure. Delivery is at
least once: queued jobs persist in the delivery outbox (at most 2048, none
older than 24 hours) and are re-sent after a restart, and a send interrupted
mid-request may repeat. Exactly-once delivery is not promised.
itself and claimed only by the state lock holder; it does not come from the
Lease, so a deleted or recreated Lease cannot fence the new holder. The volume
must be `ReadWriteOnce` block storage, because RWO attach exclusivity is what
keeps a partitioned node off the file. A restart resumes from the PVC, so
incidents are not re-announced and changes made while kwatch was down are still
found. This does not protect against total cluster, node, API, volume, or
network failure. Delivery is at least once: queued jobs persist in the delivery
outbox (at most 2048, none older than 24 hours) and are re-sent after a
restart, and a send interrupted mid-request may repeat. Exactly-once delivery
is not promised.

Production readiness means that required readiness, bounded shutdown, safe
persistence recovery, Kubernetes and provider outage behavior, bounded queues,
Expand All @@ -787,8 +811,8 @@ Required components have bounded startup and stall deadlines; components that
can be idle must still report lifecycle progress. A required failure or stall
removes readiness immediately, before any shutdown work, then cancels the
Kubernetes restarts the Pod. The Lease is not released on a failure; the
next leader takes it when it expires, and the store's epoch claim fences any
Kubernetes restarts the Pod. The state lock is not released on a failure; the
next holder takes it when it expires, and the store's epoch claim fences any
late write.
Optional components retry with `1s, 2s, 4s, 8s` backoff capped at `60s`; the
backoff resets after a minute of healthy execution. Component completion is
Expand Down Expand Up @@ -844,11 +868,11 @@ no backup is kept. The reset is counted in

## Current lifecycle safeguards

Application readiness is coordinated per leadership epoch. The process is not
ready until it holds the Lease, has claimed and opened the state file, every
source finished its initial list, and configured delivery is running. A stale
callback from an earlier epoch must not restore readiness or clear a newer
failure.
Application readiness is coordinated per state lock epoch. The process is not
ready until it holds the state lock, has claimed and opened the state file,
every source finished its initial list, and configured delivery is running. A
stale callback from an earlier epoch must not restore readiness or clear a
newer failure.

Delivery generations have explicit `accepting`, `draining`, `stopped`, and
`failed` states. Reconfiguration publishes a new generation only after the old
Expand All @@ -858,8 +882,8 @@ generation replacement have separate completion signals.

The engine writes incidents after a decision and at least once a minute, and
once more when it stops. Every write passes the store's epoch claim; a saver
must not create detached background writes that can outlive shutdown or
leadership loss.
must not create detached background writes that can outlive shutdown or state
lock loss.

CRD and dynamic watcher generations own their discovery and informer goroutines.
Failure paths cancel and wait for those routines before retrying or replacing a
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ LABEL org.opencontainers.image.source="https://github.com/abahmed/kwatch" \
RUN apk add --no-cache ca-certificates && \
adduser -D -u 1000 kwatch
COPY --from=builder /build/kwatch /bin/kwatch
USER kwatch
# Numeric, so runAsNonRoot can be verified without runAsUser; it matches the
# chart's runAsUser and runAsGroup.
USER 1000:1000
ENTRYPOINT ["/bin/kwatch"]
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ verify-manifests:
$(HELM) lin 749E t deploy/chart && ./deploy/chart/test_helm.sh
./scripts/check-manifest-parity.sh
./scripts/check-release-consistency.sh
@command -v kubectl >/dev/null 2>&1 || { \
if [ "$${CI:-}" = true ]; then \
echo "kubectl is required in CI" >&2; exit 1; fi; \
echo "SKIP: kubectl is not installed (CI runs this check)"; \
exit 0; }; \
./scripts/test-require-kind-context.sh
./scripts/test-check-e2e-artifacts.sh

verify-scenarios:
./scripts/test-kind-scenarios.sh
Expand Down
Loading
Loading
0