Your CVE Trend Is 20 Days Long and Nobody Chose That

Exporting trivy-operator's metrics to Prometheus gives you a real trend line — bounded by a storage retention value someone set for a different reason. A 30-day lookback returned 51 samples against a 20d retention config.

Your CVE Trend Is 20 Days Long and Nobody Chose That

Yesterday's post ended on the obvious fix: the VulnerabilityReport CRDs are a snapshot, so scrape them into a time series and you get history. That works, and it works with no new infrastructure — the existing kube-prometheus-stack was already scraping trivy_image_vulnerabilities for freshly deployed workloads without anyone configuring anything for them.

The instant query is genuinely good:

sum by (severity) (trivy_image_vulnerabilities{namespace="poc-imgsec"})
  Critical = 57
  High     = 432
  Medium   = 805
  Low      = 520
  Unknown  = 53

And it decomposes per image, which is what makes it usable for triage rather than dashboards: library/nginx:1.21.6 carries 31 Criticals on its own, library/python:3.9.18-slim 16, library/debian:12.4-slim 7. Eleven of the sixteen images in that namespace sit at zero. The signal is concentrated, and the query finds it in one line.

Then you ask the same series for a range.

The number that ends the roadmap slide

--- E007 trend history: 30d lookback on this series ---
samples_retained_30d=51 for severity=Critical
samples_retained_30d=51 for severity=High
samples_retained_30d=51 for severity=Low
samples_retained_30d=51 for severity=Medium
samples_retained_30d=51 for severity=Unknown

--- prometheus retention config ---
{ "storageRetention": "20d" }

Fifty-one samples across a thirty-day window, and a hard ceiling of 20d regardless. Whatever the reporting ambition was — quarterly burndown, year-over-year, "show me the effect of the base-image migration" — the data stops at twenty days, and nobody involved in the vulnerability-management conversation picked that number. It came from a Prometheus values file, chosen against a disk budget, for a monitoring stack whose original job was alerting on things that break in minutes.

The trend request spanning a quarter, the retained series covering twenty days, and the gap between them
The trend request spanning a quarter, the retained series covering twenty days, and the gap between them

Retention set for alerting is a ceiling on reporting: the useful window is whatever the metrics stack was already configured to keep.

Why the sample count matters as much as the retention

Fifty-one samples is not fifty-one days of resolution, and it is not a dense series either. It is a reminder that the trend's shape is governed by three independent settings nobody reviewed together: how often the operator re-publishes the gauge, how often Prometheus scrapes it, and how long Prometheus keeps it. The vulnerability numbers themselves move on the operator's own 24-hour rescan cadence, so the underlying signal changes roughly once a day while the storage decides how many of those daily values survive.

Stack that on top of yesterday's finding and the picture is complete: the CRDs hold one snapshot with a 24-hour TTL, and the metrics stack holds at most twenty days of them. There is no layer in this design that holds a quarter.

What to do about it

Two honest options, and one dishonest one.

The honest ones are to raise storageRetention deliberately — with the disk sizing done and the decision written down as a security reporting requirement rather than a monitoring one — or to accept that Prometheus is the operational view and push a daily aggregate somewhere that keeps rows for as long as the compliance story needs. A single row per namespace per severity per day is nothing; the point is that something has to own it.

The dishonest option is to build the quarterly dashboard anyway and let it render whatever it has. It will not error. It will just quietly draw a line that starts twenty days ago and call it the trend.

Check the retention before you promise the trend. It is one query, and it is the difference between a report you can defend and a chart that agrees with you.

Next: what continuous scanning costs per image — the measured wall-clock and footprint of one scan job, end to end.