-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OC.HealthChecks.Abstractions, and health Checks options to show d…
…etails (#13590) Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
- Loading branch information
Showing
14 changed files
with
187 additions
and
26 deletions.
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
13 changes: 0 additions & 13 deletions
13
src/OrchardCore.Modules/OrchardCore.HealthChecks/HealthChecksOptions.cs
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/OrchardCore.Modules/OrchardCore.HealthChecks/Models/HealthCheckEntry.cs
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,22 @@ | ||
namespace OrchardCore.HealthChecks.Models; | ||
|
||
/// <summary> | ||
/// Represents a health check entry for each health provider that could be displayed in the <see cref="HealthCheckResponse"/>. | ||
/// </summary> | ||
public class HealthCheckEntry | ||
{ | ||
/// <summary> | ||
/// Gets or sets the health check name. | ||
/// </summary> | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the health check status. | ||
/// </summary> | ||
public string Status { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the health check description. | ||
/// </summary> | ||
public string Description { get; set; } | ||
} |
25 changes: 25 additions & 0 deletions
25
src/OrchardCore.Modules/OrchardCore.HealthChecks/Models/HealthCheckResponse.cs
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,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace OrchardCore.HealthChecks.Models; | ||
|
||
/// <summary> | ||
/// Represents a health check response to be displayed in the JSON result when the health checks endpoint hit. | ||
/// </summary> | ||
public class HealthCheckResponse | ||
{ | ||
/// <summary> | ||
/// Gets or sets the overall health checks status. | ||
/// </summary> | ||
public string Status { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the overall health checks duration. | ||
/// </summary> | ||
public TimeSpan Duration { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the health check entries. | ||
/// </summary> | ||
public IEnumerable<HealthCheckEntry> HealthChecks { get; set; } | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...OrchardCore.Modules/OrchardCore.HealthChecks/Services/DefaultHealthCheckResponseWriter.cs
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,31 @@ | ||
using System.Linq; | ||
using System.Net.Mime; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using OrchardCore.HealthChecks.Models; | ||
|
||
namespace OrchardCore.HealthChecks.Services; | ||
|
||
public class DefaultHealthChecksResponseWriter : IHealthChecksResponseWriter | ||
{ | ||
public async Task WriteResponseAsync(HttpContext context, HealthReport report) | ||
{ | ||
var response = new HealthCheckResponse | ||
{ | ||
Status = report.Status.ToString(), | ||
Duration = report.TotalDuration, | ||
HealthChecks = report.Entries.Select(item => new HealthCheckEntry | ||
{ | ||
Name = item.Key, | ||
Status = item.Value.Status.ToString(), | ||
Description = item.Value.Description | ||
}) | ||
}; | ||
|
||
context.Response.ContentType = MediaTypeNames.Application.Json; | ||
|
||
await context.Response.WriteAsync(JsonSerializer.Serialize(response)); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/OrchardCore/OrchardCore.HealthChecks.Abstractions/HealthChecksOptions.cs
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,17 @@ | ||
namespace OrchardCore.HealthChecks; | ||
|
||
/// <summary> | ||
/// Represents options for health checks. | ||
/// </summary> | ||
public class HealthChecksOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets the health check URL. Default to "/health/live". | ||
/// </summary> | ||
public string Url { get; set; } = "/health/live"; | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to show the detailed information (name, status and description) for the checks dependency or not. Defaults to <see langword="false"/>. | ||
/// </summary> | ||
public bool ShowDetails { get; set; } | ||
} |
19 changes: 19 additions & 0 deletions
19
...rdCore/OrchardCore.HealthChecks.Abstractions/OrchardCore.HealthChecks.Abstractions.csproj
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<RootNamespace>OrchardCore.HealthChecks</RootNamespace> | ||
<!-- NuGet properties--> | ||
<Title>OrchardCore Health Chekcs Abstractions</Title> | ||
<Description> | ||
$(OCCMSDescription) | ||
|
||
Abstractions for health checks | ||
</Description> | ||
<PackageTags>$(PackageTags) OrchardCore Framework Health Checks Abstractions</PackageTags> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
</Project> |
10 changes: 10 additions & 0 deletions
10
...OrchardCore/OrchardCore.HealthChecks.Abstractions/Services/IHealthChecksResponseWriter.cs
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,10 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace OrchardCore.HealthChecks.Services; | ||
|
||
public interface IHealthChecksResponseWriter | ||
{ | ||
Task WriteResponseAsync(HttpContext context, HealthReport report); | ||
} |
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