Skip to content

Update the health check endpoint route builder extensions to make the endpoint display name configurable. (#8359) #8361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static partial class HealthCheckEndpointRouteBuilderExtensions
{
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapHealthChecks(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder builder, string pattern) { throw null; }
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapHealthChecks(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder builder, string pattern, Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions options) { throw null; }
public static Microsoft.AspNetCore.Builder.IEndpointConventionBuilder MapHealthChecks(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder builder, string pattern, Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions options, string displayName) { throw null; }
}
}
namespace Microsoft.AspNetCore.Diagnostics.HealthChecks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Builder
/// </summary>
public static class HealthCheckEndpointRouteBuilderExtensions
{
private const string DefaultDisplayName = "Health checks";

/// <summary>
/// Adds a health checks endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template.
/// </summary>
Expand All @@ -29,7 +31,7 @@ public static IEndpointConventionBuilder MapHealthChecks(
throw new ArgumentNullException(nameof(builder));
}

return MapHealthChecksCore(builder, pattern, null);
return MapHealthChecksCore(builder, pattern, null, DefaultDisplayName);
}

/// <summary>
Expand All @@ -54,18 +56,50 @@ public static IEndpointConventionBuilder MapHealthChecks(
throw new ArgumentNullException(nameof(options));
}

return MapHealthChecksCore(builder, pattern, options);
return MapHealthChecksCore(builder, pattern, options, DefaultDisplayName);
}

/// <summary>
/// Adds a health checks endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template, options and display name.
/// </summary>
/// <param name="builder">The <see cref="IEndpointRouteBuilder"/> to add the health checks endpoint to.</param>
/// <param name="pattern">The URL pattern of the health checks endpoint.</param>
/// <param name="options">A <see cref="HealthCheckOptions"/> used to configure the health checks.</param>
/// <param name="displayName">The display name for the endpoint.</param>
/// <returns>A convention builder for the health checks endpoint.</returns>
public static IEndpointConventionBuilder MapHealthChecks(
this IEndpointRouteBuilder builder,
string pattern,
HealthCheckOptions options,
string displayName)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}

if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

if (string.IsNullOrEmpty(displayName))
{
throw new ArgumentException("A valid non-empty display name must be provided.", nameof(displayName));
}

return MapHealthChecksCore(builder, pattern, options, displayName);
}

private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuilder builder, string pattern, HealthCheckOptions options)
private static IEndpointConventionBuilder MapHealthChecksCore(IEndpointRouteBuilder builder, string pattern, HealthCheckOptions options, string displayName)
{
var args = options != null ? new[] { Options.Create(options) } : Array.Empty<object>();

var pipeline = builder.CreateApplicationBuilder()
.UseMiddleware<HealthCheckMiddleware>(args)
.Build();

return builder.Map(pattern, "Health checks", pipeline);
return builder.Map(pattern, displayName, pipeline);
}
}
}