Collect per-template deployment counts - #7
Open
ak40u wants to merge 2 commits into
Open
Conversation
workspaceTemplates only carries a rounded health percentage, which cannot answer how many deploys failed in a given period: health is computed over a rolling window, so it climbs back up as old failures age out of it. Collect templateMetrics alongside it. It reports the deploy counts behind that percentage, and storing them turns health into a number of failed deploys - both as failed_deployments per snapshot and, via the template_deployment_failures view, as the deploys and failures added between consecutive runs. The query takes one template id per call, so it is built with an alias per template and sent in batches of 40: Railway rejects a query whose breadth exceeds 500 and each template costs ten nodes. Deploy counts are a different population from the existing project counts - they include redeploys of an existing install - so they go in their own table rather than as columns on template_snapshots.
Deploys are a lifetime counter; health is a percentage over a rolling window whose size Railway does not publish. Multiplying them is unsound, and the first two snapshots showed it: a template whose six deploys aged out of the window went from "6 failed" to "0 failed" with no deploy in between - minus six failures in a day. templateMetrics also answers templateHealth 100 when it has nothing to report, which reads exactly like a genuine 100%. The public health field is null in that case, so health_reported is derived from it and the view returns NULL health rather than a default dressed up as a measurement. The view keeps what holds up - deployments_added off the monotonic counter, and health_change beside it - and is renamed to template_deployment_activity since it no longer reports failures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
workspaceTemplatesreportshealthas a rounded percentage. A percentage alone does not say how much activity it covers: a template sitting at 88% could have had two failed deploys or twenty, and nothing stored says which.Change
Collect
templateMetricsalongside the existing queries. It carries the counters behind the percentage —totalDeployments,deploymentsLast90Days,activeDeployments— plussupportHealthand per-template earnings.template_deployment_snapshots. Deploy counts are a different population from the project counts already stored — they include redeploys of an existing install — so they get their own table instead of columns ontemplate_snapshots, and no existing view or dashboard changes.template_deployment_activitydifferences consecutive snapshots intodeployments_added, and reportshealth_changebeside it.ensureSchemanow drives off aREQUIRED_TABLESlist rather than a hardcoded3, so the schema file re-runs once on existing databases to add the new table. Every statement in it is idempotent.Two traps, both hit in practice
I originally stored a
failed_deploymentscolumn computed astotal_deployments * (100 - health) / 100, and afailures_addeddelta on top of it. Both are wrong, and the first two days of real data showed it:The counter and the percentage cover different periods. Deploys are counted for the lifetime of the template; health is a percentage over a rolling window whose size is not published. When the window empties, the formula reports zero failures for deploys that did fail. One of my templates went from "6 failed" to "0 failed" without a single deploy in between — a change of minus six failures in a day.
templateMetricsreturnstemplateHealth: 100when it has nothing to report, which is indistinguishable from a genuine 100%. The publichealthfield isnullin that same case. That is what thehealth_reportedcolumn is derived from, and the view returnsNULLhealth rather than a default presented as a measurement.So this PR deliberately reports no failure count. What it does report is what holds up:
deployments_added(the counter is monotonic, so the difference is real) andhealth_changenext to it. A health drop against a positivedeployments_addedis the signal worth chasing.Batching
templateMetricstakes one template id per call, so the query is built with an alias per template. Sending all of them at once fails:Each template costs ten nodes (its own plus nine fields), so requests go out in batches of 40 — under the cap with room for a field to be added later.
Verification
Run against a workspace of 57 templates across two daily collections: two batched requests per run, 189 deploys tracked, rows written and the view returning as expected. Deltas are
NULLon the first snapshot, which is correct — there is no prior row to compare against.Unit tests cover the query builder (alias/variable agreement, selected fields, batch size against the breadth cap). The database tests need a live Postgres and were not run in this environment.