Skip to content

Commit

Permalink
Merge pull request #140 from TomaszKandula/feat/hc
Browse files Browse the repository at this point in the history
feat: upgrade health checks
  • Loading branch information
TomaszKandula authored Feb 10, 2024
2 parents e5c8de6 + 2223d8b commit 9e2fbb4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fetch-depth: 0

- name: Variable substitution appsettings file for Development (NET Core)
uses: TomaszKandula/variable-substitution@v1.0.1
uses: TomaszKandula/variable-substitution@v1.0.2
with:
files: ${{ github.workspace }}/EmailSender.Configuration/appsettings.Development.json
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/master_build_test_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
- name: Move results to outputs
id: versioning
run: |
echo "::set-output name=version::${{ steps.semantic.outputs.new_release_version }}"
echo "::set-output name=published::${{ steps.semantic.outputs.new_release_published }}"
echo "version=${{ steps.semantic.outputs.new_release_version }}" >> $GITHUB_OUTPUT
echo "published=${{ steps.semantic.outputs.new_release_published }}" >> $GITHUB_OUTPUT
backend-production:

Expand All @@ -53,7 +53,7 @@ jobs:
uses: actions/checkout@v4

- name: Variable substitution appsettings file for Production (NET Core)
uses: TomaszKandula/variable-substitution@v1.0.1
uses: TomaszKandula/variable-substitution@v1.0.2
with:
files: ${{ github.workspace }}/EmailSender.Configuration/appsettings.Production.json
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stage_build_test_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v4

- name: Variable substitution appsettings file for Staging (NET Core)
uses: TomaszKandula/variable-substitution@v1.0.1
uses: TomaszKandula/variable-substitution@v1.0.2
with:
files: ${{ github.workspace }}/EmailSender.Configuration/appsettings.Staging.json
env:
Expand Down
3 changes: 3 additions & 0 deletions EmailSender.WebApi/EmailSender.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<PackageReference Include="Serilog.Sinks.AzureBlobStorage" Version="3.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.3" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.AzureStorage" Version="7.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
28 changes: 26 additions & 2 deletions EmailSender.WebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
using EmailSender.Backend.Core.Exceptions;
using EmailSender.WebApi.Configuration;
using EmailSender.WebApi.Middleware;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.ResponseCompression;
using Serilog;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace EmailSender.WebApi;
Expand Down Expand Up @@ -37,6 +40,10 @@ public void ConfigureServices(IServiceCollection services)
services.RegisterDependencies(_configuration);
services.SetupSwaggerOptions(_environment);
services.SetupDockerInternalNetwork();
services
.AddHealthChecks()
.AddSqlServer(_configuration.GetValue<string>("DbConnect"), "SQLServer")
.AddAzureBlobStorage(_configuration.GetValue<string>("AZ_Storage_ConnectionString"), "AzureStorage");
}

public void Configure(IApplicationBuilder builder)
Expand All @@ -49,13 +56,30 @@ public void Configure(IApplicationBuilder builder)
builder.UseMiddleware<CacheControl>();
builder.UseResponseCompression();
builder.UseRouting();
builder.SetupSwaggerUi(_environment);
builder.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapGet("/", context
=> context.Response.WriteAsync("Email Sender API"));
});

builder.SetupSwaggerUi(_environment);
builder.UseHealthChecks("/hc", new HealthCheckOptions
{
ResponseWriter = async (context, report) =>
{
var result = new
{
status = report.Status.ToString(),
errors = report.Entries.Select(pair
=> new
{
key = pair.Key,
value = Enum.GetName(typeof(HealthStatus), pair.Value.Status)
})
};
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(JsonConvert.SerializeObject(result));
}
});
}
}

0 comments on commit 9e2fbb4

Please sign in to comment.