Skip to content

Commit

Permalink
Add Db healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jul 4, 2024
1 parent cb2f991 commit dfe38a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/PackageRegistryService/PackageRegistryService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
Expand Down
14 changes: 14 additions & 0 deletions src/PackageRegistryService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using PackageRegistryService.API.Endpoints;
using PackageRegistryService.Data;
using Microsoft.AspNetCore.Http.Json;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using HealthChecks.UI.Client;


// ------------------------- ApplicationBuilder -------------------------
// in this section, we will add the necessary code to configure the application builder,
Expand Down Expand Up @@ -40,6 +43,7 @@
)
);


builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
Expand All @@ -48,6 +52,10 @@

builder.Services.Configure<JsonOptions>(options => options.SerializerOptions.PropertyNamingPolicy = null);

builder.Services.AddHealthChecks()
//.AddCheck<DatabaseHealthCheck>("Database");
.AddNpgSql(builder.Configuration.GetConnectionString("PostgressConnectionString"));

Check warning on line 57 in src/PackageRegistryService/Program.cs

View workflow job for this annotation

GitHub Actions / Build and test projects / build-and-test (windows-latest)

Possible null reference argument for parameter 'connectionString' in 'IHealthChecksBuilder NpgSqlHealthCheckBuilderExtensions.AddNpgSql(IHealthChecksBuilder builder, string connectionString, string healthQuery = "SELECT 1;", Action<NpgsqlConnection>? configure = null, string? name = null, HealthStatus? failureStatus = null, IEnumerable<string>? tags = null, TimeSpan? timeout = null)'.

Check warning on line 57 in src/PackageRegistryService/Program.cs

View workflow job for this annotation

GitHub Actions / Build and test projects / build-and-test (ubuntu-latest)

Possible null reference argument for parameter 'connectionString' in 'IHealthChecksBuilder NpgSqlHealthCheckBuilderExtensions.AddNpgSql(IHealthChecksBuilder builder, string connectionString, string healthQuery = "SELECT 1;", Action<NpgsqlConnection>? configure = null, string? name = null, HealthStatus? failureStatus = null, IEnumerable<string>? tags = null, TimeSpan? timeout = null)'.

Check warning on line 57 in src/PackageRegistryService/Program.cs

View workflow job for this annotation

GitHub Actions / Build and test projects / build-and-test (macos-latest)

Possible null reference argument for parameter 'connectionString' in 'IHealthChecksBuilder NpgSqlHealthCheckBuilderExtensions.AddNpgSql(IHealthChecksBuilder builder, string connectionString, string healthQuery = "SELECT 1;", Action<NpgsqlConnection>? configure = null, string? name = null, HealthStatus? failureStatus = null, IEnumerable<string>? tags = null, TimeSpan? timeout = null)'.

// ------------------------- WebApplication -------------------------
// in this section, we will add the necessary code to configure the WebApplication,
// which defines the HTTP request pipeline.
Expand Down Expand Up @@ -83,6 +91,12 @@

}

app.MapHealthChecks("/_health", new HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
//.RequireHost(); // use host of status page here to limit this endpoint

// Configure the HTTP request pipeline.

// ======================== Packages endpoints =========================
Expand Down

0 comments on commit dfe38a7

Please sign in to comment.