Skip to content

WIP: feat(releaseinfo): add Prometheus metrics for mirror lookup instrumentation#9035

Open
ironcladlou wants to merge 1 commit into
openshift:mainfrom
ironcladlou:releaseinfo-metrics-instrumentation
Open

WIP: feat(releaseinfo): add Prometheus metrics for mirror lookup instrumentation#9035
ironcladlou wants to merge 1 commit into
openshift:mainfrom
ironcladlou:releaseinfo-metrics-instrumentation

Conversation

@ironcladlou

@ironcladlou ironcladlou commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Replace ad-hoc debug logging with Prometheus histograms and counters for release image mirror lookup duration, mutex contention, and per-mirror outcomes. Enable Go runtime mutex profiling at 20% sampling for passive contention visibility via pprof.

  • Telemeter: Not forwarded
  • Cardinality: Negligible. The histograms have no labels; the counter has one label with 4 bounded values. ~30 time series total
  • Dashboards/recording rules: No updates needed

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added Prometheus metrics to track release image mirror lookup performance, including lookup duration, mutex lock wait time, and outcome counts (hit, unavailable, error, fallback).
    • Enhanced instrumentation and logging during mirror scanning to improve observability of mirror behavior.
  • Performance / Diagnostics

    • Enabled mutex profiling for the operator manager to support performance investigations.
  • Bug Fixes

    • Improved fallback handling by resetting mirrored-image state earlier to ensure accurate fallback behavior tracking.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The releaseinfo package defines and registers Prometheus histograms for mirror lookup and mutex wait durations, plus a counter vector for lookup outcomes. The lookup path records timing, mirror hits, unavailable mirrors, errors, and fallback behavior. The operator enables Go mutex profiling with a fixed sampling fraction at the start of run.

Suggested reviewers: enxebre


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
No-Sensitive-Data-In-Logs ❌ Error Lookup logs print raw image and registryReplacement values, which can expose private registry/internal hostnames. Redact or omit registry/image identifiers in these log lines, or log only sanitized host hashes/labels.
✅ Passed checks (10 passed)
Check name Status Explanation
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.
Stable And Deterministic Test Names ✅ Passed No test files were changed, and the modified Go files contain no Ginkgo test titles.
Test Structure And Quality ✅ Passed No Ginkgo test files were added or modified in this PR; it only changes production code, so the test-quality checklist is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed Only metrics instrumentation and mutex profiling were added; no node selectors, affinity, tolerations, replica changes, or topology-dependent scheduling logic.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo tests were added; the PR only changes operator init and releaseinfo metrics/lookup code, with no IPv4-only or external connectivity test code.
No-Weak-Crypto ✅ Passed Touched files only add Prometheus metrics and mutex profiling; no MD5/SHA1/DES/RC4/3DES/ECB, custom crypto, or secret comparisons found.
Container-Privileges ✅ Passed Diff only touches Go code (mutex profiling + Prometheus metrics); no K8s/container manifests or securityContext fields were changed.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding Prometheus instrumentation for releaseinfo mirror lookup behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@openshift-ci
openshift-ci Bot requested review from enxebre and jparrill July 17, 2026 15:04
@openshift-ci

openshift-ci Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ironcladlou
Once this PR has been reviewed and has the lgtm label, please assign sjenning for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release and removed do-not-merge/needs-area labels Jul 17, 2026

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
hypershift-operator/main.go (1)

248-248: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Name the mutex profile sampling rate constant. runtime.SetMutexProfileFraction(5) should use a package-level constant, e.g. mutexProfileSamplingRate, so the profiling policy is explicit and easier to review.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@hypershift-operator/main.go` at line 248, Define a package-level constant for
the mutex profiling sampling rate and update the runtime.SetMutexProfileFraction
call to use it instead of the literal 5. Name the constant
mutexProfileSamplingRate or an equivalent descriptive symbol.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@hypershift-operator/main.go`:
- Line 248: Define a package-level constant for the mutex profiling sampling
rate and update the runtime.SetMutexProfileFraction call to use it instead of
the literal 5. Name the constant mutexProfileSamplingRate or an equivalent
descriptive symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 47511dd8-d90b-4695-9cf8-5e2e995f5dd9

📥 Commits

Reviewing files that changed from the base of the PR and between 85c46e8 and 8fb20a7.

📒 Files selected for processing (3)
  • hypershift-operator/main.go
  • support/releaseinfo/metrics.go
  • support/releaseinfo/registry_image_content_policies.go

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.12%. Comparing base (9aeb1f3) to head (d68500c).
⚠️ Report is 161 commits behind head on main.

Files with missing lines Patch % Lines
...ort/releaseinfo/registry_image_content_policies.go 62.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9035      +/-   ##
==========================================
+ Coverage   43.28%   44.12%   +0.83%     
==========================================
  Files         771      780       +9     
  Lines       95503    98091    +2588     
==========================================
+ Hits        41335    43279    +1944     
- Misses      51284    51777     +493     
- Partials     2884     3035     +151     
Files with missing lines Coverage Δ
hypershift-operator/main.go 0.00% <ø> (ø)
support/releaseinfo/metrics.go 100.00% <100.00%> (ø)
...ort/releaseinfo/registry_image_content_policies.go 77.50% <62.50%> (-1.92%) ⬇️

... and 82 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.25% <78.57%> (+1.57%) ⬆️
cpo-hostedcontrolplane 46.27% <ø> (+0.95%) ⬆️
cpo-other 45.22% <ø> (+0.11%) ⬆️
hypershift-operator 54.13% <ø> (+0.54%) ⬆️
other 33.59% <ø> (+1.89%) ⬆️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jparrill jparrill 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.

Dropped some comments. Thanks!

p.lock.Lock()
defer p.lock.Unlock()
lockWaitDuration.Observe(time.Since(start).Seconds())
defer func() { lookupDuration.Observe(time.Since(start).Seconds()) }()

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.

Both lockWaitDuration and lookupDuration use the same start timestamp, so lookupDuration includes the time spent waiting for the mutex. That makes it hard to tell whether high latency comes from lock contention or from slow registry I/O — which is exactly what having two separate metrics should help with.

Would it make sense to capture a second timestamp after the lock is acquired? If the intent is to measure total wall-clock time (wait + work), that's fine too — but then the metric name/help should say "total duration including lock wait" so it's unambiguous.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I meant for it to be wall clock time, you could still get the granular time by subtracting lock duration from lookup duration. Could add another granular timing. In either case the docs can be updated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

docs updated

// Verify mirror image availability.
if _, _, err = repoSetup(ctx, replacedImage, pullSecret); err == nil {
p.mirroredReleaseImage = replacedImage
mirrorLookupTotal.WithLabelValues("mirror_hit").Inc()

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.

nit: these label values are free-form strings with no compile-time protection — a typo like "mirror_Hit" would silently create a new series. Might be worth pulling them into constants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Constants added


func run(ctx context.Context, opts *StartOptions, log logr.Logger) error {
log.Info("Starting hypershift-operator-manager", "version", supportedversion.String())
runtime.SetMutexProfileFraction(5)

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.

This enables mutex profiling for the entire HO process (not just the releaseinfo path), always on, with no opt-out. Totally reasonable for passive pprof visibility, but without a comment it reads like a debugging leftover that someone might remove later. A one-liner explaining the intent would help.

Also — minor thing — the PR description says "20% sampling" but it might be worth noting that 5 means "1 in 5 contention events sampled," just so future readers don't have to look it up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added comment

@ironcladlou
ironcladlou force-pushed the releaseinfo-metrics-instrumentation branch from 8fb20a7 to c4bd5a3 Compare July 17, 2026 15:46
…tation

Replace ad-hoc debug logging with Prometheus histograms and counters
for release image mirror lookup duration, mutex contention, and
per-mirror outcomes. Enable Go runtime mutex profiling at 20% sampling
for passive contention visibility via pprof.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ironcladlou
ironcladlou force-pushed the releaseinfo-metrics-instrumentation branch from c4bd5a3 to d68500c Compare July 17, 2026 15:49
@ironcladlou ironcladlou changed the title feat(releaseinfo): add Prometheus metrics for mirror lookup instrumentation WIP: feat(releaseinfo): add Prometheus metrics for mirror lookup instrumentation Jul 17, 2026
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 17, 2026
@openshift-ci

openshift-ci Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@ironcladlou: all tests passed!

Full PR test history. Your PR dashboard.

Details

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants