예제 #1
0
        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));
                }
            });
        }
예제 #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsMiddlewareHealthChecksOptions = new AppMetricsMiddlewareHealthChecksOptions
            {
                HealthEndpointEnabled = true,
            };

            SetupServices(services, appMetricsMiddlewareHealthChecksOptions);
        }
예제 #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsMiddlewareHelathCheckOptions = new AppMetricsMiddlewareHealthChecksOptions();

            SetupServices(
                services,
                appMetricsMiddlewareHelathCheckOptions,
                healthChecks: new[] { HealthCheckResult.Healthy() });
        }
예제 #4
0
        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);
        }
예제 #5
0
        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));
 }
예제 #7
0
        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);
        }