Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/Particular.LicensingComponent/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,3 @@ dotnet_diagnostic.IDE0010.severity = suggestion

csharp_style_var_elsewhere = true:error
csharp_style_var_for_built_in_types = true:error

# Cancellation analyzer debt. These fire because Particular.Analyzers is no longer pinned to 0.9.0.
# They are scheduled work, not accepted exceptions: remove a line once this project has no
# violations of that rule left, and never add a rule back to this list.
dotnet_diagnostic.PS0003.severity = none
dotnet_diagnostic.PS0008.severity = none
dotnet_diagnostic.PS0017.severity = none
dotnet_diagnostic.PS0019.severity = none
12 changes: 8 additions & 4 deletions src/Particular.LicensingComponent/AuditThroughput/AuditQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AuditQuery(ILogger<AuditQuery> logger, IEndpointsApi endpointsApi,
r.SemanticVersion >= MinAuditCountsVersion &&
r.Retention >= TimeSpan.FromDays(2);

public async Task<IEnumerable<ServiceControlEndpoint>> GetKnownEndpoints(CancellationToken cancellationToken)
public async Task<IEnumerable<ServiceControlEndpoint>> GetKnownEndpoints(CancellationToken cancellationToken = default)
{
var endpoints = await endpointsApi.GetEndpoints(cancellationToken);

Expand All @@ -36,9 +36,9 @@ public async Task<IEnumerable<ServiceControlEndpoint>> GetKnownEndpoints(Cancell
return scEndpoints ?? [];
}

public async Task<IEnumerable<AuditCount>> GetAuditCountForEndpoint(string endpointUrlName, CancellationToken cancellationToken) => (await auditCountApi.GetEndpointAuditCounts(endpointUrlName, cancellationToken)).Select(s => new AuditCount { Count = s.Count, UtcDate = DateOnly.FromDateTime(s.UtcDate) });
public async Task<IEnumerable<AuditCount>> GetAuditCountForEndpoint(string endpointUrlName, CancellationToken cancellationToken = default) => (await auditCountApi.GetEndpointAuditCounts(endpointUrlName, cancellationToken)).Select(s => new AuditCount { Count = s.Count, UtcDate = DateOnly.FromDateTime(s.UtcDate) });

public async Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationToken cancellationToken)
public async Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationToken cancellationToken = default)
{
try
{
Expand Down Expand Up @@ -101,14 +101,18 @@ public async Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationT

return remotesInfo;
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to get Audit Remotes");
return [];
}
}

public async Task<ConnectionSettingsTestResult> TestAuditConnection(CancellationToken cancellationToken)
public async Task<ConnectionSettingsTestResult> TestAuditConnection(CancellationToken cancellationToken = default)
{
var connectionTestResult = new ConnectionSettingsTestResult { ConnectionSuccessful = true };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AuditThroughputCollectorHostedService(
public TimeSpan DelayStart { get; set; } = TimeSpan.FromSeconds(40);
public static List<string> AuditQueues { get; set; } = [];

protected override async Task ExecuteAsync(CancellationToken cancellationToken)
protected override async Task ExecuteAsync(CancellationToken cancellationToken = default)
{
logger.LogInformation("Starting {ServiceName}", nameof(AuditThroughputCollectorHostedService));

Expand All @@ -34,7 +34,11 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
await GatherThroughput(cancellationToken);
}
catch (Exception ex) when (ex is not OperationCanceledException)
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to gather throughput from audit");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public interface IAuditQuery
SemanticVersion MinAuditCountsVersion { get; }
Func<RemoteInstanceInformation, bool> ValidRemoteInstances { get; }

Task<IEnumerable<ServiceControlEndpoint>> GetKnownEndpoints(CancellationToken cancellationToken);
Task<IEnumerable<ServiceControlEndpoint>> GetKnownEndpoints(CancellationToken cancellationToken = default);

Task<IEnumerable<AuditCount>> GetAuditCountForEndpoint(string endpointUrlName, CancellationToken cancellationToken);
Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationToken cancellationToken);
Task<ConnectionSettingsTestResult> TestAuditConnection(CancellationToken cancellationToken);
Task<IEnumerable<AuditCount>> GetAuditCountForEndpoint(string endpointUrlName, CancellationToken cancellationToken = default);
Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationToken cancellationToken = default);
Task<ConnectionSettingsTestResult> TestAuditConnection(CancellationToken cancellationToken = default);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BrokerThroughputCollectorHostedService(
{
public TimeSpan DelayStart { get; set; } = TimeSpan.FromSeconds(40);

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
protected override async Task ExecuteAsync(CancellationToken cancellationToken = default)
{
static ReadOnlyDictionary<string, string> LoadBrokerSettingValues(IEnumerable<KeyDescriptionPair> brokerKeys)
=> new(brokerKeys.Select(pair => KeyValuePair.Create(pair.Key, SettingsReader.Read<string>(ThroughputSettings.SettingsNamespace, pair.Key)))
Expand All @@ -37,36 +37,40 @@ static ReadOnlyDictionary<string, string> LoadBrokerSettingValues(IEnumerable<Ke

try
{
await Task.Delay(DelayStart, stoppingToken);
await Task.Delay(DelayStart, cancellationToken);

using PeriodicTimer timer = new(TimeSpan.FromDays(1), timeProvider);

do
{
try
{
await GatherThroughput(stoppingToken);
await GatherThroughput(cancellationToken);
}
catch (Exception ex) when (ex is not OperationCanceledException)
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to gather throughput from broker");
}
} while (await timer.WaitForNextTickAsync(stoppingToken));
} while (await timer.WaitForNextTickAsync(cancellationToken));
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
logger.LogInformation("Stopping {ServiceName}", nameof(BrokerThroughputCollectorHostedService));
}
}

async Task GatherThroughput(CancellationToken stoppingToken)
async Task GatherThroughput(CancellationToken cancellationToken)
{
logger.LogInformation("Gathering throughput from broker");

var waitingTasks = new List<Task>();
var postfixGenerator = new PostfixGenerator();

await foreach (var queueName in brokerThroughputQuery.GetQueueNames(stoppingToken))
await foreach (var queueName in brokerThroughputQuery.GetQueueNames(cancellationToken))
{
if (PlatformEndpointHelper.IsPlatformEndpoint(queueName.SanitizedName, throughputSettings))
{
Expand All @@ -78,13 +82,13 @@ async Task GatherThroughput(CancellationToken stoppingToken)
}

await Task.WhenAll(waitingTasks);
await dataStore.SaveBrokerMetadata(new BrokerMetadata(brokerThroughputQuery.ScopeType, brokerThroughputQuery.Data), stoppingToken);
await dataStore.SaveBrokerMetadata(new BrokerMetadata(brokerThroughputQuery.ScopeType, brokerThroughputQuery.Data), cancellationToken);
return;

async Task Exec(IBrokerQueue queueName, string postfix)
{
var endpointId = new EndpointIdentifier(queueName.QueueName, ThroughputSource.Broker);
var endpoint = await dataStore.GetEndpoint(endpointId, stoppingToken);
var endpoint = await dataStore.GetEndpoint(endpointId, cancellationToken);

if (endpoint == null)
{
Expand All @@ -95,14 +99,18 @@ async Task Exec(IBrokerQueue queueName, string postfix)
EndpointIndicators = [.. queueName.EndpointIndicators]
};

await dataStore.SaveEndpoint(endpoint, stoppingToken);
await dataStore.SaveEndpoint(endpoint, cancellationToken);
}

await foreach (var queueThroughput in brokerThroughputQuery.GetThroughputPerDay(queueName, endpoint.LastCollectedDate.AddDays(1), stoppingToken))
await foreach (var queueThroughput in brokerThroughputQuery.GetThroughputPerDay(queueName, endpoint.LastCollectedDate.AddDays(1), cancellationToken))
{
try
{
await dataStore.RecordEndpointThroughput(queueName.QueueName, ThroughputSource.Broker, queueThroughput.DateUTC, queueThroughput.TotalThroughput, stoppingToken);
await dataStore.RecordEndpointThroughput(queueName.QueueName, ThroughputSource.Broker, queueThroughput.DateUTC, queueThroughput.TotalThroughput, cancellationToken);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (Exception e)
{
Expand Down
16 changes: 8 additions & 8 deletions src/Particular.LicensingComponent/IThroughputCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

public interface IThroughputCollector
{
Task<List<EndpointThroughputSummary>> GetThroughputSummary(CancellationToken cancellationToken);
Task UpdateUserIndicatorsOnEndpoints(List<UpdateUserIndicator> userIndicatorUpdates, CancellationToken cancellationToken);
Task<ThroughputConnectionSettings> GetThroughputConnectionSettingsInformation(CancellationToken cancellationToken);
Task<ConnectionTestResults> TestConnectionSettings(CancellationToken cancellationToken);
Task<SignedReport> GenerateThroughputReport(string spVersion, DateTime? reportEndDate, CancellationToken cancellationToken);
Task<ReportGenerationState> GetReportGenerationState(CancellationToken cancellationToken);
Task<List<string>> GetReportMasks(CancellationToken cancellationToken);
Task UpdateReportMasks(List<string> reportMaskUpdates, CancellationToken cancellationToken);
Task<List<EndpointThroughputSummary>> GetThroughputSummary(CancellationToken cancellationToken = default);
Task UpdateUserIndicatorsOnEndpoints(List<UpdateUserIndicator> userIndicatorUpdates, CancellationToken cancellationToken = default);
Task<ThroughputConnectionSettings> GetThroughputConnectionSettingsInformation(CancellationToken cancellationToken = default);
Task<ConnectionTestResults> TestConnectionSettings(CancellationToken cancellationToken = default);
Task<SignedReport> GenerateThroughputReport(string spVersion, DateTime? reportEndDate, CancellationToken cancellationToken = default);
Task<ReportGenerationState> GetReportGenerationState(CancellationToken cancellationToken = default);
Task<List<string>> GetReportMasks(CancellationToken cancellationToken = default);
Task UpdateReportMasks(List<string> reportMaskUpdates, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class MonitoringService(ILicensingDataStore dataStore, IBrokerThroughputQuery? brokerThroughputQuery = null)
{
public async Task RecordMonitoringThroughput(byte[] throughputMessage, CancellationToken cancellationToken)
public async Task RecordMonitoringThroughput(byte[] throughputMessage, CancellationToken cancellationToken = default)
{
RecordEndpointThroughputData? message;
using (Stream stream = new MemoryStream(throughputMessage))
Expand Down Expand Up @@ -45,7 +45,7 @@ public async Task RecordMonitoringThroughput(byte[] throughputMessage, Cancellat
}
}

public async Task<ConnectionSettingsTestResult> TestMonitoringConnection(CancellationToken cancellationToken)
public async Task<ConnectionSettingsTestResult> TestMonitoringConnection(CancellationToken cancellationToken = default)
{
//NOTE can't actually test the monitoring connection apart from seeing if there has been any throughput recorded from Monitoring

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@ async Task Handle(MessageContext message, CancellationToken cancellationToken)
{
await monitoringService.RecordMonitoringThroughput(message.Body.ToArray(), cancellationToken);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (Exception ex)
{
logger.LogError(ex, "Error receiving throughput data from Monitoring");
}
}

public async Task StartAsync(CancellationToken cancellationToken)
public async Task StartAsync(CancellationToken cancellationToken = default)
{
logger.LogInformation("Starting {ServiceName}", nameof(MonitoringThroughputHostedService));

transportInfrastructure = await transportCustomization.CreateTransportInfrastructure(ServiceControlSettings.ServiceControlThroughputDataQueue, transportSettings, Handle, (_, __) => Task.FromResult(ErrorHandleResult.Handled), (_, __, ___) => Task.CompletedTask, cancellationToken: cancellationToken);
await transportInfrastructure.Receivers[ServiceControlSettings.ServiceControlThroughputDataQueue].StartReceive(cancellationToken);
}

public async Task StopAsync(CancellationToken cancellationToken)
public async Task StopAsync(CancellationToken cancellationToken = default)
{
logger.LogInformation("Stopping {ServiceName}", nameof(MonitoringThroughputHostedService));

Expand Down
16 changes: 8 additions & 8 deletions src/Particular.LicensingComponent/ThroughputCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class ThroughputCollector(ILicensingDataStore dataStore, ThroughputSettings throughputSettings, IAuditQuery auditQuery, MonitoringService monitoringService, IEnumerable<IEnvironmentDataProvider> environmentDataProviders, IBrokerThroughputQuery? throughputQuery = null)
: IThroughputCollector
{
public async Task<ThroughputConnectionSettings> GetThroughputConnectionSettingsInformation(CancellationToken cancellationToken)
public async Task<ThroughputConnectionSettings> GetThroughputConnectionSettingsInformation(CancellationToken cancellationToken = default)
{
var throughputConnectionSettings = new ThroughputConnectionSettings
{
Expand All @@ -27,7 +27,7 @@ public async Task<ThroughputConnectionSettings> GetThroughputConnectionSettingsI
return await Task.FromResult(throughputConnectionSettings);
}

public async Task<ConnectionTestResults> TestConnectionSettings(CancellationToken cancellationToken)
public async Task<ConnectionTestResults> TestConnectionSettings(CancellationToken cancellationToken = default)
{
var tasks = new List<Task>();
var brokerTask = Task.FromResult(new ConnectionSettingsTestResult { ConnectionSuccessful = false, ConnectionErrorMessages = [] });
Expand Down Expand Up @@ -55,13 +55,13 @@ public async Task<ConnectionTestResults> TestConnectionSettings(CancellationToke
return await Task.FromResult(connectionTestResults);
}

public async Task UpdateUserIndicatorsOnEndpoints(List<UpdateUserIndicator> userIndicatorUpdates, CancellationToken cancellationToken) =>
public async Task UpdateUserIndicatorsOnEndpoints(List<UpdateUserIndicator> userIndicatorUpdates, CancellationToken cancellationToken = default) =>
await dataStore.UpdateUserIndicatorOnEndpoints(userIndicatorUpdates, cancellationToken);

public async Task<List<string>> GetReportMasks(CancellationToken cancellationToken) => await dataStore.GetReportMasks(cancellationToken);
public async Task UpdateReportMasks(List<string> reportMaskUpdates, CancellationToken cancellationToken) => await dataStore.SaveReportMasks(reportMaskUpdates, cancellationToken);
public async Task<List<string>> GetReportMasks(CancellationToken cancellationToken = default) => await dataStore.GetReportMasks(cancellationToken);
public async Task UpdateReportMasks(List<string> reportMaskUpdates, CancellationToken cancellationToken = default) => await dataStore.SaveReportMasks(reportMaskUpdates, cancellationToken);

public async Task<List<EndpointThroughputSummary>> GetThroughputSummary(CancellationToken cancellationToken)
public async Task<List<EndpointThroughputSummary>> GetThroughputSummary(CancellationToken cancellationToken = default)
{
var endpointSummaries = new List<EndpointThroughputSummary>();

Expand All @@ -86,7 +86,7 @@ public async Task<List<EndpointThroughputSummary>> GetThroughputSummary(Cancella
return endpointSummaries;
}

public async Task<ReportGenerationState> GetReportGenerationState(CancellationToken cancellationToken) =>
public async Task<ReportGenerationState> GetReportGenerationState(CancellationToken cancellationToken = default) =>
throughputQuery == null ?
await GetReportGenerationStateForNonBroker(cancellationToken) :
await GetReportGenerationStateForBroker(cancellationToken);
Expand Down Expand Up @@ -115,7 +115,7 @@ async Task<ReportGenerationState> GetReportGenerationStateForNonBroker(Cancellat
};
}

public async Task<SignedReport> GenerateThroughputReport(string spVersion, DateTime? reportEndDate, CancellationToken cancellationToken)
public async Task<SignedReport> GenerateThroughputReport(string spVersion, DateTime? reportEndDate, CancellationToken cancellationToken = default)
{
var reportMasks = await dataStore.GetReportMasks(cancellationToken);
var masker = new Masker([.. reportMasks]);
Expand Down
Loading
Loading