From f2f0b4e195a8faff809261cb69ea945929491f71 Mon Sep 17 00:00:00 2001 From: Mikhail Shabanov Date: Sun, 24 Jan 2021 18:16:15 +0100 Subject: [PATCH] chore: added healthchecks --- WotBlitzStatisticsPro.GraphQl/Startup.cs | 17 +++++++++++++++-- .../WotBlitzStatisticsPro.GraphQl.csproj | 1 + k8s/web-deployment.yaml | 15 +++++++++++++++ k8s/web-service.yaml | 5 ++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/WotBlitzStatisticsPro.GraphQl/Startup.cs b/WotBlitzStatisticsPro.GraphQl/Startup.cs index 904b312..b975f87 100644 --- a/WotBlitzStatisticsPro.GraphQl/Startup.cs +++ b/WotBlitzStatisticsPro.GraphQl/Startup.cs @@ -1,7 +1,9 @@ using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using WotBlitzStatisticsPro.Common; using WotBlitzStatisticsPro.Common.Model; using WotBlitzStatisticsPro.GraphQl.Mutation; @@ -33,9 +35,12 @@ namespace WotBlitzStatisticsPro.GraphQl services.AddSingleton(mongoConfig); WotBlitzStatisticsLogicInstaller.ConfigureServices(services); + services.AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy()) + .AddMongoDb(mongoConfig.ConnectionString, tags: new[] { "services" }); // Add GraphQL Services - services.AddGraphQLServer() + services.AddGraphQLServer() .AddQueryType() .AddMutationType() .AddType() @@ -53,7 +58,15 @@ namespace WotBlitzStatisticsPro.GraphQl .UseEndpoints(endpoints => { endpoints.MapGraphQL(); - }); + endpoints.MapHealthChecks("/health/self", new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("self") + }); + endpoints.MapHealthChecks("/health/startup", new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("services") + }); + }); } } } diff --git a/WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj b/WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj index 8c605ba..d90d73f 100644 --- a/WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj +++ b/WotBlitzStatisticsPro.GraphQl/WotBlitzStatisticsPro.GraphQl.csproj @@ -9,6 +9,7 @@ + diff --git a/k8s/web-deployment.yaml b/k8s/web-deployment.yaml index b8ac97a..106b0be 100644 --- a/k8s/web-deployment.yaml +++ b/k8s/web-deployment.yaml @@ -33,6 +33,21 @@ spec: name: wot-blitz-statistics-secret key: WargamingApi__ApplicationId image: mike/wot-blitz-statistics-pro:v1 + livenessProbe: + httpGet: + path: /health/self + port: 80 + initialDelaySeconds: 10 + periodSeconds: 30 + timeoutSeconds: 1 + failureThreshold: 3 + startupProbe: + httpGet: + path: /health/startup + port: 80 + initialDelaySeconds: 30 + periodSeconds: 30 + failureThreshold: 30 imagePullPolicy: "" name: wot-blitz-statististics-web ports: diff --git a/k8s/web-service.yaml b/k8s/web-service.yaml index d2f7dcc..8cb0a36 100644 --- a/k8s/web-service.yaml +++ b/k8s/web-service.yaml @@ -11,4 +11,7 @@ spec: ports: - name: "8040" port: 8040 - targetPort: 80 \ No newline at end of file + targetPort: 80 + - name: "443" + port: 443 + targetPort: 443 \ No newline at end of file