-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have lexbox API container check fw-headless health (#1192)
Since fw-headless container isn't exposed to outside, but we might want to know if it's healthy, we'll add code into the lexbox-api health check to call the fw-headless health check and report lexbox-api's status as unhealthy if fw-headless is not healthy. (Except on local dev, where lexbox-api's status would just be Degraded so that editing fw-headless code doesn't bring down the whole API server).
- Loading branch information
Showing
8 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Reflection; | ||
|
||
namespace FwHeadless; | ||
|
||
public static class AppVersionService | ||
{ | ||
public static readonly string Version = typeof(AppVersionService).Assembly | ||
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "dev"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace LexBoxApi.Config; | ||
|
||
public class HealthChecksConfig | ||
{ | ||
public bool RequireFwHeadlessContainerVersionMatch { get; init; } = true; | ||
public bool RequireHealthyFwHeadlessContainer { get; init; } = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using LexBoxApi.Config; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace LexBoxApi.Services; | ||
|
||
public class FwHeadlessHealthCheck(IHttpClientFactory clientFactory, IOptions<HealthChecksConfig> healthCheckOptions) : IHealthCheck | ||
{ | ||
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, | ||
CancellationToken cancellationToken = new()) | ||
{ | ||
var http = clientFactory.CreateClient(); | ||
var fwHeadlessResponse = await http.GetAsync("http://fw-headless/api/healthz"); | ||
if (!fwHeadlessResponse.IsSuccessStatusCode) | ||
{ | ||
if (healthCheckOptions.Value.RequireHealthyFwHeadlessContainer) | ||
{ | ||
return HealthCheckResult.Unhealthy("fw-headless not repsonding to health check"); | ||
} | ||
else | ||
{ | ||
return HealthCheckResult.Degraded("fw-headless not repsonding to health check"); | ||
} | ||
} | ||
var fwHeadlessVersion = fwHeadlessResponse.Headers.GetValues("lexbox-version").FirstOrDefault(); | ||
if (healthCheckOptions.Value.RequireFwHeadlessContainerVersionMatch && string.IsNullOrEmpty(fwHeadlessVersion)) | ||
{ | ||
return HealthCheckResult.Degraded("fw-headless version check failed to return a value"); | ||
} | ||
if (healthCheckOptions.Value.RequireFwHeadlessContainerVersionMatch && fwHeadlessVersion != AppVersionService.Version) | ||
{ | ||
return HealthCheckResult.Degraded( | ||
$"api version: '{AppVersionService.Version}' fw-headless version: '{fwHeadlessVersion}' mismatch"); | ||
} | ||
return HealthCheckResult.Healthy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters