Skip to content

Commit b17d7f5

Browse files
committed
Improve logging and parameter handling in GetThroughputPerDay
- Added trace-level logging for skipped dates and query execution details. - Renamed variables for clarity (`startUtc` → `queryStartUtc`, `endUtc` → `queryendUtc`). - Adjusted log level for CloudWatch datapoints (`Information` → `Trace`).
1 parent 33d14d3 commit b17d7f5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,27 +195,32 @@ class AwsHttpClientFactory : HttpClientFactory
195195

196196
public override async IAsyncEnumerable<QueueThroughput> GetThroughputPerDay(IBrokerQueue brokerQueue,
197197
DateOnly startDate,
198-
[EnumeratorCancellation] CancellationToken cancellationToken = default)
198+
[EnumeratorCancellation] CancellationToken cancellationToken)
199199
{
200200
var utcNow = timeProvider.GetUtcNow();
201201
var endDate = DateOnly.FromDateTime(utcNow.DateTime).AddDays(-1); // Query date up to but not including today
202202

203-
if (endDate < startDate)
203+
var isBeforeStartDate = endDate < startDate;
204+
205+
if (isBeforeStartDate)
204206
{
207+
logger.LogTrace("Skipping {Start} {End} {UtcNow}, ", startDate, endDate, utcNow);
205208
yield break;
206209
}
207210

208-
var startUtc = startDate.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
209-
var endUtc = endDate.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
211+
var queryStartUtc = startDate.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
212+
var queryendUtc = endDate.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
213+
214+
logger.LogDebug("GetThroughputPerDay {QueueName} {UtcNow} {StartDate} {EndDate} {QueryStart} {QueryEnd}", brokerQueue.QueueName, utcNow, startDate, endDate, queryStartUtc, queryendUtc);
210215

211216
const int SecondsInDay = 24 * 60 * 60;
212217

213218
var req = new GetMetricStatisticsRequest
214219
{
215220
Namespace = "AWS/SQS",
216221
MetricName = "NumberOfMessagesDeleted",
217-
StartTime = startUtc,
218-
EndTime = endUtc, // exclusive
222+
StartTime = queryStartUtc,
223+
EndTime = queryendUtc, // exclusive
219224
Period = SecondsInDay,
220225
Statistics = ["Sum"],
221226
Dimensions =
@@ -241,7 +246,7 @@ public override async IAsyncEnumerable<QueueThroughput> GetThroughputPerDay(IBro
241246
// Cloudwatch returns data points per 5 minutes in UTC
242247
foreach (var datapoint in resp.Datapoints ?? [])
243248
{
244-
logger.LogInformation("\tDatapoint {Timestamp:O} {Sum} {Unit}", datapoint.Timestamp, datapoint.Sum, datapoint.Unit);
249+
logger.LogTrace("Datapoint {Timestamp:O} {Sum:N0}", datapoint.Timestamp, datapoint.Sum);
245250
if (datapoint.Timestamp.HasValue)
246251
{
247252
if (data.TryGetValue(DateOnly.FromDateTime(datapoint.Timestamp.Value), out var queueThroughput))

0 commit comments

Comments
 (0)