From 19262b14852eca2bdcf1a274f5ce2772ad9e8679 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Wed, 19 Jan 2022 15:23:28 +0000 Subject: [PATCH] Add Heath Checks --- .../FileProcessor.BusinessLogic.csproj | 6 +-- .../FileProcessor.File.DomainEvents.csproj | 2 +- .../FileProcessor.FileAggregate.csproj | 4 +- ...rocessor.FileImportLog.DomainEvents.csproj | 2 +- ...ileProcessor.FileImportLogAggregate.csproj | 2 +- .../FileProcessor.IntegrationTests.csproj | 2 +- FileProcessor/FileProcessor.csproj | 2 +- FileProcessor/Startup.cs | 43 ++++++++++++------- 8 files changed, 37 insertions(+), 26 deletions(-) diff --git a/FileProcessor.BusinessLogic/FileProcessor.BusinessLogic.csproj b/FileProcessor.BusinessLogic/FileProcessor.BusinessLogic.csproj index 19ce302..2d9d41c 100644 --- a/FileProcessor.BusinessLogic/FileProcessor.BusinessLogic.csproj +++ b/FileProcessor.BusinessLogic/FileProcessor.BusinessLogic.csproj @@ -9,10 +9,10 @@ - - + + - + diff --git a/FileProcessor.File.DomainEvents/FileProcessor.File.DomainEvents.csproj b/FileProcessor.File.DomainEvents/FileProcessor.File.DomainEvents.csproj index a235687..1317371 100644 --- a/FileProcessor.File.DomainEvents/FileProcessor.File.DomainEvents.csproj +++ b/FileProcessor.File.DomainEvents/FileProcessor.File.DomainEvents.csproj @@ -5,7 +5,7 @@ - + diff --git a/FileProcessor.FileAggregate/FileProcessor.FileAggregate.csproj b/FileProcessor.FileAggregate/FileProcessor.FileAggregate.csproj index c997850..823b593 100644 --- a/FileProcessor.FileAggregate/FileProcessor.FileAggregate.csproj +++ b/FileProcessor.FileAggregate/FileProcessor.FileAggregate.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/FileProcessor.FileImportLog.DomainEvents/FileProcessor.FileImportLog.DomainEvents.csproj b/FileProcessor.FileImportLog.DomainEvents/FileProcessor.FileImportLog.DomainEvents.csproj index 4842d83..fc7b898 100644 --- a/FileProcessor.FileImportLog.DomainEvents/FileProcessor.FileImportLog.DomainEvents.csproj +++ b/FileProcessor.FileImportLog.DomainEvents/FileProcessor.FileImportLog.DomainEvents.csproj @@ -5,7 +5,7 @@ - + diff --git a/FileProcessor.FileImportLogAggregate/FileProcessor.FileImportLogAggregate.csproj b/FileProcessor.FileImportLogAggregate/FileProcessor.FileImportLogAggregate.csproj index 1ebb598..7439e11 100644 --- a/FileProcessor.FileImportLogAggregate/FileProcessor.FileImportLogAggregate.csproj +++ b/FileProcessor.FileImportLogAggregate/FileProcessor.FileImportLogAggregate.csproj @@ -5,7 +5,7 @@ - + diff --git a/FileProcessor.IntegrationTests/FileProcessor.IntegrationTests.csproj b/FileProcessor.IntegrationTests/FileProcessor.IntegrationTests.csproj index b290e5e..a0c0ee1 100644 --- a/FileProcessor.IntegrationTests/FileProcessor.IntegrationTests.csproj +++ b/FileProcessor.IntegrationTests/FileProcessor.IntegrationTests.csproj @@ -17,7 +17,7 @@ - + diff --git a/FileProcessor/FileProcessor.csproj b/FileProcessor/FileProcessor.csproj index 49ae36b..536423a 100644 --- a/FileProcessor/FileProcessor.csproj +++ b/FileProcessor/FileProcessor.csproj @@ -17,7 +17,7 @@ - + diff --git a/FileProcessor/Startup.cs b/FileProcessor/Startup.cs index 10b2d65..2e7cf7e 100644 --- a/FileProcessor/Startup.cs +++ b/FileProcessor/Startup.cs @@ -31,8 +31,10 @@ namespace FileProcessor using File.DomainEvents; using FileImportLog.DomainEvents; using FIleProcessor.Models; + using HealthChecks.UI.Client; using MediatR; using Microsoft.AspNetCore.Authentication.JwtBearer; + using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; @@ -279,24 +281,28 @@ public void ConfigureServices(IServiceCollection services) public static IServiceProvider ServiceProvider { get; set; } + private HttpClientHandler ApiEndpointHttpHandler(IServiceProvider serviceProvider) + { + return new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (message, + cert, + chain, + errors) => + { + return true; + } + }; + } + private void ConfigureMiddlewareServices(IServiceCollection services) { - //services.AddHealthChecks() - // .AddSqlServer(connectionString: ConfigurationReader.GetConnectionString("HealthCheck"), - // healthQuery: "SELECT 1;", - // name: "Read Model Server", - // failureStatus: HealthStatus.Degraded, - // tags: new string[] { "db", "sql", "sqlserver" }) - // .AddEventStore(Startup.EventStoreClientSettings, - // userCredentials: Startup.EventStoreClientSettings.DefaultCredentials, - // name: "Eventstore", - // failureStatus: HealthStatus.Unhealthy, - // tags: new string[] { "db", "eventstore" }) - // .AddUrlGroup(new Uri($"{ConfigurationReader.GetValue("SecurityConfiguration", "Authority")}/health"), - // name: "Security Service", - // httpMethod: HttpMethod.Get, - // failureStatus: HealthStatus.Unhealthy, - // tags: new string[] { "security", "authorisation" }); + services.AddHealthChecks().AddEventStore(Startup.EventStoreClientSettings, + userCredentials:Startup.EventStoreClientSettings.DefaultCredentials, + name:"Eventstore", + failureStatus:HealthStatus.Unhealthy, + tags:new string[] {"db", "eventstore"}).AddEstateManagementService().AddTransactionProcessorService() + .AddSecurityService(ApiEndpointHttpHandler); services.AddSwaggerGen(c => { @@ -424,6 +430,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF app.UseEndpoints(endpoints => { endpoints.MapControllers(); + endpoints.MapHealthChecks("health", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); }); app.UseSwagger();