Skip to content
Open
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))
Comment thread
PhilBastian marked this conversation as resolved.
{
try
{
Expand Down
10 changes: 8 additions & 2 deletions 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 MaxDaysToQuery = 90;

string serviceBusName = string.Empty;
ArmClient? armClient;
Expand Down Expand Up @@ -202,8 +203,13 @@ public override async IAsyncEnumerable<QueueThroughput> 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;
Expand Down
10 changes: 9 additions & 1 deletion src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace ServiceControl.Transports.SQS;
public class AmazonSQSQuery(ILogger<AmazonSQSQuery> logger, TimeProvider timeProvider, TransportSettings transportSettings)
: BrokerThroughputQuery(logger, "AmazonSQS")
{
const int MaxDaysToQuery = 365;

AmazonCloudWatchClient? cloudWatch;
AmazonSQSClient? sqs;
string? prefix;
Expand Down Expand Up @@ -198,7 +200,13 @@ 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 earliestQueryDate = today.AddDays(-MaxDaysToQuery);
if (startDate < earliestQueryDate)
{
startDate = earliestQueryDate;
}
var endDate = today.AddDays(-1); // Query date up to but not including today

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment exists here but not on ASB, however it doesn't explain why


var isBeforeStartDate = endDate < startDate;

Expand Down
Loading