Skip to content

Commit

Permalink
Simplify option name performServiceHealthChecks -> serviceHealthCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Apr 2, 2020
1 parent fa051fe commit e6edbc7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/source/api/apollo-gateway.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ example of using `ApolloGateway`, see [The gateway](/federation/gateway/).
});
```

* `performServiceHealthChecks`: `boolean`
* `serviceHealthCheck`: `boolean`

When set to true, the gateway will issue a small query (`{ __typename }`) to
its downstream services on load and on schema update. On load, the gateway
Expand Down Expand Up @@ -164,7 +164,7 @@ const server = new ApolloServer({
});
```

### `performServiceHealthChecks`
### `serviceHealthCheck`

Calling this function on the gateway will issue a small query (`{ __typename }`)
to each downstream service to ensure they are all responsive. This function
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-gateway/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- Drop use of `loglevel-debug`. This removes the very long date and time prefix in front of each log line and also the support for the `DEBUG=apollo-gateway:` environment variable. Both of these were uncommonly necessary or seldom used (with the environment variable also being undocumented). The existing behavior can be preserved by providing a `logger` that uses `loglevel-debug`, if desired, and more details can be found in the PR. [PR #3896](https://github.com/apollographql/apollo-server/pull/3896)
- Fix Typescript generic typing for datasource contexts [#3865](https://github.com/apollographql/apollo-server/pull/3865) This is a fix for the `TContext` typings of the gateway's exposed `GraphQLDataSource` implementations. In their current form, they don't work as intended, or in any manner that's useful for typing the `context` property throughout the class methods. This introduces a type argument `TContext` to the class itself (which defaults to `Record<string, any>` for existing implementations) and removes the non-operational type arguments on the class methods themselves.
- Implement retry logic for requests to GCS [PR #3836](https://github.com/apollographql/apollo-server/pull/3836) Note: coupled with this change is a small alteration in how the gateway polls GCS for updates in managed mode. Previously, the tick was on a specific interval. Now, every tick starts after the round of fetches to GCS completes. For more details, see the linked PR.
- Gateway issues health checks to downstream services via `performServiceHealthChecks` configuration option. Note: expected behavior differs between managed and unmanaged federation. See PR for new test cases and documentation. [#3930](https://github.com/apollographql/apollo-server/pull/3930)
- Gateway issues health checks to downstream services via `serviceHealthCheck` configuration option. Note: expected behavior differs between managed and unmanaged federation. See PR for new test cases and documentation. [#3930](https://github.com/apollographql/apollo-server/pull/3930)

## 0.13.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe('Downstream service health checks', () => {
const gateway = new ApolloGateway({
logger,
serviceList: [{ name: 'accounts', url: service.url }],
performServiceHealthChecks: true,
serviceHealthCheck: true,
});

await gateway.load();
Expand All @@ -302,7 +302,7 @@ describe('Downstream service health checks', () => {

const gateway = new ApolloGateway({
serviceList: [{ name: 'accounts', url: service.url }],
performServiceHealthChecks: true,
serviceHealthCheck: true,
logger,
});

Expand All @@ -322,7 +322,7 @@ describe('Downstream service health checks', () => {

mockServiceHealthCheckSuccess(service);

const gateway = new ApolloGateway({ performServiceHealthChecks: true, logger });
const gateway = new ApolloGateway({ serviceHealthCheck: true, logger });

await gateway.load({ engine: { apiKeyHash, graphId } });
expect(gateway.schema!.getType('User')!.description).toBe('This is my User');
Expand All @@ -337,7 +337,7 @@ describe('Downstream service health checks', () => {

mockServiceHealthCheck(service).reply(500);

const gateway = new ApolloGateway({ performServiceHealthChecks: true, logger });
const gateway = new ApolloGateway({ serviceHealthCheck: true, logger });

await expect(
gateway.load({ engine: { apiKeyHash, graphId } }),
Expand Down Expand Up @@ -365,7 +365,7 @@ describe('Downstream service health checks', () => {
const onChange = jest.fn().mockImplementationOnce(() => resolve());

const gateway = new ApolloGateway({
performServiceHealthChecks: true,
serviceHealthCheck: true,
logger,
});
// @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
Expand Down Expand Up @@ -403,7 +403,7 @@ describe('Downstream service health checks', () => {
.fn()
.mockImplementationOnce(() => resolve())

const gateway = new ApolloGateway({ performServiceHealthChecks: true, logger });
const gateway = new ApolloGateway({ serviceHealthCheck: true, logger });
// @ts-ignore for testing purposes, a short pollInterval is ideal so we'll override here
gateway.experimental_pollInterval = 300;

Expand Down
10 changes: 5 additions & 5 deletions packages/apollo-gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface GatewayConfigBase {
experimental_approximateQueryPlanStoreMiB?: number;
experimental_autoFragmentization?: boolean;
fetcher?: typeof fetch;
performServiceHealthChecks?: boolean;
serviceHealthCheck?: boolean;
}

interface RemoteGatewayConfig extends GatewayConfigBase {
Expand Down Expand Up @@ -358,7 +358,7 @@ export class ApolloGateway implements GraphQLService {

// Run service health checks before we commit and update the new schema.
// This is the last chance to bail out of a schema update.
if (this.config.performServiceHealthChecks) {
if (this.config.serviceHealthCheck) {
// Here we need to construct new datasources based on the new schema info
// so we can check the health of the services we're _updating to_.
const serviceMap = result.serviceDefinitions.reduce(
Expand All @@ -373,7 +373,7 @@ export class ApolloGateway implements GraphQLService {
);

try {
await this.performServiceHealthChecks(serviceMap);
await this.serviceHealthCheck(serviceMap);
} catch (e) {
this.logger.error(
'The gateway did not update its schema due to failed service health checks. ' +
Expand Down Expand Up @@ -431,15 +431,15 @@ export class ApolloGateway implements GraphQLService {
* @example
* ```
* try {
* await gateway.performServiceHealthChecks();
* await gateway.serviceHealthCheck();
* } catch(e) {
* /* your error handling here *\/
* }
* ```
*
* @param serviceMap {DataSourceMap}
*/
protected performServiceHealthChecks(serviceMap: DataSourceMap = this.serviceMap) {
protected serviceHealthCheck(serviceMap: DataSourceMap = this.serviceMap) {
return Promise.all(
Object.entries(serviceMap).map(([name, { dataSource }]) =>
dataSource
Expand Down

0 comments on commit e6edbc7

Please sign in to comment.