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
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 11 additions & 1 deletion src/ServiceControl.Transports.ASBS/AzureQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AzureQuery(ILogger<AzureQuery> logger, TimeProvider timeProvider, T
{
const string CompleteMessageMetricName = "CompleteMessage";
const string MicrosoftServicebusNamespacesMetricsNamespace = "Microsoft.ServiceBus/Namespaces";
const int MaxDaysToCollect = 30;

string serviceBusName = string.Empty;
ArmClient? armClient;
Expand Down Expand Up @@ -201,7 +202,16 @@ public override async IAsyncEnumerable<QueueThroughput> GetThroughputPerDay(IBro
{
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(-MaxDaysToCollect);
if (startDate < earliestStartDate)
{
startDate = earliestStartDate;
}

// Collect up to yesterday, as today's data is incomplete
// We will collect today's data tomorrow
var endDate = today.AddDays(-1);
if (endDate < startDate)
{
yield break;
Expand Down
12 changes: 11 additions & 1 deletion src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class AmazonSQSQuery(ILogger<AmazonSQSQuery> logger, TimeProvider timePro
AmazonCloudWatchClient? cloudWatch;
AmazonSQSClient? sqs;
string? prefix;
const int MaxDaysToCollect = 365;

protected override void InitializeCore(ReadOnlyDictionary<string, string> settings)
{
Expand Down Expand Up @@ -198,7 +199,16 @@ public override async IAsyncEnumerable<QueueThroughput> 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 earliestStartDate = today.AddDays(-MaxDaysToCollect);
if (startDate < earliestStartDate)
{
startDate = earliestStartDate;
}

// Collect up to yesterday, as today's data is incomplete
// We will collect today's data tomorrow
var endDate = today.AddDays(-1); // Query date up to but not including today

var isBeforeStartDate = endDate < startDate;

Expand Down
Loading