From c53eb910a2bc09712c4bf036934b928f305da510 Mon Sep 17 00:00:00 2001 From: James Gunn Date: Tue, 19 Sep 2023 15:57:01 +0100 Subject: [PATCH] Remove prometheus metrics endpoint (#831) --- .../Configuration/MetricLabels.cs | 21 ------------------ .../src/TeachingRecordSystem.Api/Program.cs | 22 +------------------ .../TeachingRecordSystem.Api.csproj | 7 ------ terraform/aks/app.tf | 1 - 4 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Configuration/MetricLabels.cs diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Configuration/MetricLabels.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Configuration/MetricLabels.cs deleted file mode 100644 index 1d6731d5f..000000000 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Configuration/MetricLabels.cs +++ /dev/null @@ -1,21 +0,0 @@ -#nullable disable -using Prometheus; - -namespace TeachingRecordSystem.Api.Infrastructure.Configuration; - -public static class MetricLabels -{ - public static void ConfigureLabels(IConfiguration configuration) - { - if (configuration["CF_INSTANCE_INDEX"] != null) - { - Metrics.DefaultRegistry.SetStaticLabels(new() - { - { "app", configuration["VCAP_APPLICATION:application_name"] }, - { "organisation", configuration["VCAP_APPLICATION:organization_name"] }, - { "space", configuration["VCAP_APPLICATION:space_name"] }, - { "app_instance", configuration["CF_INSTANCE_INDEX"] } - }); - } - } -} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Program.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Program.cs index d54203b86..6306a9743 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/Program.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/Program.cs @@ -15,10 +15,8 @@ using Microsoft.Extensions.Azure; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.PowerPlatform.Dataverse.Client; -using Prometheus; using TeachingRecordSystem.Api.Endpoints.IdentityWebHooks; using TeachingRecordSystem.Api.Infrastructure.ApplicationModel; -using TeachingRecordSystem.Api.Infrastructure.Configuration; using TeachingRecordSystem.Api.Infrastructure.Filters; using TeachingRecordSystem.Api.Infrastructure.Json; using TeachingRecordSystem.Api.Infrastructure.Logging; @@ -56,15 +54,12 @@ public static void Main(string[] args) if (builder.Environment.IsProduction()) { - builder.Configuration - .AddJsonEnvironmentVariable("AppConfig") - .AddJsonEnvironmentVariable("VCAP_APPLICATION", configurationKeyPrefix: "VCAP_APPLICATION"); + builder.Configuration.AddJsonEnvironmentVariable("AppConfig"); } var platformEnvironmentName = configuration["PlatformEnvironment"]; builder.ConfigureLogging(platformEnvironmentName); - var platform = configuration.GetRequiredValue("Platform"); var pgConnectionString = configuration.GetRequiredValue("ConnectionStrings:DefaultConnection"); services.AddAuthentication(ApiKeyAuthenticationHandler.AuthenticationScheme) @@ -265,11 +260,6 @@ public static void Main(string[] args) services.AddRedis(env, configuration, healthCheckBuilder); services.AddRateLimiting(env, configuration); - if (platform == "PAAS") - { - MetricLabels.ConfigureLabels(builder.Configuration); - } - if (builder.Environment.IsProduction()) { builder.Services.Configure(options => @@ -295,11 +285,6 @@ public static void Main(string[] args) app.UseRouting(); - if (platform == "PAAS") - { - app.UseHttpMetrics(); - } - app.UseHealthChecks("/status"); app.UseAuthentication(); @@ -333,11 +318,6 @@ public static void Main(string[] args) app.MapWebHookEndpoints(); - if (platform == "PAAS") - { - app.MapMetrics(); - } - app.MapControllers(); if (configuration.GetValue("RecurringJobs:Enabled") && !builder.Environment.IsUnitTests() && !builder.Environment.IsEndToEndTests()) diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/TeachingRecordSystem.Api.csproj b/TeachingRecordSystem/src/TeachingRecordSystem.Api/TeachingRecordSystem.Api.csproj index 2265dde68..ac0e12b48 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/TeachingRecordSystem.Api.csproj +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/TeachingRecordSystem.Api.csproj @@ -23,7 +23,6 @@ - @@ -49,12 +48,6 @@ - - - PreserveNewest - - - diff --git a/terraform/aks/app.tf b/terraform/aks/app.tf index e94941414..3256e12b8 100644 --- a/terraform/aks/app.tf +++ b/terraform/aks/app.tf @@ -54,7 +54,6 @@ module "api_application_configuration" { secret_key_vault_short = "api" config_variables = { - Platform = "AKS" PlatformEnvironment = var.environment_name DistributedLockContainerName = azurerm_storage_container.locks.name DqtReporting__RunService = var.run_dqt_reporting_service