Repository navigation
go.d/k8s_state: remove only the deleted object's charts - #24402
Conversation
Chart removal and the pod node-label update matched chart IDs by an open prefix, so deleting pod "x-1" (or node, deployment, cronjob) also obsoleted every chart of a live "x-10", which never came back. Match the object's own IDs only: "<kind>_<id>." and, for pods, "pod_<id>_container_". Chart IDs, contexts and labels are unchanged.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
All reported issues were addressed across 2 files
You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
Architecture diagram
sequenceDiagram
participant K8s as K8s API Server
participant Collector as k8s_state Collector
participant Charts as Chart Store
participant Discoverers as Discoverers (nodes, pods, deployments, cronjobs)
Note over K8s,Discoverers: Runtime Object Lifecycle
loop Discover resources
Discoverers->>K8s: Watch/informers for kinds
K8s-->>Discoverers: Events (create/update/delete)
end
Note over Collector,Charts: Object deletion handling
Discoverers->>Collector: Object deleted (node/pod/deployment/cronjob)
Collector->>Charts: Iterate all charts
loop For each chart in store
Collector->>Collector: isObjectChart(chartID, kind, id)
alt Chart matches exact object ownership
Collector->>Charts: MarkObsolete + MarkNotCreated
else Chart belongs to sibling object (e.g., "x-10")
Collector->>Charts: Leave chart active
end
end
Note over Collector,Charts: Pod node-label update
Discoverers->>Collector: Pod scheduled (node assignment changed)
Collector->>Charts: Iterate pod charts
loop For each chart
Collector->>Collector: isObjectChart(chartID, "pod", id)
alt Only charts of the scheduled pod match
Collector->>Charts: Update node label dimension
Collector->>Charts: MarkNotCreated
else Charts of other pods (e.g., "x-10")
Collector->>Charts: No modification
end
end
Note over Collector,Charts: Chart ID matching logic
Note over Collector: isObjectChart checks prefix + "." boundary,<br/>or "pod_" + container suffix for pods
Note over Collector: Ensures "x-1" does not match "x-10" charts
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
|
(cherry picked from commit 877d2a7)
(cherry picked from commit 877d2a7)



Summary
When
k8s_statesaw a node, pod, deployment or cronjob deleted, it marked obsolete every chart whose ID merely started with the deleted object's ID. Deleting podweb-1also removed all charts of the running podsweb-10..web-19(same forworker-1/worker-10nodes,backup/backup-dbcronjobs, etc.). Charts are only added for new objects, so the live object's charts never came back until it was recreated or the agent restarted. Alerts on them (e.g.k8s_state_deployment_condition_available,k8s_state_cronjob_last_execution_failed) silently stopped.The pod node-label update had the same open prefix: scheduling
web-1rewrote the node label onweb-10's charts.Fix
One helper,
isObjectChart, matches only the object's own chart IDs:<kind>_<id>.and, for pods,pod_<id>_container_. Kubernetes names cannot contain_, so this boundary is exact. Used by all four removal paths and the node-label update.No chart ID, context, dimension, label or alert definition changes. Visible effect: charts and alerts of such live objects keep running, so users may now get notifications they were silently missing.
Not changed:
replaceDotsstill mapsweb.1andweb-1to the same chart ID; fixing that would change chart IDs.Tests
x-1keeps every chart of livex-10and obsoletes all ofx-1's (node, pod incl. container charts, deployment, cronjob); expected sets come from collectors that saw only one object.x-1changes the node label only on its own charts.go test -race,go vet,gofmtclean.Summary by CodeRabbit