From dbf175f913f17d2b1ac6035fad719ed78c5da0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Tom=C3=A1s?= Date: Thu, 3 Jan 2019 17:11:56 +0100 Subject: [PATCH] Fixed missing env variables in marketing.api in k8s scripts Added Resource path in webstatus UI when deploying with K8S Added Liveness healthChecks Updated k8s healthcheck configuration --- k8s/helm/deploy-all.ps1 | 2 +- k8s/helm/inf.yaml | 2 + .../marketing-api/templates/configmap.yaml | 6 +- k8s/helm/marketing-api/values.yaml | 6 +- k8s/helm/webstatus/values.yaml | 74 ++++++++++--------- src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj | 1 + src/ApiGateways/ApiGw-Base/Startup.cs | 7 ++ .../Mobile.Shopping.HttpAggregator.csproj | 1 + .../Mobile.Bff.Shopping/aggregator/Startup.cs | 7 ++ .../Web.Bff.Shopping/aggregator/Startup.cs | 7 ++ .../Web.Shopping.HttpAggregator.csproj | 1 + .../Basket/Basket.API/Basket.API.csproj | 1 + src/Services/Basket/Basket.API/Startup.cs | 10 ++- src/Services/Catalog/Catalog.API/Startup.cs | 9 ++- .../Identity/Identity.API/Identity.API.csproj | 1 + src/Services/Identity/Identity.API/Startup.cs | 10 ++- .../Locations.API/Locations.API.csproj | 1 + .../Location/Locations.API/Startup.cs | 10 ++- .../Marketing.API/Marketing.API.csproj | 1 + .../Marketing/Marketing.API/Startup.cs | 10 ++- .../Ordering/Ordering.API/Ordering.API.csproj | 1 + src/Services/Ordering/Ordering.API/Startup.cs | 13 ++-- .../Ordering.BackgroundTasks.csproj | 1 + .../Ordering.BackgroundTasks/Startup.cs | 10 ++- .../Ordering.SignalrHub.csproj | 9 ++- .../Ordering/Ordering.SignalrHub/Startup.cs | 8 ++ .../Payment/Payment.API/Payment.API.csproj | 1 + src/Services/Payment/Payment.API/Startup.cs | 10 ++- src/Web/WebMVC/Startup.cs | 11 +-- src/Web/WebMVC/WebMVC.csproj | 1 + src/Web/WebSPA/Startup.cs | 12 +-- src/Web/WebSPA/WebSPA.csproj | 1 + .../WebStatus/Controllers/HomeController.cs | 9 ++- src/Web/WebStatus/Startup.cs | 16 +++- src/Web/WebStatus/WebStatus.csproj | 14 ++-- 35 files changed, 191 insertions(+), 93 deletions(-) diff --git a/k8s/helm/deploy-all.ps1 b/k8s/helm/deploy-all.ps1 index 08313cdbb..9bd79b682 100644 --- a/k8s/helm/deploy-all.ps1 +++ b/k8s/helm/deploy-all.ps1 @@ -16,7 +16,7 @@ $dns = $externalDns $ingressValuesFile="ingress_values.yaml" -if ($ingressValuesFile) { +if ($useLocalk8s) { $ingressValuesFile="ingress_values_dockerk8s.yaml" $dns="localhost" } diff --git a/k8s/helm/inf.yaml b/k8s/helm/inf.yaml index 4c0180f45..5cc9c0894 100644 --- a/k8s/helm/inf.yaml +++ b/k8s/helm/inf.yaml @@ -14,6 +14,8 @@ inf: db: OrderingDb # Ordering API SQL db name identity: db: IdentityDb # Ordering API SQL db name + marketing: + db: MarketingDb # Marketing API SQL db name mongo: # host: my-nosql-data # Uncomment to use specify custom mongo host. By default nosql-data is used locations: diff --git a/k8s/helm/marketing-api/templates/configmap.yaml b/k8s/helm/marketing-api/templates/configmap.yaml index ea99a1b5a..45f21e57d 100644 --- a/k8s/helm/marketing-api/templates/configmap.yaml +++ b/k8s/helm/marketing-api/templates/configmap.yaml @@ -2,6 +2,7 @@ {{- $identity := include "url-of" (list .Values.app.ingress.entries.identity .) -}} {{- $webshoppingapigw := include "url-of" (list .Values.app.ingress.entries.webshoppingapigw .) -}} {{- $mongo := include "mongo-name" . -}} +{{- $sqlsrv := include "sql-name" . -}} apiVersion: v1 kind: ConfigMap @@ -19,6 +20,7 @@ data: all_EnableLoadTest: "{{ .Values.inf.misc.useLoadTest }}" internalurls__IdentityUrl: http://{{ .Values.app.svc.identity }} urls__IdentityUrl: {{ $identity }} - marketing__ConnectionString: mongodb://{{ $mongo }} - marketing__Database: {{ .Values.inf.mongo.marketing.database }} + marketing__ConnectionString: Server={{ $sqlsrv }};Initial Catalog={{ .Values.inf.sql.marketing.db }};User Id={{ .Values.inf.sql.common.user }};Password={{ .Values.inf.sql.common.pwd }}; + marketing__MongoConnectionString: mongodb://{{ $mongo }} + marketing__MongoDatabase: {{ .Values.inf.mongo.marketing.database }} marketing__PicBaseUrl: http://{{ $webshoppingapigw }}/api/v1/c/catalog/items/[0]/pic/ \ No newline at end of file diff --git a/k8s/helm/marketing-api/values.yaml b/k8s/helm/marketing-api/values.yaml index 8779685d6..b898af73c 100644 --- a/k8s/helm/marketing-api/values.yaml +++ b/k8s/helm/marketing-api/values.yaml @@ -44,8 +44,10 @@ env: key: urls__IdentityUrl - name: ConnectionString key: marketing__ConnectionString - - name: Database - key: marketing__Database + - name: MongoConnectionString + key: marketing__MongoConnectionString + - name: MongoDatabase + key: marketing__MongoDatabase - name: PicBaseUrl key: marketing__PicBaseUrl # values define environment variables with a fixed value (no configmap involved) (name is name of var, and value is its value) diff --git a/k8s/helm/webstatus/values.yaml b/k8s/helm/webstatus/values.yaml index 10f2b7112..88cae5d7f 100644 --- a/k8s/helm/webstatus/values.yaml +++ b/k8s/helm/webstatus/values.yaml @@ -13,7 +13,9 @@ service: ingress: enabled: true - annotations: {} + annotations: { + + } tls: [] resources: {} @@ -32,73 +34,73 @@ env: configmap: - name: ApplicationInsights__InstrumentationKey key: all__InstrumentationKey - - name: HealthChecks-UI__HealthChecks__1__Name + - name: HealthChecks-UI__HealthChecks__0__Name key: name__mvc__hc - - name: HealthChecks-UI__HealthChecks__1__Uri + - name: HealthChecks-UI__HealthChecks__0__Uri key: internalurls__mvc__hc - - name: HealthChecks-UI__HealthChecks__2__Name + - name: HealthChecks-UI__HealthChecks__1__Name key: name__spa__hc - - name: HealthChecks-UI__HealthChecks__2__Uri + - name: HealthChecks-UI__HealthChecks__1__Uri key: internalurls__spa__hc - - name: HealthChecks-UI__HealthChecks__3__Name + - name: HealthChecks-UI__HealthChecks__2__Name key: name__apigwws__hc - - name: HealthChecks-UI__HealthChecks__3__Uri + - name: HealthChecks-UI__HealthChecks__2__Uri key: internalurls__apigwws__hc - - name: HealthChecks-UI__HealthChecks__4__Name + - name: HealthChecks-UI__HealthChecks__3__Name key: name__apigwwm__hc - - name: HealthChecks-UI__HealthChecks__4__Uri + - name: HealthChecks-UI__HealthChecks__3__Uri key: internalurls__apigwwm__hc - - name: HealthChecks-UI__HealthChecks__5__Name + - name: HealthChecks-UI__HealthChecks__4__Name key: name__apigwms__hc - - name: HealthChecks-UI__HealthChecks__5__Uri - key: internalurls__apigwms__hcç - - name: HealthChecks-UI__HealthChecks__6__Name + - name: HealthChecks-UI__HealthChecks__4__Uri + key: internalurls__apigwms__hc + - name: HealthChecks-UI__HealthChecks__5__Name key: name__apigwmm__hc - - name: HealthChecks-UI__HealthChecks__6__Uri + - name: HealthChecks-UI__HealthChecks__5__Uri key: internalurls__apigwmm__hc - - name: HealthChecks-UI__HealthChecks__7__Name + - name: HealthChecks-UI__HealthChecks__6__Name key: name__apigwwsagg__hc - - name: HealthChecks-UI__HealthChecks__7__Uri + - name: HealthChecks-UI__HealthChecks__6__Uri key: internalurls__apigwwsagg__hc - - name: HealthChecks-UI__HealthChecks__8__Name + - name: HealthChecks-UI__HealthChecks__7__Name key: name__apigwmsagg__hc - - name: HealthChecks-UI__HealthChecks__8__Uri + - name: HealthChecks-UI__HealthChecks__7__Uri key: internalurls__apigwmsagg__hc - - name: HealthChecks-UI__HealthChecks__9__Name + - name: HealthChecks-UI__HealthChecks__8__Name key: name__ordering__hc - - name: HealthChecks-UI__HealthChecks__9__Uri + - name: HealthChecks-UI__HealthChecks__8__Uri key: internalurls__ordering__hc - - name: HealthChecks-UI__HealthChecks__10__Name + - name: HealthChecks-UI__HealthChecks__9__Name key: name__orderingbackground__hc - - name: HealthChecks-UI__HealthChecks__10__Uri + - name: HealthChecks-UI__HealthChecks__9__Uri key: internalurls__orderingbackground__hc - - name: HealthChecks-UI__HealthChecks__11__Name + - name: HealthChecks-UI__HealthChecks__10__Name key: name__signalrhub__hc - - name: HealthChecks-UI__HealthChecks__11__Uri + - name: HealthChecks-UI__HealthChecks__10__Uri key: internalurls__signalrhub__hc - - name: HealthChecks-UI__HealthChecks__12__Name + - name: HealthChecks-UI__HealthChecks__11__Name key: name__basket__hc - - name: HealthChecks-UI__HealthChecks__12__Uri + - name: HealthChecks-UI__HealthChecks__11__Uri key: internalurls__basket__hc - - name: HealthChecks-UI__HealthChecks__13__Name + - name: HealthChecks-UI__HealthChecks__12__Name key: name__catalog__hc - - name: HealthChecks-UI__HealthChecks__13__Uri + - name: HealthChecks-UI__HealthChecks__12__Uri key: internalurls__catalog__hc - - name: HealthChecks-UI__HealthChecks__14__Name + - name: HealthChecks-UI__HealthChecks__13__Name key: name__identity__hc - - name: HealthChecks-UI__HealthChecks__14__Uri + - name: HealthChecks-UI__HealthChecks__13__Uri key: internalurls__identity__hc - - name: HealthChecks-UI__HealthChecks__15__Name + - name: HealthChecks-UI__HealthChecks__14__Name key: name__marketing__hc - - name: HealthChecks-UI__HealthChecks__15__Uri + - name: HealthChecks-UI__HealthChecks__14__Uri key: internalurls__marketing__hc - - name: HealthChecks-UI__HealthChecks__16__Name + - name: HealthChecks-UI__HealthChecks__15__Name key: name__locations__hc - - name: HealthChecks-UI__HealthChecks__16__Uri + - name: HealthChecks-UI__HealthChecks__15__Uri key: internalurls__locations__hc - - name: HealthChecks-UI__HealthChecks__17__Name + - name: HealthChecks-UI__HealthChecks__16__Name key: name__payment__hc - - name: HealthChecks-UI__HealthChecks__17__Uri + - name: HealthChecks-UI__HealthChecks__16__Uri key: internalurls__payment__hc # values define environment variables with a fixed value (no configmap involved) (name is name of var, and value is its value) values: diff --git a/src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj b/src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj index f98e29c20..5c2f9ed77 100644 --- a/src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj +++ b/src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj @@ -12,6 +12,7 @@ + diff --git a/src/ApiGateways/ApiGw-Base/Startup.cs b/src/ApiGateways/ApiGw-Base/Startup.cs index 38dcf1d52..012229a48 100644 --- a/src/ApiGateways/ApiGw-Base/Startup.cs +++ b/src/ApiGateways/ApiGw-Base/Startup.cs @@ -8,6 +8,7 @@ using Ocelot.DependencyInjection; using Ocelot.Middleware; using System; using HealthChecks.UI.Client; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace OcelotApiGw { @@ -26,6 +27,7 @@ namespace OcelotApiGw var authenticationProviderKey = "IdentityApiKey"; services.AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy()) .AddUrlGroup(new Uri(_cfg["CatalogUrlHC"]), name: "catalogapi-check", tags: new string[] { "catalogapi" }) .AddUrlGroup(new Uri(_cfg["OrderingUrlHC"]), name: "orderingapi-check", tags: new string[] { "orderingapi" }) .AddUrlGroup(new Uri(_cfg["BasketUrlHC"]), name: "basketapi-check", tags: new string[] { "basketapi" }) @@ -93,6 +95,11 @@ namespace OcelotApiGw ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + loggerFactory.AddConsole(_cfg.GetSection("Logging")); app.UseCors("CorsPolicy"); diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj index 8adc50166..69cc8197f 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj @@ -15,6 +15,7 @@ + diff --git a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs index 2a19dde84..dd77d3c1b 100644 --- a/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs @@ -19,6 +19,7 @@ using Polly.Extensions.Http; using Swashbuckle.AspNetCore.Swagger; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator { @@ -35,6 +36,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator public void ConfigureServices(IServiceCollection services) { services.AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy()) .AddUrlGroup(new Uri(Configuration["CatalogUrlHC"]), name: "catalogapi-check", tags: new string[] { "catalogapi" }) .AddUrlGroup(new Uri(Configuration["OrderingUrlHC"]), name: "orderingapi-check", tags: new string[] { "orderingapi" }) .AddUrlGroup(new Uri(Configuration["BasketUrlHC"]), name: "basketapi-check", tags: new string[] { "basketapi" }) @@ -65,6 +67,11 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + app.UseCors("CorsPolicy"); if (env.IsDevelopment()) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs index a4777774e..4cd2c0503 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs @@ -20,6 +20,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Net.Http; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator { @@ -36,6 +37,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator public void ConfigureServices(IServiceCollection services) { services.AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy()) .AddUrlGroup(new Uri(Configuration["CatalogUrlHC"]), name: "catalogapi-check", tags: new string[] { "catalogapi" }) .AddUrlGroup(new Uri(Configuration["OrderingUrlHC"]), name: "orderingapi-check", tags: new string[] { "orderingapi" }) .AddUrlGroup(new Uri(Configuration["BasketUrlHC"]), name: "basketapi-check", tags: new string[] { "basketapi" }) @@ -65,6 +67,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + app.UseCors("CorsPolicy"); if (env.IsDevelopment()) diff --git a/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj b/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj index 5dfb94e93..6b2b47516 100644 --- a/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj +++ b/src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj @@ -15,6 +15,7 @@ + diff --git a/src/Services/Basket/Basket.API/Basket.API.csproj b/src/Services/Basket/Basket.API/Basket.API.csproj index 0e5aabcc9..91fe879bd 100644 --- a/src/Services/Basket/Basket.API/Basket.API.csproj +++ b/src/Services/Basket/Basket.API/Basket.API.csproj @@ -21,6 +21,7 @@ + diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index 416ed98f4..18805ce94 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -25,6 +25,7 @@ using Microsoft.eShopOnContainers.Services.Basket.API.Model; using Microsoft.eShopOnContainers.Services.Basket.API.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using RabbitMQ.Client; @@ -194,9 +195,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); app.UseStaticFiles(); app.UseCors("CorsPolicy"); @@ -322,6 +324,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API { var hcBuilder = services.AddHealthChecks(); + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + hcBuilder .AddRedis( configuration["ConnectionString"], diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 847d89580..89deb9eef 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -30,6 +30,7 @@ using System.Data.Common; using System.Reflection; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.eShopOnContainers.Services.Catalog.API { @@ -80,9 +81,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); app.UseCors("CorsPolicy"); @@ -156,6 +158,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API var hcBuilder = services.AddHealthChecks(); hcBuilder + .AddCheck("self", () => HealthCheckResult.Healthy()) .AddSqlServer( configuration["ConnectionString"], name: "CatalogDB-check", diff --git a/src/Services/Identity/Identity.API/Identity.API.csproj b/src/Services/Identity/Identity.API/Identity.API.csproj index 83c85d442..5e1100eb3 100644 --- a/src/Services/Identity/Identity.API/Identity.API.csproj +++ b/src/Services/Identity/Identity.API/Identity.API.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Services/Identity/Identity.API/Startup.cs b/src/Services/Identity/Identity.API/Startup.cs index aa7000aa7..aa390779e 100644 --- a/src/Services/Identity/Identity.API/Startup.cs +++ b/src/Services/Identity/Identity.API/Startup.cs @@ -21,6 +21,7 @@ using System; using System.Reflection; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.eShopOnContainers.Services.Identity.API { @@ -67,6 +68,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API } services.AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy()) .AddSqlServer(Configuration["ConnectionString"], name: "IdentityDB-check", tags: new string[] { "IdentityDB" }); @@ -138,16 +140,16 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API app.UsePathBase(pathBase); } - app.UseHealthChecks("/hc", new HealthCheckOptions() { Predicate = _ => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); app.UseStaticFiles(); diff --git a/src/Services/Location/Locations.API/Locations.API.csproj b/src/Services/Location/Locations.API/Locations.API.csproj index 4c4121f0a..eaca0c6fb 100644 --- a/src/Services/Location/Locations.API/Locations.API.csproj +++ b/src/Services/Location/Locations.API/Locations.API.csproj @@ -15,6 +15,7 @@ + diff --git a/src/Services/Location/Locations.API/Startup.cs b/src/Services/Location/Locations.API/Startup.cs index b08bff883..6ca0ecc6f 100644 --- a/src/Services/Location/Locations.API/Startup.cs +++ b/src/Services/Location/Locations.API/Startup.cs @@ -21,6 +21,7 @@ using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Reposito using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using RabbitMQ.Client; using Swashbuckle.AspNetCore.Swagger; @@ -162,9 +163,10 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API app.UsePathBase(pathBase); } -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); app.UseHealthChecks("/hc", new HealthCheckOptions() { @@ -282,6 +284,8 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API { var hcBuilder = services.AddHealthChecks(); + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + hcBuilder .AddMongoDb( configuration["ConnectionString"], diff --git a/src/Services/Marketing/Marketing.API/Marketing.API.csproj b/src/Services/Marketing/Marketing.API/Marketing.API.csproj index bf0d267e8..a582842ed 100644 --- a/src/Services/Marketing/Marketing.API/Marketing.API.csproj +++ b/src/Services/Marketing/Marketing.API/Marketing.API.csproj @@ -30,6 +30,7 @@ + diff --git a/src/Services/Marketing/Marketing.API/Startup.cs b/src/Services/Marketing/Marketing.API/Startup.cs index e43687a72..40f1b2695 100644 --- a/src/Services/Marketing/Marketing.API/Startup.cs +++ b/src/Services/Marketing/Marketing.API/Startup.cs @@ -28,6 +28,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares; + using Microsoft.Extensions.Diagnostics.HealthChecks; using RabbitMQ.Client; using Swashbuckle.AspNetCore.Swagger; using System; @@ -193,9 +194,10 @@ ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); app.UseCors("CorsPolicy"); @@ -313,6 +315,8 @@ { var hcBuilder = services.AddHealthChecks(); + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + hcBuilder .AddSqlServer( configuration["ConnectionString"], diff --git a/src/Services/Ordering/Ordering.API/Ordering.API.csproj b/src/Services/Ordering/Ordering.API/Ordering.API.csproj index ddd915147..65a074242 100644 --- a/src/Services/Ordering/Ordering.API/Ordering.API.csproj +++ b/src/Services/Ordering/Ordering.API/Ordering.API.csproj @@ -38,6 +38,7 @@ + diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index df93b2e44..39b424583 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -37,6 +37,7 @@ using System.Reflection; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; + using Microsoft.Extensions.Diagnostics.HealthChecks; public class Startup { @@ -81,14 +82,14 @@ { loggerFactory.CreateLogger("init").LogDebug($"Using PATH BASE '{pathBase}'"); app.UsePathBase(pathBase); - } - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + } app.UseCors("CorsPolicy"); + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); app.UseHealthChecks("/hc", new HealthCheckOptions() { @@ -185,6 +186,8 @@ { var hcBuilder = services.AddHealthChecks(); + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + hcBuilder .AddSqlServer( configuration["ConnectionString"], diff --git a/src/Services/Ordering/Ordering.BackgroundTasks/Ordering.BackgroundTasks.csproj b/src/Services/Ordering/Ordering.BackgroundTasks/Ordering.BackgroundTasks.csproj index b62c7f99c..064556274 100644 --- a/src/Services/Ordering/Ordering.BackgroundTasks/Ordering.BackgroundTasks.csproj +++ b/src/Services/Ordering/Ordering.BackgroundTasks/Ordering.BackgroundTasks.csproj @@ -20,6 +20,7 @@ + diff --git a/src/Services/Ordering/Ordering.BackgroundTasks/Startup.cs b/src/Services/Ordering/Ordering.BackgroundTasks/Startup.cs index a0afc0ea8..5844a3964 100644 --- a/src/Services/Ordering/Ordering.BackgroundTasks/Startup.cs +++ b/src/Services/Ordering/Ordering.BackgroundTasks/Startup.cs @@ -17,6 +17,7 @@ using RabbitMQ.Client; using System; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Ordering.BackgroundTasks { @@ -110,9 +111,10 @@ namespace Ordering.BackgroundTasks ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); } @@ -162,6 +164,8 @@ namespace Ordering.BackgroundTasks { var hcBuilder = services.AddHealthChecks(); + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + hcBuilder .AddSqlServer( configuration["ConnectionString"], diff --git a/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj b/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj index 2ec270e5d..626e7d41a 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj +++ b/src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj @@ -14,11 +14,12 @@ - + + - - - + + + diff --git a/src/Services/Ordering/Ordering.SignalrHub/Startup.cs b/src/Services/Ordering/Ordering.SignalrHub/Startup.cs index 186ebf954..6e10fd346 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/Startup.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/Startup.cs @@ -19,6 +19,7 @@ using System; using System.IdentityModel.Tokens.Jwt; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Ordering.SignalrHub { @@ -136,6 +137,11 @@ namespace Ordering.SignalrHub ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + app.UseCors("CorsPolicy"); app.UseAuthentication(); @@ -227,6 +233,8 @@ namespace Ordering.SignalrHub { var hcBuilder = services.AddHealthChecks(); + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + if (configuration.GetValue("AzureServiceBusEnabled")) { hcBuilder diff --git a/src/Services/Payment/Payment.API/Payment.API.csproj b/src/Services/Payment/Payment.API/Payment.API.csproj index fbfd6bd54..bc5298af4 100644 --- a/src/Services/Payment/Payment.API/Payment.API.csproj +++ b/src/Services/Payment/Payment.API/Payment.API.csproj @@ -15,6 +15,7 @@ + diff --git a/src/Services/Payment/Payment.API/Startup.cs b/src/Services/Payment/Payment.API/Startup.cs index 7cfba1298..5241fc1c7 100644 --- a/src/Services/Payment/Payment.API/Startup.cs +++ b/src/Services/Payment/Payment.API/Startup.cs @@ -18,6 +18,7 @@ using RabbitMQ.Client; using System; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Payment.API { @@ -106,9 +107,10 @@ namespace Payment.API ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); ConfigureEventBus(app); } @@ -184,6 +186,8 @@ namespace Payment.API { var hcBuilder = services.AddHealthChecks(); + hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); + if (configuration.GetValue("AzureServiceBusEnabled")) { hcBuilder diff --git a/src/Web/WebMVC/Startup.cs b/src/Web/WebMVC/Startup.cs index a3d2f9bb6..d69b21459 100644 --- a/src/Web/WebMVC/Startup.cs +++ b/src/Web/WebMVC/Startup.cs @@ -13,7 +13,7 @@ using Microsoft.eShopOnContainers.WebMVC.Services; using Microsoft.eShopOnContainers.WebMVC.ViewModels; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using Polly; using Polly.Extensions.Http; @@ -78,10 +78,10 @@ namespace Microsoft.eShopOnContainers.WebMVC app.UsePathBase(pathBase); } - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); app.UseSession(); app.UseStaticFiles(); @@ -138,6 +138,7 @@ namespace Microsoft.eShopOnContainers.WebMVC public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration) { services.AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy()) .AddUrlGroup(new Uri(configuration["PurchaseUrlHC"]), name: "purchaseapigw-check", tags: new string[] { "purchaseapigw" }) .AddUrlGroup(new Uri(configuration["MarketingUrlHC"]), name: "marketingapigw-check", tags: new string[] { "marketingapigw" }) .AddUrlGroup(new Uri(configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" }); diff --git a/src/Web/WebMVC/WebMVC.csproj b/src/Web/WebMVC/WebMVC.csproj index de3c0ee6c..0ca1afa85 100644 --- a/src/Web/WebMVC/WebMVC.csproj +++ b/src/Web/WebMVC/WebMVC.csproj @@ -27,6 +27,7 @@ + diff --git a/src/Web/WebSPA/Startup.cs b/src/Web/WebSPA/Startup.cs index 53bf2906c..5fe5d03b2 100644 --- a/src/Web/WebSPA/Startup.cs +++ b/src/Web/WebSPA/Startup.cs @@ -16,6 +16,7 @@ using System.IO; using WebSPA.Infrastructure; using HealthChecks.UI.Client; using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.Diagnostics.HealthChecks; namespace eShopConContainers.WebSPA { @@ -44,6 +45,7 @@ namespace eShopConContainers.WebSPA RegisterAppInsights(services); services.AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy()) .AddUrlGroup(new Uri(Configuration["PurchaseUrlHC"]), name: "purchaseapigw-check", tags: new string[] { "purchaseapigw" }) .AddUrlGroup(new Uri(Configuration["MarketingUrlHC"]), name: "marketingapigw-check", tags: new string[] { "marketingapigw" }) .AddUrlGroup(new Uri(Configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" }); @@ -87,6 +89,11 @@ namespace eShopConContainers.WebSPA app.UseHsts(); } + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); + app.UseHealthChecks("/hc", new HealthCheckOptions() { Predicate = _ => true, @@ -115,11 +122,6 @@ namespace eShopConContainers.WebSPA app.UsePathBase(pathBase); } - -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously - app.Use(async (context, next) => { await next(); diff --git a/src/Web/WebSPA/WebSPA.csproj b/src/Web/WebSPA/WebSPA.csproj index 4141bff44..d42ef3de2 100644 --- a/src/Web/WebSPA/WebSPA.csproj +++ b/src/Web/WebSPA/WebSPA.csproj @@ -91,6 +91,7 @@ + diff --git a/src/Web/WebStatus/Controllers/HomeController.cs b/src/Web/WebStatus/Controllers/HomeController.cs index f2afab4b7..15f912bc2 100644 --- a/src/Web/WebStatus/Controllers/HomeController.cs +++ b/src/Web/WebStatus/Controllers/HomeController.cs @@ -1,17 +1,22 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; using System.Threading.Tasks; namespace WebStatus.Controllers { public class HomeController : Controller { - public HomeController() + private IConfiguration _configuration; + + public HomeController(IConfiguration configuration) { + _configuration = configuration; } public IActionResult Index() { - return Redirect("/hc-ui"); + var basePath = _configuration["PATH_BASE"]; + return Redirect($"{basePath}/hc-ui"); } public IActionResult Error() diff --git a/src/Web/WebStatus/Startup.cs b/src/Web/WebStatus/Startup.cs index 9e7d56e8a..b97ca1616 100644 --- a/src/Web/WebStatus/Startup.cs +++ b/src/Web/WebStatus/Startup.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; namespace WebStatus @@ -26,6 +27,9 @@ namespace WebStatus RegisterAppInsights(services); services.AddOptions(); + services.AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy()); + services.AddHealthChecksUI(); services.AddMvc() @@ -55,11 +59,15 @@ namespace WebStatus app.UsePathBase(pathBase); } -#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200)); -#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously + app.UseHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); - app.UseHealthChecksUI(config => config.UIPath = "/hc-ui"); + app.UseHealthChecksUI(config => { + config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources"; + config.UIPath = "/hc-ui"; + }); app.UseStaticFiles(); diff --git a/src/Web/WebStatus/WebStatus.csproj b/src/Web/WebStatus/WebStatus.csproj index c55f0d446..26b9f4560 100644 --- a/src/Web/WebStatus/WebStatus.csproj +++ b/src/Web/WebStatus/WebStatus.csproj @@ -5,18 +5,22 @@ ..\..\..\docker-compose.dcproj - - + + + + + + + + + - - -