Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting of composable Health Checks #591

Merged
merged 8 commits into from
Aug 14, 2023

Conversation

MaxDac
Copy link
Contributor

@MaxDac MaxDac commented Aug 11, 2023

Summary

Implements the porting of the composable Health Check classes implementation for .NET Health Checks.

Each composable class implements a different behaviour, specialising in only one responsibility, thus granting more granular maintenance and flexibility compared to an implementation that leverages a chain of inheritance. For instance, using the composition it will be theoretically possible to invert the wrapping order of the classes, or remove a composable class in the middle of the "chain".

These composable classes are the following:

  • ObserverHealthCheck: this is the outermost wrapper, as it implements the exception handling and the activity definition.
  • StartupHealthCheck: implements the behaviour by which the health check is executed only at start-up time, to prevent the deployment of a faulty version of the application.
  • HttpEndpointHealthCheck: this class is the core of the HTTP Endpoint health checks, in that it performs the call to the endpoints that must be checked by the active monitoring and offers extension by the injection of a IHealthCheckResponseChecker interface, which exposes a method that checks the response returned from the HTTP call.

There are two example of different composition strategies in the project, both pointing to the load feedback endpoint:

Liveness Health Check

This health checks simply checks whether the related endpoint is reachable, and the request handling should be short circuited by the server, returning 200. This is accomplished by specifying the MarkAsLivenessCheck activity marker.

Execution Health Check

In this case, the activity marker selected is simply the HealthCheckActivityMarker, which marks the activity as belonging to a health check without dictating the short-circuiting of the request by the server.
This strategy should be used when the execution of the endpoint is equally important as its availability.

The short-circuiting behaviour in the server endpoint has been implemented using the Action Filter -LivenessCheckActionFilterAttribute, that checks whether the endpoint current activity (if existent) has been marked accordingly, as mentioned above.

Implementation details

Another diagnostic package has been created to avoid adding .NET 7 specific dependencies to the project. In particular, the implementation of the activity markers for request short-circuiting and the LivenessCheckActionFilterAttribute dependent on ASP.NET Core dependencies have been implemented in the new package.

Another Unit Test project has been created for the same purpose, as the controller endpoint filter implementation is heavily dependent on .NET 7.

@MaxDac MaxDac marked this pull request as ready for review August 11, 2023 13:35
@MaxDac MaxDac requested a review from a team as a code owner August 11, 2023 13:35
Copy link
Member

@K-Cully K-Cully left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the comments already present, this is OSS; please add documentation.

@MaxDac MaxDac requested a review from K-Cully August 11, 2023 14:17
@MaxDac MaxDac merged commit afc9a23 into main Aug 14, 2023
5 checks passed
@MaxDac MaxDac deleted the mdacunzo/feature/adding-composable-health-checks branch August 14, 2023 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants