From a65e9c01eb4f8ff9f60d9f0900f59ae402ee5036 Mon Sep 17 00:00:00 2001 From: dsanz Date: Tue, 4 Jul 2017 11:27:16 +0200 Subject: [PATCH] Add Healthchecks to Locations.API and MArketing.API --- docker-compose.override.yml | 3 +++ src/Services/Location/Locations.API/Locations.API.csproj | 2 ++ src/Services/Location/Locations.API/Program.cs | 1 + src/Services/Location/Locations.API/Startup.cs | 7 +++++++ src/Services/Marketing/Marketing.API/Marketing.API.csproj | 2 ++ src/Services/Marketing/Marketing.API/Program.cs | 1 + src/Services/Marketing/Marketing.API/Startup.cs | 6 ++++++ src/Web/WebMVC/Startup.cs | 1 + src/Web/WebSPA/Startup.cs | 1 + src/Web/WebStatus/Startup.cs | 4 +++- src/Web/WebStatus/appsettings.json | 4 +++- 11 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index f5ad0c9f3..2d7274d8b 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -82,6 +82,7 @@ services: - OrderingUrlHC=http://ordering.api/hc - IdentityUrlHC=http://identity.api/hc #Local: Use ${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}, if using external IP or DNS name from browser. - BasketUrlHC=http://basket.api/hc + - MarketingUrlHC=http://marketing.api/hc - UseCustomizationData=True ports: - "5104:80" @@ -119,6 +120,8 @@ services: - OrderingUrl=http://ordering.api/hc - BasketUrl=http://basket.api/hc - IdentityUrl=http://identity.api/hc + - LocationsUrl=http://locations.api/hc + - MarketingUrl=http://marketing.api/hc - mvc=http://webmvc/hc - spa=http://webspa/hc ports: diff --git a/src/Services/Location/Locations.API/Locations.API.csproj b/src/Services/Location/Locations.API/Locations.API.csproj index b9ef671dc..402cc0da5 100644 --- a/src/Services/Location/Locations.API/Locations.API.csproj +++ b/src/Services/Location/Locations.API/Locations.API.csproj @@ -41,6 +41,8 @@ + + diff --git a/src/Services/Location/Locations.API/Program.cs b/src/Services/Location/Locations.API/Program.cs index 345956401..db2a5532a 100644 --- a/src/Services/Location/Locations.API/Program.cs +++ b/src/Services/Location/Locations.API/Program.cs @@ -14,6 +14,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API { var host = new WebHostBuilder() .UseKestrel() + .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .UseApplicationInsights() diff --git a/src/Services/Location/Locations.API/Startup.cs b/src/Services/Location/Locations.API/Startup.cs index f767f227b..8bfaa44b4 100644 --- a/src/Services/Location/Locations.API/Startup.cs +++ b/src/Services/Location/Locations.API/Startup.cs @@ -16,6 +16,8 @@ using Microsoft.Extensions.Logging; using RabbitMQ.Client; using System.Reflection; using System; +using Microsoft.Extensions.HealthChecks; +using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Locations.API { @@ -51,6 +53,11 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API services.Configure(Configuration); + services.AddHealthChecks(checks => + { + checks.AddValueTaskCheck("HTTP Endpoint", () => new ValueTask(HealthCheckResult.Healthy("Ok"))); + }); + services.AddSingleton(sp => { var logger = sp.GetRequiredService>(); diff --git a/src/Services/Marketing/Marketing.API/Marketing.API.csproj b/src/Services/Marketing/Marketing.API/Marketing.API.csproj index 4a6e2d4ea..72b18c397 100644 --- a/src/Services/Marketing/Marketing.API/Marketing.API.csproj +++ b/src/Services/Marketing/Marketing.API/Marketing.API.csproj @@ -56,6 +56,8 @@ + + diff --git a/src/Services/Marketing/Marketing.API/Program.cs b/src/Services/Marketing/Marketing.API/Program.cs index 2bf3b3d9c..8bac1bbae 100644 --- a/src/Services/Marketing/Marketing.API/Program.cs +++ b/src/Services/Marketing/Marketing.API/Program.cs @@ -10,6 +10,7 @@ { var host = new WebHostBuilder() .UseKestrel() + .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .UseWebRoot("Pics") diff --git a/src/Services/Marketing/Marketing.API/Startup.cs b/src/Services/Marketing/Marketing.API/Startup.cs index f5f726c62..5550ef507 100644 --- a/src/Services/Marketing/Marketing.API/Startup.cs +++ b/src/Services/Marketing/Marketing.API/Startup.cs @@ -26,6 +26,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API using Polly; using System.Threading.Tasks; using System.Data.SqlClient; + using Microsoft.Extensions.HealthChecks; public class Startup { @@ -60,6 +61,11 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API services.Configure(Configuration); + services.AddHealthChecks(checks => + { + checks.AddValueTaskCheck("HTTP Endpoint", () => new ValueTask(HealthCheckResult.Healthy("Ok"))); + }); + services.AddDbContext(options => { options.UseSqlServer(Configuration["ConnectionString"], diff --git a/src/Web/WebMVC/Startup.cs b/src/Web/WebMVC/Startup.cs index ef0228604..189eaedc6 100644 --- a/src/Web/WebMVC/Startup.cs +++ b/src/Web/WebMVC/Startup.cs @@ -64,6 +64,7 @@ namespace Microsoft.eShopOnContainers.WebMVC checks.AddUrlCheck(Configuration["OrderingUrl"] + "/hc", TimeSpan.FromMinutes(minutes)); checks.AddUrlCheck(Configuration["BasketUrl"] + "/hc", TimeSpan.FromMinutes(minutes)); checks.AddUrlCheck(Configuration["IdentityUrl"] + "/hc", TimeSpan.FromMinutes(minutes)); + checks.AddUrlCheck(Configuration["MarketingUrl"] + "/hc", TimeSpan.FromMinutes(minutes)); }); // Add application services. diff --git a/src/Web/WebSPA/Startup.cs b/src/Web/WebSPA/Startup.cs index 5ca7eb22c..4f73d744d 100644 --- a/src/Web/WebSPA/Startup.cs +++ b/src/Web/WebSPA/Startup.cs @@ -57,6 +57,7 @@ namespace eShopConContainers.WebSPA checks.AddUrlCheck(Configuration["OrderingUrlHC"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheck(Configuration["BasketUrlHC"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheck(Configuration["IdentityUrlHC"], TimeSpan.FromMinutes(minutes)); + checks.AddUrlCheck(Configuration["MarketingUrlHC"], TimeSpan.FromMinutes(minutes)); }); services.Configure(Configuration); diff --git a/src/Web/WebStatus/Startup.cs b/src/Web/WebStatus/Startup.cs index 0b9ecb937..82f7f16ea 100644 --- a/src/Web/WebStatus/Startup.cs +++ b/src/Web/WebStatus/Startup.cs @@ -42,8 +42,10 @@ namespace WebStatus checks.AddUrlCheckIfNotNull(Configuration["BasketUrl"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheckIfNotNull(Configuration["CatalogUrl"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheckIfNotNull(Configuration["IdentityUrl"], TimeSpan.FromMinutes(minutes)); + checks.AddUrlCheckIfNotNull(Configuration["LocationsUrl"], TimeSpan.FromMinutes(minutes)); + checks.AddUrlCheckIfNotNull(Configuration["MarketingUrl"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheckIfNotNull(Configuration["mvc"], TimeSpan.FromMinutes(minutes)); - checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.FromMinutes(minutes)); + checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.FromMinutes(minutes)); }); services.AddMvc(); } diff --git a/src/Web/WebStatus/appsettings.json b/src/Web/WebStatus/appsettings.json index 06c5970b2..d2f1f4727 100644 --- a/src/Web/WebStatus/appsettings.json +++ b/src/Web/WebStatus/appsettings.json @@ -8,5 +8,7 @@ "OrderingUrl": "http://localhost:5102/hc", "BasketUrl": "http://localhost:5103/hc", "CatalogUrl": "http://localhost:5101/hc", - "IdentityUrl": "http://localhost:5105/hc" + "IdentityUrl": "http://localhost:5105/hc", + "MarketingUrl": "http://localhost:5110/hc", + "LocationsUrl": "http://localhost:5109/hc" }