Browse Source

Autorefresh on healthchecks with config timeout

pull/223/head
Eduard Tomas 7 years ago
parent
commit
5d098b1478
9 changed files with 64 additions and 25 deletions
  1. +6
    -1
      src/Services/Catalog/Catalog.API/Startup.cs
  2. +6
    -1
      src/Services/Identity/Identity.API/Startup.cs
  3. +6
    -1
      src/Services/Ordering/Ordering.API/Startup.cs
  4. +15
    -10
      src/Web/WebMVC/Startup.cs
  5. +10
    -4
      src/Web/WebSPA/Startup.cs
  6. +1
    -0
      src/Web/WebStatus/Controllers/HomeController.cs
  7. +2
    -2
      src/Web/WebStatus/Extensions/HealthCheckBuilderExtensions.cs
  8. +12
    -6
      src/Web/WebStatus/Startup.cs
  9. +6
    -0
      src/Web/WebStatus/Views/Shared/_Layout.cshtml

+ 6
- 1
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -50,7 +50,12 @@
services.AddHealthChecks(checks => services.AddHealthChecks(checks =>
{ {
checks.AddSqlCheck("CatalogDb", Configuration["ConnectionString"]);
var minutes = 1;
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
{
minutes = minutesParsed;
}
checks.AddSqlCheck("CatalogDb", Configuration["ConnectionString"], TimeSpan.FromMinutes(minutes));
}); });
services.AddMvc(options => services.AddMvc(options =>


+ 6
- 1
src/Services/Identity/Identity.API/Startup.cs View File

@ -66,7 +66,12 @@ namespace eShopOnContainers.Identity
services.AddHealthChecks(checks => services.AddHealthChecks(checks =>
{ {
checks.AddSqlCheck("Identity_Db", Configuration.GetConnectionString("DefaultConnection"));
var minutes = 1;
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
{
minutes = minutesParsed;
}
checks.AddSqlCheck("Identity_Db", Configuration.GetConnectionString("DefaultConnection"), TimeSpan.FromMinutes(minutes));
}); });
services.AddTransient<IEmailSender, AuthMessageSender>(); services.AddTransient<IEmailSender, AuthMessageSender>();


+ 6
- 1
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -61,7 +61,12 @@
services.AddHealthChecks(checks => services.AddHealthChecks(checks =>
{ {
checks.AddSqlCheck("OrderingDb", Configuration["ConnectionString"]);
var minutes = 1;
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
{
minutes = minutesParsed;
}
checks.AddSqlCheck("OrderingDb", Configuration["ConnectionString"], TimeSpan.FromMinutes(minutes));
}); });
services.AddEntityFrameworkSqlServer() services.AddEntityFrameworkSqlServer()


+ 15
- 10
src/Web/WebMVC/Startup.cs View File

@ -54,16 +54,21 @@ namespace Microsoft.eShopOnContainers.WebMVC
services.AddHealthChecks(checks => services.AddHealthChecks(checks =>
{ {
checks.AddUrlCheck(Configuration["CatalogUrl"]);
checks.AddUrlCheck(Configuration["OrderingUrl"]);
checks.AddUrlCheck(Configuration["BasketUrl"]);
checks.AddUrlCheck(Configuration["IdentityUrl"]);
var minutes = 1;
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
{
minutes = minutesParsed;
}
checks.AddUrlCheck(Configuration["CatalogUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheck(Configuration["OrderingUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheck(Configuration["BasketUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheck(Configuration["IdentityUrl"], TimeSpan.FromMinutes(minutes));
}); });
// Add application services. // Add application services.
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<ICatalogService, CatalogService>();
services.AddTransient<IOrderingService, OrderingService>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<ICatalogService, CatalogService>();
services.AddTransient<IOrderingService, OrderingService>();
services.AddTransient<IBasketService, BasketService>(); services.AddTransient<IBasketService, BasketService>();
services.AddTransient<IIdentityParser<ApplicationUser>, IdentityParser>(); services.AddTransient<IIdentityParser<ApplicationUser>, IdentityParser>();
@ -76,7 +81,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
{ {
services.AddSingleton<IHttpClient, StandardHttpClient>(); services.AddSingleton<IHttpClient, StandardHttpClient>();
} }
}
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
@ -113,10 +118,10 @@ namespace Microsoft.eShopOnContainers.WebMVC
AuthenticationScheme = "oidc", AuthenticationScheme = "oidc",
SignInScheme = "Cookies", SignInScheme = "Cookies",
Authority = identityUrl.ToString(), Authority = identityUrl.ToString(),
PostLogoutRedirectUri = callBackUrl.ToString(),
PostLogoutRedirectUri = callBackUrl.ToString(),
ClientId = "mvc", ClientId = "mvc",
ClientSecret = "secret", ClientSecret = "secret",
ResponseType = "code id_token",
ResponseType = "code id_token",
SaveTokens = true, SaveTokens = true,
GetClaimsFromUserInfoEndpoint = true, GetClaimsFromUserInfoEndpoint = true,
RequireHttpsMetadata = false, RequireHttpsMetadata = false,


+ 10
- 4
src/Web/WebSPA/Startup.cs View File

@ -45,10 +45,16 @@ namespace eShopConContainers.WebSPA
{ {
services.AddHealthChecks(checks => services.AddHealthChecks(checks =>
{ {
checks.AddUrlCheck(Configuration["CatalogUrl"]);
checks.AddUrlCheck(Configuration["OrderingUrl"]);
checks.AddUrlCheck(Configuration["BasketUrl"]);
checks.AddUrlCheck(Configuration["IdentityUrl"]);
var minutes = 1;
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
{
minutes = minutesParsed;
}
checks.AddUrlCheck(Configuration["CatalogUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheck(Configuration["OrderingUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheck(Configuration["BasketUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheck(Configuration["IdentityUrl"], TimeSpan.FromMinutes(minutes));
}); });
services.Configure<AppSettings>(Configuration); services.Configure<AppSettings>(Configuration);


+ 1
- 0
src/Web/WebStatus/Controllers/HomeController.cs View File

@ -28,6 +28,7 @@ namespace WebStatus.Controllers
data.AddResult(checkResult.Key, checkResult.Value); data.AddResult(checkResult.Key, checkResult.Value);
} }
ViewBag.RefreshSeconds = 60;
return View(data); return View(data);
} }


+ 2
- 2
src/Web/WebStatus/Extensions/HealthCheckBuilderExtensions.cs View File

@ -8,11 +8,11 @@ namespace WebStatus.Extensions
{ {
public static class HealthCheckBuilderExtensions public static class HealthCheckBuilderExtensions
{ {
public static HealthCheckBuilder AddUrlCheckIfNotNull(this HealthCheckBuilder builder, string url)
public static HealthCheckBuilder AddUrlCheckIfNotNull(this HealthCheckBuilder builder, string url, TimeSpan cacheDuration)
{ {
if (!string.IsNullOrEmpty(url)) if (!string.IsNullOrEmpty(url))
{ {
builder.AddUrlCheck(url);
builder.AddUrlCheck(url, cacheDuration);
} }
return builder; return builder;


+ 12
- 6
src/Web/WebStatus/Startup.cs View File

@ -32,12 +32,18 @@ namespace WebStatus
// Add framework services. // Add framework services.
services.AddHealthChecks(checks => services.AddHealthChecks(checks =>
{ {
checks.AddUrlCheckIfNotNull(Configuration["OrderingUrl"]);
checks.AddUrlCheckIfNotNull(Configuration["BasketUrl"]);
checks.AddUrlCheckIfNotNull(Configuration["CatalogUrl"]);
checks.AddUrlCheckIfNotNull(Configuration["IdentityUrl"]);
checks.AddUrlCheckIfNotNull(Configuration["mvc"]);
checks.AddUrlCheckIfNotNull(Configuration["spa"]);
var minutes = 1;
if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed))
{
minutes = minutesParsed;
}
checks.AddUrlCheckIfNotNull(Configuration["OrderingUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["BasketUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["CatalogUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["IdentityUrl"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["mvc"], TimeSpan.FromMinutes(minutes));
checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.FromMinutes(minutes));
}); });
services.AddMvc(); services.AddMvc();
} }


+ 6
- 0
src/Web/WebStatus/Views/Shared/_Layout.cshtml View File

@ -16,6 +16,12 @@
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" /> asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" /> <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment> </environment>
@if (ViewBag.RefreshSeconds != null && ViewBag.RefreshSeconds > 0)
{
<meta http-equiv="refresh" content="@ViewBag.RefreshSeconds">
}
@Html.Raw(JavaScriptSnippet.FullScript) @Html.Raw(JavaScriptSnippet.FullScript)
</head> </head>
<body> <body>


Loading…
Cancel
Save