From 40f44ce7a012bddf6b24c9fd50f2462d7d55a88d Mon Sep 17 00:00:00 2001 From: Unai Zorrilla Castro Date: Mon, 18 May 2020 17:41:04 +0200 Subject: [PATCH] Remove TODO's --- build/dependencies.props | 4 +- .../ApplicationBuilderExtensions.cs | 30 ++++----- .../LivenessPrometheusMetrics.cs | 1 - ...heusGatewayHealthCheckBuilderExtensions.cs | 64 +++++++++---------- .../LivenessPrometheusMetrics.cs | 1 - 5 files changed, 49 insertions(+), 51 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 79aade0fc6..4f8717d290 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -121,8 +121,8 @@ 3.1.1-preview3 3.1.1 3.1.1 - 3.1.2 - 3.1.2 + 3.1.3 + 3.1.3 3.1.1 3.1.1 3.1.1 diff --git a/src/HealthChecks.Prometheus.Metrics/Extensions/ApplicationBuilderExtensions.cs b/src/HealthChecks.Prometheus.Metrics/Extensions/ApplicationBuilderExtensions.cs index 753749d2d3..cc82653ff6 100644 --- a/src/HealthChecks.Prometheus.Metrics/Extensions/ApplicationBuilderExtensions.cs +++ b/src/HealthChecks.Prometheus.Metrics/Extensions/ApplicationBuilderExtensions.cs @@ -1,18 +1,18 @@ using HealthChecks.Prometheus.Metrics; -using Microsoft.AspNetCore.Diagnostics.HealthChecks; -using Microsoft.AspNetCore.Http; - +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.AspNetCore.Http; + namespace Microsoft.AspNetCore.Builder -{ - public static class PrometheusHealthCheckMiddleware - { - public static IApplicationBuilder UseHealthChecksPrometheusExporter(this IApplicationBuilder applicationBuilder, PathString endpoint) - { - applicationBuilder.UseHealthChecks(endpoint, new HealthCheckOptions - { - ResponseWriter = PrometheusResponseWriter.WritePrometheusResultText - }); - return applicationBuilder; - } - } +{ + public static class PrometheusHealthCheckMiddleware + { + public static IApplicationBuilder UseHealthChecksPrometheusExporter(this IApplicationBuilder applicationBuilder, PathString endpoint) + { + applicationBuilder.UseHealthChecks(endpoint, new HealthCheckOptions + { + ResponseWriter = PrometheusResponseWriter.WritePrometheusResultText + }); + return applicationBuilder; + } + } } \ No newline at end of file diff --git a/src/HealthChecks.Prometheus.Metrics/LivenessPrometheusMetrics.cs b/src/HealthChecks.Prometheus.Metrics/LivenessPrometheusMetrics.cs index 508ee2e614..071d38ae03 100644 --- a/src/HealthChecks.Prometheus.Metrics/LivenessPrometheusMetrics.cs +++ b/src/HealthChecks.Prometheus.Metrics/LivenessPrometheusMetrics.cs @@ -13,7 +13,6 @@ public abstract class LivenessPrometheusMetrics internal LivenessPrometheusMetrics() { - // TODO: Allow injecting a custom registry Registry = global::Prometheus.Metrics.DefaultRegistry; var factory = global::Prometheus.Metrics.WithCustomRegistry(Registry); diff --git a/src/HealthChecks.Publisher.Prometheus/DependencyInjection/PrometheusGatewayHealthCheckBuilderExtensions.cs b/src/HealthChecks.Publisher.Prometheus/DependencyInjection/PrometheusGatewayHealthCheckBuilderExtensions.cs index ec7ca04aab..cd6fc1fe83 100644 --- a/src/HealthChecks.Publisher.Prometheus/DependencyInjection/PrometheusGatewayHealthCheckBuilderExtensions.cs +++ b/src/HealthChecks.Publisher.Prometheus/DependencyInjection/PrometheusGatewayHealthCheckBuilderExtensions.cs @@ -1,38 +1,38 @@ -using HealthChecks.Publisher.Prometheus; -using Microsoft.Extensions.Diagnostics.HealthChecks; +using HealthChecks.Publisher.Prometheus; +using Microsoft.Extensions.Diagnostics.HealthChecks; using System; -using System.Net.Http; - -namespace Microsoft.Extensions.DependencyInjection -{ - public static class PrometheusGatewayHealthCheckBuilderExtensions - { - /// - /// Add a health check publisher for Prometheus Gateway. - /// - /// - /// For each published a new metric value indicating the health check status (2 Healthy, 1 - /// Degraded, 0 Unhealthy) and the total time the health check took to execute on seconds. - /// - /// The . - /// Endpoint url e.g. http://myendpoint:9091 - /// The job name the series can be filtered on (typically the application name). - /// If there are multiple instances. - /// The . - [Obsolete("This package is deprecated! We recomend using the pull model instead of Gateway. Try to use the package AspNetCore.HealthChecks.Prometheus.Metrics instead of.")] - public static IHealthChecksBuilder AddPrometheusGatewayPublisher(this IHealthChecksBuilder builder, - string endpoint, string job, string instance = null) - { - builder.Services - .AddHttpClient(); - - builder.Services +using System.Net.Http; + +namespace Microsoft.Extensions.DependencyInjection +{ + public static class PrometheusGatewayHealthCheckBuilderExtensions + { + /// + /// Add a health check publisher for Prometheus Gateway. + /// + /// + /// For each published a new metric value indicating the health check status (2 Healthy, 1 + /// Degraded, 0 Unhealthy) and the total time the health check took to execute on seconds. + /// + /// The . + /// Endpoint url e.g. http://myendpoint:9091 + /// The job name the series can be filtered on (typically the application name). + /// If there are multiple instances. + /// The . + [Obsolete("This package is deprecated! We recomend using the pull model instead of Gateway. Try to use the package AspNetCore.HealthChecks.Prometheus.Metrics instead of.")] + public static IHealthChecksBuilder AddPrometheusGatewayPublisher(this IHealthChecksBuilder builder, + string endpoint, string job, string instance = null) + { + builder.Services + .AddHttpClient(); + + builder.Services .AddSingleton(sp => { return new PrometheusGatewayPublisher(() => sp.GetRequiredService().CreateClient(), endpoint, job, instance); - }); - - return builder; + }); + + return builder; } - } + } } \ No newline at end of file diff --git a/src/HealthChecks.Publisher.Prometheus/LivenessPrometheusMetrics.cs b/src/HealthChecks.Publisher.Prometheus/LivenessPrometheusMetrics.cs index 0d31e5ec90..bdac709e1e 100644 --- a/src/HealthChecks.Publisher.Prometheus/LivenessPrometheusMetrics.cs +++ b/src/HealthChecks.Publisher.Prometheus/LivenessPrometheusMetrics.cs @@ -13,7 +13,6 @@ public abstract class LivenessPrometheusMetrics internal LivenessPrometheusMetrics() { - // TODO: Allow injecting a custom registry Registry = Metrics.DefaultRegistry; var factory = Metrics.WithCustomRegistry(Registry);