protected void SetupServices( IServiceCollection services, AppMetricsMiddlewareHealthChecksOptions appMetricsMiddlewareHealthChecksOptions, IEnumerable <HealthCheckResult> healthChecks = null) { services .AddLogging() .AddRouting(options => { options.LowercaseUrls = true; }); services .AddHealthChecks() .AddHealthCheckMiddleware( options => { options.HealthEndpointEnabled = appMetricsMiddlewareHealthChecksOptions.HealthEndpointEnabled; options.HealthEndpoint = appMetricsMiddlewareHealthChecksOptions.HealthEndpoint; }, optionsBuilder => { optionsBuilder.AddJsonFormatters(); }) .AddChecks( factory => { var checks = healthChecks != null ? healthChecks.ToList() : new List <HealthCheckResult>(); for (var i = 0; i < checks.Count; i++) { var check = checks[i]; factory.Register("Check" + i, () => new ValueTask <HealthCheckResult>(check)); } }); }
public void ConfigureServices(IServiceCollection services) { var appMetricsMiddlewareHealthChecksOptions = new AppMetricsMiddlewareHealthChecksOptions { HealthEndpointEnabled = true, }; SetupServices(services, appMetricsMiddlewareHealthChecksOptions); }
public void ConfigureServices(IServiceCollection services) { var appMetricsMiddlewareHelathCheckOptions = new AppMetricsMiddlewareHealthChecksOptions(); SetupServices( services, appMetricsMiddlewareHelathCheckOptions, healthChecks: new[] { HealthCheckResult.Healthy() }); }
public void Can_load_settings_from_configuration() { var options = new AppMetricsMiddlewareHealthChecksOptions(); var provider = SetupServicesAndConfiguration(); Action resolveOptions = () => { options = provider.GetRequiredService <AppMetricsMiddlewareHealthChecksOptions>(); }; resolveOptions.ShouldNotThrow(); options.HealthEndpoint.Should().Be("/health-test"); options.HealthEndpointEnabled.Should().Be(false); }
public void ConfigureServices(IServiceCollection services) { var appMetricsMiddlewareHelathCheckOptions = new AppMetricsMiddlewareHealthChecksOptions { HealthEndpointEnabled = true }; SetupServices( services, appMetricsMiddlewareHelathCheckOptions, healthChecks: new[] { HealthCheckResult.Healthy(), HealthCheckResult.Degraded(), HealthCheckResult.Unhealthy() }); }
public HealthCheckEndpointMiddleware( RequestDelegate next, AppMetricsMiddlewareHealthChecksOptions appMiddlewareOptions, ILoggerFactory loggerFactory, IProvideHealth health, IHealthResponseWriter healthResponseWriter) { _next = next; _appMiddlewareOptions = appMiddlewareOptions; _health = health; _logger = loggerFactory.CreateLogger <HealthCheckEndpointMiddleware>(); _healthResponseWriter = healthResponseWriter ?? throw new ArgumentNullException(nameof(healthResponseWriter)); }
public void Can_override_settings_from_configuration() { var options = new AppMetricsMiddlewareHealthChecksOptions(); var provider = SetupServicesAndConfiguration( (o) => { o.HealthEndpointEnabled = true; }); Action resolveOptions = () => { options = provider.GetRequiredService <AppMetricsMiddlewareHealthChecksOptions>(); }; resolveOptions.ShouldNotThrow(); options.HealthEndpointEnabled.Should().Be(true); }