CMP-4373: Fix stale compliance_state metric and suite result#1263
CMP-4373: Fix stale compliance_state metric and suite result#1263Vincent056 wants to merge 2 commits into
Conversation
|
Skipping CI for Draft Pull Request. |
|
@Vincent056: This pull request references CMP-4373 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Vincent056 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The ComplianceSuite controller only refreshed the suite status and the compliance_state gauge on a scan *phase* transition. A rescan returns a scan to the same terminal phase (DONE) it started from, so when only the *result* changed (e.g. NON-COMPLIANT -> COMPLIANT after remediation) the phase-only check in updateScanStatus skipped the update, leaving the suite status, the ScanSettingBinding/Policy events, and the compliance_state gauge reporting a stale value until the operator was restarted. The gauge also lives only in the operator's in-memory registry and was written exclusively on that transition path and never cleaned up. As a result a live suite could be missing from metrics after a restart, and a deleted suite left a stale series firing alerts indefinitely. Fix: - Compare the scan result as well as the phase in updateScanStatus so a result change at an unchanged phase is no longer skipped. - Re-assert compliance_state from the authoritative suite result on every reconcile of a Done suite, so the gauge survives an operator restart. - Delete the compliance_state series for a suite in suiteDeleteHandler so deleted suites stop being reported. Add a regression test covering the result-changed-without-phase-change case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feb92d8 to
6a57249
Compare
|
🤖 To deploy this PR, run the following command: |
|
🤖 To deploy this PR, run the following command: |
Adds TestComplianceStateMetricSurvivesOperatorRestart (serial) covering the two deterministically reproducible facets of CMP-4373: - the compliance_state gauge is re-synced from the suite status after an operator restart (before the fix the in-memory series was lost), and - the series is removed when the suite is deleted (before the fix a stale NON-COMPLIANT value lingered). A NON-COMPLIANT platform scan is used so the gauge value (1) is distinguishable from an absent series, which parses as 0. Adds a RestartComplianceOperator framework helper used by the test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
🤖 To deploy this PR, run the following command: |
|
/test e2e-aws-parallel |
|
@Vincent056: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What
The ComplianceSuite controller could report a stale compliance result —
oc get compliancesuite/ thecompliance_operator_compliance_stategauge /ScanSettingBinding events showing NON-COMPLIANT while the underlying
ComplianceScan was COMPLIANT — until the operator pod was restarted. This is CMP-4373.
Root cause
updateScanStatusrefreshed the suite status (and therefore the metric and theevents derived from it) only on a scan phase transition:
A rescan returns a scan to the same terminal phase (
DONE) it started from, sowhen only the result changed (e.g. NON-COMPLIANT → COMPLIANT after
remediation) the phase-only check skipped the update and the suite result went stale.
Two related gauge-lifecycle gaps made it worse:
compliance_statelives only inthe operator's in-memory registry and was written exclusively on that transition
path and never cleaned up — so a live suite could be missing from metrics after
a restart, and a deleted suite left a stale series firing alerts indefinitely.
Fix
updateScanStatus.compliance_statefrom the authoritativesuite.Status.Resultonevery reconcile of a
Donesuite (survives operator restart).compliance_stateseries for a suite insuiteDeleteHandler.Tests
DONEmust update the suite result. Fails on
master, passes with this change.the released 1.9.1 image (stale value, absent-after-restart, ghost-on-delete) and
confirmed each is resolved by this build.
Jira
CMP-4373