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

chore: Refactor probes and add more health checks #1159

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Sep 18, 2024

  • Adds health check for Redis, PosgreSQL and the wellknown-endpoints.
  • Ensures that we have different endpoints for readiness/liveness/startup/health

Related to #292

Summary by CodeRabbit

  • New Features

    • Added health check capabilities for Redis, PostgreSQL, and well-known endpoints.
    • Introduced multiple health check endpoints: /startup, /liveness, /readiness, and /health.
  • Enhancements

    • Improved health monitoring with a new HTTP client and health check configurations.
  • Bug Fixes

    • Enhanced error handling for health checks to provide clearer feedback on endpoint status.

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Warning

Rate limit exceeded

@arealmaas has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 18 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between a275c12 and 8889b77.

Walkthrough

Walkthrough

The pull request introduces several enhancements to the health check capabilities of the application. It adds multiple package references related to health checks and dependency injection. A new health check class for well-known endpoints is implemented, and the infrastructure is updated to include health checks for Redis and PostgreSQL. Additionally, the application's Program.cs file is modified to define multiple health check endpoints, improving the monitoring of application health status.

Changes

Files Change Summary
src/Digdir.Domain.Dialogporten.Infrastructure/Digdir.Domain.Dialogporten.Infrastructure.csproj Added package references for AspNetCore.HealthChecks.NpgSql, AspNetCore.HealthChecks.Redis, AspNetCore.HealthChecks.UI.Client, and Microsoft.Extensions.DependencyInjection.
src/Digdir.Domain.Dialogporten.Infrastructure/HealthChecks/WellKnownHealthChecks.cs Introduced WellKnownEndpointsHealthCheck class implementing IHealthCheck, with a method CheckHealthAsync for checking well-known endpoints from configuration.
src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs Enhanced AddInfrastructure method to include a new HTTP client and health checks for Redis, PostgreSQL, and well-known endpoints.
src/Digdir.Domain.Dialogporten.WebApi/Program.cs Modified health check configuration to include a self-check and defined multiple health check endpoints: /startup, /liveness, /readiness, and /health.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@oskogstad oskogstad changed the title chore: Add health checks for Redis and PostgreSQL [DRAFT] chore: Add health checks for Redis and PostgreSQL Sep 18, 2024
@arealmaas arealmaas changed the title [DRAFT] chore: Add health checks for Redis and PostgreSQL chore: Add health checks for Redis and PostgreSQL Sep 20, 2024
@arealmaas arealmaas changed the title chore: Add health checks for Redis and PostgreSQL chore: Refactor probes and add more health checks Sep 20, 2024
@arealmaas arealmaas marked this pull request as ready for review September 20, 2024 17:13
@arealmaas arealmaas requested a review from a team as a code owner September 20, 2024 17:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between c2559d8 and a275c12.

Files selected for processing (4)
  • src/Digdir.Domain.Dialogporten.Infrastructure/Digdir.Domain.Dialogporten.Infrastructure.csproj (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/HealthChecks/WellKnownHealthChecks.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs (2 hunks)
  • src/Digdir.Domain.Dialogporten.WebApi/Program.cs (3 hunks)
Additional comments not posted (9)
src/Digdir.Domain.Dialogporten.Infrastructure/Digdir.Domain.Dialogporten.Infrastructure.csproj (4)

4-4: LGTM!

The AspNetCore.HealthChecks.NpgSql package reference is a good addition for implementing health checks with PostgreSQL database. The version 8.0.2 is a stable release.


5-5: LGTM!

The AspNetCore.HealthChecks.Redis package reference is a good addition for implementing health checks with Redis cache. The version 8.0.1 is a stable release.


7-7: LGTM!

The AspNetCore.HealthChecks.UI.Client package reference is a good addition for integrating with the health checks UI. The version 8.0.1 is a stable release.


13-13: LGTM!

The Microsoft.Extensions.DependencyInjection package reference is a good addition for dependency injection, which is typically used for registering health checks. The version 8.0.0 is a stable release.

src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs (3)

187-188: LGTM!

Adding a dedicated HTTP client for health checks is a good practice to isolate health check traffic from the application's main HTTP traffic. The handler lifetime of 10 seconds is reasonable for managing resources efficiently.


190-205: Comprehensive health checks added.

The addition of health checks for Redis, PostgreSQL, and well-known endpoints enhances the monitoring capabilities of the application. The configuration of each health check with a name, failure status, and tags is well-structured and allows for granular monitoring.

Using the Unhealthy failure status for all health checks is appropriate to indicate a critical issue when a health check fails. The tags "dependencies" and "auth" enable filtering and categorization of health check results.


33-37: Required using statements added.

The addition of the using statements for health check-related namespaces is necessary for the implementation of health checks. They import the required types and namespaces for configuring health checks in the InfrastructureExtensions class.

src/Digdir.Domain.Dialogporten.WebApi/Program.cs (2)

135-136: Correctly adding health checks service and self-check.

The health checks service is properly configured, and the self-check with the tag "self" is appropriately added.


211-215: Appropriate configuration of liveness endpoint.

The /liveness endpoint is correctly mapped to the "self" health check, which is suitable for liveness probes.

Comment on lines +206 to +210
app.MapHealthChecks("/startup", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("dependencies"),
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
Copy link
Contributor

@coderabbitai coderabbitai bot Sep 20, 2024

Choose a reason for hiding this comment

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

Missing registration of dependency health checks with 'dependencies' tag.

The endpoints /startup, /readiness, and /health are configured to report on health checks tagged with "dependencies", but no health checks are registered with this tag in the provided code. As a result, these endpoints may not return any checks, leading to incomplete health status reports.

Consider registering health checks for your dependencies (e.g., Redis, PostgreSQL) and tagging them with "dependencies". Here's how you might update your health check registration:

             .AddHealthChecks()
                 .AddCheck("self", () => HealthCheckResult.Healthy(), tags: ["self"])
+                .AddRedis(
+                    builder.Configuration.GetConnectionString("Redis"),
+                    name: "Redis",
+                    tags: new[] { "dependencies" })
+                .AddNpgSql(
+                    builder.Configuration.GetConnectionString("PostgreSQL"),
+                    name: "PostgreSQL",
+                    tags: new[] { "dependencies" });

Ensure that the connection strings "Redis" and "PostgreSQL" are correctly configured in your appsettings.json or environment variables.

Also applies to: 216-220, 221-225

Copy link
Collaborator

Choose a reason for hiding this comment

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

But these are registered in InfrastructureExtensions though right?

Copy link
Contributor

Choose a reason for hiding this comment

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

@arealmaas, you're absolutely correct. The dependency health checks are registered in InfrastructureExtensions.cs with the 'dependencies' tag. I apologize for the oversight in my previous comment.

🐰🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries mate! We all do mistakes 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

@arealmaas, thank you for your understanding! 😊

(_/)
( ^.^)
/(")(")

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make me a haiku poem about the code changes in this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

@arealmaas,

Sure, here's a haiku about the code changes in this file:

New health checks in place,
Startup, liveness endpoints,
Dependencies checked.

arealmaas and others added 4 commits September 20, 2024 19:19
…lKnownHealthChecks.cs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…lKnownHealthChecks.cs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

sonarcloud bot commented Sep 20, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants