GRPCHealthIndicator

The GRPCHealthIndicator is used for health checks related to GRPC

  
class GRPCHealthIndicator extends HealthIndicator {
  checkService<GrpcOptions extends GrpcClientOptionsLike = GrpcClientOptionsLike>(key: string, service: string, options: CheckGRPCServiceOptions<GrpcOptions> = {}): Promise<HealthIndicatorResult>

  // inherited from terminus/lib/HealthIndicator
  protected getStatus(key: string, isHealthy: boolean, data?: { [key: string]: any; }): HealthIndicatorResult
}

Methods

checkService()

Checks if the given service is up using the standard health check specification of GRPC.


checkService<GrpcOptions extends GrpcClientOptionsLike = GrpcClientOptionsLike>(key: string, service: string, options: CheckGRPCServiceOptions<GrpcOptions> = {}): Promise<HealthIndicatorResult>

Parameters

Option Type Description
key string

The key which will be used for the result object

service string

The service which should be checked

options CheckGRPCOptions

Configuration for the request


Optional. Default is `{}`.

Examples

    
grpc.checkService('hero_service', 'hero.health.v1')
    
// Change the timeout
grpc.checkService('hero_service', 'hero.health.v1', { timeout: 300 })
    
// You can customize the health check
// by giving these options. Nonetheless it is still seen
// as best practice to implement the recommended GRPC specs
grpc.checkService('hero_service', 'hero.health.v1', {
  timeout: 500,
  package: 'grpc.health.v2',
  protoPath: join(__dirname, './protos/my-custom-health.v1'),
  // The name of the service you need for the health check
  healthServiceName: 'Health',
  // Your custom function which checks the service
  healthServiceCheck: (healthService: any, service: string) =>
    healthService.check({ service }).toPromise(),
})

Returns

Promise<HealthIndicatorResult>

Throws

HealthCheckError Gets thrown in case a health check failed

TimeoutError Gets thrown in case a health check exceeded the given timeout

UnhealthyResponseCodeError Gets thrown in case the received response is unhealthy

https://github.com/grpc/grpc/blob/master/doc/health-checking.md