Skip to content
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

If needed... Extensions for Health checks #28

Open
3 tasks
majco333 opened this issue Jun 13, 2019 · 0 comments
Open
3 tasks

If needed... Extensions for Health checks #28

majco333 opened this issue Jun 13, 2019 · 0 comments
Labels
area-AspNetCore Kros.AspNetCore library next

Comments

@majco333
Copy link
Collaborator

majco333 commented Jun 13, 2019

Add extensions for health checks:

  • proxy support
  • json output support
  • add tests

Notes:
Report and writer
Tests

public static class UrisHealthCheckBuilderExtensions
{
///


/// Add a health check for single uri.
///

/// The .
/// The uri to check.
/// The health check name. Optional. If null the type name 'uri-group' will be used for the name.
///
/// The that should be reported when the health check fails. If null then
/// the default status of will be reported.
///
/// A list of tags that can be used to filter sets of health checks.
/// The proxy for http request. Optional
/// The .
public static IHealthChecksBuilder AddUrlGroup(this IHealthChecksBuilder builder, Uri uri, string name, Uri proxy,
HealthStatus? failureStatus = null, IEnumerable tags = null)
{
if (proxy == null)
{
builder.Services.AddHttpClient("HealthCheck");
}
else
{
builder.Services
.AddHttpClient("HealthCheck")
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
{
Proxy = new WebProxy(proxy)
});
}

        var options = new UriHealthCheckOptions();
        options.AddUri(uri);

        var registrationName = name;
        return builder.Add(new HealthCheckRegistration(
            registrationName,
            sp => CreateHealthCheck(sp, registrationName, options),
            failureStatus,
            tags));
    }

    private static UriHealthCheck CreateHealthCheck(IServiceProvider sp, string name, UriHealthCheckOptions options)
    {
        var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
        return new UriHealthCheck(options, () => httpClientFactory.CreateClient("HealthCheck"));
    }
}
@majco333 majco333 self-assigned this Jun 13, 2019
@majco333 majco333 added the next label Jun 14, 2019
@majco333 majco333 removed their assignment Jun 14, 2019
@majco333 majco333 changed the title Extensions for Health checks If needed... Extensions for Health checks Jun 14, 2019
@satano satano added the area-AspNetCore Kros.AspNetCore library label Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-AspNetCore Kros.AspNetCore library next
Projects
None yet
Development

No branches or pull requests

2 participants