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

Add Redis Health Check #13589

Merged
merged 25 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3702139
Add RedisHealthCheck
hishamco Apr 22, 2023
a743935
Add RedisHealthCheck extension method
hishamco Apr 22, 2023
8b62e57
Call AddRedisCheck()
hishamco Apr 22, 2023
1aa2c94
Use IRedisService instead
hishamco Apr 22, 2023
82e9a55
Merge branch 'main' into hishamco/redis-health-check
hishamco May 14, 2023
632f4da
Address feedback
hishamco May 14, 2023
4c16f14
Add a separate Startup
hishamco May 14, 2023
f298f6e
Fix unable to load IRedisService while activating RedisHealthCheck
hishamco May 14, 2023
f5811ed
Fix the returned HealthCheckResult
hishamco May 14, 2023
08a4924
Merge branch 'main' into hishamco/redis-health-check
Piedone Mar 21, 2024
41804d1
Merge branch 'main' into hishamco/redis-health-check
hishamco Mar 26, 2024
8a23f3b
Merge branch 'main' into hishamco/redis-health-check
hishamco Mar 26, 2024
9e0cf80
Merge branch 'main' into hishamco/redis-health-check
hishamco Mar 27, 2024
5174d47
Add description for unhealthy status
hishamco Mar 27, 2024
38d06ab
Add docs
hishamco Mar 27, 2024
71d39d5
Address feedback
hishamco Mar 28, 2024
d7bb336
Merge branch 'main' into hishamco/redis-health-check
hishamco Mar 28, 2024
bfcf5ab
Fix the build
hishamco Mar 28, 2024
447fea6
Fix seconds argument
hishamco Mar 29, 2024
b4928d8
Merge branch 'main' into hishamco/redis-health-check
hishamco Apr 1, 2024
e93590a
Timeout as const
hishamco Apr 1, 2024
5f9a144
Use expression body
hishamco Apr 1, 2024
2f5242e
Merge branch 'main' into hishamco/redis-health-check
hishamco Apr 1, 2024
5720a64
Update the comment
hishamco Apr 1, 2024
6cac17e
Update src/OrchardCore.Modules/OrchardCore.Redis/HealthChecks/Startup.cs
hishamco Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OrchardCore.Redis.HealthChecks;

namespace Microsoft.Extensions.DependencyInjection;

public static class RedisHealthCheckExtensions
{
public static IHealthChecksBuilder AddRedisCheck(this IHealthChecksBuilder healthChecksBuilder)
=> healthChecksBuilder.AddCheck<RedisHealthCheck>("Redis Health Check");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.Extensions.Diagnostics.HealthChecks;
using StackExchange.Redis;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Extensions.Options;

namespace OrchardCore.Redis.HealthChecks;

public class RedisHealthCheck : IHealthCheck
{
private readonly RedisOptions _redisOptions;

public RedisHealthCheck(IOptions<RedisOptions> redisOptions)
{
_redisOptions = redisOptions.Value;
}

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
await ConnectionMultiplexer.ConnectAsync(_redisOptions.Configuration);
hishamco marked this conversation as resolved.
Show resolved Hide resolved

return HealthCheckResult.Healthy();
}
catch
{
return HealthCheckResult.Unhealthy();
Piedone marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
4 changes: 4 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Redis/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public override void ConfigureServices(IServiceCollection services)
services.AddSingleton<IRedisService, RedisService>();
services.AddSingleton<IModularTenantEvents>(sp => sp.GetRequiredService<IRedisService>());
services.AddSingleton<IRedisDatabaseFactory, RedisDatabaseFactory>();

services
.AddHealthChecks()
.AddRedisCheck();
}
}

Expand Down