Skip to content

freshness asked Prometheus 98 times per fill, now once - #2942

Merged
Flotapponnier merged 1 commit into
devfrom
fix/freshness-one-prom-query
Oct 10, 2026
Merged

Flotapponnier merged 1 commit into
devfrom
fix/freshness-one-prom-query

Conversation

@Flotapponnier

@Flotapponnier Flotapponnier commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

/api/freshness ran one Prometheus instant query per live spec on every cache fill (30 s): 98 per fill, 509k a day, 30% of every outbound call OCB functions make. Each one bills as an Observability Event, the largest line on the Vercel bill ($2.4/day).

Prometheus.dataAgesSec() returns every metric's age in one union query. Each metric gets its own timestamp(<metric>) term because timestamp() only returns the sample time on a bare selector; wrapped in label_replace it returns evaluation time and every recording rule reads 0 s old (caught on the first live comparison).

Verified against prod Prometheus: 246/246 live specs agree with the old per-spec probe within one scrape interval; 77 distinct metrics in ~240 ms. Unit test added for the batching and the name filter.

Expected effect: 500k fewer outbound calls/day ($16/month on events, plus Fluid CPU and Prom load on the VPS).

/api/freshness ran one instant query per live spec on every 30 s cache
fill: 509k Prom queries a day, 30% of all outbound calls the project
made, each billed as an Observability Event.

Prometheus.dataAgesSec() folds them into one union query. timestamp()
must wrap the bare selector, otherwise it returns evaluation time and
every recording rule reads 0 s old, so each metric gets its own term.
Checked live: 246/246 specs agree with the per-spec probe within one
scrape interval, 77 metrics in ~240 ms.
@Flotapponnier
Flotapponnier force-pushed the fix/freshness-one-prom-query branch from 2fc409a to ebdc625 Compare October 10, 2026 13:57
@Flotapponnier
Flotapponnier merged commit e8a3260 into dev Oct 10, 2026
2 checks passed
Flotapponnier added a commit that referenced this pull request Oct 10, 2026
/api/freshness ran one instant query per live spec on every 30 s cache
fill: 509k Prom queries a day, 30% of all outbound calls the project
made, each billed as an Observability Event.

Prometheus.dataAgesSec() folds them into one union query. timestamp()
must wrap the bare selector, otherwise it returns evaluation time and
every recording rule reads 0 s old, so each metric gets its own term.
Checked live: 246/246 specs agree with the per-spec probe within one
scrape interval, 77 metrics in ~240 ms.

(cherry picked from commit e8a3260)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant