Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Added a separate endpoint for named checks in the sample, updated log…
Browse files Browse the repository at this point in the history
…ging to use the new name property
  • Loading branch information
karl-sjogren committed Dec 2, 2019
1 parent b2b3ca5 commit 672a4f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
5 changes: 2 additions & 3 deletions samples/MvcSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ public void Configuration(IAppBuilder app)
// "select 'a'"),
new PingHealthCheck(new PingHealthCheckOptions().AddHost("localhost", 1000)));

/* Sample with named checks
// Sample with named checks
app.UseHealthChecks(
"/_health",
"/_health_named",
new HealthCheckWrapper(new NoopHealthCheck(), "Noop health check"),
new HealthCheckWrapper(new PingHealthCheck(new PingHealthCheckOptions().AddHost("localhost", 1000)), "Ping to localhost"));
*/
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<HealthReport> CheckHealthAsync(
{
var stopwatch = Stopwatch.StartNew();

Log.HealthCheckBegin(_logger, wrapper.HealthCheck);
Log.HealthCheckBegin(_logger, wrapper);

HealthReportEntry entry;
try
Expand All @@ -76,8 +76,8 @@ public async Task<HealthReport> CheckHealthAsync(
exception: result.Exception,
data: result.Data);

Log.HealthCheckEnd(_logger, wrapper.HealthCheck, entry, duration);
Log.HealthCheckData(_logger, wrapper.HealthCheck, entry);
Log.HealthCheckEnd(_logger, wrapper, entry, duration);
Log.HealthCheckData(_logger, wrapper, entry);
}

// Allow cancellation to propagate.
Expand All @@ -91,7 +91,7 @@ public async Task<HealthReport> CheckHealthAsync(
exception: ex,
data: null);

Log.HealthCheckError(_logger, wrapper.HealthCheck, ex, duration);
Log.HealthCheckError(_logger, wrapper, ex, duration);
}

entries[wrapper.Name] = entry;
Expand Down Expand Up @@ -173,42 +173,42 @@ public static void HealthCheckProcessingEnd(ILogger logger, HealthStatus status,
_healthCheckProcessingEnd(logger, duration.TotalMilliseconds, status, null);
}

public static void HealthCheckBegin(ILogger logger, IHealthCheck healthCheck)
public static void HealthCheckBegin(ILogger logger, HealthCheckWrapper healthCheck)
{
_healthCheckBegin(logger, healthCheck.GetType().Name, null);
_healthCheckBegin(logger, healthCheck.Name, null);
}

public static void HealthCheckEnd(ILogger logger, IHealthCheck healthCheck, HealthReportEntry entry, TimeSpan duration)
public static void HealthCheckEnd(ILogger logger, HealthCheckWrapper healthCheck, HealthReportEntry entry, TimeSpan duration)
{
switch (entry.Status)
{
case HealthStatus.Healthy:
_healthCheckEndHealthy(logger, healthCheck.GetType().Name, duration.TotalMilliseconds, entry.Status, entry.Description, null);
_healthCheckEndHealthy(logger, healthCheck.Name, duration.TotalMilliseconds, entry.Status, entry.Description, null);
break;

case HealthStatus.Degraded:
_healthCheckEndDegraded(logger, healthCheck.GetType().Name, duration.TotalMilliseconds, entry.Status, entry.Description, null);
_healthCheckEndDegraded(logger, healthCheck.Name, duration.TotalMilliseconds, entry.Status, entry.Description, null);
break;

case HealthStatus.Unhealthy:
_healthCheckEndUnhealthy(logger, healthCheck.GetType().Name, duration.TotalMilliseconds, entry.Status, entry.Description, null);
_healthCheckEndUnhealthy(logger, healthCheck.Name, duration.TotalMilliseconds, entry.Status, entry.Description, null);
break;
}
}

public static void HealthCheckError(ILogger logger, IHealthCheck healthCheck, Exception exception, TimeSpan duration)
public static void HealthCheckError(ILogger logger, HealthCheckWrapper healthCheck, Exception exception, TimeSpan duration)
{
_healthCheckError(logger, healthCheck.GetType().Name, duration.TotalMilliseconds, exception);
_healthCheckError(logger, healthCheck.Name, duration.TotalMilliseconds, exception);
}

public static void HealthCheckData(ILogger logger, IHealthCheck healthCheck, HealthReportEntry entry)
public static void HealthCheckData(ILogger logger, HealthCheckWrapper healthCheck, HealthReportEntry entry)
{
if (entry.Data.Count > 0 && logger.IsEnabled(LogLevel.Debug))
{
logger.Log(
LogLevel.Debug,
EventIds.HealthCheckData,
new HealthCheckDataLogValue(healthCheck.GetType().Name, entry.Data),
new HealthCheckDataLogValue(healthCheck.Name, entry.Data),
null,
(state, ex) => state.ToString());
}
Expand Down

0 comments on commit 672a4f8

Please sign in to comment.