8000 πŸ›‘οΈ Improve production reliability and human-friendly alerts by abahmed Β· Pull Request #512 Β· 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
run: go test -race -tags integration ./internal/integration/...
- name: Upload coverage to Codecov
if: success() && github.ref == 'refs/heads/main'
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
Expand Down Expand Up @@ -133,15 +133,15 @@ jobs:
- 'go.sum'
- name: Set up QEMU
if: steps.changes.outputs.image == 'true'
uses: docker/setup-qemu-action@1f40c72289eff860ee54a304f1438e3cff362e0a # v4
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4
- name: Set up Docker Buildx
if: steps.changes.outputs.image == 'true'
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
# Same platform list as the release build. Nothing is pushed, and the
# cache is read-only so pull requests never add to the repo cache quota.
- name: Build every release platform
if: steps.changes.outputs.image == 'true'
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
context: .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Initialize CodeQL
uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
uses: github/codeql-action/init@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
uses: github/codeql-action/analyze@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
with:
category: "/language:${{matrix.language}}"
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ jobs:
echo "source_date_epoch=$(git show -s --format=%ct HEAD)" >> "$GITHUB_OUTPUT"

- name: Set up QEMU
uses: docker/setup-qemu-action@1f40c72289eff860ee54a304f1438e3cff362e0a # v4
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4

- name: Login to GitHub Container Registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
Expand All @@ -117,7 +117,7 @@ jobs:

- name: Build and push Docker image
id: build
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
context: .
Expand Down
37 changes: 34 additions & 3 deletions .github/workflows/scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ on:
required: false
default: "60m"
type: string
reported_ref:
description: "Release tag or commit to compare with main"
required: false
default: ""
type: string
reported_version:
description: "Optional human-readable reported Kwatch version"
required: false
default: ""
type: string
compare_with_main:
description: >-
Run the reported ref and latest main in separate Kind clusters
required: false
default: false
type: boolean

permissions:
contents: read
Expand All @@ -40,7 +56,7 @@ jobs:
scenarios:
name: Kind regression scenarios
runs-on: ubuntu-latest
timeout-minutes: 75
timeout-minutes: 150
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
Expand Down Expand Up @@ -88,11 +104,26 @@ jobs:
SCENARIO_SHARD: "${{ inputs.shard }}"
SOURCE_REF: main
SUITE_TIMEOUT: "${{ inputs.suite_timeout }}"
run: ./scripts/test-kind-scenarios.sh
REPORTED_REF: "${{ inputs.reported_ref }}"
REPORTED_VERSION: "${{ inputs.reported_version }}"
COMPARE_WITH_MAIN: "${{ inputs.compare_with_main }}"
run: |
set -euo pipefail
if [ "$COMPARE_WITH_MAIN" = true ]; then
test -n "$REPORTED_REF" || {
echo "reported_ref is required in compare mode" >&2
exit 2
}
./scripts/test-kind-scenarios-compare.sh
else
./scripts/test-kind-scenarios.sh
fi

- name: Upload scenario diagnostics
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
# actions/upload-artifact v7.0.1
uses: >-
actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: kwatch-e2e-${{ github.run_id }}
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ jobs:
publish_results: true

- name: Upload Scorecard results
uses: github/codeql-action/upload-sarif@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
uses: github/codeql-action/upload-sarif@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
with:
sarif_file: scorecard-results.sarif
4 changes: 2 additions & 2 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4

- name: Build local image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: .
load: true
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
verify-focused verify-fast verify-race verify-security \
verify-manifests verify-docs verify-operational coverage coverage-check

.PHONY: verify-scenarios verify-scenario
.PHONY: verify-scenarios verify-scenario verify-negative-regressions

# Binary names
BINARY_NAME := kwatch
Expand Down Expand Up @@ -49,6 +49,7 @@ help:
@echo " make verify-operational Run the disposable Kind production smoke test"
@echo " make verify-scenarios Run real-cluster regression scenarios"
@echo " make verify-scenario Run selected real-cluster scenarios"
@echo " make verify-negative-regressions Run safety regression checks"
@echo " make verify-docs Validate code-owned documentation metadata"
@echo " make verify-focused PKGS=... Validate only changed package groups"
@echo " make verify-catalogs Verify checked-in generated catalogs"
Expand Down Expand Up @@ -188,6 +189,9 @@ verify-scenarios:
verify-scenario:
./scripts/test-kind-scenarios.sh

verify-negative-regressions:
./scripts/test-negative-regressions.sh

verify-operational:
@command -v kind > /dev/null || { \
echo "kind is required; run this target in CI or a disposable cluster"; \
Expand Down
85 changes: 85 additions & 0 deletions cmd/kwatch-e2e-issue/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/abahmed/kwatch/test/e2e/issue"
)

type outputMetadata struct {
Namespace string `json:"namespace"`
Image string `json:"image"`
Source string `json:"source"`
}

func main() {
issueFile := flag.String("issue-file", "", "path to a GitHub issue body")
outputDir := flag.String(
"output-dir", "", "directory for reviewed reproduction data",
)
namespace := flag.String("namespace", "kwatch-issue", "scenario namespace")
image := flag.String("image", "kwatch-e2e-workload:test",
"already-loaded local workload image")
flag.Parse()
if err := run(*issueFile, *outputDir, *namespace, *image); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func run(issueFile, outputDir, namespace, image string) error {
if strings.TrimSpace(issueFile) == "" || strings.TrimSpace(outputDir) == "" {
return fmt.Errorf("--issue-file and --output-dir are required")
}
if err := issue.ValidateImage(image); err != nil {
return err
}
body, err := os.ReadFile(issueFile)
if err != nil {
return fmt.Errorf("read issue body: %w", err)
}
reproduction, err := issue.Parse(string(body))
if err != nil {
return fmt.Errorf("parse issue reproduction: %w", err)
}
resources, err := issue.SanitizeResources(
reproduction.ResourcesYAML, namespace, image,
)
if err != nil {
return fmt.Errorf("sanitize resources: %w", err)
}
if err := os.MkdirAll(outputDir, 0o750); err != nil {
return fmt.Errorf("create output directory: %w", err)
}
files := map[string][]byte{
"config.yaml": reproduction.ConfigYAML,
"resources.yaml": resources,
"expectation.txt": []byte(reproduction.Expectation + "\n"),
}
for name, content := range files {
path := filepath.Join(outputDir, name)
if err := os.WriteFile(path, content, 0o640); err != nil {
return fmt.Errorf("write %s: %w", name, err)
}
}
metadata, err := json.MarshalIndent(outputMetadata{
Namespace: namespace,
Image: image,
Source: "sanitized issue blocks; not executed",
}, "", " ")
if err != nil {
return fmt.Errorf("encode metadata: %w", err)
}
metadata = append(metadata, '\n')
if err := os.WriteFile(
filepath.Join(outputDir, "metadata.json"), metadata, 0o640,
); err != nil {
return fmt.Errorf("write metadata: %w", err)
}
return nil
}
32 changes: 32 additions & 0 deletions cmd/kwatch-e2e-sanitize/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"
"io"
"os"

"github.com/abahmed/kwatch/internal/message"
)

const maxArtifactInputBytes = 32 << 20

func main() {
data, err := io.ReadAll(io.LimitReader(
os.Stdin, maxArtifactInputBytes+1,
))
if err != nil {
_, _ = os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
if len(data) > maxArtifactInputBytes {
_, _ = os.Stderr.WriteString(fmt.Sprintf(
"artifact exceeds %d-byte limit\n", maxArtifactInputBytes,
))
os.Exit(1)
}
_, err = os.Stdout.WriteString(message.RedactEvidence(string(data)))
if err != nil {
_, _ = os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
8 changes: 8 additions & 0 deletions deploy/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: KWATCH_LEADER_ELECTION_NAME
value: {{ printf "%s-leader" (include "kwatch.fullname" .) | quote }}
- name: GOMEMLIMIT
Expand Down
5 changes: 5 additions & 0 deletions deploy/chart/templates/kwatchconfig-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ spec:
type: boolean
includeLogs:
type: boolean
message:
type: object
properties:
includePrivateLogAddresses:
type: boolean
severityByReason:
type: object
additionalProperties:
Expand Down
1 change: 1 addition & 0 deletions deploy/config-catalog.meta.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ maxRecentLogLines|Alerts|Maximum recent log lines attached to an incident.|activ
containerRestartThreshold|Alerts|Alert when a container reaches this cumulative restart count; zero disables it.|active|
includeEvents|Alerts|Include recent Kubernetes events in incident messages.|active|
includeLogs|Alerts|Include recent container logs in incident messages.|active|
message.includePrivateLogAddresses|Alerts|Keep private application addresses visible in evidence; credentials remain redacted.|active|
namespaces|Scope|Comma-separated namespaces to watch; leave empty to watch every namespace.|active|
namespaceSelector|Scope|Kubernetes label selector used to choose namespaces.|active|
reasons|Scope|Comma-separated event reasons to allow or exclude with a leading !.|active|
Expand Down
1 change: 1 addition & 0 deletions deploy/config-catalog.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ maxRecentLogLines|integer|50|Alerts|Maximum recent log lines attached to an inci
containerRestartThreshold|integer|0|Alerts|Alert when a container reaches this cumulative restart count; zero disables it.|active|
includeEvents|boolean|true|Alerts|Include recent Kubernetes events in incident messages.|active|
includeLogs|boolean|true|Alerts|Include recent container logs in incident messages.|active|
message.includePrivateLogAddresses|boolean|false|Alerts|Keep private application addresses visible in evidence; credentials remain redacted.|active|
namespaces|list|all|Scope|Comma-separated namespaces to watch; leave empty to watch every namespace.|active|
namespaceSelector|string|empty|Scope|Kubernetes label selector used to choose namespaces.|active|
reasons|list|all|Scope|Comma-separated event reasons to allow or exclude with a leading !.|active|
Expand Down
5 changes: 5 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ spec:
type: boolean
includeLogs:
type: boolean
message:
type: object
properties:
includePrivateLogAddresses:
type: boolean
severityByReason:
type: object
additionalProperties:
Expand Down
8 changes: 8 additions & 0 deletions deploy/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: KWATCH_LEADER_ELECTION_NAME
value: "kwatch-leader"
- name: GOMEMLIMIT
Expand Down
5 changes: 5 additions & 0 deletions docs/adr/0007-structured-persistence-migration-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ migrated. Current versions are left unchanged. Unsupported future versions and
malformed metadata are preserved and reported; they are never silently
overwritten.

Incident shard format v4 changes oversized incident storage: shards use a
checksum-based generation name and the manifest is the publication point.
Readers continue to accept format v3 fixed shard names. A rollback to a
pre-v4 binary requires a backup or reset of a v4 sharded incident snapshot.

## Consequences

Startup and health diagnostics can show the complete migration outcome rather
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ talks to the outside world.
| `app.caBundlePath` | πŸ“œ Path to a PEM CA bundle for outbound HTTP |
| `includeEvents` | πŸ“‹ Include K8s events in alerts (default: true). At most the 40 most recent are attached; older ones are summarised as `... N earlier event(s) omitted`. A churning pod can accumulate hundreds, and an unbounded list pushes the message past the chat provider's size limits, which loses the whole alert rather than just the surplus |
| `includeLogs` | πŸ“‹ Include container logs in alerts (default: true) |
| `message.includePrivateLogAddresses` | 🌐 Keep private application addresses visible in evidence; credentials remain redacted (default: false) |

## πŸ’“ Health checks

Expand Down
7 changes: 7 additions & 0 deletions docs/production-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ Kwatch state ConfigMaps. Migration failures are reported through the health
diagnostics and must be resolved or rolled back using the release notes before
restarting the workload.

Incident shard format v4 writes large snapshots as checksum-verified,
generation-named ConfigMaps. Shards are written first and the manifest is
published last, so an interrupted write leaves the prior generation restorable.
The loader accepts format v3's fixed shard names and migrates them on the next
successful save. Before rolling back to a binary that predates format v4,
retain a backup of `kwatch-incidents` and restore the pre-v4 incident data.

## Outages and capacity

Kubernetes API and provider outages are handled through bounded retries and
Expand Down
Loading
Loading
0