Skip to content

ROX-35938: Add secured cluster cert expiry to expiry metrics tracker#21938

Draft
parametalol wants to merge 2 commits into
masterfrom
michael/ROX-35938-cluster-expiry
Draft

ROX-35938: Add secured cluster cert expiry to expiry metrics tracker#21938
parametalol wants to merge 2 commits into
masterfrom
michael/ROX-35938-cluster-expiry

Conversation

@parametalol

Copy link
Copy Markdown
Contributor

Description

The rox_central_cert_exp_hours custom Prometheus metric only reported
Central, Scanner, Scanner V4, and Central DB cert expiry — the four values in
the v1.GetCertExpiry_Component proto enum. Secured cluster (Sensor) cert
expiry was missing: it can't be one more enum value, since there can be any
number of secured clusters, and Central doesn't dial out to Sensor the way it
dials Scanner to check the cert.

This adds a synthetic SECURED_CLUSTER component (not a new proto enum
value) sourced from the already-existing storage.ClusterCertExpiryStatus
(populated whenever Sensor connects), with the cluster name carried in a new
Name label. Clusters that haven't connected yet (no cert data) are skipped.

Also switches the tracker from MakeGlobalTrackerBase to the scoped
MakeTrackerBase: Cluster is a SAC-scoped resource, and this tracker now
surfaces per-cluster data, so it needs to respect each caller's Access Scope
the same way the clusters/image_vulnerabilities/node_vulnerabilities
trackers in this package already do.

Fixes ROX-35938.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

  • Extended central/metrics/custom/expiry/tracker_test.go to cover a connected secured cluster (produces a SECURED_CLUSTER finding with the right Name and computed hours) and a never-connected one (produces no finding).
  • go build ./central/metrics/..., go vet ./central/metrics/custom/..., golangci-lint run ./central/metrics/custom/..., and go test ./central/metrics/custom/... all pass.

The rox_central_cert_exp_hours metric only covered the four values in
the v1.GetCertExpiry_Component proto enum (Central, Scanner, Scanner
V4, Central DB), so secured cluster Sensor cert expiry was invisible
to it. Sensor cert expiry can't be one more enum value since there can
be any number of secured clusters, so track() now also walks the
cluster datastore and emits a synthetic SECURED_CLUSTER component per
cluster (name carried in a new Name label), sourced from the existing
storage.ClusterCertExpiryStatus.

Switched the tracker from MakeGlobalTrackerBase to the scoped
MakeTrackerBase, since Cluster is a SAC-scoped resource and this
tracker now surfaces per-cluster data - matching the convention
already used by the clusters/image_vulnerabilities/node_vulnerabilities
trackers in this package.

Prompt: "open Jira bug for this problem, then create a branch with
michael/ROX-<jira number> prefix, commit the change", following up on
"I need secured cluster cert expiry. Can we add an artificial
'SECURED_CLUSTER' component to the tracker, and for secured clusters
add `name` label with the secured cluster name?"

Partially generated with the help of Claude Code.
Prompt: "PR", following the CHANGELOG.md convention already used for
ROX-35181 (another custom Prometheus metric addition).

Partially generated with the help of Claude Code.
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 103441c6-f4a6-4ad2-9985-2a4295ead22d

📥 Commits

Reviewing files that changed from the base of the PR and between 8c3809c and d1169e5.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • central/metrics/custom/expiry/labels.go
  • central/metrics/custom/expiry/tracker.go
  • central/metrics/custom/expiry/tracker_test.go
  • central/metrics/custom/runner.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Extended the rox_central_cert_exp_hours Prometheus metric to include secured-cluster (Sensor) certificate expiry.
    • Added the secured cluster name to the metric’s Name label.
    • Reports secured-cluster certificate status under the SECURED_CLUSTER component.

Walkthrough

The expiry metrics tracker now accepts a cluster datastore, reports Sensor certificate expiry for connected secured clusters using the SECURED_CLUSTER component and Name label, and is wired through the custom metrics runner with corresponding tests and changelog documentation.

Changes

Secured cluster expiry metrics

Layer / File(s) Summary
Expiry tracking and validation
central/metrics/custom/expiry/labels.go, central/metrics/custom/expiry/tracker.go, central/metrics/custom/expiry/tracker_test.go
The tracker reads cluster Sensor certificate status, emits SECURED_CLUSTER findings with cluster names and expiration hours, and tests connected versus never-connected clusters.
Runner wiring and release documentation
central/metrics/custom/runner.go, CHANGELOG.md
The runner supplies the cluster datastore to the expiry tracker, and the changelog describes the new metric output.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CustomMetricsRunner
  participant ExpiryTracker
  participant ExpiryService
  participant ClusterDataStore
  CustomMetricsRunner->>ExpiryTracker: collect expiry findings
  ExpiryTracker->>ExpiryService: read certificate expiry
  ExpiryTracker->>ClusterDataStore: WalkClusters
  ClusterDataStore-->>ExpiryTracker: Sensor certificate status
  ExpiryTracker-->>CustomMetricsRunner: SECURED_CLUSTER finding with Name
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding secured cluster cert expiry to the expiry metrics tracker.
Description check ✅ Passed The description follows the template closely and includes the change summary, docs, testing, and validation details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch michael/ROX-35938-cluster-expiry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Build Images Ready

Images are ready for commit d1169e5. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.12.x-583-gd1169e5d8e

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.87500% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.35%. Comparing base (8765bde) to head (d1169e5).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
central/metrics/custom/expiry/tracker.go 73.33% 5 Missing and 3 partials ⚠️
central/metrics/custom/expiry/labels.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21938      +/-   ##
==========================================
- Coverage   51.40%   51.35%   -0.05%     
==========================================
  Files        2857     2857              
  Lines      178776   178847      +71     
==========================================
- Hits        91899    91853      -46     
- Misses      78853    78954     +101     
- Partials     8024     8040      +16     
Flag Coverage Δ
go-unit-tests 51.35% <71.87%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant