Browse Source

docs(core): Add more documentation on health checks

Michael Bromley 5 years ago
parent
commit
47c1675975

+ 32 - 0
docs/content/docs/developer-guide/deployment.md

@@ -16,6 +16,38 @@ A typical pattern is to run the Vendure app on the server, e.g. at `http://local
 
 Here is a good guide to setting up a production-ready server for an app such as Vendure: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04
 
+## Health/Readiness Checks
+
+If you wish to deploy with Kubernetes or some similar system, you can make use of the health check endpoint. This is a regular REST route (note: _not_ GraphQL), available at `/health`.
+
+```text 
+REQUEST: GET http://localhost:3000/health
+```
+```json
+{
+  "status": "ok",
+  "info": {
+    "database": {
+      "status": "up"
+    },
+    "worker": {
+      "status": "up"
+    }
+  },
+  "error": {},
+  "details": {
+    "database": {
+      "status": "up"
+    },
+    "worker": {
+      "status": "up"
+    }
+  }
+}
+```
+
+Health checks are built on the [Nestjs Terminus module](https://docs.nestjs.com/recipes/terminus). You can also add your own health checks by creating plugins that make use of the [HealthCheckRegistryService]({{< relref "health-check-registry-service" >}}).
+
 ## Admin UI
 
 If you have customized the Admin UI with extensions, it can make sense to [compile your extensions ahead-of-time as part of the deployment process]({{< relref "/docs/plugins/extending-the-admin-ui" >}}#compiling-as-a-deployment-step).

+ 31 - 2
packages/core/src/health-check/health-check-registry.service.ts

@@ -3,15 +3,43 @@ import { HealthIndicatorFunction } from '@nestjs/terminus';
 /**
  * @description
  * This service is used to register health indicator functions to be included in the
- * health check. It wraps the [Nestjs Terminus module](https://docs.nestjs.com/recipes/terminus),
+ * health check. Health checks can be used by automated services such as Kubernetes
+ * to determine the state of applications it is running. They are also useful for
+ * administrators to get an overview of the health of all the parts of the
+ * Vendure stack.
+ *
+ * It wraps the [Nestjs Terminus module](https://docs.nestjs.com/recipes/terminus),
  * so see those docs for information on creating custom health checks.
  *
  * Plugins which rely on external services (web services, databases etc.) can make use of this
  * service to add a check for that dependency to the Vendure health check.
  *
+ * To use it in your plugin, you'll need to import the {@link PluginCommonModule}:
+ *
+ * @example
+ * ```TypeScript
+ * import { HealthCheckRegistryService, PluginCommonModule, VendurePlugin } from '\@vendure/core';
+ * import { TerminusModule } from '\@nestjs/terminus';
+ *
+ * \@VendurePlugin({
+ *   imports: [PluginCommonModule, TerminusModule],
+ * })
+ * export class MyPlugin {
+ *   constructor(
+ *     private registry: HealthCheckRegistryService
+ *     private dns: DNSHealthIndicator
+ *   ) {
+ *     registry.registerIndicatorFunction(
+ *       () => this.dns.pingCheck('vendure-docs', 'https://www.vendure.io/docs/'),
+ *     )
+ *   }
+ * }
+ * ```
+ *
  * @docsCategory health-check
  */
 export class HealthCheckRegistryService {
+    /** @internal */
     get healthIndicatorFunctions(): HealthIndicatorFunction[] {
         return this._healthIndicatorFunctions;
     }
@@ -19,8 +47,9 @@ export class HealthCheckRegistryService {
 
     /**
      * @description
-     * Registers one or more `HealthIndicatorFunctions` (see [Nestjs docs](https://docs.nestjs.com/recipes/terminus#custom-health-indicator))
+     * Registers one or more `HealthIndicatorFunctions` (see [Nestjs docs](https://docs.nestjs.com/recipes/terminus#setting-up-a-healthcheck))
      * to be added to the health check endpoint.
+     * The indicator will also appear in the Admin UI's "system status" view.
      */
     registerIndicatorFunction(fn: HealthIndicatorFunction | HealthIndicatorFunction[]) {
         const fnArray = Array.isArray(fn) ? fn : [fn];