Skip to content

Commit

Permalink
PIDP-775 HealthCheck endpoints for PlrIntake (#421)
Browse files Browse the repository at this point in the history
* Liveness and readiness endpoint

* nl

---------

Co-authored-by: James Hollinger <39168456+james-hollinger@users.noreply.github.com>
  • Loading branch information
mar-uha and james-hollinger authored Nov 10, 2023
1 parent 0a275d0 commit 96bef2b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

namespace PlrIntake.Infrastructure.HealthChecks;

public class HealthCheckTag
{
/// <summary>
/// Represents a "liveness" check.
/// A service that fails a liveness check is considered to be unrecoverable and has to be restarted by the orchestrator.
/// </summary>
public static readonly HealthCheckTag Liveness = new("liveness");

/// <summary>
/// Represents a "readiness" check.
/// A service that fails a readiness check is considered to be unable to serve traffic temporarily.
/// </summary>
public static readonly HealthCheckTag Readiness = new("readiness");

public string Value { get; }

private HealthCheckTag(string value) => this.Value = value;

public static implicit operator string(HealthCheckTag type) => type.Value;
}
16 changes: 14 additions & 2 deletions backend/services.plr-intake/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace PlrIntake;

using FluentValidation.AspNetCore;
using HealthChecks.ApplicationStatus.DependencyInjection;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.EntityFrameworkCore;
using Serilog;
using SoapCore;
Expand All @@ -11,6 +13,7 @@ namespace PlrIntake;
using PlrIntake.Data;
using PlrIntake.Features;
using PlrIntake.Features.Intake;
using PlrIntake.Infrastructure.HealthChecks;

public class Startup
{
Expand Down Expand Up @@ -40,7 +43,9 @@ public void ConfigureServices(IServiceCollection services)
services.AddSoapServiceOperationTuner(new IntakeServiceOperationTuner(config));
services.AddSoapCore();

services.AddHealthChecks();
services.AddHealthChecks()
.AddApplicationStatus(tags: new[] { HealthCheckTag.Liveness.Value })
.AddNpgSql(config.ConnectionStrings.PlrDatabase, tags: new[] { HealthCheckTag.Readiness.Value });
}

private PlrIntakeConfiguration InitializeConfiguration(IServiceCollection services)
Expand Down Expand Up @@ -85,7 +90,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
endpoints.UseSoapEndpoint<IIntakeService>("/api/PLRHL7", intakeBinding, SoapSerializer.XmlSerializer);
endpoints.MapControllers();
endpoints.MapHealthChecks("/health/liveness").AllowAnonymous();
endpoints.MapHealthChecks("/health/liveness", new HealthCheckOptions
{
Predicate = registration => registration.Tags.Contains(HealthCheckTag.Liveness)
}).AllowAnonymous();
endpoints.MapHealthChecks("/health/readiness", new HealthCheckOptions
{
Predicate = registration => registration.Tags.Contains(HealthCheckTag.Readiness)
}).AllowAnonymous();
});
}
}
1 change: 1 addition & 0 deletions backend/services.plr-intake/plr-intake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<RootNamespace>PlrIntake</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.ApplicationStatus" Version="6.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="6.0.2" />
<PackageReference Include="DomainResult" Version="2.0.0" />
<PackageReference Include="FluentValidation" Version="10.3.6" />
Expand Down

0 comments on commit 96bef2b

Please sign in to comment.