Skip to content

Expose the Keycloak version as a build info metric - #55266

Open
Inf1mum wants to merge 2 commits into
keycloak:mainfrom
Inf1mum:fix/55259-build-info-metric
Open

Inf1mum wants to merge 2 commits into
keycloak:mainfrom
Inf1mum:fix/55259-build-info-metric

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #55259

What

Registers a constant gauge keycloak.build.info with a version tag whenever metrics are enabled. The Prometheus registry renders it as keycloak_build_info, so scraping the management interface's /metrics endpoint yields:

# HELP keycloak_build_info Keycloak server version
# TYPE keycloak_build_info gauge
keycloak_build_info{version="999.0.0-SNAPSHOT"} 1.0

This follows the Prometheus *_info convention already used by jvm_info, and gives inventory and monitoring tools that already scrape /metrics a least-privilege way to read the Keycloak version — today it is only available from /admin/serverinfo, which requires a token with manage-realm (the permission split is tracked in #48961), or from the startup log.

How

A new Micrometer MeterBinder bean (KeycloakBuildInfoMeter) in the Quarkus runtime registers the gauge on the Version constant. Quarkus applies MeterBinder beans to the global registry on startup (the same mechanism HistogramMeterFilter relies on for MeterFilter beans), so the metric appears whenever metrics are enabled and needs no additional configuration.

Docs

The "Self-provided metrics" observability guide gains a Build info section (metric table, tags, example scrape).

Testing

  • quarkus/tests/integration MetricsDistTest#testMetricsEndpoint now asserts TYPE keycloak_build_info gauge and the keycloak_build_info{version="..."} sample (runs in the Quarkus IT CI job).
  • Rendering verified locally against the exact micrometer stack used on main (micrometer-core 1.17.1, micrometer-registry-prometheus 1.17.1, prometheus-metrics 1.7.0): a gauge named keycloak.build.info with a version tag scrapes exactly as shown above.
  • mvn -pl quarkus/runtime compile and mvn -pl quarkus/runtime install pass.

Registers a constant Micrometer gauge keycloak.build.info with a
version tag via a MeterBinder bean in the Quarkus runtime, rendered
as keycloak_build_info{version="..."} 1 on the metrics endpoint
whenever metrics are enabled. This follows the Prometheus *_info
convention of jvm_info and gives inventory and monitoring tools a
least-privilege way to read the Keycloak version without an admin
token for /admin/serverinfo.

Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
@Inf1mum
Inf1mum requested review from a team as code owners November 17, 2026 11:54
Copilot AI balanced review requested due to automatic review settings November 17, 2026 11:54

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.

🟢 Approval recommended

No active review issues are reported for the change exposing Keycloak version information through metrics.

No open issues 🎉

What changed in this PR

Exposes the Keycloak version through the existing metrics endpoint, enabling fleet inventory and upgrade tracking without access to the admin API.

Changes:

  • Adds a constant keycloak_build_info gauge with a version tag, registered when metrics are enabled.
  • Extends the metrics integration test to check the gauge type and version label.
  • Documents the metric, its tag, and an example scrape response.
File Description
quarkus/​tests/​integration/​src/​test/​java/​org/​keycloak/​it/​cli/​dist/​MetricsDistTest.java Adds assertions for the build-info metric.
quarkus/​runtime/​src/​main/​java/​org/​keycloak/​quarkus/​runtime/​services/​metrics/​KeycloakBuildInfoMeter.java Registers the constant version gauge through a Micrometer binder.
docs/​guides/​observability/​metrics-for-troubleshooting-keycloak.adoc Documents build-info metrics for inventory and monitoring.

Review effort: Balanced

The CI Build job failed on spotless:check because jakarta.inject.Singleton
was grouped after the io.micrometer imports instead of before the
org.keycloak import, as required by the project import-order rules.

Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 13:17
@Inf1mum

Inf1mum commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

The red Build job was a Spotless import-order violation in KeycloakBuildInfoMeter.java (the jakarta.inject.Singleton import was grouped after the io.micrometer imports). Reordered and verified locally with mvn spotless:check in eba954d — the Build job should be green on this push.

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.

🟢 Approval recommended

No active review issues block the addition of Keycloak version information to the metrics endpoint.

No open issues 🎉

Review effort: Balanced

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.

Expose the Keycloak version as a build info metric

2 participants