Skip to content

Commit

Permalink
Adding in secondary logic for a health check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris committed Jun 29, 2019
1 parent e78e992 commit bfdad66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions HealthChecks.SomeModelService/Health/ApiHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public Task<HealthCheckResult> CheckHealthAsync(
var isHealthy = true;
if(isHealthy)
{
return Task.FromResult(HealthCheckResult.Healthy("healthy"));
return Task.FromResult(HealthCheckResult.Healthy("I am one healthy microservice API"));
}

return Task.FromResult(HealthCheckResult.Unhealthy("unhealthy"));
return Task.FromResult(HealthCheckResult.Unhealthy("I am the sad, unhealthy microservice API"));
}
}
}
16 changes: 16 additions & 0 deletions HealthChecks.SomeModelService/Health/SecondaryHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthChecks.SomeModelService.Health
{
public class SecondaryHealthCheck : IHealthCheck
{
public Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context,
CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(HealthCheckResult.Degraded("Not feeling so well, boss!"));
}
}
}
11 changes: 9 additions & 2 deletions HealthChecks.SomeModelService/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
using Autofac;
using System.Linq;
using System.Threading.Tasks;
using Autofac;
using HealthChecks.Configuration;
using HealthChecks.SomeModelService.Health;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using IHostingEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;

namespace HealthChecks.SomeModelService
Expand All @@ -27,7 +33,8 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddHealthChecks()
.AddCheck<ApiHealthCheck>("api");
.AddCheck<ApiHealthCheck>("api")
.AddCheck<SecondaryHealthCheck>("secondary");
//add additional healthchecks here, as needed
//as described here https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks

Expand Down

0 comments on commit bfdad66

Please sign in to comment.