-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
health checks: configure path in apollo-server, doc better #5270
health checks: configure path in apollo-server, doc better #5270
Conversation
@jutaz: 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/ |
Tagging @abernix for review (can't assign reviewers) |
Hmm. One thing that's a challenge is that paths in the middlewares are sometimes relative to where the middleware is applied to your server and sometimes not. But I guess just letting you swap out a hardcoded constant for a different one is reasonable. I really wish that the health check was just a feature of |
I guess this boils down to - are we viewing TL;DR - I'll happily change this implementation to whatever maintainers think is best suited implementation, just LMK 👍 |
That's my perspective for sure. So yeah, let's just make this |
@glasser Sorry for a slow response on this one - I've changed this PR so that only |
Planning to come back to this once 3.0.0 is released (it's in final release candidate state now). |
@glasser - is this ready to merge in all checks are still green? |
@gidich yep, got it on the queue (see label addition) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(oops meant to send this yesterday)
@@ -15,6 +15,7 @@ export { GraphQLOptions } from 'apollo-server-core'; | |||
|
|||
export interface GetMiddlewareOptions { | |||
path?: string; | |||
healthCheckPath?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really want to extend the interface for apollo-server-express
; for the framework integration packages I'd rather leave this as a simple not super configurable feature which you can easily reimplement directly in your framework if you need more control. We can give this some sort of __internal_healthCheckPath
name to make it clear that this isn't supported and doesn't need to be documented. I can make this change soon if you don't beat me to it.
fe2554c
to
877b19e
Compare
I got a little carried away here and turned this into an opportunity to rewrite the docs and guidance around health checks. |
@glasser yup, makes sense - thanks for doing that! |
@@ -22,6 +22,16 @@ export interface GetMiddlewareOptions { | |||
bodyParserConfig?: OptionsJson | boolean; | |||
onHealthCheck?: (req: express.Request) => Promise<any>; | |||
disableHealthCheck?: boolean; | |||
// There's no real point to allowing you to customize the health check path in | |||
// an Apollo Server web framework integration package. You're already using | |||
// Express --- just define a health check yourself! This option only exists to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with the message but I think the way it's written might trivialize this a bit. Can we link out to some example or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tweaked the wording a little. Not sure an example will help: it's just "make your web server do its normal thing".
e54fb5d
to
eb40ae0
Compare
Our health check feature is kind of bizarre. It doesn't actually check that your GraphQL server can, well, serve GraphQL: it just checks if it can serve HTTP. And the way it matches path names doesn't work very well in contexts like Lambda where your whole server is often mounted at a sub-path. In many cases, it would be better to just run a trivial GraphQL operation as a health check. Additionally, it's strange that we let you configure the functionality of the health check in framework integrations, when it would be just as easy to define your own handler in your framework. I suppose it's nice that the health check exists in the batteries-included `apollo-server` package, since you do often want to have a health check (though again, running a GraphQL operation is often better) and that package doesn't let you tweak HTTP serving directly. And it's a bit of a shame that you can't set the health check path in that package. So, this PR: - Adds a `healthCheckPath` constructor option to the `apollo-server` package. You can also pass `null` to disable the health check, which wasn't previously possible with that package. This is based on work by @jutaz though the PR has been thoroughly reworked since then. - Reorganizes the `ApolloServer` reference docs so that the `apollo-server`-specific options are all together, and documents both the new option and the accidentally-undocumented `onHealthCheck`. - Rewrites the health check docs to encourage the use of GraphQL-level health checks, and to separate guidance around HTTP-level health checks in `apollo-server` (you can tweak it a bit if you want!) from HTTP-level health checks in framework integration packages (if you're doing something fancy just use the framework directly!) Fixes apollographql#3577. Fixes apollographql#5731.
eb40ae0
to
b006d97
Compare
Our health check feature is kind of bizarre. It doesn't actually check
that your GraphQL server can, well, serve GraphQL: it just checks if it
can serve HTTP. And the way it matches path names doesn't work very well
in contexts like Lambda where your whole server is often mounted at a
sub-path. In many cases, it would be better to just run a trivial
GraphQL operation as a health check.
Additionally, it's strange that we let you configure the functionality
of the health check in framework integrations, when it would be just as
easy to define your own handler in your framework.
I suppose it's nice that the health check exists in the
batteries-included
apollo-server
package, since you do often want tohave a health check (though again, running a GraphQL operation is often
better) and that package doesn't let you tweak HTTP serving directly.
And it's a bit of a shame that you can't set the health check path in
that package.
So, this PR:
healthCheckPath
constructor option to theapollo-server
package. You can also pass
null
to disable the health check, whichwasn't previously possible with that package. This is based on work by
@jutaz though the PR has been thoroughly reworked since then by @glasser.
ApolloServer
reference docs so that theapollo-server
-specific options are all together, and documents boththe new option and the accidentally-undocumented
onHealthCheck
.health checks, and to separate guidance around HTTP-level health
checks in
apollo-server
(you can tweak it a bit if you want!) fromHTTP-level health checks in framework integration packages (if you're
doing something fancy just use the framework directly!)
Fixes #3577. Fixes #5731.