This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services | |
.AddHealthChecks() | |
.AddRabbitMQ() | |
.CheckOnlyWhen(Registrations.RabbitMQ, | |
conditionToRun: () => Configuration["Store"] == "RabbitMQ", | |
options: new ConditionalHealthCheckOptions | |
{ | |
HealthStatusWhenNotChecked = HealthStatus.Degraded, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"status": "Healthy", | |
"totalDuration": "00:00:00.0152933", | |
"entries": [ | |
{ | |
"name": "redis", | |
"status": "Healthy", | |
"tags": [ | |
"NotChecked" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHealthChecks() | |
.AddRedis(Configuration["Redis:ConnectionString"]) | |
.AddRabbitMQ() | |
.CheckOnlyWhen<FeatureFlagsPolicy>(new[] { Registrations.Redis, Registrations.RabbitMQ }, | |
conditionalHealthCheckPolicyCtorArgs: "BlackFridayPromotion"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FeatureFlagsPolicy : IConditionalHealthCheckPolicy | |
{ | |
private readonly IFeatureFlags _featureFlags; | |
private readonly ILogger<FeatureFlagsPolicy> _logger; | |
private string FeatureName { get; } | |
public FeatureFlagsPolicy(string featureName, | |
IFeatureFlags featureFlags, | |
ILogger<FeatureFlagsPolicy> logger) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IFeatureFlags | |
{ | |
Task<bool> IsSet(string featureName); | |
} | |
public class FeatureFlags : IFeatureFlags | |
{ | |
public Task<bool> IsSet(string featureName) | |
=> Task.FromResult(false); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHealthChecks() | |
// Specify a typed policy to enable executing a health check | |
// This policy could have an exhaustive implementation and | |
// reused with other dependencies. | |
.AddCheck("MyDependency", () => HealthCheckResult.Healthy()) | |
.CheckOnlyWhen<FeatureFlagsPolicy>("MyDependency", | |
conditionalHealthCheckPolicyCtorArgs: "NewFeature"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IConditionalHealthCheckPolicy | |
{ | |
Task<bool> Evaluate(HealthCheckContext context); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHealthChecks() | |
// Check on RabbitMQ only a specific feature flag is set. | |
// The condition is executed asynchronously with every health check request | |
// and it has access to the ServiceProvider and the HealthCheckContext. | |
.AddRabbitMQ() | |
.CheckOnlyWhen(Registrations.RabbitMQ, async (sp, context, token) => | |
{ | |
var featureFlags = sp.GetService<IFeatureFlags>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHealthChecks() | |
// Express the condition as a predicate. | |
// Due to this, the condition is evaluated with every request | |
// | |
// In this example when the `ADependency:Setting` config is changed, | |
// then the health check on `A Dependency` is re-evaluated as usual. | |
// | |
// In the Redis example such a condition is evaluated once, at startup. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHealthChecks() | |
// Check on Redis only when the environment is other than development | |
.AddRedis(Configuration["Redis:ConnectionString"]) | |
.CheckOnlyWhen(Registrations.Redis, !Environment.IsDevelopment()); | |
} |
NewerOlder