Reputation: 4362
Is there an inbuilt health check for service fabric? I have a guest executable written in NET Core 2.2 and utilising the health check feature within it. For example, I have a simple health check that returns unhealthy state:
services
.AddHealthChecks()
.AddCheck<DocumentDbHealthCheck>("cosmos-database");
internal class DocumentDbHealthCheck : IHealthCheck
{
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(HealthCheckResult.Unhealthy());
}
}
I have hooked this up using:
app.UseHealthChecks(@"/foo/bar/v1/healthcheck");
However, when I locally startup my service fabric instance the state is healthy, I was expecting this to be in an errored / unhealthy state.
Is it possible to have service fabric hit the API healthcheck route?
Upvotes: 1
Views: 2680
Reputation: 11341
The Healthcheck introduced on AspNetCore is a mechanism to return data about the status of some service, it does not affect the actual state of the service.
In Service Fabric, If you want to report the health from within the service to the Service Fabric health system, you can use the ReportReplicaHealth()
API. something like this:
HealthInformation healthInformation = new HealthInformation("ServiceCode", "StateDictionary", HealthState.Error);
this.Partition.ReportReplicaHealth(healthInformation);
This will show in the SF Explorer as an Error.
You can also report issues using the FabricClient as described here, in this case, you would create a service to monitor other services and then report their status, aka Watchdog.
AFAIK, Service Fabric does not have an HTTP Probe mechanism to check for the health of a service, it uses the internal metrics reported by the service direct to the health sub system.
If you are planning to use it to validate if a service is healthy before sending request to it, you could user the load balancer http probes or you could just put it behind a Proxy that handles failures and forward the request to a valid node, like the Built-in Reverse Proxy as described here.
Upvotes: 2