Skip to content

Commit

Permalink
Merge branch 'release/6.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vc-ci committed Apr 14, 2023
2 parents 74b2bb4 + 2443978 commit 8e91997
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Authors>VirtoCommerce</Authors>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>6.14.0</VersionPrefix>
<VersionPrefix>6.15.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using VirtoCommerce.Storefront.Model.Stores;

namespace VirtoCommerce.Storefront.Infrastructure.HealthCheck
{
public class PlatformConnectionHealthChecker : IHealthCheck
{
private readonly IStoreService _storeService;

public PlatformConnectionHealthChecker(IStoreService storeService)
{
_storeService = storeService;
}

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
await _storeService.GetAllStoresAsync();
return HealthCheckResult.Healthy("Connection to the Platform is OK");
}
catch
{
return HealthCheckResult.Unhealthy("Connection to the Platform fails");
}

}
}
}
21 changes: 21 additions & 0 deletions VirtoCommerce.Storefront/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
Expand All @@ -18,11 +19,13 @@
using Microsoft.AspNetCore.Rewrite;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.WebEncoders;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using ProxyKit;
using Swashbuckle.AspNetCore.SwaggerGen;
Expand All @@ -36,6 +39,7 @@
using VirtoCommerce.Storefront.Infrastructure;
using VirtoCommerce.Storefront.Infrastructure.ApplicationInsights;
using VirtoCommerce.Storefront.Infrastructure.Autorest;
using VirtoCommerce.Storefront.Infrastructure.HealthCheck;
using VirtoCommerce.Storefront.Infrastructure.Swagger;
using VirtoCommerce.Storefront.Middleware;
using VirtoCommerce.Storefront.Model;
Expand Down Expand Up @@ -71,6 +75,11 @@ public void ConfigureServices(IServiceCollection services)
services.AddMemoryCache();
services.AddResponseCaching();

services.AddHealthChecks()
.AddCheck<PlatformConnectionHealthChecker>("Platform connection health",
failureStatus: HealthStatus.Unhealthy,
tags: new[] { "PlatformConnection" });

services.Configure<StorefrontOptions>(Configuration.GetSection("VirtoCommerce"));

//The IHttpContextAccessor service is not registered by default
Expand Down Expand Up @@ -354,6 +363,18 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
// Do not write telemetry to debug output
TelemetryDebugWriter.IsTracingDisabled = true;

app.UseHealthChecks("/storefrontapi/health", new HealthCheckOptions
{
ResponseWriter = async (context, report) =>
{
context.Response.ContentType = "application/json; charset=utf-8";

var reportJson =
JsonConvert.SerializeObject(report.Entries, Formatting.Indented, new StringEnumConverter());
await context.Response.WriteAsync(reportJson);
}
});

app.UseResponseCaching();

app.UseResponseCompression();
Expand Down

0 comments on commit 8e91997

Please sign in to comment.