Skip to content

feat(policy-server): break out dashboard rejection panels by policy_mode#1742

Open
officialasishkumar wants to merge 2 commits into
kubewarden:mainfrom
officialasishkumar:issue-1284-grafana-dashboard-policy-mode
Open

feat(policy-server): break out dashboard rejection panels by policy_mode#1742
officialasishkumar wants to merge 2 commits into
kubewarden:mainfrom
officialasishkumar:issue-1284-grafana-dashboard-policy-mode

Conversation

@officialasishkumar
Copy link
Copy Markdown

Summary

Closes #1284.

The Kubewarden Grafana dashboard currently aggregates every accepted=false evaluation
into a single number, so it cannot distinguish:

  • policy_mode=protect + accepted=false: the admission request was actually blocked
    by the cluster.
  • policy_mode=monitor + accepted=false: the admission request was allowed through
    by the cluster, but would have been blocked if the policy was in protect mode.

The policy_mode label is already attached to kubewarden_policy_evaluations_total in
crates/policy-server/src/metrics.rs,
so the only thing missing was surfacing that dimension in the dashboard.

What changes

The validate-origin rejection panels in crates/policy-server/kubewarden-dashboard.json now
group by policy_mode and carry explanatory descriptions:

Panel id Title (after) What changed
66 Rejected admission requests rate (by policy mode) query now sum by (policy_mode) (rate(...)), legend {{policy_mode}}, new description
40 Rejected admission requests (by policy mode) query now sum by (policy_mode) (...), new description
48 Request rejection percentage (by policy mode) numerator now grouped by policy_mode, new description
8 Pod creation rejections (by policy mode) query now sum by (policy_mode) (...), new description
32 Rejected requests by $policy_name policy (by policy mode) per-policy total grouped by policy_mode
56 $policy_name policy request rejection percentage (by policy mode) per-policy percentage grouped by policy_mode
34 Rate of validate requests to $policy_name policy grouped by policy_mode so this rate panel stays aligned with the rejection panels above
67 Accepted requests rate no query change, new description noting that monitor- and protect-mode evaluations are both counted
68 Mutated requests rate no query change, new description noting that monitor-mode mutations are reported but not applied by the cluster

The audit-origin panels (#96, #85, #89, #92, #75, #78, #70) are intentionally
left untouched. Audit scans are background reports against existing resources and do not
block anything regardless of policy mode, so adding a policy_mode breakdown would add
noise without changing the operational meaning.

No template variables, panel ids, or gridPos values are touched, so the dashboard
re-imports cleanly without re-laying-out anything.

Test plan

  • jq -e . crates/policy-server/kubewarden-dashboard.json parses successfully
  • schemaVersion and version fields are unchanged
  • Panel count is unchanged (49 panels), no gridPos values touched
  • Only the panel ids listed above are modified; all other panel JSON is byte-identical
  • Manual import into a Grafana instance shows the two policy_mode series on the
    time-series rejection panel, the two values side-by-side on the stat panels, and the
    description tooltip on each updated panel

Copilot AI review requested due to automatic review settings May 14, 2026 06:16
@officialasishkumar officialasishkumar requested a review from a team as a code owner May 14, 2026 06:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the Kubewarden Grafana dashboard to break down rejection/mutation metrics by policy_mode and adds descriptive tooltips so users can distinguish between actually blocked requests (protect mode) and observed-only requests (monitor mode).

Changes:

  • Updated PromQL expressions to sum by (policy_mode) (...) and legend formats to {{policy_mode}} for rejection-related panels.
  • Renamed several panel titles to include "(by policy mode)" and added description fields explaining the protect vs. monitor semantics.
  • Updated the "Accepted requests rate" and "Mutated requests rate" panels with explanatory descriptions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"editorMode": "code",
"exemplar": true,
"expr": "sum(kubewarden_policy_evaluations_total{accepted=\"false\",request_origin=\"validate\"})*100/sum(kubewarden_policy_evaluations_total{})",
"expr": "sum by (policy_mode) (kubewarden_policy_evaluations_total{accepted=\"false\",request_origin=\"validate\"})*100/sum(kubewarden_policy_evaluations_total{})",
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Aligned the percentage denominator with validate-origin evaluations grouped by policy_mode in 3a821e5.

"type": "stat"
"title": "Request rejection percentage (by policy mode)",
"type": "stat",
"description": "Share of all policy evaluations that rejected the admission request, broken down by the policy's mode. policy_mode=protect is the share that was actually blocked; policy_mode=monitor is the share that would have been blocked in protect mode."
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the description wording to match validate admission evaluations in 3a821e5.

Comment on lines 2693 to 2694
"title": "Rejected requests by $policy_name policy (by policy mode)",
"type": "stat"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Verified the rejected-requests description is on the intended panel and moved it next to the title/type in 3a821e5.

@flavio
Copy link
Copy Markdown
Member

flavio commented May 14, 2026

Can you share with us a screenshot of before and after?

@flavio flavio moved this from Pending review to Blocked in Kubewarden Admission Controller May 14, 2026
The Kubewarden Grafana dashboard treated every `accepted=false`
evaluation as a single concept and could not distinguish between
admission requests that were actually blocked (policy in `protect`
mode) and admission requests that the cluster still let through but
that would have been blocked if the policy was in `protect` mode
(policy in `monitor` mode). The `policy_mode` label is already
attached to `kubewarden_policy_evaluations_total` in
`crates/policy-server/src/metrics.rs`, so the breakdown only needs
to be surfaced in the dashboard queries.

This commit updates the validate-origin rejection panels so they
group by `policy_mode`, and adds explanatory `description` fields
that spell out the semantics:

- "Rejected admission requests rate (by policy mode)" (kubewarden#66)
- "Rejected admission requests (by policy mode)" (kubewarden#40)
- "Request rejection percentage (by policy mode)" (kubewarden#48)
- "Pod creation rejections (by policy mode)" (kubewarden#8)
- "Rejected requests by $policy_name policy (by policy mode)" (kubewarden#32)
- "$policy_name policy request rejection percentage (by policy mode)" (kubewarden#56)
- "Rate of validate requests to $policy_name policy" (kubewarden#34) also
  receives the `policy_mode` legend so the per-policy rate panel is
  aligned with the rejection panels above.

The "Accepted requests rate" (kubewarden#67) and "Mutated requests rate" (kubewarden#68)
panels keep their existing queries (the `policy_mode` dimension does
not change which requests were accepted), but receive descriptions
that clarify how the cluster interprets each policy mode. In
particular, mutations from monitor-mode policies are reported but
not applied.

The audit-origin panels are intentionally left untouched: audit
scans are background reports against existing resources and do not
block anything regardless of policy mode, so adding a
`policy_mode` breakdown there would add noise without changing the
operational meaning.

Closes kubewarden#1284

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@officialasishkumar officialasishkumar force-pushed the issue-1284-grafana-dashboard-policy-mode branch from 65ad793 to 3a821e5 Compare May 14, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[policy-server]: Feature Request: update grafana dashboard to take the policy mode into account

3 participants