Metrics: every scrape builds a migration graph to say whether migrations are applied #1113
Labels
No labels
accessibility
authentication
breaking change
bug
documentation
enhancement
interface
internationalisation
observability
performance
security
tier
1
tier
2
tier
3
tier/4
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Postulo/postulo#1113
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What exists today
src/postulo/core/metrics.py:93-101_migrations_are_applied()creates aMigrationExecutor(connection)and computesmigration_plan(leaf_nodes())on every call;collect()(:104) calls it at:152on every scrape, then runs about 15COUNTs (:163-259).Measured with
CaptureQueriesContexton the second GET of/metricswith the endpoint on and a token, underpostulo.config.settings.test(probeaudit/m_scripts/test_probe_queries.py): 37 queries and 62 ms for the request;_migrations_are_applied()alone 52 ms (the migration modules already imported). Of the 37 queries, 8 are the database cache used by the throttle and the rest the counts and the migration table read.What changed from the candidate: the counts are not the cost worth fixing. They are what the endpoint exists to report, each is a single
COUNTover one table, and caching them for less than a scrape interval saves nothing. The migration graph is the part that is pure overhead: it is rebuilt from every migration file of every app on every scrape, and its answer cannot change while the process lives, because new migrations arrive only with new code and new code means a new process. The endpoint is off by default (POSTULO_METRICS_ENABLED), so only operators who turned it on pay.What would change
Remember a true answer for the life of the process: a module-level flag set the first time
_migrations_are_applied()returns true, after which it returns true without building anything. A false answer is still checked again at each scrape, so an instance started beforemigratefinished reports the change. Leave the counts as they are.What it saves or protects
small: about 52 ms of the scrape's CPU (measured on a desktop, several times that on a Pi) at every Prometheus scrape, typically every 15 to 60 s
Accessibility
none
Decisions
Found by the efficiency and reliability audit of 2026-10-30 (finding Q2; index postulo/postulo#1108). Checked against
mainatdaee30b15(2026-10-30).