diff --git a/src/Particular.LicensingComponent/BrokerThroughput/BrokerThroughputCollectorHostedService.cs b/src/Particular.LicensingComponent/BrokerThroughput/BrokerThroughputCollectorHostedService.cs index 39dea964d7..b8c37d8521 100644 --- a/src/Particular.LicensingComponent/BrokerThroughput/BrokerThroughputCollectorHostedService.cs +++ b/src/Particular.LicensingComponent/BrokerThroughput/BrokerThroughputCollectorHostedService.cs @@ -98,12 +98,7 @@ async Task Exec(IBrokerQueue queueName, string postfix) await dataStore.SaveEndpoint(endpoint, stoppingToken); } - var defaultStartDate = DateOnly.FromDateTime(timeProvider.GetUtcNow().DateTime).AddDays(-30); - var startDate = endpoint.LastCollectedDate < defaultStartDate - ? defaultStartDate - : endpoint.LastCollectedDate.AddDays(1); - - await foreach (var queueThroughput in brokerThroughputQuery.GetThroughputPerDay(queueName, startDate, stoppingToken)) + await foreach (var queueThroughput in brokerThroughputQuery.GetThroughputPerDay(queueName, endpoint.LastCollectedDate.AddDays(1), stoppingToken)) { try { diff --git a/src/ServiceControl.Transports.ASBS/AzureQuery.cs b/src/ServiceControl.Transports.ASBS/AzureQuery.cs index a8c436a725..ef2ac43465 100644 --- a/src/ServiceControl.Transports.ASBS/AzureQuery.cs +++ b/src/ServiceControl.Transports.ASBS/AzureQuery.cs @@ -27,6 +27,7 @@ public class AzureQuery(ILogger logger, TimeProvider timeProvider, T { const string CompleteMessageMetricName = "CompleteMessage"; const string MicrosoftServicebusNamespacesMetricsNamespace = "Microsoft.ServiceBus/Namespaces"; + const int MaxDaysToQuery = 90; string serviceBusName = string.Empty; ArmClient? armClient; @@ -202,8 +203,13 @@ public override async IAsyncEnumerable GetThroughputPerDay(IBro [EnumeratorCancellation] CancellationToken cancellationToken) { logger.LogInformation($"Gathering metrics for \"{brokerQueue.QueueName}\" queue"); - - var endDate = DateOnly.FromDateTime(timeProvider.GetUtcNow().DateTime).AddDays(-1); + var today = DateOnly.FromDateTime(timeProvider.GetUtcNow().DateTime); + var earliestStartDate = today.AddDays(-MaxDaysToQuery); + if (startDate < earliestStartDate) + { + startDate = earliestStartDate; + } + var endDate = today.AddDays(-1); if (endDate < startDate) { yield break; diff --git a/src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs b/src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs index c1d44ad09d..87e57464ff 100644 --- a/src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs +++ b/src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs @@ -23,6 +23,8 @@ namespace ServiceControl.Transports.SQS; public class AmazonSQSQuery(ILogger logger, TimeProvider timeProvider, TransportSettings transportSettings) : BrokerThroughputQuery(logger, "AmazonSQS") { + const int MaxDaysToQuery = 365; + AmazonCloudWatchClient? cloudWatch; AmazonSQSClient? sqs; string? prefix; @@ -198,7 +200,13 @@ public override async IAsyncEnumerable GetThroughputPerDay(IBro [EnumeratorCancellation] CancellationToken cancellationToken) { var utcNow = timeProvider.GetUtcNow(); - var endDate = DateOnly.FromDateTime(utcNow.DateTime).AddDays(-1); // Query date up to but not including today + var today = DateOnly.FromDateTime(utcNow.DateTime); + var earliestQueryDate = today.AddDays(-MaxDaysToQuery); + if (startDate < earliestQueryDate) + { + startDate = earliestQueryDate; + } + var endDate = today.AddDays(-1); // Query date up to but not including today var isBeforeStartDate = endDate < startDate;