Skip to content

fix(trivy): deduplicate vulnerability counts to avoid per-container m…#175

Merged
dotdc merged 1 commit intodotdc:masterfrom
jnt2007:master
Mar 18, 2026
Merged

fix(trivy): deduplicate vulnerability counts to avoid per-container m…#175
dotdc merged 1 commit intodotdc:masterfrom
jnt2007:master

Conversation

@jnt2007
Copy link
Copy Markdown
Contributor

@jnt2007 jnt2007 commented Mar 13, 2026

Problem

The trivy_image_vulnerabilities metric is emitted once per container instance
that uses a given image, not once per unique image. When the same image (e.g.
bitnami/kubectl:1.35.0) is used by N containers in a namespace, the current
sum(trivy_image_vulnerabilities{...}) multiplies the actual vulnerability count
by N.
Example: 40 unique Medium vulnerabilities in an image used by 8 containers →
dashboard shows 320 instead of 40.
image

Fix

Wrap each sum() with max by (namespace, image_registry, image_repository, image_tag, severity) to deduplicate across container instances before summing:

-- Before
sum(trivy_image_vulnerabilities{...})
-- After
sum(max by (namespace, image_registry, image_repository, image_tag, severity)
  (trivy_image_vulnerabilities{...}))
image

The max by selects one representative time series per unique image+severity
combination, discarding the per-pod/container labels (container_name, pod,
resource_name, etc.) that cause the inflation.

Panels affected (9)

  • CRITICAL, HIGH, MEDIUM, LOW, UNKNOWN stat panels
  • TOTAL stat panel
  • Total vulnerabilities by namespaces (timeseries)
  • Total vulnerabilities by severity in selected namespace(s) (timeseries)
  • Vulnerability count per image and severity in $namespace namespace(s) (table)

Notes

  • Dashboard version bumped from 15 → 16
  • Follows Conventional Commits style

@jnt2007 jnt2007 requested a review from dotdc as a code owner March 13, 2026 16:47
@jnt2007
Copy link
Copy Markdown
Contributor Author

jnt2007 commented Mar 17, 2026

@dotdc hi. Could you please review the PR? Thanks ❤️

@dotdc dotdc merged commit 02277c2 into dotdc:master Mar 18, 2026
1 check passed
@dotdc
Copy link
Copy Markdown
Owner

dotdc commented Mar 18, 2026

🎉 This PR is included in version 3.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@dotdc dotdc added the released label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants