Repository navigation
feat: Add health endpoint basic structures and routes - #9588
Conversation
Signed-off-by: Kump3r <[email protected]>
Signed-off-by: Kump3r <[email protected]>
…r now Signed-off-by: Kump3r <[email protected]>
Signed-off-by: Kump3r <[email protected]>
Signed-off-by: Kump3r <[email protected]>
Signed-off-by: Kump3r <[email protected]>
PR Checklist:
|
| Group | Stale behaviour | HTTP impact |
|---|---|---|
Runtime (scheduler, tracker, scanner) |
Promotes overall status to degraded |
200 with "status": "degraded" |
| GC + System | Visible in JSON body | No change to status or HTTP code |
A component is considered stale if it hasn't run within staleMultiplier × interval (default multiplier: 2.0, configurable via --health-component-stale-multiplier). Paused components are excluded — pausing is an intentional operator action.
Rationale
A stale scheduler means builds silently stop being picked up — that is a meaningful degradation operators and load balancers should know about. A stale GC collector is a problem that accumulates over time but does not immediately break builds, so it should not cause noisy status changes for tooling that keys off the top-level status or HTTP code.
Example response (runtime component stale)
{
"status": "degraded",
"database": { "status": "healthy" },
"workers": { "status": "healthy", "total": 3, "running": 3 },
"components": [
{ "name": "scheduler", "healthy": false, "paused": false, "last_ran": "2026-06-08T10:00:00Z", "stale": true },
{ "name": "tracker", "healthy": true, "paused": false, "last_ran": "2026-06-08T10:05:00Z", "stale": false },
{ "name": "collector_volumes", "healthy": false, "paused": false, "last_ran": "2026-06-07T08:00:00Z", "stale": true }
]
}Regarding this:
The one concern worth discussing: every call to the health endpoint would do an extra database read to check scheduler state. Under aggressive probing (e.g. k8s checking every few seconds across many ATC instances) that adds load. We could mitigate it by caching the result for a few seconds.
To my current design idea, I think we can use one single cheap query for all:
ComponentFactory.All() is a single SELECT id, name, interval, last_ran, paused FROM components - no joins, no subqueries, no aggregation. The components table has at most ~23 rows. It returns everything needed to compute staleness (last_ran, interval, paused) in one round trip.
So the full health check becomes exactly 3 queries total:
| Query | Purpose |
|---|---|
SELECT pg_is_in_recovery() |
DB writability check |
SELECT ... FROM workers |
Worker count + states |
SELECT ... FROM components |
All 23 component states |
All three are already used elsewhere on hot paths - no joins, no aggregation. The staleness calculation (time.Since(lastRan) > multiplier × interval) happens in Go after the fetch, not in SQL.
The only scenario worth watching is high-frequency probing (e.g. k8s liveness every 2s × 10 ATC replicas ≈ 15 queries/second against the same 3 tables). Still cheap in absolute terms, but we can add a short in-memory cache later if metrics show it adding up.
Signed-off-by: Kump3r <[email protected]>
|
Just throwing my thoughts down as I'm skimming.
Haven't look at the code yet. |
Good catch. The original thinking was to keep In practice that future hasn't arrived. Right now there is exactly one way a component becomes unhealthy: it goes stale. So Dropping Also thanks for confirming the other implementation details and decisions so far! |
Manual TestingConnect to the database: docker compose exec db psql -U dev concourse Trigger overall
|
…plementation. Signed-off-by: Kump3r <[email protected]>
Signed-off-by: Kump3r <[email protected]>
f1ce8e1 to
35ec721
Compare
|
Okay the overall idea got its shape, what is left to be done from my POV is:
Both of which I prefer to do after the review, as it doesn't make sense to invest time if stuff needs to be reworked based on that. |
|
I will review this! Keep getting pulled off on side quests as you can probably tell 😅 I'll stop putting it off and review over the next few days. |
taylorsilva
left a comment
There was a problem hiding this comment.
Reviewed most of this. Looking good so far! Let me know your thoughts on the things I called out (WDYT).
|
Read your replies and replied where necessary. Feel free to ping me when you've pushed changes to this again. No rush! :) |
Signed-off-by: Kump3r <[email protected]>
|
Added a note to each section with my 2 cents, I more or less tried addressing everything, leaving the test suit refactor as a hanging. Think it is a bit out of scope here and am not sure how to make it any better sadly. Sorry for that, if you have any concrete suggestions I will dive deeper into that, based on my current understanding and knowledge, I would have to refactor a lot of tests just to make this work and not sure whether that brings any value, besides code clarity :/ |
Signed-off-by: Taylor Silva <[email protected]>
There was a problem hiding this comment.
I've reviewed the latest changes and they LGTM.
I pushed a commit resolving our issue with how the test setup worked. I used the options pattern to make it easier for us to introduce similar test changes in the future. Now all the setup code is consolidated into one set of functions instead of having duplicate funcs.
If someone wants to configure something in the api.NewHandler(), they just add fields to the apiServerConfig struct and new apiConfigOpt func for the new fields.
I added a few fields as examples. Didn't include apiConfigOpt funcs for them since we don't need to change them from the default. Also helped make those values more descriptive when reading the code.
|
Thanks @taylorsilva for the support in RFC and in reviewing. I will address the follow-up packaging (helm/bosh/fly/client lib) in separate PR's. |
Changes proposed by this PR
Initial work based on concourse/rfcs#141
atc/health.go- Health DTOs and constantsatc/health_test.go- Comprehensive unit testsatc/routes.go- Modified with health route constants and mappingNotes to reviewer
This is the very beginning of the
/api/v1/healthendpoint feature. The focus of this PR is to establish basic structure and data types. Actual logic will follow in separate PR's following the "Implementation plan" I created in the rfc PR. The focus on the review here that I desire is the design and validity of the data structures and JSON schema. Since I will follow-up with the actual health server in the next PR, I used stubs for now in places, where the handler was expected.