From bd74e10d84669591aa06fb200b33494812a0b32a Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 23 Oct 2024 14:27:13 +0200 Subject: [PATCH 1/7] fix(service): enable health-check for servicebus --- .../InfrastructureExtensions.cs | 6 +++++- src/Digdir.Domain.Dialogporten.WebApi/Program.cs | 11 ++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs index 0b0aaa955..1e382f605 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs @@ -192,7 +192,11 @@ internal static void AddPubSubCapabilities(InfrastructureBuilderContext builderC return; } - // x.ConfigureHealthCheckOptions(options => options.Tags.Add("self")); + x.ConfigureHealthCheckOptions(options => + { + options.Tags.Add("self"); + options.Tags.Add("dependencies"); + }); x.AddConfigureEndpointsCallback((_, cfg) => { if (cfg is IServiceBusReceiveEndpointConfigurator sb) diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs index f69497778..46f784ee2 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs @@ -26,17 +26,15 @@ using Microsoft.Extensions.Options; // Using two-stage initialization to catch startup errors. -var telemetryConfiguration = TelemetryConfiguration.CreateDefault(); Log.Logger = new LoggerConfiguration() .MinimumLevel.Warning() .Enrich.FromLogContext() .WriteTo.Console(formatProvider: CultureInfo.InvariantCulture) - .WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces) .CreateBootstrapLogger(); try { - BuildAndRun(args, telemetryConfiguration); + BuildAndRun(args); } catch (Exception ex) when (ex is not OperationCanceledException) { @@ -48,7 +46,7 @@ Log.CloseAndFlush(); } -static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfiguration) +static void BuildAndRun(string[] args) { var builder = WebApplication.CreateBuilder(args); @@ -56,9 +54,8 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura .MinimumLevel.Warning() .ReadFrom.Configuration(context.Configuration) .ReadFrom.Services(services) - .Enrich.FromLogContext() - .WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces)); - + .Enrich.FromLogContext()); + builder.Configuration .AddAzureConfiguration(builder.Environment.EnvironmentName) .AddLocalConfiguration(builder.Environment); From 94793d28a6c39971287baaee1e2ee623c147695a Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 23 Oct 2024 14:34:56 +0200 Subject: [PATCH 2/7] fix(service): enable health-check for servicebus --- .azure/applications/service/main.bicep | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.azure/applications/service/main.bicep b/.azure/applications/service/main.bicep index 26812e1a8..e62011c26 100644 --- a/.azure/applications/service/main.bicep +++ b/.azure/applications/service/main.bicep @@ -131,7 +131,9 @@ var port = 8080 var probes = [ { periodSeconds: 5 - initialDelaySeconds: 2 + failureThreshold: 10 + initialDelaySeconds: 20 + timeoutSeconds: 10 type: 'Liveness' httpGet: { path: '/health/liveness' From b85b01427d2459acbb1f676cfe50c8d2d9c4206d Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 23 Oct 2024 14:35:57 +0200 Subject: [PATCH 3/7] cleanup --- .azure/applications/service/main.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/applications/service/main.bicep b/.azure/applications/service/main.bicep index e62011c26..ebaf5eb34 100644 --- a/.azure/applications/service/main.bicep +++ b/.azure/applications/service/main.bicep @@ -133,7 +133,7 @@ var probes = [ periodSeconds: 5 failureThreshold: 10 initialDelaySeconds: 20 - timeoutSeconds: 10 + timeoutSeconds: 20 type: 'Liveness' httpGet: { path: '/health/liveness' From 2f91a4d3fe6f2f7fe223369576af81dfc3488b84 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 23 Oct 2024 14:43:02 +0200 Subject: [PATCH 4/7] cleanup --- .azure/applications/service/main.bicep | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.azure/applications/service/main.bicep b/.azure/applications/service/main.bicep index ebaf5eb34..26812e1a8 100644 --- a/.azure/applications/service/main.bicep +++ b/.azure/applications/service/main.bicep @@ -131,9 +131,7 @@ var port = 8080 var probes = [ { periodSeconds: 5 - failureThreshold: 10 - initialDelaySeconds: 20 - timeoutSeconds: 20 + initialDelaySeconds: 2 type: 'Liveness' httpGet: { path: '/health/liveness' From 0d0f28d09f5b088b695b3a070d876e35bbf18523 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 23 Oct 2024 14:43:22 +0200 Subject: [PATCH 5/7] cleanup --- .../InfrastructureExtensions.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs index 1e382f605..18b6b9b64 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs @@ -192,11 +192,7 @@ internal static void AddPubSubCapabilities(InfrastructureBuilderContext builderC return; } - x.ConfigureHealthCheckOptions(options => - { - options.Tags.Add("self"); - options.Tags.Add("dependencies"); - }); + x.ConfigureHealthCheckOptions(options => options.Tags.Add("dependencies")); x.AddConfigureEndpointsCallback((_, cfg) => { if (cfg is IServiceBusReceiveEndpointConfigurator sb) From d5da4a6a1c9c74a03911bd5330dc0dd8f786e2db Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 23 Oct 2024 14:44:20 +0200 Subject: [PATCH 6/7] cleanup --- src/Digdir.Domain.Dialogporten.WebApi/Program.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs index 46f784ee2..03013c193 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs @@ -34,7 +34,7 @@ try { - BuildAndRun(args); + BuildAndRun(args, telemetryConfiguration); } catch (Exception ex) when (ex is not OperationCanceledException) { @@ -46,7 +46,7 @@ Log.CloseAndFlush(); } -static void BuildAndRun(string[] args) +static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfiguration) { var builder = WebApplication.CreateBuilder(args); @@ -54,8 +54,9 @@ static void BuildAndRun(string[] args) .MinimumLevel.Warning() .ReadFrom.Configuration(context.Configuration) .ReadFrom.Services(services) - .Enrich.FromLogContext()); - + .Enrich.FromLogContext() + .WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces)); + builder.Configuration .AddAzureConfiguration(builder.Environment.EnvironmentName) .AddLocalConfiguration(builder.Environment); From 4eb99c4c1ea8b97f8f36505810711432bb521f50 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 23 Oct 2024 14:45:02 +0200 Subject: [PATCH 7/7] cleanup --- src/Digdir.Domain.Dialogporten.WebApi/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs index 03013c193..f69497778 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs @@ -26,10 +26,12 @@ using Microsoft.Extensions.Options; // Using two-stage initialization to catch startup errors. +var telemetryConfiguration = TelemetryConfiguration.CreateDefault(); Log.Logger = new LoggerConfiguration() .MinimumLevel.Warning() .Enrich.FromLogContext() .WriteTo.Console(formatProvider: CultureInfo.InvariantCulture) + .WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces) .CreateBootstrapLogger(); try