Skip to content

apollo-server-lambda: Implement onHealthCheck on createHandler.#3458

Merged
abernix merged 6 commits into
apollographql:masterfrom
glenthomas:master
Nov 13, 2019
Merged

apollo-server-lambda: Implement onHealthCheck on createHandler.#3458
abernix merged 6 commits into
apollographql:masterfrom
glenthomas:master

Conversation

@glenthomas

Copy link
Copy Markdown
Contributor

Fixes #3443

I have added the common health check functionality to the apollo-server-lambda package.

When the request path matches /.well-known/apollo/server-health then the lambda will execute the supplied onHealthCheck function and return the standard pass/fail response. If no onHealthCheck function is supplied then the lambda will return a default pass response to signal that the server is available.

@apollo-cla

Copy link
Copy Markdown

@MrGlenThomas: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@sesteva

sesteva commented Oct 30, 2019

Copy link
Copy Markdown

+1

1 similar comment
@lukefrizzell

Copy link
Copy Markdown

+1

@abernix abernix 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.

Thanks for opening this! I think there's a problem with the HTTP status code that's set during failure conditions, but other than that, thank you for putting this together!

.catch(() => {
return callback(null, {
body: JSON.stringify({ status: 'fail' }),
statusCode: 200,

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.

I think this status code should be 503 — do you agree?

Suggested change
statusCode: 200,
statusCode: 503,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had thought that the health check should return 200 to signal that the request completed successfully and the body inspected for a result, otherwise the 503 could mean that the health check could not be reached (which isn't really that important to know). Having considered it again I think returning a 503 on failure does make sense, some health checks may work on status code alone and I have seen that this is how it has been implemented in the other Apollo packages.

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.

I can certainly understand that thinking. The bit about some health check implementations relying on the status code exclusively is the most relevant. Parsing JSON responses is not functionality that all probes/tools support (or it adds too much configuration to make it worthwhile).

For the above reason, and consistency with the other Apollo implementations (and documentation clarity!) I think we should go with 503 here, unless we think that won't play nice with AWS for some reason.

@Glen-Moonpig Glen-Moonpig Nov 13, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes that's fine. Route 53 health checks require the endpoint to respond with an HTTP status code of 2xx or 3xx to signal healthy, so that will work.

@abernix

abernix commented Nov 13, 2019

Copy link
Copy Markdown
Member

I've also added a CHANGELOG.md.

@abernix abernix changed the title Added health check for apollo-server-lambda apollo-server-lambda: Implement onHealthCheck on createHandler. Nov 13, 2019
@abernix abernix merged commit 84e1aa5 into apollographql:master Nov 13, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Health check endpoint for apollo-server-lambda

6 participants