Repository navigation
add: Health endpoint go-client methods and fly command - #9640
Conversation
Signed-off-by: Kump3r <[email protected]>
taylorsilva
left a comment
There was a problem hiding this comment.
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:
Line 173 in 3c3fc8d
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.
|
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. |
Signed-off-by: Kump3r <[email protected]>
|
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. |
Changes proposed by this PR
Follow-up to #9588 — adds client library support and a CLI command for the health endpoint.
GetHealth() (atc.Health, error)to thego-concourseclient interfaceGET /api/v1/healthclient method usinghttpAgentso 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)concoursefakes/fake_client.gowith the new methodfly healthcommand with table output and--jsonflag,registered as aliashNotes to reviewer
httpAgentoverconnection.Send: the health endpoint deliberately returns 503 with a JSON body when the cluster is failing.connection.Sendtreats non-2xx as an error and skips decoding —httpAgent.Sendlets us decode 503 responses the same as 200, so callers always get a populatedatc.Healthstruct regardless of cluster state.No
target.Validate()in the fly command: the health endpoint is unauthenticated. CallingValidate()would hit/api/v1/infoand do a version check before the actual health call, which is unnecessary overhead. Follows the same pattern asfly 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 statusworks.Integration tests use
createFlyRc+atcServer.Reset(): the suiteBeforeEachruns a full login sequence and queues 4 handlers. Sincefly healthskips login, we write the target directly to~/.flyrcand reset the server to discard those unused handlers. Same pattern asfly statusintegration tests.