Skip to content
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

Merged

Conversation

jutaz
Copy link
Contributor

@jutaz jutaz commented Jun 3, 2021

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 by @glasser.
  • 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 #3577. Fixes #5731.

@apollo-cla
Copy link

@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/

@jutaz
Copy link
Contributor Author

jutaz commented Jun 3, 2021

Tagging @abernix for review (can't assign reviewers)

@glasser
Copy link
Member

glasser commented Jun 7, 2021

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 apollo-server and people using a middleware integration just defined their own health check. It has very little to do with serving GraphQL and doesn't really fit with the rest of the project. Because of that, I'm tempted to say this new argument should only be an apollo-server thing, and if you want to customize your health check path with a different library then you can just define it in your own code.

@jutaz
Copy link
Contributor Author

jutaz commented Jun 8, 2021

I'm tempted to say this new argument should only be an apollo-server thing, and if you want to customize your health check path with a different library then you can just define it in your own code.

I guess this boils down to - are we viewing apollo-server as the only "batteries included" solution and other vendor-specific packages are "bring your own implementation"? I'm certainly impartial to the solution (personally only care about apollo-server which I'm using), but I wonder if there's a reason to still keep the abstraction for health checks in other packages.

TL;DR - I'll happily change this implementation to whatever maintainers think is best suited implementation, just LMK 👍

@glasser
Copy link
Member

glasser commented Jun 9, 2021

That's my perspective for sure. So yeah, let's just make this apollo-server-specific?

@jutaz
Copy link
Contributor Author

jutaz commented Jun 23, 2021

@glasser Sorry for a slow response on this one - I've changed this PR so that only apollo-server and apollo-server-express (which is required to have this change due to the fact that apollo-server relies on it internally) would expose the healthCheckPath

@glasser
Copy link
Member

glasser commented Jul 2, 2021

Planning to come back to this once 3.0.0 is released (it's in final release candidate state now).

@gidich
Copy link

gidich commented Sep 24, 2021

@glasser - is this ready to merge in all checks are still green?

@glasser
Copy link
Member

glasser commented Sep 28, 2021

@gidich yep, got it on the queue (see label addition)

Copy link
Member

@glasser glasser left a 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;
Copy link
Member

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.

@glasser glasser force-pushed the feature/configurable-health-check-path branch from fe2554c to 877b19e Compare October 1, 2021 00:06
@glasser glasser changed the title Make the health-check path configurable. health checks: configure path in apollo-server, doc better Oct 1, 2021
@glasser
Copy link
Member

glasser commented Oct 1, 2021

I got a little carried away here and turned this into an opportunity to rewrite the docs and guidance around health checks.

@jutaz
Copy link
Contributor Author

jutaz commented Oct 1, 2021

@glasser yup, makes sense - thanks for doing that!

@glasser glasser added 2021-10 and removed 2021-09 labels Oct 1, 2021
@@ -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
Copy link
Member

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?

Copy link
Member

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".

@glasser glasser force-pushed the feature/configurable-health-check-path branch 2 times, most recently from e54fb5d to eb40ae0 Compare October 8, 2021 00:04
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.
@glasser glasser force-pushed the feature/configurable-health-check-path branch from eb40ae0 to b006d97 Compare October 8, 2021 00:05
@glasser glasser merged commit a0ccf23 into apollographql:main Oct 8, 2021
@jutaz jutaz deleted the feature/configurable-health-check-path branch June 10, 2022 12:59
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants