Skip to content

feat: expose metrics for the git commit#588

Open
xcoulon wants to merge 1 commit intocodeready-toolchain:masterfrom
xcoulon:prometheus_metric_commit
Open

feat: expose metrics for the git commit#588
xcoulon wants to merge 1 commit intocodeready-toolchain:masterfrom
xcoulon:prometheus_metric_commit

Conversation

@xcoulon
Copy link
Contributor

@xcoulon xcoulon commented Mar 24, 2026

similar to codeready-toolchain/host-operator#1249

e2e tests: codeready-toolchain/toolchain-e2e#1269

Signed-off-by: Xavier Coulon xcoulon@redhat.com

Summary by CodeRabbit

  • New Features
    • Prometheus now exposes version and shortened-commit metrics immediately on startup, improving build observability.
  • Tests
    • Added automated tests validating version/commit metrics and the /metrics endpoint end-to-end.
  • Chores
    • Updated vulnerability suppression configuration.
    • Minor whitespace and linter comment adjustments in tests.

@openshift-ci openshift-ci bot requested review from jrosental and rsoaresd March 24, 2026 16:26
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 694602af-d43f-46c9-98ed-514576ff5aee

📥 Commits

Reviewing files that changed from the base of the PR and between decec76 and 0ad7cac.

📒 Files selected for processing (8)
  • .govulncheck.yaml
  • cmd/main.go
  • pkg/configuration/configuration.go
  • pkg/configuration/version.go
  • pkg/configuration/version_test.go
  • pkg/server/metrics_server.go
  • pkg/server/metrics_server_test.go
  • pkg/verification/sender/twilio_sender_test.go
💤 Files with no reviewable changes (1)
  • pkg/configuration/configuration.go
✅ Files skipped from review due to trivial changes (3)
  • pkg/server/metrics_server.go
  • pkg/verification/sender/twilio_sender_test.go
  • .govulncheck.yaml
🚧 Files skipped from review as they are similar to previous changes (3)
  • cmd/main.go
  • pkg/server/metrics_server_test.go
  • pkg/configuration/version_test.go

Walkthrough

Adds a new version metrics module that exposes commit/build/start metadata as Prometheus gauges, registers those metrics at startup, moves version variables into the new module, and adds tests for metric registration and the /metrics HTTP endpoint.

Changes

Cohort / File(s) Summary
Version metrics module & tests
pkg/configuration/version.go, pkg/configuration/version_test.go
Adds exported Commit, BuildTime, StartTime, two prometheus.GaugeVec variables, and RegisterVersionMetrics(registry *prometheus.Registry) to create, label, set, and register commit and short-commit gauges; includes unit tests validating gauge labels and values.
Configuration refactor
pkg/configuration/configuration.go
Removed package-level exported variables Commit, BuildTime, and StartTime (relocated to version.go).
Main integration
cmd/main.go
Calls configuration.RegisterVersionMetrics(regsvcRegistry) immediately after creating the Prometheus registry to register version gauges before starting metrics server.
Metrics server & test
pkg/server/metrics_server.go, pkg/server/metrics_server_test.go
Whitespace tweak in route registration; new integration test starts the metrics server and asserts the metrics output contains both commit gauges.
Test lint suppression
pkg/verification/sender/twilio_sender_test.go
Added //nolint:gosec comment on a test config literal.
Vulnerability config
.govulncheck.yaml
Replaced empty ignored-vulnerabilities with three explicit suppression entries (GO-2026-4601, GO-2026-4602, GO-2026-4603) including info URLs and silence-until dates.

Sequence Diagram(s)

sequenceDiagram
    participant Main as Main (cmd/main.go)
    participant Config as configuration.RegisterVersionMetrics
    participant Registry as Prometheus Registry
    participant Server as Metrics Server
    participant Client as HTTP Client

    Main->>Registry: create regsvcRegistry
    Main->>Config: RegisterVersionMetrics(regsvcRegistry)
    Config->>Registry: create GaugeVecs (commit, short_commit)
    Config->>Config: set gauge values (SetToCurrentTime) with labels
    Config->>Registry: registry.MustRegister(gauges)
    Main->>Server: StartMetricsServer(registry, port)
    Client->>Server: GET /metrics
    Server->>Registry: gather metrics
    Registry-->>Server: metrics payload (includes commit gauges)
    Server-->>Client: 200 OK + metrics text
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.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 PR title 'feat: expose metrics for the git commit' directly and clearly summarizes the main change across all modified files: moving version-related variables to a new module and registering them as Prometheus metrics.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
pkg/server/metrics_server_test.go (1)

22-29: Add a small delay after starting the server to ensure it's ready.

There may be a race between server startup and the HTTP request. Consider adding a brief delay or retry logic.

Proposed fix
 	srv, _ := server.StartMetricsServer(registry, 18083)
 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 	defer cancel()
-	defer srv.Shutdown(ctx)
+	defer func() {
+		if err := srv.Shutdown(ctx); err != nil {
+			t.Logf("failed to shutdown server: %v", err)
+		}
+	}()
+
+	// Give the server time to start
+	time.Sleep(100 * time.Millisecond)

 	// make a request to the metrics server

-	resp, err := http.Get("http://localhost:80/metrics")
+	resp, err := http.Get("http://localhost:18083/metrics")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/server/metrics_server_test.go` around lines 22 - 29, After calling
StartMetricsServer (srv := server.StartMetricsServer(...)) there is a race with
the immediate http.Get; add a short readiness wait or retry loop before making
the request: either insert a small time.Sleep (e.g. tens of milliseconds) after
srv is returned or implement simple polling that attempts GET /metrics with a
short backoff until it succeeds or a timeout is reached; update the test in
metrics_server_test.go around the StartMetricsServer and http.Get lines and
ensure the existing ctx/cancel and srv.Shutdown(ctx) behavior remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/server/metrics_server_test.go`:
- Line 25: The call to srv.Shutdown(ctx) in metrics_server_test.go ignores its
error return which fails errcheck; update the teardown to check and handle the
error (e.g., capture the error and assert no error with require.NoError(t, err)
or t.Fatalf on err) so replace the current defer srv.Shutdown(ctx) with a defer
that checks the returned error from srv.Shutdown(ctx) and fails the test if
non-nil (reference srv.Shutdown and ctx to locate the call).
- Line 22: Test uses privileged port 80 which causes CI failures; update the
call to StartMetricsServer in metrics_server_test.go to use an unprivileged high
port (e.g., 8080 or 0 for an ephemeral port) and update the corresponding
request URL used to query the server (the URL built for the test request) to
match the new port; ensure you adjust both the StartMetricsServer(registry, 80)
invocation and the related request URL so the test targets the same
non-privileged port.

In `@pkg/server/metrics_server.go`:
- Line 27: Remove the trailing whitespace/tabs on the indicated blank line in
pkg/server/metrics_server.go (around line 27) so the file passes gofmt; run
gofmt (or go fmt) to reformat the file and commit the change. Ensure there are
no other trailing spaces in the file before pushing.

---

Nitpick comments:
In `@pkg/server/metrics_server_test.go`:
- Around line 22-29: After calling StartMetricsServer (srv :=
server.StartMetricsServer(...)) there is a race with the immediate http.Get; add
a short readiness wait or retry loop before making the request: either insert a
small time.Sleep (e.g. tens of milliseconds) after srv is returned or implement
simple polling that attempts GET /metrics with a short backoff until it succeeds
or a timeout is reached; update the test in metrics_server_test.go around the
StartMetricsServer and http.Get lines and ensure the existing ctx/cancel and
srv.Shutdown(ctx) behavior remains unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7b275d67-7c63-4ee4-911d-97f40b5768ab

📥 Commits

Reviewing files that changed from the base of the PR and between ec5eedc and 26016e7.

📒 Files selected for processing (7)
  • cmd/main.go
  • pkg/configuration/configuration.go
  • pkg/configuration/version.go
  • pkg/configuration/version_test.go
  • pkg/server/metrics_server.go
  • pkg/server/metrics_server_test.go
  • pkg/verification/sender/twilio_sender_test.go
💤 Files with no reviewable changes (1)
  • pkg/configuration/configuration.go

DisableCompression: true,
}),
)))

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix formatting to pass gofmt check.

The static analysis tool reports this line is not properly formatted. Remove trailing whitespace/tabs to pass CI.

Proposed fix
 	)))
-	
+
 	log.Info("Starting the registration-service metrics server...")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
)))
log.Info("Starting the registration-service metrics server...")
🧰 Tools
🪛 GitHub Check: GolangCI Lint

[failure] 27-27:
File is not properly formatted (gofmt)

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

In `@pkg/server/metrics_server.go` at line 27, Remove the trailing whitespace/tabs
on the indicated blank line in pkg/server/metrics_server.go (around line 27) so
the file passes gofmt; run gofmt (or go fmt) to reformat the file and commit the
change. Ensure there are no other trailing spaces in the file before pushing.

@xcoulon xcoulon force-pushed the prometheus_metric_commit branch 2 times, most recently from 8ed5128 to decec76 Compare March 24, 2026 16:33
similar to codeready-toolchain/host-operator#1249

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@xcoulon xcoulon force-pushed the prometheus_metric_commit branch from decec76 to 0ad7cac Compare March 24, 2026 16:52
@sonarqubecloud
Copy link

@openshift-ci
Copy link

openshift-ci bot commented Mar 24, 2026

@xcoulon: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e 0ad7cac link true /test e2e

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.

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

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

Nice 👍

@openshift-ci
Copy link

openshift-ci bot commented Mar 25, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, MatousJobanek, mfrancisc, xcoulon

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:
  • OWNERS [MatousJobanek,alexeykazakov,mfrancisc,xcoulon]

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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants