Skip to content

Commit 6971fb1

Browse files
committed
Added comments to document WHY the logic is like it is
1 parent b17d7f5 commit 6971fb1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ServiceControl.Transports.SQS/AmazonSQSQuery.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,15 @@ public override async IAsyncEnumerable<QueueThroughput> GetThroughputPerDay(IBro
208208
yield break;
209209
}
210210

211+
// Convert DATES that state up to but INCLUDING the TO value to a timestamp from X to Y EXCLUDING
212+
// Example: 2025-01-01 to 2025-01-10 => 2025-01-01T00:00:00 to 2025-01-11T00:00:00
213+
211214
var queryStartUtc = startDate.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
212-
var queryendUtc = endDate.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
215+
var queryEndUtc = endDate
216+
.AddDays(1) // Convert from INCLUDING to EXCLUDING, thus need to bump one day, using ToDateTime(TimeOnly.MaxValue) would be wrong
217+
.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
213218

214-
logger.LogDebug("GetThroughputPerDay {QueueName} {UtcNow} {StartDate} {EndDate} {QueryStart} {QueryEnd}", brokerQueue.QueueName, utcNow, startDate, endDate, queryStartUtc, queryendUtc);
219+
logger.LogDebug("GetThroughputPerDay {QueueName} {UtcNow} {StartDate} {EndDate} {QueryStart} {QueryEnd}", brokerQueue.QueueName, utcNow, startDate, endDate, queryStartUtc, queryEndUtc);
215220

216221
const int SecondsInDay = 24 * 60 * 60;
217222

@@ -220,7 +225,7 @@ public override async IAsyncEnumerable<QueueThroughput> GetThroughputPerDay(IBro
220225
Namespace = "AWS/SQS",
221226
MetricName = "NumberOfMessagesDeleted",
222227
StartTime = queryStartUtc,
223-
EndTime = queryendUtc, // exclusive
228+
EndTime = queryEndUtc, // The value specified is exclusive; results include data points up to the specified time stamp.
224229
Period = SecondsInDay,
225230
Statistics = ["Sum"],
226231
Dimensions =

0 commit comments

Comments
 (0)