Skip to content

DEVOPS-2883: Add statefulset checker - #50

Merged
bio-boris merged 7 commits into
masterfrom
add-statefulset-checker
Oct 2, 2026
Merged

bio-boris merged 7 commits into
masterfrom
add-statefulset-checker

Conversation

@bio-boris

@bio-boris bio-boris commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a new CheckMK local check for StatefulSet readiness and rollout health
  • report CRIT when replicas are not ready, a rollout is incomplete, or a scale-down is stuck mid-way (replicas != desired)
  • handle missing microk8s kubectl, kubectl errors, and malformed/unexpected JSON as UNKNOWN

Testing

  • python3 -m py_compile lakehouse/statefulset_checker
  • lakehouse/statefulset_checker (normal run against a live cluster)
  • Malformed kubectl JSON shape (e.g. [], null, object without items): confirmed get_statefulsets() now exits cleanly with UNKNOWN: unexpected kubectl JSON shape instead of raising AttributeError
  • Stuck scale-down (status.replicas still above spec.replicas, e.g. desired=5 / replicas=6 / ready=6): confirmed now reports CRIT ... replicas 6/5 instead of passing silently

Deployment

  • Deploy to: /usr/lib/check_mk_agent/local/statefulset_checker
  • Make executable: chmod +x /usr/lib/check_mk_agent/local/statefulset_checker
  • Status mapping: 0 (OK) all StatefulSets fully ready and deployed, 2 (CRIT) missing ready replicas / incomplete rollout / stuck scale-down, 3 (UNKNOWN) kubectl or parse error

Related: DEVOPS-2883 — prod MinIO outage that exposed the monitoring gap this check addresses (Service-level health checks masked a single downed StatefulSet replica).

Copilot AI lite review requested due to automatic review settings September 22, 2026 17:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Moderate correctness and failure-handling issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds a CheckMK local check for Kubernetes StatefulSet readiness and rollout health.

Changes:

  • Queries StatefulSets via microk8s kubectl.
  • Reports readiness and rollout failures as CRIT.
  • Handles command, timeout, and JSON failures as UNKNOWN.
File Summary
lakehouse/​statefulset_checker Implements StatefulSet collection, validation, health checks, and CheckMK output. Unresolved issues remain around service ID collisions, malformed JSON, scale-down detection, and executable errors.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lakehouse/statefulset_checker Outdated
Comment thread lakehouse/statefulset_checker Outdated
@bio-boris bio-boris changed the title Add statefulset checker DEVOPS-2883: Add statefulset checker Sep 22, 2026
…downs

- get_statefulsets() now validates the decoded payload is a dict with a
  list-valued items field before use, instead of calling .get() on
  whatever json.loads() returns (a bare list or null would previously
  raise instead of hitting the advertised UNKNOWN path).
- service_line() now flags replicas != desired instead of only
  replicas < desired, so a StatefulSet stuck mid-scale-down (status.replicas
  still above spec.replicas) reports CRIT instead of passing silently.

Addresses Copilot review comments on PR #50.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Nonzero start ordinals are calculated incorrectly, and empty clusters emit no monitorable service.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Account for StatefulSet ordinal start when calculating rollout updates

lakehouse/​statefulset_checker:67

The partition is an absolute pod ordinal, but this calculation assumes ordinals always begin at zero. For a StatefulSet with spec.ordinals.start: 10, three replicas, and partition 11, pods 11 and 12 must be updated, while this returns zero and can report the rollout OK without either update. Account for spec.ordinals.start when deriving the expected count.

Comment thread lakehouse/statefulset_checker
bio-boris and others added 2 commits September 22, 2026 17:14
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…d rollout detection

Address code review findings: pipe-separate perfdata metrics so Checkmk
parses all of them, stop collapsing '-' into the service-name separator
(which could collide distinct namespace/name pairs), emit an OK roll-up
when no StatefulSets exist, catch OSError broadly around the kubectl
call, and detect incomplete rollouts via currentRevision/updateRevision
instead of hand-rolled partition math.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Nested malformed JSON can still crash, and partitioned rolling updates incorrectly remain CRIT.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Validate item and nested map shapes before dereferencing

lakehouse/​statefulset_checker:52

The shape check stops at the outer items list. Inputs such as {"items":[null]} or an item with "metadata": null pass this guard and then raise AttributeError in main()/service_line() instead of producing the promised UNKNOWN result. Validate each item and the nested maps that are dereferenced before returning the list.

Comment thread lakehouse/statefulset_checker Outdated
Co-authored-by: bio-boris <1258634+bio-boris@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Non-object StatefulSet entries can still cause an uncaught exception instead of an UNKNOWN result.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Validate list entries before sorting to prevent AttributeError

lakehouse/​statefulset_checker:50

The shape check still accepts non-object entries such as {"items":[null]}. main() then calls item.get(...) while sorting and raises AttributeError, so this unexpected JSON bypasses the promised UNKNOWN result. Validate every list entry before returning it.

@kkellerlbl

Copy link
Copy Markdown
Member

LGTM. It might be cleaner to use the native kubernetes Python library instead of calling out to a shell, but it's probably not worth the effort.

@bio-boris
bio-boris merged commit 79b19f4 into master Oct 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants