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

Fixed issue with bindle heath check, added response status code #957

Merged
merged 21 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
14b9d1e
Channel overview component - frontend
StefanNedelcu Jun 2, 2022
6dc992c
Merge branch 'add-support-for-redis-revisions' into feature/channel-o…
StefanNedelcu Jun 8, 2022
0600390
Switch to the current api endpoint
StefanNedelcu Jun 8, 2022
6517996
Merge branch 'main' into feature/channel-overview-page
StefanNedelcu Jun 8, 2022
b8d998c
Merge pull request #38 from equilobe/feature/channel-overview-page
StefanNedelcu Jun 10, 2022
d5ac1db
Fixed right panel scroll off screen
gogeterobert Jun 10, 2022
345bd68
Now ignores itself when checking for unique name
gogeterobert Jun 10, 2022
9fead57
Merge pull request #39 from equilobe/bugfix-839/right-panel-scroll-of…
gogeterobert Jun 10, 2022
ee3ba67
Merge pull request #40 from equilobe/bugfix-849/update-channel-not-wo…
gogeterobert Jun 10, 2022
36b6c50
Merge branch 'deislabs:main' into main
gogeterobert Jun 10, 2022
e540470
Merge pull request #36 from equilobe/feature/get-status-from-nomad
gogeterobert Jun 14, 2022
64ba606
Merge branch 'deislabs:main' into main
gogeterobert Jun 14, 2022
725ae9f
Merge branch 'deislabs:main' into main
gogeterobert Jun 15, 2022
89569f5
Merge branch 'deislabs:main' into main
gogeterobert Jun 16, 2022
e18676b
Merge branch 'deislabs:main' into main
gogeterobert Jun 16, 2022
3ef9b0d
Merge branch 'deislabs:main' into main
gogeterobert Jun 18, 2022
4d4606b
Merge branch 'deislabs:main' into main
gogeterobert Jun 21, 2022
85a919f
Fixed issue with bindle heath check, added 503 response when unhealth…
gogeterobert Jun 27, 2022
f50163c
Fixed indentation in HealthCheckExtensions
gogeterobert Jun 27, 2022
bb0b31b
Added newline at end of file
gogeterobert Jun 27, 2022
33018c0
Moved healthz endpoint name as parameter to make it visible in Progra…
gogeterobert Jun 27, 2022
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
8 changes: 4 additions & 4 deletions src/Infrastructure/HealthChecks/BindleHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public BindleHealthCheck(IConfiguration configuration)
_client = new BindleClient(configuration.GetConnectionString("Bindle"));
}

public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
_client.QueryInvoices();
return Task.FromResult(HealthCheckResult.Healthy("A healthy result."));
await _client.QueryInvoices();
return HealthCheckResult.Healthy("A healthy result.");
}
catch (Exception)
{
return Task.FromResult(new HealthCheckResult(context.Registration.FailureStatus, "An unhealthy result."));
return new HealthCheckResult(context.Registration.FailureStatus, "An unhealthy result.");
}
}
}
43 changes: 43 additions & 0 deletions src/Web/Extensions/HealthCheckExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Newtonsoft.Json;
using System.Net.Mime;

namespace Hippo.Web.Extensions;

public static class HealthCheckExtensions
{
public static IEndpointConventionBuilder MapCustomHealthChecks(
this IEndpointRouteBuilder endpoints, string endpoint)
{
return endpoints.MapHealthChecks(endpoint, new HealthCheckOptions
{
ResultStatusCodes =
{
[HealthStatus.Healthy] = StatusCodes.Status200OK,
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
},
ResponseWriter = async (context, report) =>
{
var result = JsonConvert.SerializeObject(
new HealthInfo
{
ServiceName = "Hippo",
Status = report.Status.ToString(),
Subservices = new List<HealthInfo>(
report.Entries.Select(e => new HealthInfo
{
ServiceName = e.Key ?? string.Empty,
Description = e.Value.Description ?? string.Empty,
Status = Enum.GetName(typeof(HealthStatus), e.Value.Status)
?? string.Empty,
})
)
}
);
context.Response.ContentType = MediaTypeNames.Application.Json;
await context.Response.WriteAsync(result);
}
});
}
}
9 changes: 9 additions & 0 deletions src/Web/Extensions/HealthInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Hippo.Web.Extensions;

public class HealthInfo
{
public string ServiceName { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public List<HealthInfo> Subservices { get; set; } = new List<HealthInfo>();
}
7 changes: 4 additions & 3 deletions src/Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Text;
using System.Text.Json.Serialization;
using FluentValidation.AspNetCore;
using Hippo.Application;
using Hippo.Application.Common.Config;
Expand All @@ -8,13 +6,16 @@
using Hippo.Infrastructure.Data;
using Hippo.Infrastructure.HealthChecks;
using Hippo.Infrastructure.Identity;
using Hippo.Web.Extensions;
using Hippo.Web.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using System.Text;
using System.Text.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -116,7 +117,7 @@
"API",
"api/{controller}/{action}/{id?}"
);
endpoints.MapHealthChecks("/healthz");
endpoints.MapCustomHealthChecks("/healthz");
endpoints.MapSwagger();
});

Expand Down