318
CHAPTER 7 | Implement resilient applications
// Program.cs from WebStatus(Watch Dog) service
//
// Registers required services for health checks
builder.
Services
.
AddHealthChecksUI
();
// build the app, register other middleware
app.
UseHealthChecksUI
(config => config.
UIPath
=
"/hc-ui"
);
Health checks when using orchestrators
To monitor the availability
of your microservices, orchestrators like Kubernetes and Service Fabric
periodically perform health checks by sending requests to test the microservices. When an
orchestrator determines that a service/container is unhealthy, it stops routing
requests to that
instance. It also usually creates a new instance of that container.
For instance, most orchestrators can use health checks to manage zero-downtime deployments. Only
when the status of a service/container changes to healthy will the orchestrator start routing traffic to
service/container instances.
Health monitoring is especially important when an orchestrator performs an application upgrade.
Some orchestrators (like Azure Service Fabric) update services in phases
—
for example, they might
update one-
fifth of the cluster surface for each application upgrade. The set of nodes that’s upgraded
at the same time is referred to as an
upgrade domain
. After each upgrade domain has been upgraded
and
is available to users, that upgrade domain must pass health checks before the deployment moves
to the next upgrade domain.
Another aspect of service health is reporting metrics from the service. This is an advanced capability of
the health model of some orchestrators, like Service Fabric. Metrics are important when using an
orchestrator because they are used to balance resource usage. Metrics
also can be an indicator of
system health. For example, you might have an application that has many microservices, and each
instance reports a requests-per-second (RPS) metric. If one service is using more resources (memory,
processor, etc.)
than another service, the orchestrator could move service instances around in the
cluster to try to maintain even resource utilization.
Note that Azure Service Fabric provides its own
Health Monitoring model
,
which is more advanced
than simple health checks.
Dostları ilə paylaş: