Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,30 @@

namespace TransactionProcessor.HealthChecksUI
{
using HealthChecks.UI.Core;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using Newtonsoft.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;

public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
public void ConfigureServices(IServiceCollection services){
services.AddTransient<CustomHealthReportDelegatingHandler>();

services.AddHealthChecksUI(settings =>
{
settings.UseApiEndpointHttpMessageHandler(ApiEndpointHttpHandler);
settings.UseApiEndpointDelegatingHandler<CustomHealthReportDelegatingHandler>();
}).AddInMemoryStorage();
}

Expand All @@ -47,11 +60,40 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecksUI();
});
}
}

public class CustomHealthReportDelegatingHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Headers.Add("Accept", new[] { "application/json" });
HttpResponseMessage response = null;
try
{
response = await base.SendAsync(request, cancellationToken);
}
catch(HttpRequestException ex){
// Just ignore this
JsonSerializerOptions _options = new(JsonSerializerDefaults.Web)
{
Converters =
{
new JsonStringEnumConverter(namingPolicy: null, allowIntegerValues: false)
}
};
UIHealthReport report = UIHealthReport.CreateFrom(ex);
report.Status = UIHealthStatus.Unhealthy;
String json = JsonSerializer.Serialize(report, _options);
response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
response.Content = new StringContent(json, Encoding.UTF8, "application/json");
}
return response;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,7 @@
{
"Name": "Estate Management Service",
"Uri": "http://192.168.0.133:5000/healthui"
},
{
"Name": "Security Service",
"Uri": "https://192.168.0.133:5001/healthui"
},
{
"Name": "Transaction Processor Service",
"Uri": "http://192.168.0.133:5002/healthui"
},
{
"Name": "Transaction Processor ACL Service",
"Uri": "http://192.168.0.133:5003/healthui"
},
{
"Name": "Estate Management UI",
"Uri": "https://192.168.0.133:5004/healthui"
},
{
"Name": "Messaging Service",
"Uri": "http://192.168.0.133:5006/healthui"
},
{
"Name": "Voucher Management ACL Service",
"Uri": "http://192.168.0.133:5008/healthui"
},
{
"Name": "File Processor Service",
"Uri": "http://192.168.0.133:5009/healthui"
}
}
],
"EvaluationTimeInSeconds": 300,
"MinimumSecondsBetweenFailureNotifications": 60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,48 @@
},
"AllowedHosts": "*",
"HealthChecksUI": {
// "HealthChecks": [
// {
// "Name": "Estate Management Service",
// "Uri": "http://192.168.0.133:5000/health"
// },
// {
// "Name": "Security Service",
// "Uri": "http://192.168.0.133:5001/health"
// },
// {
// "Name": "Transaction Processor Service",
// "Uri": "http://192.168.0.133:5002/health"
// },
// {
// "Name": "Transaction Processor ACL Service",
// "Uri": "http://192.168.0.133:5003/health"
// },
// {
// "Name": "Estate Management UI",
// "Uri": "http://192.168.0.133:5004/health"
// },
// {
// "Name": "Estate Reporting Service",
// "Uri": "http://192.168.0.133:5005/health"
// },
// {
// "Name": "Messaging Service",
// "Uri": "http://192.168.0.133:5006/health"
// },
// {
// "Name": "Voucher Management Service",
// "Uri": "http://192.168.0.133:5007/health"
// },
// {
// "Name": "Voucher Management ACL Service",
// "Uri": "http://192.168.0.133:5008/health"
// },
// {
// "Name": "File Processor Service",
// "Uri": "http://192.168.0.133:5009/health"
// }
// ],
"HealthChecks": [
{
"Name": "Estate Management Service",
"Uri": "http://192.168.0.133:5000/health"
},
{
"Name": "Security Service",
"Uri": "http://192.168.0.133:5001/health"
},
{
"Name": "Transaction Processor Service",
"Uri": "http://192.168.0.133:5002/health"
},
{
"Name": "Transaction Processor ACL Service",
"Uri": "http://192.168.0.133:5003/health"
},
{
"Name": "Estate Management UI",
"Uri": "http://192.168.0.133:5004/health"
},
{
"Name": "Estate Reporting Service",
"Uri": "http://192.168.0.133:5005/health"
},
{
"Name": "Messaging Service",
"Uri": "http://192.168.0.133:5006/health"
},
{
"Name": "Voucher Management Service",
"Uri": "http://192.168.0.133:5007/health"
},
{
"Name": "Voucher Management ACL Service",
"Uri": "http://192.168.0.133:5008/health"
},
{
"Name": "File Processor Service",
"Uri": "http://192.168.0.133:5009/health"
}
],
"EvaluationTimeInSeconds": 300,
"MinimumSecondsBetweenFailureNotifications": 60
}
Expand Down