diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesExtensions.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesExtensions.cs index f4f60965655..1eb3faf2ddc 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesExtensions.cs @@ -50,7 +50,7 @@ public static IServiceCollection AddKubernetesProbes(this IServiceCollection ser var wrapperOptions = new KubernetesProbesOptions(); return services - .AddTcpEndpointHealthCheck(ProbeTags.Liveness, options => + .AddTcpEndpointProbe(ProbeTags.Liveness, options => { wrapperOptions.LivenessProbe = options; configure(wrapperOptions); @@ -64,7 +64,7 @@ public static IServiceCollection AddKubernetesProbes(this IServiceCollection ser options.FilterChecks = (check) => check.Tags.Contains(ProbeTags.Liveness) && originalPredicate(check); } }) - .AddTcpEndpointHealthCheck(ProbeTags.Startup, options => + .AddTcpEndpointProbe(ProbeTags.Startup, options => { wrapperOptions.StartupProbe = options; configure(wrapperOptions); @@ -78,7 +78,7 @@ public static IServiceCollection AddKubernetesProbes(this IServiceCollection ser options.FilterChecks = (check) => check.Tags.Contains(ProbeTags.Startup) && originalPredicate(check); } }) - .AddTcpEndpointHealthCheck(ProbeTags.Readiness, (options) => + .AddTcpEndpointProbe(ProbeTags.Readiness, (options) => { wrapperOptions.ReadinessProbe = options; configure(wrapperOptions); diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesOptions.EndpointOptions.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesOptions.EndpointOptions.cs deleted file mode 100644 index 43bb7bec48f..00000000000 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesOptions.EndpointOptions.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics.CodeAnalysis; -using Microsoft.Extensions.Diagnostics.HealthChecks; -using Microsoft.Shared.Data.Validation; - -namespace Microsoft.Extensions.Diagnostics.Probes; - -public partial class KubernetesProbesOptions -{ - /// - /// Options to control TCP-based health check probes. - /// - [SuppressMessage("Major Code Smell", "S109:Magic numbers should not be used", Justification = "In place numbers make the ranges cleaner")] - [SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "It's fine")] - public class EndpointOptions - { - private const int DefaultMaxPendingConnections = 10; - private const int DefaultTcpPort = 2305; - - /// - /// Gets or sets the TCP port that gets opened if the service is healthy and closed otherwise. - /// - /// - /// The default value is 2305. - /// - [Range(1, 65535)] - public int TcpPort { get; set; } = DefaultTcpPort; - - /// - /// Gets or sets the maximum length of the pending connections queue. - /// - /// - /// The default value is 10. - /// - [Range(1, 10000)] - public int MaxPendingConnections { get; set; } = DefaultMaxPendingConnections; - - /// - /// Gets or sets the interval at which the health of the application is assessed. - /// - /// - /// The default value is 30 seconds. - /// - [TimeSpan("00:00:05", "00:05:00")] - public TimeSpan HealthAssessmentPeriod { get; set; } = TimeSpan.FromSeconds(30); - - /// - /// Gets or sets a predicate that is used to include health checks based on user-defined criteria. - /// - /// - /// The default value is , which has the effect of enabling all health checks. - /// - public Func? FilterChecks { get; set; } - } -} diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesOptions.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesOptions.cs index 59f7fbed4df..8ec7a1c78db 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesOptions.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/KubernetesProbesOptions.cs @@ -6,7 +6,7 @@ namespace Microsoft.Extensions.Diagnostics.Probes; /// /// Options for Kubernetes probes. /// -public partial class KubernetesProbesOptions +public class KubernetesProbesOptions { private const int DefaultLivenessProbePort = 2305; private const int DefaultStartupProbePort = 2306; @@ -18,7 +18,7 @@ public partial class KubernetesProbesOptions /// /// Default port is 2305. /// - public EndpointOptions LivenessProbe { get; set; } = new EndpointOptions + public TcpEndpointProbesOptions LivenessProbe { get; set; } = new TcpEndpointProbesOptions { TcpPort = DefaultLivenessProbePort, }; @@ -29,7 +29,7 @@ public partial class KubernetesProbesOptions /// /// Default port is 2306. /// - public EndpointOptions StartupProbe { get; set; } = new EndpointOptions + public TcpEndpointProbesOptions StartupProbe { get; set; } = new TcpEndpointProbesOptions { TcpPort = DefaultStartupProbePort, }; @@ -40,7 +40,7 @@ public partial class KubernetesProbesOptions /// /// Default port is 2307. /// - public EndpointOptions ReadinessProbe { get; set; } = new EndpointOptions + public TcpEndpointProbesOptions ReadinessProbe { get; set; } = new TcpEndpointProbesOptions { TcpPort = DefaultReadinessProbePort, }; diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckExtensions.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesExtensions.cs similarity index 67% rename from src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckExtensions.cs rename to src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesExtensions.cs index 566b9b6a076..c3b5dbb04d6 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesExtensions.cs @@ -5,16 +5,17 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.Probes; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Microsoft.Shared.Diagnostics; -namespace Microsoft.Extensions.Diagnostics.Probes; +namespace Microsoft.Extensions.DependencyInjection; /// -/// Extension methods for for . +/// Extension methods for setting up TCP-based health check probes. /// -internal static class TcpEndpointHealthCheckExtensions +public static class TcpEndpointProbesExtensions { /// /// Registers health status reporting using a TCP port @@ -22,11 +23,11 @@ internal static class TcpEndpointHealthCheckExtensions /// /// The to add the services to. /// The value of . - internal static IServiceCollection AddTcpEndpointHealthCheck(this IServiceCollection services) + public static IServiceCollection AddTcpEndpointProbe(this IServiceCollection services) { _ = Throw.IfNull(services); - return services.AddTcpEndpointHealthCheck(Microsoft.Extensions.Options.Options.DefaultName); + return services.AddTcpEndpointProbe(Microsoft.Extensions.Options.Options.DefaultName); } /// @@ -36,19 +37,19 @@ internal static IServiceCollection AddTcpEndpointHealthCheck(this IServiceCollec /// The to add the services to. /// Name used to retrieve the options. /// The value of . - internal static IServiceCollection AddTcpEndpointHealthCheck(this IServiceCollection services, string name) + public static IServiceCollection AddTcpEndpointProbe(this IServiceCollection services, string name) { _ = Throw.IfNull(services); _ = services.AddHealthChecks(); _ = services - .AddOptionsWithValidateOnStart(name); + .AddOptionsWithValidateOnStart(name); _ = services.AddSingleton(provider => { - var options = provider.GetRequiredService>().Get(name); - return ActivatorUtilities.CreateInstance(provider, options); + var options = provider.GetRequiredService>().Get(name); + return ActivatorUtilities.CreateInstance(provider, options); }); return services; @@ -59,18 +60,18 @@ internal static IServiceCollection AddTcpEndpointHealthCheck(this IServiceCollec /// if service is considered as healthy . /// /// The to add the services to. - /// Configuration for . + /// Configuration for . /// The value of . - internal static IServiceCollection AddTcpEndpointHealthCheck( + public static IServiceCollection AddTcpEndpointProbe( this IServiceCollection services, - Action configure) + Action configure) { _ = Throw.IfNull(services); _ = Throw.IfNull(configure); _ = services.Configure(configure); - return services.AddTcpEndpointHealthCheck(); + return services.AddTcpEndpointProbe(); } /// @@ -79,19 +80,19 @@ internal static IServiceCollection AddTcpEndpointHealthCheck( /// /// The to add the services to. /// Name for the options. - /// Configuration for . + /// Configuration for . /// The value of . - internal static IServiceCollection AddTcpEndpointHealthCheck( + public static IServiceCollection AddTcpEndpointProbe( this IServiceCollection services, string name, - Action configure) + Action configure) { _ = Throw.IfNull(services); _ = Throw.IfNull(configure); _ = services.Configure(name, configure); - return services.AddTcpEndpointHealthCheck(name); + return services.AddTcpEndpointProbe(name); } /// @@ -99,18 +100,18 @@ internal static IServiceCollection AddTcpEndpointHealthCheck( /// if service is considered as healthy . /// /// The to add the services to. - /// Configuration for . + /// Configuration for . /// The value of . - internal static IServiceCollection AddTcpEndpointHealthCheck( + public static IServiceCollection AddTcpEndpointProbe( this IServiceCollection services, IConfigurationSection configurationSection) { _ = Throw.IfNull(services); _ = Throw.IfNull(configurationSection); - _ = services.Configure(configurationSection); + _ = services.Configure(configurationSection); - return services.AddTcpEndpointHealthCheck(); + return services.AddTcpEndpointProbe(); } /// @@ -119,9 +120,9 @@ internal static IServiceCollection AddTcpEndpointHealthCheck( /// /// The to add the services to. /// Name for the options. - /// Configuration for . + /// Configuration for . /// The value of . - internal static IServiceCollection AddTcpEndpointHealthCheck( + public static IServiceCollection AddTcpEndpointProbe( this IServiceCollection services, string name, IConfigurationSection configurationSection) @@ -129,8 +130,8 @@ internal static IServiceCollection AddTcpEndpointHealthCheck( _ = Throw.IfNull(services); _ = Throw.IfNull(configurationSection); - _ = services.Configure(name, configurationSection); + _ = services.Configure(name, configurationSection); - return services.AddTcpEndpointHealthCheck(name); + return services.AddTcpEndpointProbe(name); } } diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesOptions.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesOptions.cs new file mode 100644 index 00000000000..af777ea08ab --- /dev/null +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesOptions.cs @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Shared.Data.Validation; + +namespace Microsoft.Extensions.Diagnostics.Probes; + +/// +/// Options to control TCP-based health check probes. +/// +[SuppressMessage("Major Code Smell", "S109:Magic numbers should not be used", Justification = "In place numbers make the ranges cleaner")] +public class TcpEndpointProbesOptions +{ + private const int DefaultMaxPendingConnections = 10; + private const int DefaultTcpPort = 2305; + + /// + /// Gets or sets the TCP port that gets opened if the service is healthy and closed otherwise. + /// + /// + /// The default value is 2305. + /// + [Range(1, 65535)] + public int TcpPort { get; set; } = DefaultTcpPort; + + /// + /// Gets or sets the maximum length of the pending connections queue. + /// + /// + /// The default value is 10. + /// + [Range(1, 10000)] + public int MaxPendingConnections { get; set; } = DefaultMaxPendingConnections; + + /// + /// Gets or sets the interval at which the health of the application is assessed. + /// + /// + /// The default value is 30 seconds. + /// + [TimeSpan("00:00:05", "00:05:00")] + public TimeSpan HealthAssessmentPeriod { get; set; } = TimeSpan.FromSeconds(30); + + /// + /// Gets or sets a predicate that is used to include health checks based on user-defined criteria. + /// + /// + /// The default value is , which has the effect of enabling all health checks. + /// + public Func? FilterChecks { get; set; } +} diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckOptionsValidator.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesOptionsValidator.cs similarity index 68% rename from src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckOptionsValidator.cs rename to src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesOptionsValidator.cs index 0a11191883e..2ae823df7e6 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckOptionsValidator.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesOptionsValidator.cs @@ -6,6 +6,6 @@ namespace Microsoft.Extensions.Diagnostics.Probes; [OptionsValidator] -internal sealed partial class EndpointOptionsValidator : IValidateOptions +internal sealed partial class TcpEndpointProbesOptionsValidator : IValidateOptions { } diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckService.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesService.cs similarity index 84% rename from src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckService.cs rename to src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesService.cs index 77905ee0bfa..8ede62ff92c 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointHealthCheckService.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Probes/TcpEndpointProbesService.cs @@ -16,18 +16,18 @@ namespace Microsoft.Extensions.Diagnostics.Probes; /// /// Opens a TCP port if the service is healthy and closes it otherwise. /// -internal sealed class TcpEndpointHealthCheckService : BackgroundService +internal sealed class TcpEndpointProbesService : BackgroundService { internal TimeProvider TimeProvider { get; set; } = TimeProvider.System; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly HealthCheckService _healthCheckService; - private readonly KubernetesProbesOptions.EndpointOptions _options; -#pragma warning disable CA2213 // 'TcpEndpointHealthCheckService' contains field '_listener' that is of IDisposable type 'TcpListener' + private readonly TcpEndpointProbesOptions _options; +#pragma warning disable CA2213 // 'TcpEndpointProbesService' contains field '_listener' that is of IDisposable type 'TcpListener' private readonly TcpListener _listener; #pragma warning restore CA2213 - public TcpEndpointHealthCheckService(ILogger logger, HealthCheckService healthCheckService, KubernetesProbesOptions.EndpointOptions options) + public TcpEndpointProbesService(ILogger logger, HealthCheckService healthCheckService, TcpEndpointProbesOptions options) { _logger = logger; _healthCheckService = healthCheckService; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/KubernetesProbesExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/KubernetesProbesExtensionsTests.cs index 5e283a7bceb..6629dce7ca9 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/KubernetesProbesExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/KubernetesProbesExtensionsTests.cs @@ -33,8 +33,8 @@ public void AddKubernetesProbes_RegistersAllProbes() services.AddKubernetesProbes().AddHealthChecks(); }); - var hostedServices = host.Services.GetServices().Where(service => service.GetType().Name == "TcpEndpointHealthCheckService"); - var configurations = host.Services.GetServices>(); + var hostedServices = host.Services.GetServices().Where(service => service.GetType().Name == "TcpEndpointProbesService"); + var configurations = host.Services.GetServices>(); Assert.Equal(3, hostedServices.Count()); Assert.Single(configurations); @@ -74,8 +74,8 @@ public void AddKubernetesProbes_WithConfigureAction_RegistersAllProbes() }).AddHealthChecks(); }); - var hostedServices = host.Services.GetServices().Where(service => service.GetType().Name == "TcpEndpointHealthCheckService"); - var configurations = host.Services.GetServices>(); + var hostedServices = host.Services.GetServices().Where(service => service.GetType().Name == "TcpEndpointProbesService"); + var configurations = host.Services.GetServices>(); Assert.Equal(3, hostedServices.Count()); Assert.Single(configurations); @@ -102,8 +102,8 @@ public void AddKubernetesProbes_WithConfigurationSection_RegistersAllProbes() services.AddKubernetesProbes(configuration.GetSection("KubernetesProbes")).AddHealthChecks(); }); - var hostedServices = host.Services.GetServices().Where(service => service.GetType().Name == "TcpEndpointHealthCheckService"); - var configurations = host.Services.GetServices>(); + var hostedServices = host.Services.GetServices().Where(service => service.GetType().Name == "TcpEndpointProbesService"); + var configurations = host.Services.GetServices>(); Assert.Equal(3, hostedServices.Count()); Assert.Single(configurations); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointHealthCheckExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointProbesExtensionsTests.cs similarity index 75% rename from test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointHealthCheckExtensionsTests.cs rename to test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointProbesExtensionsTests.cs index 94ec7cfa4a8..e77df5d3d7a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointHealthCheckExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointProbesExtensionsTests.cs @@ -21,39 +21,39 @@ namespace Microsoft.Extensions.Diagnostics.Probes.Test; -public class TcpEndpointHealthCheckExtensionsTests +public class TcpEndpointProbesExtensionsTests { [Fact] - public void AddTcpEndpointHealthCheckTest_WithoutConfig() + public void AddTcpEndpointProbeTest_WithoutConfig() { using var host = CreateWebHost(services => { services .AddRouting() - .AddTcpEndpointHealthCheck(); + .AddTcpEndpointProbe(); }); - var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointHealthCheckService); + var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointProbesService); Assert.Single(hostedServices); } [Fact] - public void AddTcpEndpointHealthCheckTest_WithAction() + public void AddTcpEndpointProbeTest_WithAction() { using var host = CreateWebHost(services => { services .AddRouting() - .AddTcpEndpointHealthCheck(o => + .AddTcpEndpointProbe(o => { o.FilterChecks = _ => false; o.HealthAssessmentPeriod = TimeSpan.FromSeconds(15); }); }); - var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointHealthCheckService); - var configurations = host.Services.GetServices>(); + var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointProbesService); + var configurations = host.Services.GetServices>(); Assert.Single(hostedServices); var config = Assert.Single(configurations); @@ -61,36 +61,36 @@ public void AddTcpEndpointHealthCheckTest_WithAction() } [Fact] - public void AddTcpEndpointHealthCheckTest_WithName_WithoutConfig() + public void AddTcpEndpointProbeTest_WithName_WithoutConfig() { using var host = CreateWebHost(services => { services .AddRouting() - .AddTcpEndpointHealthCheck("Liveness"); + .AddTcpEndpointProbe("Liveness"); }); - var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointHealthCheckService); + var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointProbesService); Assert.Single(hostedServices); } [Fact] - public void AddTcpEndpointHealthCheckTest_WithName_WithAction() + public void AddTcpEndpointProbeTest_WithName_WithAction() { using var host = CreateWebHost(services => { services .AddRouting() - .AddTcpEndpointHealthCheck("Liveness", o => + .AddTcpEndpointProbe("Liveness", o => { o.FilterChecks = _ => false; o.HealthAssessmentPeriod = TimeSpan.FromSeconds(5); }); }); - var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointHealthCheckService); - var configurations = host.Services.GetServices>(); + var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointProbesService); + var configurations = host.Services.GetServices>(); Assert.Single(hostedServices); var config = Assert.Single(configurations); @@ -99,7 +99,7 @@ public void AddTcpEndpointHealthCheckTest_WithName_WithAction() } [Fact] - public void AddTcpEndpointHealthCheckTest_WithConfigurationSection() + public void AddTcpEndpointProbeTest_WithConfigurationSection() { var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary @@ -112,11 +112,11 @@ public void AddTcpEndpointHealthCheckTest_WithConfigurationSection() { services .AddRouting() - .AddTcpEndpointHealthCheck(config.GetSection("TcpHealthCheck")); + .AddTcpEndpointProbe(config.GetSection("TcpHealthCheck")); }); - var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointHealthCheckService); - var configurations = host.Services.GetServices>(); + var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointProbesService); + var configurations = host.Services.GetServices>(); Assert.Single(hostedServices); var configuration = Assert.Single(configurations); @@ -124,7 +124,7 @@ public void AddTcpEndpointHealthCheckTest_WithConfigurationSection() } [Fact] - public void AddTcpEndpointHealthCheckTest_WithName_WithConfigurationSection() + public void AddTcpEndpointProbeTest_WithName_WithConfigurationSection() { var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary @@ -137,11 +137,11 @@ public void AddTcpEndpointHealthCheckTest_WithName_WithConfigurationSection() { services .AddRouting() - .AddTcpEndpointHealthCheck("Liveness", config.GetSection("TcpHealthCheck")); + .AddTcpEndpointProbe("Liveness", config.GetSection("TcpHealthCheck")); }); - var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointHealthCheckService); - var configurations = host.Services.GetServices>(); + var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointProbesService); + var configurations = host.Services.GetServices>(); Assert.Single(hostedServices); Assert.Single(configurations); @@ -151,18 +151,18 @@ public void AddTcpEndpointHealthCheckTest_WithName_WithConfigurationSection() } [Fact] - public void AddTcpEndpointHealthCheckTest_MultipleNamed() + public void AddTcpEndpointProbeTest_MultipleNamed() { using var host = CreateWebHost(services => { services .AddRouting() - .AddTcpEndpointHealthCheck("Liveness") - .AddTcpEndpointHealthCheck("Readiness"); + .AddTcpEndpointProbe("Liveness") + .AddTcpEndpointProbe("Readiness"); }); - var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointHealthCheckService); - var configurations = host.Services.GetServices>(); + var hostedServices = host.Services.GetServices().Where(x => x is TcpEndpointProbesService); + var configurations = host.Services.GetServices>(); Assert.Equal(2, hostedServices.Count()); Assert.Single(configurations); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointHealthCheckServiceTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointProbesServiceTests.cs similarity index 75% rename from test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointHealthCheckServiceTests.cs rename to test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointProbesServiceTests.cs index ff9c93ff871..ee236aa9d66 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointHealthCheckServiceTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/TcpEndpointProbesServiceTests.cs @@ -12,8 +12,8 @@ namespace Microsoft.Extensions.Diagnostics.Probes.Test; -[CollectionDefinition(nameof(TcpEndpointHealthCheckServiceTests), DisableParallelization = true)] -public class TcpEndpointHealthCheckServiceTests +[CollectionDefinition(nameof(TcpEndpointProbesServiceTests), DisableParallelization = true)] +public class TcpEndpointProbesServiceTests { [Fact] public async Task ExecuteAsync_CheckListenerOpenAndCloseAfterHealthStatusEvents() @@ -24,13 +24,13 @@ public async Task ExecuteAsync_CheckListenerOpenAndCloseAfterHealthStatusEvents( var healthCheckService = new MockHealthCheckService(); - var options = new KubernetesProbesOptions.EndpointOptions + var options = new TcpEndpointProbesOptions { TcpPort = port, }; var timeProvider = new FakeTimeProvider(); - using var tcpEndpointHealthCheckService = new TcpEndpointHealthCheckService( - new FakeLogger(), + using var tcpEndpointProbesService = new TcpEndpointProbesService( + new FakeLogger(), healthCheckService, options) { @@ -39,8 +39,8 @@ public async Task ExecuteAsync_CheckListenerOpenAndCloseAfterHealthStatusEvents( Assert.False(IsTcpOpened(port)); - await tcpEndpointHealthCheckService.StartAsync(cts.Token); - await tcpEndpointHealthCheckService.UpdateHealthStatusAsync(cts.Token); + await tcpEndpointProbesService.StartAsync(cts.Token); + await tcpEndpointProbesService.UpdateHealthStatusAsync(cts.Token); Assert.True(IsTcpOpened(port)); @@ -49,7 +49,7 @@ public async Task ExecuteAsync_CheckListenerOpenAndCloseAfterHealthStatusEvents( Assert.True(IsTcpOpened(port)); healthCheckService.IsHealthy = false; - await tcpEndpointHealthCheckService.UpdateHealthStatusAsync(cts.Token); + await tcpEndpointProbesService.UpdateHealthStatusAsync(cts.Token); Assert.False(IsTcpOpened(port)); @@ -58,7 +58,7 @@ public async Task ExecuteAsync_CheckListenerOpenAndCloseAfterHealthStatusEvents( Assert.False(IsTcpOpened(port)); healthCheckService.IsHealthy = true; - await tcpEndpointHealthCheckService.UpdateHealthStatusAsync(cts.Token); + await tcpEndpointProbesService.UpdateHealthStatusAsync(cts.Token); Assert.True(IsTcpOpened(port)); @@ -73,13 +73,13 @@ public async Task ExecuteAsync_Does_Nothing_On_Cancellation() var healthCheckService = new MockHealthCheckService(); - var options = new KubernetesProbesOptions.EndpointOptions + var options = new TcpEndpointProbesOptions { TcpPort = port, }; var timeProvider = new FakeTimeProvider(); - using var tcpEndpointHealthCheckService = new TcpEndpointHealthCheckService( - new FakeLogger(), + using var tcpEndpointProbesService = new TcpEndpointProbesService( + new FakeLogger(), healthCheckService, options) { @@ -89,7 +89,7 @@ public async Task ExecuteAsync_Does_Nothing_On_Cancellation() using var cts = new CancellationTokenSource(); cts.Cancel(); - await tcpEndpointHealthCheckService.StartAsync(cts.Token); + await tcpEndpointProbesService.StartAsync(cts.Token); Assert.False(IsTcpOpened(port)); }