Skip to content

Commit d228153

Browse files
committed
wip
1 parent f49dcf6 commit d228153

File tree

17 files changed

+346
-93
lines changed

17 files changed

+346
-93
lines changed

src/Particular.LicensingComponent/AuditThroughput/AuditThroughputCollectorHostedService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public class AuditThroughputCollectorHostedService(
1313
ILicensingDataStore dataStore,
1414
IAuditQuery auditQuery,
1515
TimeProvider timeProvider,
16-
IBrokerThroughputQuery? brokerThroughputQuery = null) : BackgroundService
16+
PlatformEndpointHelper platformEndpointHelper,
17+
IBrokerThroughputQuery? brokerThroughputQuery = null
18+
) : BackgroundService
1719
{
1820
public TimeSpan DelayStart { get; set; } = TimeSpan.FromSeconds(40);
1921
public static List<string> AuditQueues { get; set; } = [];
@@ -98,7 +100,7 @@ Endpoint ConvertToEndpoint(ServiceControlEndpoint scEndpoint)
98100
EndpointIndicators = [EndpointIndicator.KnownEndpoint.ToString()]
99101
};
100102

101-
if (PlatformEndpointHelper.IsPlatformEndpoint(scEndpoint.Name, throughputSettings))
103+
if (platformEndpointHelper.IsPlatformEndpoint(scEndpoint.Name, throughputSettings))
102104
{
103105
endpoint.EndpointIndicators.Append(EndpointIndicator.PlatformEndpoint.ToString());
104106
}

src/Particular.LicensingComponent/BrokerThroughput/BrokerThroughputCollectorHostedService.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@ namespace Particular.LicensingComponent.BrokerThroughput;
22

33
using System.Collections.ObjectModel;
44
using Contracts;
5+
using Microsoft.Extensions.Configuration;
56
using Microsoft.Extensions.Hosting;
67
using Microsoft.Extensions.Logging;
78
using Persistence;
89
using ServiceControl.Configuration;
910
using ServiceControl.Transports.BrokerThroughput;
1011
using Shared;
1112

13+
14+
1215
public class BrokerThroughputCollectorHostedService(
1316
ILogger<BrokerThroughputCollectorHostedService> logger,
1417
IBrokerThroughputQuery brokerThroughputQuery,
1518
ThroughputSettings throughputSettings,
1619
ILicensingDataStore dataStore,
17-
TimeProvider timeProvider)
18-
: BackgroundService
20+
TimeProvider timeProvider,
21+
PlatformEndpointHelper platformEndpointHelper,
22+
IConfiguration configuration
23+
): BackgroundService
1924
{
2025
public TimeSpan DelayStart { get; set; } = TimeSpan.FromSeconds(40);
2126

2227
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2328
{
24-
static ReadOnlyDictionary<string, string> LoadBrokerSettingValues(IEnumerable<KeyDescriptionPair> brokerKeys)
25-
=> new(brokerKeys.Select(pair => KeyValuePair.Create(pair.Key, SettingsReader.Read<string>(ThroughputSettings.SettingsNamespace, pair.Key)))
26-
.Where(pair => !string.IsNullOrEmpty(pair.Value)).ToDictionary());
27-
2829
brokerThroughputQuery.Initialize(LoadBrokerSettingValues(brokerThroughputQuery.Settings));
2930

3031
if (brokerThroughputQuery.HasInitialisationErrors(out var errorMessage))
@@ -59,6 +60,15 @@ static ReadOnlyDictionary<string, string> LoadBrokerSettingValues(IEnumerable<Ke
5960
}
6061
}
6162

63+
ReadOnlyDictionary<string, string> LoadBrokerSettingValues(IEnumerable<KeyDescriptionPair> brokerKeys)
64+
{
65+
var section = configuration.GetSection(ThroughputSettings.SettingsNamespace.Root);
66+
67+
return new ReadOnlyDictionary<string, string>(brokerKeys.Select(pair => KeyValuePair.Create(pair.Key, section.GetValue<string>(pair.Key)))
68+
.Where(pair => !string.IsNullOrEmpty(pair.Value))
69+
.ToDictionary());
70+
}
71+
6272
async Task GatherThroughput(CancellationToken stoppingToken)
6373
{
6474
logger.LogInformation("Gathering throughput from broker");
@@ -68,7 +78,7 @@ async Task GatherThroughput(CancellationToken stoppingToken)
6878

6979
await foreach (var queueName in brokerThroughputQuery.GetQueueNames(stoppingToken))
7080
{
71-
if (PlatformEndpointHelper.IsPlatformEndpoint(queueName.SanitizedName, throughputSettings))
81+
if (platformEndpointHelper.IsPlatformEndpoint(queueName.SanitizedName, throughputSettings))
7282
{
7383
continue;
7484
}

src/Particular.LicensingComponent/MonitoringThroughput/MonitoringService.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
using ServiceControl.Transports.BrokerThroughput;
99
using Shared;
1010

11-
public class MonitoringService(ILicensingDataStore dataStore, IBrokerThroughputQuery? brokerThroughputQuery = null)
11+
public class MonitoringService(
12+
ILicensingDataStore dataStore,
13+
ServiceControlSettings serviceControlSettings,
14+
IBrokerThroughputQuery? brokerThroughputQuery = null
15+
)
1216
{
1317
public async Task RecordMonitoringThroughput(byte[] throughputMessage, CancellationToken cancellationToken)
1418
{
@@ -61,7 +65,7 @@ public async Task<ConnectionSettingsTestResult> TestMonitoringConnection(Cancell
6165
diagnostics.AppendLine("No throughput from Monitoring recorded in the last 30 days");
6266
connectionTestResult.ConnectionSuccessful = false;
6367
}
64-
diagnostics.AppendLine($"Listening on queue {ServiceControlSettings.ServiceControlThroughputDataQueue}");
68+
diagnostics.AppendLine($"Listening on queue {serviceControlSettings.ServiceControlThroughputDataQueue}");
6569

6670
connectionTestResult.Diagnostics = diagnostics.ToString();
6771

src/Particular.LicensingComponent/MonitoringThroughput/MonitoringThroughputHostedService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ namespace Particular.LicensingComponent.MonitoringThroughput;
66
using ServiceControl.Transports;
77
using Shared;
88

9-
class MonitoringThroughputHostedService(ITransportCustomization transportCustomization, TransportSettings transportSettings, ILogger<MonitoringThroughputHostedService> logger, MonitoringService monitoringService) : IHostedService
9+
class MonitoringThroughputHostedService(
10+
ITransportCustomization transportCustomization,
11+
TransportSettings transportSettings,
12+
ILogger<MonitoringThroughputHostedService> logger,
13+
MonitoringService monitoringService ,
14+
ServiceControlSettings serviceControlSettings
15+
) : IHostedService
1016
{
1117
TransportInfrastructure? transportInfrastructure;
1218

@@ -26,8 +32,8 @@ public async Task StartAsync(CancellationToken cancellationToken)
2632
{
2733
logger.LogInformation("Starting {ServiceName}", nameof(MonitoringThroughputHostedService));
2834

29-
transportInfrastructure = await transportCustomization.CreateTransportInfrastructure(ServiceControlSettings.ServiceControlThroughputDataQueue, transportSettings, Handle, (_, __) => Task.FromResult(ErrorHandleResult.Handled), (_, __) => Task.CompletedTask);
30-
await transportInfrastructure.Receivers[ServiceControlSettings.ServiceControlThroughputDataQueue].StartReceive(cancellationToken);
35+
transportInfrastructure = await transportCustomization.CreateTransportInfrastructure(serviceControlSettings.ServiceControlThroughputDataQueue, transportSettings, Handle, (_, __) => Task.FromResult(ErrorHandleResult.Handled), (_, __) => Task.CompletedTask);
36+
await transportInfrastructure.Receivers[serviceControlSettings.ServiceControlThroughputDataQueue].StartReceive(cancellationToken);
3137
}
3238

3339
public async Task StopAsync(CancellationToken cancellationToken)
@@ -36,7 +42,7 @@ public async Task StopAsync(CancellationToken cancellationToken)
3642

3743
if (transportInfrastructure != null)
3844
{
39-
await transportInfrastructure.Receivers[ServiceControlSettings.ServiceControlThroughputDataQueue].StopReceive(cancellationToken);
45+
await transportInfrastructure.Receivers[serviceControlSettings.ServiceControlThroughputDataQueue].StopReceive(cancellationToken);
4046
await transportInfrastructure.Shutdown(cancellationToken);
4147
}
4248
}

src/Particular.LicensingComponent/Shared/PlatformEndpointHelper.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
using Contracts;
44
using Particular.LicensingComponent.AuditThroughput;
55

6-
public static class PlatformEndpointHelper
6+
public class PlatformEndpointHelper(ServiceControlSettings serviceControlSettings)
77
{
8-
public static bool IsPlatformEndpoint(string endpointName, ThroughputSettings throughputSettings)
9-
{
10-
return endpointName.Equals(throughputSettings.ErrorQueue, StringComparison.OrdinalIgnoreCase)
11-
|| endpointName.Equals(throughputSettings.ServiceControlQueue, StringComparison.OrdinalIgnoreCase)
12-
|| endpointName.EndsWith(".Timeouts", StringComparison.OrdinalIgnoreCase)
13-
|| endpointName.EndsWith(".TimeoutsDispatcher", StringComparison.OrdinalIgnoreCase)
14-
|| endpointName.StartsWith($"{throughputSettings.ServiceControlQueue}.", StringComparison.OrdinalIgnoreCase)
15-
|| endpointName.Equals(ServiceControlSettings.ServiceControlThroughputDataQueue, StringComparison.OrdinalIgnoreCase)
16-
|| endpointName.StartsWith("Particular.Monitoring", StringComparison.OrdinalIgnoreCase)
17-
|| AuditThroughputCollectorHostedService.AuditQueues.Any(a => endpointName.Equals(a, StringComparison.OrdinalIgnoreCase));
18-
}
8+
public bool IsPlatformEndpoint(string endpointName, ThroughputSettings throughputSettings) =>
9+
endpointName.Equals(throughputSettings.ErrorQueue, StringComparison.OrdinalIgnoreCase)
10+
|| endpointName.Equals(throughputSettings.ServiceControlQueue, StringComparison.OrdinalIgnoreCase)
11+
|| endpointName.EndsWith(".Timeouts", StringComparison.OrdinalIgnoreCase)
12+
|| endpointName.EndsWith(".TimeoutsDispatcher", StringComparison.OrdinalIgnoreCase)
13+
|| endpointName.StartsWith($"{throughputSettings.ServiceControlQueue}.", StringComparison.OrdinalIgnoreCase)
14+
|| endpointName.Equals(serviceControlSettings.ServiceControlThroughputDataQueue, StringComparison.OrdinalIgnoreCase)
15+
|| endpointName.StartsWith("Particular.Monitoring", StringComparison.OrdinalIgnoreCase)
16+
|| AuditThroughputCollectorHostedService.AuditQueues.Any(a => endpointName.Equals(a, StringComparison.OrdinalIgnoreCase));
1917
}
2018
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
namespace Particular.LicensingComponent.Shared
22
{
3+
using Microsoft.Extensions.Configuration;
34
using Particular.LicensingComponent.Contracts;
4-
using ServiceControl.Configuration;
55

6-
public static class ServiceControlSettings
6+
public class ServiceControlSettings (IConfiguration configuration)
77
{
8-
public static readonly string MessageTransport = "ServiceControl";
9-
10-
public static string ServiceControlThroughputDataQueueSetting = "ServiceControlThroughputDataQueue";
11-
public static string ServiceControlThroughputDataQueue = SettingsReader.Read(ThroughputSettings.SettingsNamespace, ServiceControlThroughputDataQueueSetting, "ServiceControl.ThroughputData");
8+
public const string MessageTransport = "ServiceControl";
9+
public const string ServiceControlThroughputDataQueueSetting = "ServiceControlThroughputDataQueue";
10+
public string ServiceControlThroughputDataQueue => configuration
11+
.GetSection(ThroughputSettings.SettingsNamespace.Root)
12+
.GetValue<string>(ServiceControlThroughputDataQueueSetting, "ServiceControl.ThroughputData");
1213

1314
static string MonitoringQueue = $"Monitoring/{ServiceControlThroughputDataQueueSetting}";
14-
static string MonitoringQueueDescription = $"Queue to send monitoring throughput data to for processing by ServiceControl. This setting only needs to be specified if the Monitoring instance is not hosted in the same machine as the Error instance is running on.";
15+
static string MonitoringQueueDescription = "Queue to send monitoring throughput data to for processing by ServiceControl. This setting only needs to be specified if the Monitoring instance is not hosted in the same machine as the Error instance is running on.";
1516

1617
public static List<ThroughputConnectionSetting> GetServiceControlConnectionSettings()
1718
{
@@ -23,4 +24,4 @@ public static List<ThroughputConnectionSetting> GetMonitoringConnectionSettings(
2324
return [new ThroughputConnectionSetting(MonitoringQueue, MonitoringQueueDescription)];
2425
}
2526
}
26-
}
27+
}

src/ServiceControl.Audit/HostApplicationBuilderExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public static void AddServiceControlAudit(this IHostApplicationBuilder builder,
3333
Settings settings,
3434
EndpointConfiguration configuration)
3535
{
36+
var section = builder.Configuration.GetSection(Settings.SectionName);
37+
3638
var persistenceConfiguration = PersistenceConfigurationFactory.LoadPersistenceConfiguration(settings);
37-
var persistenceSettings = persistenceConfiguration.BuildPersistenceSettings(settings);
39+
//var persistenceSettings = persistenceConfiguration.BuildPersistenceSettings(settings);
3840

3941
RecordStartup(settings, configuration, persistenceConfiguration);
4042

src/ServiceControl.Audit/Infrastructure/Hosting/HostArguments.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace ServiceControl.Audit.Infrastructure.Hosting
99

1010
class HostArguments
1111
{
12-
public HostArguments(string[] args)
12+
public HostArguments(string[] args, Settings settings)
1313
{
14-
if (SettingsReader.Read<bool>(Settings.SettingsRootNamespace, "MaintenanceMode"))
14+
if (settings.MaintenanceMode)
1515
{
1616
args = [.. args, "-m"];
1717
}

0 commit comments

Comments
 (0)