feat: expose Prometheus metrics and instrument requests - #2847
feat: expose Prometheus metrics and instrument requests#2847charleswool wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2847 +/- ##
=======================================
Coverage 76.63% 76.63%
=======================================
Files 89 89
Lines 4104 4104
=======================================
Hits 3145 3145
Misses 812 812
Partials 147 147 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR wires the existing pkg/metrics (OpenTelemetry + Prometheus) into the Gatekeeper provider so it actually exposes a /metrics endpoint and emits request-duration metrics for the verify/mutate paths.
Changes:
- Add request-duration instrumentation in
internal/httpserververify/mutate handlers. - Add
--metrics-portflag and initialize the Prometheus exporter during provider startup (non-fatal on init failure). - Update Gatekeeper provider unit tests for the new flag and metrics init behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
internal/httpserver/handlers.go |
Adds timing + reporting for verification and mutation request durations. |
cmd/ratify-gatekeeper-provider/main.go |
Introduces --metrics-port and initializes the Prometheus exporter during startup. |
cmd/ratify-gatekeeper-provider/main_test.go |
Updates parsing and startup tests for the new metrics flag/init path. |
Comments suppressed due to low confidence (1)
cmd/ratify-gatekeeper-provider/main_test.go:123
- This test mutates global function variables (
startManagerFunc,initMetricsFunc) without restoring them, which can make the test suite order-dependent. Also, returning a freshly-allocatederrors.New(...)each call makes it harder to assert that the metrics init error is not returned bystartRatify.
startManagerFunc = func(_ chan struct{}, _, _ bool) {}
initMetricsFunc = func(string, int) error { return errors.New("metrics boom") }
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a8c584c to
2b8f465
Compare
The metrics package (OTel + Prometheus, ported from v1) was never wired into the gatekeeper provider: the exporter was never initialized and no request duration was recorded, so the provider emitted no metrics and served no /metrics endpoint. Initialize the Prometheus exporter on startup behind a new --metrics-port flag (default 8888, 0 disables) and record verification/mutation request durations in the verify/mutate handlers. Exporter init failures are logged but non-fatal. Signed-off-by: Charles Wu <yuewu2@microsoft.com>
2b8f465 to
deaa305
Compare
|
Closing — this is now an empty PR. #2848 was stacked on this branch and carried commit Everything from this PR is on
The follow-ups #2849 and #2873 no longer need to be stacked on this branch; I'll rebase them straight onto |
Description
The
pkg/metricspackage (OpenTelemetry + Prometheus, ported from v1) was never wired into the gatekeeper provider:InitMetricsExporterwas never called and no request duration was ever recorded, so the provider emitted no metrics and served no/metricsendpoint.Change
--enable-metricsflag (defaultfalse) plus--metrics-port(default8888), matching the v1 flag convention. Exporter init failures are logged but non-fatal (metrics must not take down verification).ratify_verification_request/ratify_mutation_requestdurations inverify/mutate.initMetricsFuncis a package var so tests stay hermetic (no port bind / global mux registration).Follow-ups (separate PRs):
Testing
errors.IsthatstartRatifydoes not return the metrics-init error).verify/mutateinstrumentation covered by existing handler tests.go build ./...,go vet, package tests, andgolangci-lintpass.