Skip to content

metrics: add default_runtime#9870

Merged
openshift-merge-bot[bot] merged 1 commit into
cri-o:mainfrom
haircommander:default-runtime-metric
Apr 17, 2026
Merged

metrics: add default_runtime#9870
openshift-merge-bot[bot] merged 1 commit into
cri-o:mainfrom
haircommander:default-runtime-metric

Conversation

@haircommander

@haircommander haircommander commented Apr 7, 2026

Copy link
Copy Markdown
Member

we consistently need to find which runtime a user is using, and have talked about adding this for a while. Now's the time!

What type of PR is this?

/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

add `container_runtime_crio_default_runtime` metric to display which default runtime the node is configured to use

Summary by CodeRabbit

  • New Features

    • Added a default-runtime metric to the metrics endpoint; it is set at startup and updated on configuration reload to reflect the currently configured default runtime.
  • Tests

    • Added an integration test validating the default-runtime metric is exposed and reports value 1 for the configured runtime before and after reload.
  • Documentation

    • Updated metrics collectors docs to include the default-runtime collector.

@haircommander haircommander requested a review from mrunalp as a code owner April 7, 2026 18:31
@openshift-ci openshift-ci Bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Apr 7, 2026
@openshift-ci openshift-ci Bot requested review from QiWang19 and klihub April 7, 2026 18:31
@openshift-ci openshift-ci Bot added kind/feature Categorizes issue or PR as related to a new feature. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Apr 7, 2026
@openshift-ci

openshift-ci Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: haircommander

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

The pull request process is described 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 7, 2026
@haircommander

Copy link
Copy Markdown
Member Author

assisted by claude

@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a Prometheus gauge metric and collector to track CRI-O's configured default runtime, sets that metric at daemon startup and on SIGHUP reload, registers the metric conditionally with the collectors list, adds a Bats test to validate the metric, and documents the new collector.

Changes

Cohort / File(s) Summary
Metrics definition & registration
server/metrics/collectors/collectors.go, server/metrics/metrics.go
Added DefaultRuntime collector (crio_default_runtime), introduced metricDefaultRuntime *prometheus.GaugeVec, registered it in the collector→metric map, and added MetricDefaultRuntimeSet(runtime string) to reset and set the runtime label to 1.
Daemon lifecycle hooks
cmd/crio/main.go, server/server.go
Call metrics.Instance().MetricDefaultRuntimeSet(config.DefaultRuntime) at startup (after config.Validate(true)) and on SIGHUP reload (after s.config.Reload(ctx)) to initialize/update the default-runtime metric.
Tests
test/metrics.bats
Added default runtime metric test that verifies /metrics exposes container_runtime_crio_default_runtime{runtime="..."} 1 before and after a reload that changes the configured default runtime.
Documentation
docs/crio.8.md
Appended default_runtime to the default --metrics-collectors list in the man page.

Sequence Diagram(s)

sequenceDiagram
    participant Main as cmd/crio/main
    participant Server as server (SIGHUP/reload)
    participant Metrics as server/metrics
    participant PromReg as PrometheusRegistry
    participant Scraper as MetricsScraper

    Main->>Metrics: MetricDefaultRuntimeSet(DefaultRuntime)
    Metrics->>PromReg: Reset()
    Metrics->>PromReg: GetMetricWithLabelValues(runtime=DefaultRuntime) / Set(1)
    Server->>Metrics: on SIGHUP -> MetricDefaultRuntimeSet(NewDefault)
    Metrics->>PromReg: Reset()
    Metrics->>PromReg: GetMetricWithLabelValues(runtime=NewDefault) / Set(1)
    Scraper->>PromReg: GET /metrics
    PromReg-->>Scraper: container_runtime_crio_default_runtime{runtime="..."} 1
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped in code with whiskers bright,
A tiny gauge to mark runtime's light,
Config chose which one to show,
Start or reload — the metric will glow,
Nibble, set, and off we go! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'metrics: add default_runtime' is concise, clear, and directly describes the main change: adding a new default_runtime metric to the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.53%. Comparing base (d486907) to head (50bad6d).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9870      +/-   ##
==========================================
- Coverage   67.57%   67.53%   -0.04%     
==========================================
  Files         212      214       +2     
  Lines       29373    29628     +255     
==========================================
+ Hits        19848    20010     +162     
- Misses       7827     7909      +82     
- Partials     1698     1709      +11     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@haircommander haircommander force-pushed the default-runtime-metric branch from 5a5ede5 to 48f1369 Compare April 8, 2026 16:42
@haircommander

Copy link
Copy Markdown
Member Author

/retest
@cri-o/cri-o-maintainers PTAL

@haircommander

Copy link
Copy Markdown
Member Author

/cherry-pick release-1.35

@openshift-cherrypick-robot

Copy link
Copy Markdown

@haircommander: once the present PR merges, I will cherry-pick it on top of release-1.35 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release-1.35

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.

@haircommander

Copy link
Copy Markdown
Member Author

/override ci/prow/e2e-aws-ovn

@openshift-ci

openshift-ci Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

@haircommander: Overrode contexts on behalf of haircommander: ci/prow/e2e-aws-ovn

Details

In response to this:

/override ci/prow/e2e-aws-ovn

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.

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

It looks like reloading config is not considered (+its integration test)

@haircommander haircommander force-pushed the default-runtime-metric branch from 48f1369 to 4fe04af Compare April 15, 2026 20:49
@haircommander

Copy link
Copy Markdown
Member Author

great point, updated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
server/server.go (2)

635-635: Guard the reload metric write behind EnableMetrics.

This runs on every successful reload and still touches global metrics state even when metrics are disabled. Consider gating it to avoid unnecessary singleton interaction.

Proposed change
-			metrics.Instance().MetricDefaultRuntimeSet(s.config.DefaultRuntime)
+			if s.config.EnableMetrics {
+				metrics.Instance().MetricDefaultRuntimeSet(s.config.DefaultRuntime)
+			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/server.go` at line 635, The reload handler currently always calls
metrics.Instance().MetricDefaultRuntimeSet(s.config.DefaultRuntime), touching
global metrics even when metrics are disabled; wrap that call in a guard
checking the server config's metrics toggle (e.g., s.config.EnableMetrics or
equivalent) so the metric update runs only when metrics are enabled, keeping the
metrics singleton untouched otherwise and preserving current behavior when
enabled.

635-635: Please mirror this metric feature in downstream repos.

Since this line adds runtime-metric behavior on reload, make sure cri-o.io and packaging repos are updated so docs/defaults stay aligned.

Based on learnings, "When adding/changing features, update related repositories: cri-o.io website and packaging repositories".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/server.go` at line 635, This change calls
metrics.Instance().MetricDefaultRuntimeSet(s.config.DefaultRuntime) to record
the default runtime on reload; mirror this metric behavior in downstream repos
by updating cri-o.io and packaging to set and document the same default-runtime
metric on config reloads, ensure documentation pages and defaults in packaging
templates reflect s.config.DefaultRuntime semantics and examples, and add any
necessary metric initialization code or config hooks in those repositories
equivalent to MetricDefaultRuntimeSet so docs, packaging defaults, and runtime
behavior stay aligned.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/server.go`:
- Line 635: The reload handler currently always calls
metrics.Instance().MetricDefaultRuntimeSet(s.config.DefaultRuntime), touching
global metrics even when metrics are disabled; wrap that call in a guard
checking the server config's metrics toggle (e.g., s.config.EnableMetrics or
equivalent) so the metric update runs only when metrics are enabled, keeping the
metrics singleton untouched otherwise and preserving current behavior when
enabled.
- Line 635: This change calls
metrics.Instance().MetricDefaultRuntimeSet(s.config.DefaultRuntime) to record
the default runtime on reload; mirror this metric behavior in downstream repos
by updating cri-o.io and packaging to set and document the same default-runtime
metric on config reloads, ensure documentation pages and defaults in packaging
templates reflect s.config.DefaultRuntime semantics and examples, and add any
necessary metric initialization code or config hooks in those repositories
equivalent to MetricDefaultRuntimeSet so docs, packaging defaults, and runtime
behavior stay aligned.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 60176a72-bf68-42f4-8592-4d0f7af87cdd

📥 Commits

Reviewing files that changed from the base of the PR and between 48f1369 and 4fe04af.

📒 Files selected for processing (7)
  • cmd/crio/main.go
  • docs/crio.8.md
  • server/metrics/collectors/collectors.go
  • server/metrics/metrics.go
  • server/server.go
  • test/metrics.bats
  • test/updateunified/updateunified
🚧 Files skipped from review as they are similar to previous changes (5)
  • cmd/crio/main.go
  • docs/crio.8.md
  • server/metrics/collectors/collectors.go
  • server/metrics/metrics.go
  • test/metrics.bats

@bitoku

bitoku commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

/retest

2 similar comments
@bitoku

bitoku commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

/retest

@bitoku

bitoku commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

/retest

@bitoku

bitoku commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

we consistently need to find which runtime a user is using, and have talked about adding this for a while. Now's the time!

Signed-off-by: Peter Hunt <pehunt@redhat.com>
@haircommander haircommander force-pushed the default-runtime-metric branch from 4fe04af to 50bad6d Compare April 16, 2026 16:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
server/metrics/collectors/collectors.go (1)

70-71: Prefer a rationale-focused comment for DefaultRuntime

The constant is good, but the new comment explains what the key is rather than why this collector exists. Consider rewording it to capture operational intent (for example, exposing configured runtime for observability/alerting).

As per coding guidelines, "Add comments explaining 'why' not 'what' in Go code."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/metrics/collectors/collectors.go` around lines 70 - 71, The comment
for the constant DefaultRuntime currently restates what the key is; update it to
explain why this collector exists (operational intent) — e.g., state that
DefaultRuntime exposes the container runtime configured in CRI-O so operators
and alerting/observability systems can detect runtime changes or mismatches;
locate the comment above the DefaultRuntime Collector constant and replace the
“what” description with a concise “why” rationale focused on
observability/alerting/operational use.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/metrics/collectors/collectors.go`:
- Around line 70-71: The comment for the constant DefaultRuntime currently
restates what the key is; update it to explain why this collector exists
(operational intent) — e.g., state that DefaultRuntime exposes the container
runtime configured in CRI-O so operators and alerting/observability systems can
detect runtime changes or mismatches; locate the comment above the
DefaultRuntime Collector constant and replace the “what” description with a
concise “why” rationale focused on observability/alerting/operational use.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: df07bcca-ea54-438a-bb38-693c8367c70b

📥 Commits

Reviewing files that changed from the base of the PR and between 4fe04af and 50bad6d.

📒 Files selected for processing (7)
  • cmd/crio/main.go
  • docs/crio.8.md
  • server/metrics/collectors/collectors.go
  • server/metrics/metrics.go
  • server/server.go
  • test/metrics.bats
  • test/updateunified/updateunified
✅ Files skipped from review due to trivial changes (2)
  • docs/crio.8.md
  • cmd/crio/main.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • server/server.go
  • server/metrics/metrics.go
  • test/metrics.bats

@bitoku bitoku closed this Apr 17, 2026
@bitoku bitoku reopened this Apr 17, 2026
@bitoku

bitoku commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

/retest

@bitoku

bitoku commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 17, 2026
@openshift-merge-bot openshift-merge-bot Bot merged commit 9801c04 into cri-o:main Apr 17, 2026
96 of 117 checks passed
@openshift-cherrypick-robot

Copy link
Copy Markdown

@haircommander: new pull request created: #9897

Details

In response to this:

/cherry-pick release-1.35

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.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants