refactor(logging): ♻ mv AppInsights ServerTelemetryChannelStoragePath to config

This commit is contained in:
Collin M. Barrett 2020-09-14 20:39:59 -05:00
parent a80da4772b
commit 25c726b9a2
8 changed files with 37 additions and 14 deletions

4
.env
View file

@ -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

View file

@ -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}

View file

@ -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);

View file

@ -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!;
}

View file

@ -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<IArchiveFiles, GitFileArchiver>();
}

View file

@ -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<QueryDbContext>(o =>
{
o.UseNpgsql(configuration.GetConnectionString("DirectoryConnection"),

View file

@ -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<ApplicationInsightsOptions>()
.ServerTelemetryChannelStoragePath
};
services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel);
services.AddApplicationInsightsTelemetry();
}

View file

@ -0,0 +1,9 @@
namespace FilterLists.SharedKernel.Logging.Options
{
internal class ApplicationInsightsOptions
{
public const string Key = "ApplicationInsights";
public string ServerTelemetryChannelStoragePath { get; set; } = null!;
}
}