Repository navigation
feat: add per-artifact verification result metric - #3049
Merged
fseldow merged 2 commits intoOct 22, 2026
Merged
Conversation
charleswool
requested review from
akashsinghal,
binbin-li,
fseldow,
jimmyraywv,
luisdlp,
susanshi and
toddysm
as code owners
October 22, 2026 06:21
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The additive instrumentation preserves verification behavior, has focused test coverage, and has no identified blocking issues.
No open issues 🎉
What changed in this PR
Adds per-artifact verification outcome metrics to the v2 provider, extending request-path observability without changing verification behavior.
Changes:
- Adds
ratify_verification_result_countwith result, cache-hit, and workload-namespace labels. - Reports outcomes alongside existing logs and supplies namespace context to per-artifact metrics.
- Adds tests for outcome mapping, cache hits, verification errors, malformed requests, and disabled metrics.
| File | Description |
|---|---|
pkg/metrics/stats_reporter.go |
Defines and reports the verification outcome counter. |
pkg/metrics/stats_reporter_test.go |
Tests counter attributes and uninitialized behavior. |
internal/httpserver/handlers.go |
Reports artifact outcomes with namespace-aware metrics context. |
internal/httpserver/handlers_test.go |
Tests reporting paths and outcome classification. |
Review effort: Balanced
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3049 +/- ##
==========================================
+ Coverage 85.32% 85.44% +0.12%
==========================================
Files 53 53
Lines 2868 2886 +18
==========================================
+ Hits 2447 2466 +19
+ Misses 326 324 -2
- Partials 95 96 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
fseldow
reviewed
Oct 22, 2026
fseldow
reviewed
Oct 22, 2026
fseldow
reviewed
Oct 22, 2026
fseldow
approved these changes
Oct 22, 2026
Add ratify_verification_result_count, a counter incremented once per verified artifact with a bounded result label (succeeded, failed, error) and a cache_hit label. It is reported at the same point the outcome is logged, so cache hits and singleflight-deduplicated callers are counted. Per-artifact metrics now carry the workload namespace parsed from the Gatekeeper key, which was previously always empty. Signed-off-by: Charles Wu <yuewu2@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add cache-miss succeeded/failed cases to TestVerify_ReportsResultMetric so the non-cached result reporting branch is exercised, and remove comments flagged as unnecessary in review. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Charles Wu <yuewu2@microsoft.com>
charleswool
force-pushed
the
feat/verification-result-metric
branch
from
October 22, 2026 12:18
768382a to
445f91b
Compare
fseldow
approved these changes
Oct 22, 2026
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 v2 provider exports three metrics today:
ratify_verification_requestandratify_mutation_request(latency histograms with no labels) andratify_system_error_count(#2873). None of them says what the verdict was, so an operator cannot answer "what share of images is being denied?" or alert on a spike in verification errors without parsing logs.Change
ratify_verification_result_count, incremented once per verified artifact with:result: a closed set,succeeded|failed|error.failedmeans verification completed and the artifact did not satisfy the policy (e.g. unsigned / untrusted);errormeans no verdict could be reached (no executor configured, registry failure, etc.). Exported asmetrics.VerificationResult*constants.cache_hit: whether the outcome was served from the verify cache.workload_namespace: as on the other Ratify metrics.singleflight-deduplicated callers are counted exactly like the log line, and a request that fails before any artifact is processed (bad body) is not counted.workload_namespacewas always empty in v2 because nothing calledSetContextWithNamespace. The handler now builds a metrics-only context from the[namespace]prefix of the Gatekeeper key. This also fills the label on the existingratify_system_error_count{error="verify_artifact"}. The executor still receives the original request context.Label cardinality stays bounded: 3 × 2 × number of namespaces. No image reference, digest or error text is used as a label.
Example:
Which issue(s) does this PR resolve?
None filed; follow-up to #2873 ("outcome labels on request histograms ... left as a follow-up").
Type of change
Testing and verification
TestVerify_ReportsResultMetric: cache hit succeeded, cache hit failed with a namespaced key, cache miss with error. Each asserts exactly one report with the expectedresult,cache_hitand namespace.TestVerify_InvalidRequestReportsNoResult: a malformed body reports nothing.TestVerificationOutcome,TestReportVerificationResultandTestReportVerificationResult_Uninitialized: attribute mapping, plus a no-op when metrics are disabled.internal/httpserver, the same pattern asinitMetricsFunc, so tests stay hermetic.go build ./...,go vet,go testforinternal/httpserver,pkg/metricsandcmd/..., andgolangci-lintv2.12.2 (./..., 0 issues) pass.Checklist
instrumentation/will follow separately.