feat: expose Prometheus metrics and instrument requests - #2847
Open
charleswool wants to merge 4 commits into
Open
feat: expose Prometheus metrics and instrument requests#2847charleswool wants to merge 4 commits into
charleswool wants to merge 4 commits into
Conversation
charleswool
requested review from
akashsinghal,
binbin-li,
fseldow,
jimmyraywv,
luisdlp,
susanshi and
toddysm
as code owners
July 30, 2026 00:04
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:
|
Contributor
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.
This was referenced Jul 30, 2026
charleswool
force-pushed
the
feat/wire-metrics
branch
3 times, most recently
from
August 4, 2026 06:09
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>
charleswool
force-pushed
the
feat/wire-metrics
branch
from
August 5, 2026 06:02
2b8f465 to
deaa305
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.