-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Taillefer
committed
May 30, 2023
1 parent
3881ea4
commit 0bd2c5e
Showing
14 changed files
with
469 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 37 additions & 4 deletions
41
...Extensions.Diagnostics.HealthChecks.Core/CoreHealthChecksExtensions.TelemetryPublisher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,53 @@ | ||
// 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.Diagnostics.CodeAnalysis; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Telemetry.Metering; | ||
using Microsoft.Shared.Diagnostics; | ||
|
||
namespace Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
public static partial class CoreHealthChecksExtensions | ||
{ | ||
/// <summary> | ||
/// Registers a health status publisher which emits logs and metrics tracking the application's health. | ||
/// Registers a health check publisher which emits telemetry representing the application's health. | ||
/// </summary> | ||
/// <param name="services">The <see cref="IServiceCollection" /> to add the publisher to.</param> | ||
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> | ||
/// <param name="services">The dependency injection container to add the publisher to.</param> | ||
/// <returns>The value of <paramref name="services"/>.</returns> | ||
/// <exception cref="ArgumentNullException">If <paramref name="services" /> is <see langword="null" />.</exception> | ||
public static IServiceCollection AddTelemetryHealthCheckPublisher(this IServiceCollection services) | ||
=> services | ||
=> Throw.IfNull(services) | ||
.RegisterMetering() | ||
.AddSingleton<IHealthCheckPublisher, TelemetryHealthCheckPublisher>(); | ||
|
||
/// <summary> | ||
/// Registers a health check publisher which emits telemetry representing the application's health. | ||
/// </summary> | ||
/// <param name="services">The dependency injection container to add the publisher to.</param> | ||
/// <param name="section">Configuration for <see cref="TelemetryHealthCheckPublisherOptions"/>.</param> | ||
/// <returns>The value of <paramref name="services"/>.</returns> | ||
/// <exception cref="ArgumentNullException">If <paramref name="services" /> or <paramref name="section"/> are <see langword="null" />.</exception> | ||
[Experimental] | ||
public static IServiceCollection AddTelemetryHealthCheckPublisher(this IServiceCollection services, IConfigurationSection section) | ||
=> Throw.IfNull(services) | ||
.Configure<TelemetryHealthCheckPublisherOptions>(Throw.IfNull(section)) | ||
.RegisterMetering() | ||
.AddSingleton<IHealthCheckPublisher, TelemetryHealthCheckPublisher>(); | ||
|
||
/// <summary> | ||
/// Registers a health check publisher which emits telemetry representing the application's health. | ||
/// </summary> | ||
/// <param name="services">The dependency injection container to add the publisher to.</param> | ||
/// <param name="configure">Configuration for <see cref="TelemetryHealthCheckPublisherOptions"/>.</param> | ||
/// <returns>The value of <paramref name="services"/>.</returns> | ||
/// <exception cref="ArgumentNullException">If <paramref name="services" /> or <paramref name="configure"/> are <see langword="null" />.</exception> | ||
[Experimental] | ||
public static IServiceCollection AddTelemetryHealthCheckPublisher(this IServiceCollection services, Action<TelemetryHealthCheckPublisherOptions> configure) | ||
=> Throw.IfNull(services) | ||
.Configure(Throw.IfNull(configure)) | ||
.RegisterMetering() | ||
.AddSingleton<IHealthCheckPublisher, TelemetryHealthCheckPublisher>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...icrosoft.Extensions.Diagnostics.HealthChecks.Core/TelemetryHealthCheckPublisherOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
/// <summary> | ||
/// Options for the telemetry health check publisher. | ||
/// </summary> | ||
[Experimental] | ||
public class TelemetryHealthCheckPublisherOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether to log only when unhealthy reports are received. Set to false to always log. | ||
/// </summary> | ||
/// <remarks> | ||
/// Default set to false. | ||
/// </remarks> | ||
[Experimental] | ||
public bool LogOnlyUnhealthy { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.