feat: expose metrics for the git commit#588
feat: expose metrics for the git commit#588xcoulon wants to merge 1 commit intocodeready-toolchain:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
💤 Files with no reviewable changes (1)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
cmd/main.gopkg/configuration/configuration.gopkg/configuration/version.gopkg/configuration/version_test.gopkg/server/metrics_server.gopkg/server/metrics_server_test.gopkg/verification/sender/twilio_sender_test.go
💤 Files with no reviewable changes (1)
- pkg/configuration/configuration.go
pkg/server/metrics_server.go
Outdated
| DisableCompression: true, | ||
| }), | ||
| ))) | ||
|
|
There was a problem hiding this comment.
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.
| ))) | |
| 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.
8ed5128 to
decec76
Compare
similar to codeready-toolchain/host-operator#1249 Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
decec76 to
0ad7cac
Compare
|
|
@xcoulon: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |



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