Skip to content

Commit 60d82ce

Browse files
committed
wip
1 parent 1b7510e commit 60d82ce

File tree

21 files changed

+401
-488
lines changed

21 files changed

+401
-488
lines changed

src/ServiceControl.AcceptanceTests.RavenDB/StartupModeTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ public async Task InitializeSettings()
2424
{
2525
var transportIntegration = new ConfigureEndpointLearningTransport();
2626

27-
settings = new Settings(
28-
transportType: transportIntegration.TypeName,
29-
forwardErrorMessages: false,
30-
errorRetentionPeriod: TimeSpan.FromDays(1),
31-
persisterType: "RavenDB")
27+
settings = new Settings
3228
{
29+
TransportType = transportIntegration.TypeName,
30+
ErrorRetentionPeriod = TimeSpan.FromDays(1),
31+
PersistenceType = "RavenDB",
3332
TransportConnectionString = transportIntegration.ConnectionString,
3433
AssemblyLoadContextResolver = static _ => AssemblyLoadContext.Default
3534
};
@@ -56,7 +55,7 @@ public async Task CanRunMaintenanceMode()
5655

5756
[Test]
5857
public async Task CanRunImportFailedMessagesMode()
59-
=> await new TestableImportFailedErrorsCommand().Execute(new HostArguments(Array.Empty<string>()), settings);
58+
=> await new TestableImportFailedErrorsCommand().Execute(new HostArguments([], settings), settings);
6059

6160
class TestableImportFailedErrorsCommand() : ImportFailedErrorsCommand()
6261
{

src/ServiceControl.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ async Task InitializeServiceControl(ScenarioContext context)
4949
{
5050
var logPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
5151
Directory.CreateDirectory(logPath);
52-
var loggingSettings = new LoggingSettings(Settings.SettingsRootNamespace, defaultLevel: LogLevel.Debug, logPath: logPath);
52+
var loggingSettings = new LoggingSettings
53+
{
54+
LogLevel = LogLevel.Debug,
55+
LogPath = logPath
56+
};
5357
LoggerUtil.ActiveLoggers = Loggers.Test;
5458

55-
var settings = new Settings(transportToUse.TypeName, persistenceToUse.PersistenceType, loggingSettings, forwardErrorMessages: false, errorRetentionPeriod: TimeSpan.FromDays(10))
59+
var settings = new Settings
5660
{
61+
TransportType = transportToUse.TypeName,
62+
PersistenceType = persistenceToUse.PersistenceType,
63+
LoggingSettings = loggingSettings,
64+
ErrorRetentionPeriod = TimeSpan.FromDays(10),
5765
InstanceName = instanceName,
5866
AllowMessageEditing = true,
5967
ForwardErrorMessages = false,
@@ -104,7 +112,7 @@ async Task InitializeServiceControl(ScenarioContext context)
104112
using (new DiagnosticTimer($"Creating infrastructure for {instanceName}"))
105113
{
106114
var setupCommand = new SetupCommand();
107-
await setupCommand.Execute(new HostArguments([]), settings);
115+
await setupCommand.Execute(new HostArguments([], settings), settings);
108116
}
109117

110118
var configuration = new EndpointConfiguration(instanceName);

src/ServiceControl.Audit.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ async Task InitializeServiceControl(ScenarioContext context)
4646
Directory.CreateDirectory(logPath);
4747

4848

49-
var loggingSettings = new LoggingSettings(new LoggingOptions
49+
var loggingSettings = new LoggingSettings
5050
{
51-
// TODO:
52-
}, defaultLevel: LogLevel.Debug, logPath: logPath);
51+
LogLevel = LogLevel.Debug,
52+
LogPath = logPath
53+
};
54+
5355
LoggerUtil.ActiveLoggers = Loggers.Test;
5456

5557
var configuration = new ConfigurationBuilder()

src/ServiceControl.Audit/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
var serviceControlAuditSection = bootstrapConfig.GetSection(Settings.SectionName);
2222

23-
var loggingSettings = new LoggingSettings(serviceControlAuditSection.Get<LoggingOptions>());
23+
var loggingSettings = LoggingSettingsFactory.Create(serviceControlAuditSection);
2424
LoggingConfigurator.ConfigureLogging(loggingSettings);
2525
logger = LoggerUtil.CreateStaticLogger(typeof(Program));
2626

src/ServiceControl.Infrastructure/LoggingSettings.cs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,61 @@ namespace ServiceControl.Infrastructure;
44
using System.Collections.Generic;
55
using System.IO;
66
using Microsoft.Extensions.Logging;
7+
using Microsoft.Extensions.Options;
78

8-
public class LoggingSettings
9+
public static class LoggingOptionsToSettings
910
{
10-
public LoggingSettings(
11-
LoggingOptions options,
12-
LogLevel defaultLevel = LogLevel.Information,
13-
string logPath = null
14-
)
11+
public static void Map(LoggingOptions src, LoggingSettings dst)
1512
{
1613
var activeLoggers = Loggers.None;
17-
if (options.LoggingProviders.Contains("NLog"))
14+
if (src.LoggingProviders.Contains("NLog"))
1815
{
1916
activeLoggers |= Loggers.NLog;
2017
}
21-
if (options.LoggingProviders.Contains("Seq"))
18+
19+
if (src.LoggingProviders.Contains("Seq"))
2220
{
2321
activeLoggers |= Loggers.Seq;
24-
if (!string.IsNullOrWhiteSpace(options.SeqAddress))
22+
if (!string.IsNullOrWhiteSpace(src.SeqAddress))
2523
{
26-
LoggerUtil.SeqAddress = options.SeqAddress;
24+
LoggerUtil.SeqAddress = src.SeqAddress;
2725
}
2826
}
29-
if (options.LoggingProviders.Contains("Otlp"))
27+
28+
if (src.LoggingProviders.Contains("Otlp"))
3029
{
3130
activeLoggers |= Loggers.Otlp;
3231
}
32+
3333
//this defaults to NLog because historically that was the default, and we don't want to break existing installs that don't have the config key to define loggingProviders
3434
LoggerUtil.ActiveLoggers = activeLoggers == Loggers.None ? Loggers.NLog : activeLoggers;
3535

36-
LogLevel = InitializeLogLevel(options.LogLevel, defaultLevel);
37-
LogPath = Environment.ExpandEnvironmentVariables(options.LogPath ?? DefaultLogLocation());
38-
}
39-
40-
public LogLevel LogLevel { get; }
36+
dst.LogLevel = InitializeLogLevel(src.LogLevel, dst.LogLevel);
37+
dst.LogPath = Environment.ExpandEnvironmentVariables(src.LogPath ?? DefaultLogLocation());
4138

42-
public string LogPath { get; }
43-
44-
static LogLevel InitializeLogLevel(string levelText, LogLevel defaultLevel)
45-
{
46-
if (string.IsNullOrWhiteSpace(levelText))
39+
static LogLevel InitializeLogLevel(string levelText, LogLevel defaultLevel)
4740
{
48-
return defaultLevel;
49-
}
41+
if (string.IsNullOrWhiteSpace(levelText))
42+
{
43+
return defaultLevel;
44+
}
5045

51-
return ParseLogLevel(levelText, defaultLevel);
46+
return ParseLogLevel(levelText, defaultLevel);
47+
}
5248
}
5349

5450
// SC installer always populates LogPath in app.config on installation/change/upgrade so this will only be used when
5551
// debugging or if the entry is removed manually. In those circumstances default to the folder containing the exe
5652
static string DefaultLogLocation() => Path.Combine(AppContext.BaseDirectory, ".logs");
5753

5854
// This is not a complete mapping of NLog levels, just the ones that are different.
59-
static readonly Dictionary<string, LogLevel> NLogAliases =
60-
new(StringComparer.OrdinalIgnoreCase)
61-
{
62-
["info"] = LogLevel.Information,
63-
["warn"] = LogLevel.Warning,
64-
["fatal"] = LogLevel.Critical,
65-
["off"] = LogLevel.None
66-
};
55+
static readonly Dictionary<string, LogLevel> NLogAliases = new(StringComparer.OrdinalIgnoreCase)
56+
{
57+
["info"] = LogLevel.Information,
58+
["warn"] = LogLevel.Warning,
59+
["fatal"] = LogLevel.Critical,
60+
["off"] = LogLevel.None
61+
};
6762

6863
static LogLevel ParseLogLevel(string value, LogLevel defaultLevel)
6964
{
@@ -83,10 +78,17 @@ static LogLevel ParseLogLevel(string value, LogLevel defaultLevel)
8378
}
8479
}
8580

81+
82+
public class LoggingSettings // TODO: Register
83+
{
84+
public LogLevel LogLevel { get; set; } = LogLevel.Information;
85+
public string LogPath { get; set; }
86+
}
87+
8688
public record LoggingOptions
8789
{
8890
public string LogLevel { get; set; }
8991
public string LogPath { get; set; }
9092
public string LoggingProviders { get; set; }
91-
public string SeqAddress {get; set;}
93+
public string SeqAddress { get; set; }
9294
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace ServiceControl.Infrastructure;
2+
3+
using Microsoft.Extensions.Configuration;
4+
5+
public static class LoggingSettingsFactory
6+
{
7+
public static LoggingSettings Create(IConfiguration configuration)
8+
{
9+
var opt = configuration.Get<LoggingOptions>();
10+
var dst = new LoggingSettings();
11+
LoggingOptionsToSettings.Map(opt, dst);
12+
return dst;
13+
}
14+
}

src/ServiceControl.Monitoring/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
var section = bootstrapConfig.GetSection(Settings.SectionName);
2020

21-
var loggingSettings = new LoggingSettings(section.Get<LoggingOptions>());
21+
var loggingSettings = LoggingSettingsFactory.Create(bootstrapConfig);
2222
LoggingConfigurator.ConfigureLogging(loggingSettings);
2323
logger = LoggerUtil.CreateStaticLogger<Program>();
2424

src/ServiceControl.Persistence.Tests.RavenDB/PersistenceTestsContext.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task Setup(IHostApplicationBuilder hostBuilder)
2626

2727
embeddedServer = await SharedEmbeddedServer.GetInstance();
2828

29-
PersistenceSettings = new RavenPersisterSettings
29+
var settings = new RavenPersisterSettings
3030
{
3131
AuditRetentionPeriod = retentionPeriod,
3232
ErrorRetentionPeriod = retentionPeriod,
@@ -36,7 +36,9 @@ public async Task Setup(IHostApplicationBuilder hostBuilder)
3636
ThroughputDatabaseName = $"{databaseName}-throughput",
3737
};
3838

39-
var persistence = new RavenPersistenceConfiguration().Create(PersistenceSettings);
39+
PersistenceSettings = settings;
40+
41+
var persistence = new RavenPersistence(settings);
4042

4143
persistence.AddPersistence(hostBuilder.Services);
4244
persistence.AddInstaller(hostBuilder.Services);

src/ServiceControl.UnitTests/Infrastructure/Settings/SettingsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class SettingsTests
1212
public void Should_read_RemoteInstances_from_serialized_json()
1313
{
1414
var configValue = """[{"api_uri":"http://instance1"},{"api_uri":"http://instance2"}]""";
15-
var remoteInstances = Settings.ParseRemoteInstances(configValue);
15+
var remoteInstances = SettingsConfiguration.ParseRemoteInstances(configValue);
1616

1717
Assert.That(
1818
new[] { new RemoteInstanceSetting("http://instance1"), new RemoteInstanceSetting("http://instance2") },

src/ServiceControl/Hosting/Commands/ImportFailedErrorsCommand.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.Extensions.DependencyInjection;
88
using Microsoft.Extensions.Hosting;
99
using Microsoft.Extensions.Logging;
10+
using Microsoft.Extensions.Options;
1011
using NServiceBus;
1112
using Operations;
1213
using Particular.ServiceControl;
@@ -16,11 +17,19 @@
1617

1718
class ImportFailedErrorsCommand : AbstractCommand
1819
{
20+
public class ForceDisableIngestion : IPostConfigureOptions<Settings> // TODO: Register
21+
{
22+
public void PostConfigure(string name, Settings options)
23+
{
24+
options.IngestErrorMessages = false;
25+
options.RunRetryProcessor = false;
26+
options.DisableHealthChecks = true;
27+
}
28+
}
29+
1930
public override async Task Execute(HostArguments args, Settings settings)
2031
{
21-
settings.IngestErrorMessages = false;
22-
settings.RunRetryProcessor = false;
23-
settings.DisableHealthChecks = true;
32+
new ForceDisableIngestion().PostConfigure(null, settings); // TODO
2433

2534
EndpointConfiguration endpointConfiguration = CreateEndpointConfiguration(settings);
2635

0 commit comments

Comments
 (0)