Skip to content

add: Health endpoint go-client methods and fly command - #9640

Merged
taylorsilva merged 2 commits into
concourse:masterfrom
Kump3r:health-endpoint-client
Jul 13, 2026
Merged

taylorsilva merged 2 commits into
concourse:masterfrom
Kump3r:health-endpoint-client

Conversation

@Kump3r

@Kump3r Kump3r commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Changes proposed by this PR

Follow-up to #9588 — adds client library support and a CLI command for the health endpoint.

  • Added GetHealth() (atc.Health, error) to the go-concourse client interface
  • Implemented GET /api/v1/health client method using httpAgent so the response body is decoded on both 200 and 503 (a 503 from this endpoint means the cluster is failing, not that the request itself failed)
  • Regenerated concoursefakes/fake_client.go with the new method
  • Added fly health command with table output and --json flag, registered as alias h
  • Table shows overall status, database, workers (total/running + unhealthy worker names), and all components with their last run time

Notes to reviewer

  • httpAgent over connection.Send: the health endpoint deliberately returns 503 with a JSON body when the cluster is failing. connection.Send treats non-2xx as an error and skips decoding — httpAgent.Send lets us decode 503 responses the same as 200, so callers always get a populated atc.Health struct regardless of cluster state.

  • No target.Validate() in the fly command: the health endpoint is unauthenticated. Calling Validate() would hit /api/v1/info and do a version check before the actual health call, which is unnecessary overhead. Follows the same pattern as fly status.

  • Exit code is always 0: a failing cluster is informational, not a fly error. The cluster state is conveyed through the JSON body and table output. Consistent with how fly status works.

  • Integration tests use createFlyRc + atcServer.Reset(): the suite BeforeEach runs a full login sequence and queues 4 handlers. Since fly health skips login, we write the target directly to ~/.flyrc and reset the server to discard those unused handlers. Same pattern as fly status integration tests.

@Kump3r
Kump3r requested a review from a team July 10, 2026 07:45
@taylorsilva taylorsilva added this to the v8.3.0 milestone Jul 10, 2026
@taylorsilva taylorsilva moved this from Todo to In Progress in Pull Requests Jul 10, 2026

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried manually testing it first and got HTTP 401. Can reproduce by doing:

$ fly -t l logout
$ fly -t l health
error: Unexpected Response
Status: 401 Unauthorized
Body: not authorized

I had to fly login first to get it to work. I think you need to use LoadUnauthenticatedTarget() instead of LoadTarget() to avoid this scenario:

func LoadUnauthenticatedTarget(

Not sure if that function is appropriate here either, func signature is much longer! Might need a new one to mirror the usability of LoadTarget(). Feel free to rename/refactor the functions in target.go, LoadUnauthenticatedTarget() is only used in one place.

Table and json output looks good otherwise.

@Kump3r

Kump3r commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor Author

I noticed this as well during my testing, but I couldn’t find any other fly commands without authentication, so decided I should follow that pattern. I will take a look at your recommendation.

@Kump3r

Kump3r commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Okay it was a simple enough change, I decided to just mirror the LoadTarget with nil for token and switch the health command to use it instead. Also added a test with a specifically expired token, so I can check that the token is not required.

@Kump3r
Kump3r requested a review from taylorsilva July 11, 2026 10:03
@taylorsilva
taylorsilva merged commit c49b8ad into concourse:master Jul 13, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests Jul 13, 2026
Comment thread fly/rc/target.go Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants