From 25c726b9a29d37f6110025b80e8d5e28a2e71760 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Mon, 14 Sep 2020 20:39:59 -0500 Subject: [PATCH] =?UTF-8?q?refactor(logging):=20=E2=99=BB=20mv=20AppInsigh?= =?UTF-8?q?ts=20ServerTelemetryChannelStoragePath=20to=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +++- docker-compose.yml | 10 ++++++---- .../ConfigurationExtensions.cs | 2 +- .../Options/GitOptions.cs | 2 +- .../Persistence/ConfigurationExtensions.cs | 6 +++--- .../ConfigurationExtensions.cs | 2 +- .../ConfigurationExtensions.cs | 16 +++++++++++++--- .../Options/ApplicationInsightsOptions.cs | 9 +++++++++ 8 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 services/SharedKernel/FilterLists.SharedKernel.Logging/Options/ApplicationInsightsOptions.cs diff --git a/.env b/.env index 89b3432d2..b9d3e692e 100644 --- a/.env +++ b/.env @@ -1,6 +1,8 @@ +APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH=application-insights + ARCHIVAL_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY= ARCHIVAL_REDIS_CONNECTION_STRING=archival-scheduling-db:6379 -ARCHIVAL_GIT_REPOSITORY_DIRECTORY=archives +ARCHIVAL_GIT_REPOSITORY_PATH=archives ARCHIVAL_GIT_USER_NAME=FilterLists Archival ARCHIVAL_GIT_USER_EMAIL=noreply@filterlists.com diff --git a/docker-compose.yml b/docker-compose.yml index 08e923a75..70f06aafa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,12 +21,13 @@ services: - archival-scheduling-db - directory-api volumes: - - archival-application-insights:/app/application-insights - - archival-archives:/app/${ARCHIVAL_GIT_REPOSITORY_DIRECTORY} + - archival-application-insights:/app/${APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH} + - archival-archives:/app/${ARCHIVAL_GIT_REPOSITORY_PATH} environment: + ApplicationInsights__ServerTelemetryChannelStoragePath: ${APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH} ApplicationInsights__InstrumentationKey: ${ARCHIVAL_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY} ConnectionStrings__SchedulingConnection: ${ARCHIVAL_REDIS_CONNECTION_STRING} - Git__RepositoryDirectory: ${ARCHIVAL_GIT_REPOSITORY_DIRECTORY} + Git__RepositoryPath: ${ARCHIVAL_GIT_REPOSITORY_PATH} Git__UserName: ${ARCHIVAL_GIT_USER_NAME} Git__UserEmail: ${ARCHIVAL_GIT_USER_EMAIL} @@ -48,8 +49,9 @@ services: depends_on: - directory-db volumes: - - directory-application-insights:/app/application-insights + - directory-application-insights:/app/${APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH} environment: + ApplicationInsights__ServerTelemetryChannelStoragePath: ${APPLICATION_INSIGHTS_SERVER_TELEMETRY_CHANNEL_STORAGE_PATH} ApplicationInsights__InstrumentationKey: ${DIRECTORY_APPLICATION_INSIGHTS_INSTRUMENTATION_KEY} ConnectionStrings__DirectoryConnection: ${DIRECTORY_CONNECTION_STRING} diff --git a/services/Archival/FilterLists.Archival.Infrastructure/ConfigurationExtensions.cs b/services/Archival/FilterLists.Archival.Infrastructure/ConfigurationExtensions.cs index f6b8034b0..0a5b68492 100644 --- a/services/Archival/FilterLists.Archival.Infrastructure/ConfigurationExtensions.cs +++ b/services/Archival/FilterLists.Archival.Infrastructure/ConfigurationExtensions.cs @@ -21,7 +21,7 @@ public static void AddInfrastructureServices(this IServiceCollection services, I { _ = configuration ?? throw new ArgumentNullException(nameof(configuration)); - services.AddSharedKernelLogging(); + services.AddSharedKernelLogging(configuration); services.AddSchedulingServices(configuration); services.AddApiClients(); services.AddPersistenceServices(configuration); diff --git a/services/Archival/FilterLists.Archival.Infrastructure/Options/GitOptions.cs b/services/Archival/FilterLists.Archival.Infrastructure/Options/GitOptions.cs index f26fee822..c891b486b 100644 --- a/services/Archival/FilterLists.Archival.Infrastructure/Options/GitOptions.cs +++ b/services/Archival/FilterLists.Archival.Infrastructure/Options/GitOptions.cs @@ -4,7 +4,7 @@ internal class GitOptions { public const string Key = "Git"; - public string RepositoryDirectory { get; set; } = null!; + public string RepositoryPath { get; set; } = null!; public string UserName { get; set; } = null!; public string UserEmail { get; set; } = null!; } diff --git a/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ConfigurationExtensions.cs b/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ConfigurationExtensions.cs index 6e4d71f8c..a0b1e023d 100644 --- a/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ConfigurationExtensions.cs +++ b/services/Archival/FilterLists.Archival.Infrastructure/Persistence/ConfigurationExtensions.cs @@ -15,12 +15,12 @@ public static void AddPersistenceServices(this IServiceCollection services, ICon var gitOptions = new GitOptions(); configuration.GetSection(GitOptions.Key).Bind(gitOptions); - if (!Repository.IsValid(gitOptions.RepositoryDirectory)) + if (!Repository.IsValid(gitOptions.RepositoryPath)) { - Repository.Init(gitOptions.RepositoryDirectory); + Repository.Init(gitOptions.RepositoryPath); } - return new Repository(gitOptions.RepositoryDirectory); + return new Repository(gitOptions.RepositoryPath); }); services.AddTransient(); } diff --git a/services/Directory/FilterLists.Directory.Infrastructure/ConfigurationExtensions.cs b/services/Directory/FilterLists.Directory.Infrastructure/ConfigurationExtensions.cs index ec305d203..33b9bfc26 100644 --- a/services/Directory/FilterLists.Directory.Infrastructure/ConfigurationExtensions.cs +++ b/services/Directory/FilterLists.Directory.Infrastructure/ConfigurationExtensions.cs @@ -17,7 +17,7 @@ public static IHostBuilder UseInfrastructure(this IHostBuilder hostBuilder) public static void AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration) { - services.AddSharedKernelLogging(); + services.AddSharedKernelLogging(configuration); services.AddDbContextPool(o => { o.UseNpgsql(configuration.GetConnectionString("DirectoryConnection"), diff --git a/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs b/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs index 78c21bbd4..76ab48a6e 100644 --- a/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs +++ b/services/SharedKernel/FilterLists.SharedKernel.Logging/ConfigurationExtensions.cs @@ -1,6 +1,9 @@ -using Microsoft.ApplicationInsights.Channel; +using System; +using FilterLists.SharedKernel.Logging.Options; +using Microsoft.ApplicationInsights.Channel; using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel; using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; @@ -14,9 +17,16 @@ public static IHostBuilder UseLogging(this IHostBuilder hostBuilder) return hostBuilder.UseSerilog(); } - public static void AddSharedKernelLogging(this IServiceCollection services) + public static void AddSharedKernelLogging(this IServiceCollection services, IConfiguration configuration) { - using var serverTelemetryChannel = new ServerTelemetryChannel {StorageFolder = "application-insights"}; + _ = configuration ?? throw new ArgumentNullException(nameof(configuration)); + + using var serverTelemetryChannel = new ServerTelemetryChannel + { + StorageFolder = configuration.GetSection(ApplicationInsightsOptions.Key) + .Get() + .ServerTelemetryChannelStoragePath + }; services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel); services.AddApplicationInsightsTelemetry(); } diff --git a/services/SharedKernel/FilterLists.SharedKernel.Logging/Options/ApplicationInsightsOptions.cs b/services/SharedKernel/FilterLists.SharedKernel.Logging/Options/ApplicationInsightsOptions.cs new file mode 100644 index 000000000..21a233811 --- /dev/null +++ b/services/SharedKernel/FilterLists.SharedKernel.Logging/Options/ApplicationInsightsOptions.cs @@ -0,0 +1,9 @@ +namespace FilterLists.SharedKernel.Logging.Options +{ + internal class ApplicationInsightsOptions + { + public const string Key = "ApplicationInsights"; + + public string ServerTelemetryChannelStoragePath { get; set; } = null!; + } +}