Skip to content

Commit

Permalink
Add Elastic Search and SQL Server Health checks (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderlan authored Oct 10, 2023
1 parent 8f7203c commit e3f4e8c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 35 deletions.
5 changes: 2 additions & 3 deletions Orion.Api/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void ConfigureApp(this IApplicationBuilder app)

app.ConfigureGlobalization();

app.UseHealthChecks("/health-check");
app.ConfigureHealthCheck();

app.UseRouting();

Expand Down Expand Up @@ -59,14 +59,13 @@ public static void ConfigureServices(this IServiceCollection services, IConfigur
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();


services.Configure<ApiBehaviorOptions>(options =>
{
options.SuppressModelStateInvalidFilter = true;
});

services.AddLocalization(options => options.ResourcesPath = @"Resources");
services.AddHealthChecks();
services.AddApplicationHealthChecks(configuration);

services.ConfigureSwagger();
services.ConfigureApiVersioning();
Expand Down
32 changes: 32 additions & 0 deletions Orion.Api/Configuration/HealthCheckConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;

namespace Orion.Api.Configuration
{
public static class HealthCheckConfiguration
{
public static void ConfigureHealthCheck(this IApplicationBuilder app)
{
app.UseHealthChecks("/health", new HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
}

public static void AddApplicationHealthChecks(this IServiceCollection services, IConfiguration configuration)
{
services.AddHealthChecks().AddSqlServer(configuration["DatabaseOptions:ConnectionString"],
tags: new[]
{
"database"
});

services.AddHealthChecks().AddElasticsearch(configuration["ElasticConfiguration:Uri"],
tags: new[]
{
"elasticsearch",
"kibana"
});
}
}
}
3 changes: 3 additions & 0 deletions Orion.Api/Orion.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Elasticsearch" Version="7.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="7.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.1.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
26 changes: 0 additions & 26 deletions Orion.Test/API/HealthCheckApiTest.cs

This file was deleted.

7 changes: 2 additions & 5 deletions Orion.Test/Configuration/ApiTestInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Orion.Test.Configuration
public abstract class ApiTestInitializer : IDisposable
{
protected string AuthToken;
protected readonly HttpClient Client;
protected readonly HttpClient Client;
protected readonly HttpClient AuthenticatedClient;
protected IServiceProvider ServiceProvider { get; private set; }

Expand All @@ -26,10 +26,7 @@ public ApiTestInitializer()
.Build();

builder
.UseConfiguration(config)
.ConfigureServices(services =>
{
});
.UseConfiguration(config);
});
ServiceProvider = appFactory.Services;
Client = appFactory.CreateClient();
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

**About this Project**

*A project reference for creating REST APIs with C# and .NET (v7.0).*
*A simple project template for creating a .NET API (v7.0)*

The main objective is to start projects with a clean and simple architecture, without having to redo the entire configuration whenever starting a new project with similar characteristics.

Expand Down

0 comments on commit e3f4e8c

Please sign in to comment.