8000 🔢 Say how many replicas are ready in early roll-ups by abahmed · Pull Request #624 · 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/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
persist-credentials: false

- name: Install Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
# Read from go.mod so the CI Go version can never drift from the repo.
go-version-file: go.mod
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
persist-credentials: false

- name: Install Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod

Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:

- name: Install Go
if: steps.run.outputs.build == 'true'
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod

Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:
# GitHub release downloads, which can fail with 504s.
- name: Set up Go for Kind
if: steps.changes.outputs.chart == 'true'
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ jobs:
persist-credentials: false

- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod

Expand Down Expand Up @@ -303,7 +303,7 @@ jobs:
# kind comes from the Go module proxy (checksum-verified), not
# GitHub release downloads, which can fail with 504s.
- name: Set up Go for Kind
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:

# A tagged build must not ship without the production license key.
- name: Install Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Install Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
persist-credentials: false

- name: Install Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Without --platform=$BUILDPLATFORM this stage runs under QEMU for arm64,
# arm/v7 and arm/v6, which is what made a release build take over an hour.
# Go cross-compiles fine and CGO is off, so emulation buys nothing.
FROM --platform=$BUILDPLATFORM golang:1.27.4-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS builder
FROM --platform=$BUILDPLATFORM golang:1.27.4-alpine@sha256:70bd7ddea8b6cbe5d6943cde279d6b67feb10cc924fb9100d1d8757c1575b280 AS builder

ARG RELEASE_VERSION="dev"
ARG GIT_COMMIT="none"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.27.4

require (
github.com/bwmarrin/discordgo v0.29.0
github.com/chromedp/cdproto v0.160.5
github.com/chromedp/cdproto v0.160.8
github.com/chromedp/chromedp v0.24.0
github.com/go-logr/logr v1.4.4
github.com/google/go-github/v55 v55.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/bwmarrin/discordgo v0.29.0 h1:FmWeXFaKUwrcL3Cx65c20bTRW+vOb6k8AnaP+Eg
github.com/bwmarrin/discordgo v0.29.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chromedp/cdproto v0.160.5 h1:fdN6joxIAiiXYOr/VZoD3H/sPxC/0TKLTqOSbvYpZ3c=
github.com/chromedp/cdproto v0.160.5/go.mod h1:h68JaIuFr9o3yiayxEYhBdvaxgYO3shDrPSYhNlyfu0=
github.com/chromedp/cdproto v0.160.8 h1:4PfdGeKLRU/q8Rn9kIEmGEUnN4I+Kcf/8jkMLDFUIwA=
github.com/chromedp/cdproto v0.160.8/go.mod h1:h68JaIuFr9o3yiayxEYhBdvaxgYO3shDrPSYhNlyfu0=
github.com/chromedp/chromedp v0.24.0 h1:bARawUSS5gshTOsNbFz2YFJyjaQCt7IHcW6E2mqDABQ=
github.com/chromedp/chromedp v0.24.0/go.mod h1:cz9BPo2oR1YBCu7e+KTdO+7uMvTTuEYh11fErlxdCuQ=
github.com/cloudflare/circl v1.6.5 h1:O64F26HEqNhznd/hrC5KZXVKYuKM2rx4deZDTc4ihQA=
Expand Down
4 changes: 4 additions & 0 deletions internal/incident/decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ type Facts struct {
Grouping *Grouping
Split *ReplicaSplit
Users *Users
// Replicas is how many replicas the root workload has ready, set
// on an announcement or an update; nil when unknown or none is
// short (ReplicaCountOf).
Replicas *ReplicaCount
}

// WakeContext is a cluster wake-up, as a message mentions it: the
Expand Down
25 changes: 25 additions & 0 deletions internal/incident/replica_count.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package incident

import "github.com/abahmed/kwatch/internal/inventory"

// ReplicaCount is how many replicas a workload wants and how many of
// them are ready, as the model read at the time of a message.
type ReplicaCount struct {
Desired int
Ready int
}

// ReplicaCountOf reads the replica counts of the workload p is rooted
// at. nil when the model is nil, the root is not a workload the model
// holds, or it has no replicas short, so a message never states a count
// that says nothing.
func ReplicaCountOf(model inventory.Reader, p Incident) *ReplicaCount {
if model == nil {
return nil
}
desired, ready, ok := ReplicasOf(model, p.Root)
if !ok || desired <= 0 || ready >= desired {
return nil
}
return &ReplicaCount{Desired: int(desired), Ready: int(ready)}
}
2 changes: 1 addition & 1 deletion internal/notification/compose/lead.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func subjectWithState(f caseFacts, subject inventory.EntityID) string {
// Another object's finding is not subject's state.
return name + " " + f.othersState(subject)
}
return name + " " + leadState(f)
return name + " " + withReplicaCount(f, leadState(f))
}

// causePhrase states the cause relative to the subject: "node n1 is low
Expand Down
4 changes: 4 additions & 0 deletions internal/notification/compose/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type caseFacts struct {
causeState incident.CauseState
// reach is where users reach what is affected, set by the pipeline.
reach []incident.Reach
// replicas is how many replicas the root workload has ready, when
// known, set by the pipeline.
replicas *incident.ReplicaCount
// gathered are the checks whose read came back ok, and confirmed
// says why gathered evidence proves the cause (investigate confirms
// only an incident with a cause or a failing root); both empty in
Expand Down Expand Up @@ -73,6 +76,7 @@ func gatherFacts(d incident.Decision, now time.Time, fix *inventory.Cha 10BC8 nge,
evidence: d.Facts.Evidence, changes: d.Facts.Changes,
window: d.Facts.Window, wake: d.Facts.Wake,
causeState: d.Facts.Cause, reach: d.Facts.Reach,
replicas: d.Facts.Replicas,
gathered: incident.GatheredChecks(d.Facts.Report)}
if c := d.Facts.Correlation; c != nil {
f.confirmed = c.Confirmed
Expand Down
31 changes: 31 additions & 0 deletions internal/notification/compose/replica_count.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package compose

import (
"strconv"
"strings"

"github.com/abahmed/kwatch/internal/inventory/kube"
)

const notReadyFor = "has not been ready for "

// withReplicaCount says how many replicas are ready when the lead is a
// pod that has not been ready and the pipeline knows the workload's
// counts: "has had no ready replicas (0 of 2) for three minutes". The
// wait stays the pod's own. Without the counts, or for any other state,
// the state is returned as it is.
func withReplicaCount(f caseFacts, state string) string {
wait, ok := strings.CutPrefix(state, notReadyFor)
if !ok || f.replicas == nil || f.lead.Entity.Kind != kube.KindPod ||
f.lead.Entity == f.p.Root {
return state
}
ready, desired := strconv.Itoa(f.replicas.Ready),
strconv.Itoa(f.replicas.Desired)
if f.replicas.Ready == 0 {
return "has had no ready replicas (0 of " + desired + ") for " +
wait
}
return "has had only " + ready + " of " + desired +
" replicas ready for " + wait
}
45 changes: 45 additions & 0 deletions internal/notification/compose/replica_count_test.go
10BC8
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package compose

import (
"testing"

"github.com/abahmed/kwatch/internal/detection"
"github.com/abahmed/kwatch/internal/incident"
"github.com/abahmed/kwatch/internal/inventory"
"github.com/abahmed/kwatch/internal/inventory/kube"
)

func TestWithReplicaCount(t *testing.T) {
root := inventory.EntityID{Kind: kube.KindDeployment,
Namespace: "billing", Name: "api"}
pod := inventory.EntityID{Kind: kube.KindPod,
Namespace: "billing", Name: "api-1"}
state := "has not been ready for three minutes"
cases := []struct {
name string
count *incident.ReplicaCount
lead inventory.EntityID
state string
want string
}{
{"none ready", &incident.ReplicaCount{Desired: 2}, pod, state,
"has had no ready replicas (0 of 2) for three minutes"},
{"some ready", &incident.ReplicaCount{Desired: 3, Ready: 1}, pod,
state, "has had only 1 of 3 replicas ready for three minutes"},
{"unknown count", nil, pod, state, state},
{"other state", &incident.ReplicaCount{Desired: 2}, pod,
"keeps crashing", "keeps crashing"},
{"not a pod", &incident.ReplicaCount{Desired: 2}, root, state,
state},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
f := caseFacts{p: incident.Incident{Root: root},
lead: detection.Finding{Entity: tc.lead},
replicas: tc.count}
if got := withReplicaCount(f, tc.state); got != tc.want {
t.Errorf("got %q, want %q", got, tc.want)
}
})
}
}
3 changes: 3 additions & 0 deletions internal/pipeline/announcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func (a *announcer) announce(
a.collect.NoteQuietResolves(quiet)
a.collect.NoteDecisions(decisions)
decisions = a.inScope(decisions)
for i := range decisions {
decisions[i] = a.withReplicas(decisions[i])
}
c := a.collect
decisions, summarised := a.collected(ctx, now, "startup", decisions,
c.CollectStartup)
Expand Down
11 changes: 11 additions & 0 deletions internal/pipeline/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,16 @@ func (a *announcer) withShape(d incident.Decision) incident.Decision {
d.Facts.Grouping = incident.GroupingOf(a.history, d.Incident)
d.Facts.Split = incident.ReplicaSplitOf(a.history, d.Incident)
d.Facts.Users = incident.UsersOf(a.history, d.Incident)
return a.withReplicas(d)
}

// withReplicas adds how many replicas of the root workload are ready, so
// a title in a roll-up, a summary or a digest can say the scale of the
// problem as the model reads it now.
func (a *announcer) withReplicas(d incident.Decision) incident.Decision {
if d.Action == incident.Resolve || a.history == nil {
return d
}
d.Facts.Replicas = incident.ReplicaCountOf(a.history, d.Incident)
return d
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
10:12:15 settled
🟠 api in shop (prod-eu-1) has not been ready for eight minutes. Cause not found yet: its registry is healthy and unchanged. The failing pods run on nodes n1 and n2, which joined 3 minutes before they began failing. Service api can't serve traffic. To see the object's state and events, run kubectl describe deployment api -n shop
🟠 api in shop (prod-eu-1) has not been ready for eight minutes.
| 🟠 **api** in **shop** (**prod-eu-1**) has not been ready for eight minutes.
🟠 api in shop (prod-eu-1) has had no ready replicas (0 of 2) for eight minutes. Cause not found yet: its registry is healthy and unchanged. The failing pods run on nodes n1 and n2, which joined 3 minutes before they began failing. Service api can't serve traffic. To see the object's state and events, run kubectl describe deployment api -n shop
🟠 api in shop (prod-eu-1) has had no ready replicas (0 of 2) for eight minutes.
| 🟠 **api** in **shop** (**prod-eu-1**) has had no ready replicas (0 of 2) for eight minutes.
| Cause not found yet: its registry is healthy and unchanged.
| The failing pods run on nodes n1 and n2, which joined 3 minutes before they began failing.
| Service **api** can't serve traffic.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
10:05:15 settled
🟠 pay in shop (prod-eu-1) has not been ready for three minutes. Cause not found yet: its node and registry are healthy and unchanged. To see the pods' state and events, run kubectl describe pods pay- -n shop
🟠 pay in shop (prod-eu-1) has not been ready for three minutes.
| 🟠 **pay** in **shop** (**prod-eu-1**) has not been ready for three minutes.
🟠 pay in shop (prod-eu-1) has had only 1 of 2 replicas ready for three minutes. Cause not found yet: its node and registry are healthy and unchanged. To see the pods' state and events, run kubectl describe pods pay- -n shop
🟠 pay in shop (prod-eu-1) has had only 1 of 2 replicas ready for three minutes.
| 🟠 **pay** in **shop** (**prod-eu-1**) has had only 1 of 2 replicas ready for three minutes.
| Cause not found yet: its node and registry are healthy and unchanged.
| To see the pods' state and events, run
| ```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
10:04:15 settled
🟠 web in shop (prod-eu-1) has not been ready for three minutes. Cause not found yet: its node and registry are healthy and unchanged. It runs a single replica. To see the pods' state and events, run kubectl describe pods web- -n shop
🟠 web in shop (prod-eu-1) has not been ready for three minutes.
| 🟠 **web** in **shop** (**prod-eu-1**) has not been ready for three minutes.
🟠 web in shop (prod-eu-1) has had no ready replicas (0 of 1) for three minutes. Cause not found yet: its node and registry are healthy and unchanged. It runs a single replica. To see the pods' state and events, run kubectl describe pods web- -n shop
🟠 web in shop (prod-eu-1) has had no ready replicas (0 of 1) for three minutes.
| 🟠 **web** in **shop** (**prod-eu-1**) has had no ready replicas (0 of 1) for three minutes.
| Cause not found yet: its node and registry are healthy and unchanged.
| It runs a single replica.
| To see the pods' state and events, run
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
10:09:15 settled
🟠 coredns in kube-system (prod-eu-1) has not been ready for three minutes. Cause not found yet: its node and registry are healthy and unchanged. To see the pods' state and events, run kubectl describe pods coredns- -n kube-system
🟠 coredns in kube-system (prod-eu-1) has not been ready for three minutes.
| 🟠 **coredns** in **kube-system** (**prod-eu-1**) has not been ready for three minutes.
🟠 coredns in kube-system (prod-eu-1) has had only 1 of 2 replicas ready for three minutes. Cause not found yet: its node and registry are healthy and unchanged. To see the pods' state and events, run kubectl describe pods coredns- -n kube-system
🟠 coredns in kube-system (prod-eu-1) has had only 1 of 2 replicas ready for three minutes.
| 🟠 **coredns** in **kube-system** (**prod-eu-1**) has had only 1 of 2 replicas ready for three minutes.
| Cause not found yet: its node and registry are healthy and unchanged.
| To see the pods' state and events, run
| ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| kubectl logs deploy/invoices -c app -n billing --previous
| ```
10:05:30 material change
🟠 kube-proxy in kube-system (prod-eu-1) has not been ready for three minutes. The last run of container app in pod invoices-bcf7f095-c in billing lasted ten seconds; two restarts since the pod was created one hour ago.
🟠 kube-proxy in kube-system (prod-eu-1) has not been ready for three minutes.
| 🟠 **kube-proxy** in **kube-system** (**prod-eu-1**) has not been ready for three minutes.
🟠 kube-proxy in kube-system (prod-eu-1) has had only 2 of 3 replicas ready for three minutes. The last run of container app in pod invoices-bcf7f095-c in billing lasted ten seconds; two restarts since the pod was created one hour ago.
🟠 kube-proxy in kube-system (prod-eu-1) has had only 2 of 3 replicas ready for three minutes.
| 🟠 **kube-proxy** in **kube-system** (**prod-eu-1**) has had only 2 of 3 replicas ready for three minutes.
| The last run of container app in pod invoices-bcf7f095-c in **billing** lasted ten seconds; two restarts since the pod was created one hour ago.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
| kubectl logs ds/logship -c app -n observability --previous
| ```
10:16:15 settled
🟠 cart in shop (prod-eu-1) has not been ready for three minutes. Cause not found yet: its node and registry are healthy and unchanged. It runs a single replica. To see the object's state and events, run kubectl describe deployment cart -n shop
🟠 cart in shop (prod-eu-1) has not been ready for three minutes.
| 🟠 **cart** in **shop** (**prod-eu-1**) has not been ready for three minutes.
🟠 cart in shop (prod-eu-1) has had no ready replicas (0 of 1) for three minutes. Cause not found yet: its node and registry are healthy and unchanged. It runs a single replica. To see the object's state and events, run kubectl describe deployment cart -n shop
🟠 cart in shop (prod-eu-1) has had no ready replicas (0 of 1) for three minutes.
| 🟠 **cart** in **shop** (**prod-eu-1**) has had no ready replicas (0 of 1) for three minutes.
| Cause not found yet: its node and registry are healthy and unchanged.
| It runs a single replica.
| To see the object's state and events, run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| kubectl logs deploy/invoices -c app -n billing --previous
| ```
10:08:30 material change
🟠 cni-agent in kube-system (prod-eu-1) has not been ready for three minutes. The last run of container app in pod invoices-bcf7f095-b in billing lasted ten seconds; two restarts since the pod was created about one hour ago.
🟠 cni-agent in kube-system (prod-eu-1) has not been ready for three minutes.
| 🟠 **cni-agent** in **kube-system** (**prod-eu-1**) has not been ready for three minutes.
🟠 cni-agent in kube-system (prod-eu-1) has had only 2 of 3 replicas ready for three minutes. The last run of container app in pod invoices-bcf7f095-b in billing lasted ten seconds; two restarts since the pod was created about one hour ago.
🟠 cni-agent in kube-system (prod-eu-1) has had only 2 of 3 replicas ready for three minutes.
| 🟠 **cni-agent** in **kube-system** (**prod-eu-1**) has had only 2 of 3 replicas ready for three minutes.
| The last run of container app in pod invoices-bcf7f095-b in **billing** lasted ten seconds; two restarts since the pod was created about one hour ago.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
| kubectl describe node n1
| ```
10:07:10 cause revised
🔴 Cause changed (earlier: node n1): cart in shop (prod-eu-1) has not been ready for three minutes. Node n1 has recovered; cart in shop (prod-eu-1) still has two open failures.
🔴 Cause changed (earlier: node n1): cart in shop (prod-eu-1) has not been ready for three minutes.
| 🔴 Cause changed (earlier: node n1): **cart** in **shop** (**prod-eu-1**) has not been ready for three minutes.
🔴 Cause changed (earlier: node n1): cart in shop (prod-eu-1) has had only 1 of 2 replicas ready for three minutes. Node n1 has recovered; cart in shop (prod-eu-1) still has two open failures.
🔴 Cause changed (earlier: node n1): cart in shop (prod-eu-1) has had only 1 of 2 replicas ready for three minutes.
| 🔴 Cause changed (earlier: node n1): **cart** in **shop** (**prod-eu-1**) has had only 1 of 2 replicas ready for three minutes.
| Node n1 has recovered; **cart** in **shop** (**prod-eu-1**) still has two open failures.
10:17:40 healthy for 3m0s
✅ cart in shop (prod-eu-1) is healthy again. It was failing for ten minutes and recovered on its own.
Expand Down
Loading
Loading
0