Create reusable code for checking Elasticsearch health.
We need to create "health check" endpoints for the various APIs. It would be good to avoid writing the same code multiple times, so instead, we'll create a class in NCI.OCPL.Api.Common to perform the most common checks and individual services can create instances of this class as needed.
The most common (only?) check we do at this time is to check the host/cluster health by checking index health.
⚠️ I need to think on this a bit. Instead of a string, the constructor should take an object with a method/property returning string. Then we don't need lots of hijinks in the startup code to instantiate the thing.
classDiagram
class IHealthCheckService {
<<interface>>
IsHealthy() bool
}
class ESHealthCheckService {
+ESHealthCheckService(esClient, indexName, logger)
+IsHealthy() bool
}
ESHealthCheckService <|-- IHealthCheckService
The ESHealthCheckService constructor takes as parameters an instance of IElasticClient, the name of the specific index to check, and an instance of ILogger<ESHealthCheck>.
The IsHealthy method returns true if the index is healthy and false otherwise.
Create reusable code for checking Elasticsearch health.
We need to create "health check" endpoints for the various APIs. It would be good to avoid writing the same code multiple times, so instead, we'll create a class in
NCI.OCPL.Api.Common
to perform the most common checks and individual services can create instances of this class as needed.The most common (only?) check we do at this time is to check the host/cluster health by checking index health.
⚠️ I need to think on this a bit. Instead of a string, the constructor should take an object with a method/property returning string. Then we don't need lots of hijinks in the startup code to instantiate the thing.
The ESHealthCheckService constructor takes as parameters an instance of
IElasticClient
, the name of the specific index to check, and an instance ofILogger<ESHealthCheck>
.The
IsHealthy
method returnstrue
if the index is healthy andfalse
otherwise.Resources:
Prerequisites
Sub-Tasks
Notes