change ordering of activity log month data to sort by ascending order… (#15259)

* change ordering of activity log month data to sort by ascending order of timestamp

* changelog

* changelog
This commit is contained in:
Hridoy Roy 2022-05-03 13:39:29 -07:00 committed by GitHub
parent 5e6437ab70
commit 9a5b46436e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

3
changelog/15259.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
core/activity: Order month data in ascending order of timestamps
```

View File

@ -1663,9 +1663,17 @@ func (a *ActivityLog) handleQuery(ctx context.Context, startTime, endTime time.T
}
}
// Sort the months in the descending order of activity
// Sort the months in ascending order of timestamps
sort.Slice(months, func(i, j int) bool {
return months[i].Counts.Clients > months[j].Counts.Clients
firstTimestamp, errOne := time.Parse(time.RFC3339, months[i].Timestamp)
secondTimestamp, errTwo := time.Parse(time.RFC3339, months[j].Timestamp)
if errOne == nil && errTwo == nil {
return firstTimestamp.Before(secondTimestamp)
}
// Keep the nondeterministic ordering in storage
a.logger.Error("unable to parse activity log timestamps", "timestamp",
months[i].Timestamp, "error", errOne, "timestamp", months[j].Timestamp, "error", errTwo)
return i < j
})
// Within each month sort everything by descending order of activity
@ -2476,9 +2484,17 @@ func (a *ActivityLog) partialMonthClientCount(ctx context.Context) (map[string]i
}
}
// Sort the months in the descending order of activity
// Sort the months in ascending order of timestamps
sort.Slice(months, func(i, j int) bool {
return months[i].Counts.Clients > months[j].Counts.Clients
firstTimestamp, errOne := time.Parse(time.RFC3339, months[i].Timestamp)
secondTimestamp, errTwo := time.Parse(time.RFC3339, months[j].Timestamp)
if errOne == nil && errTwo == nil {
return firstTimestamp.Before(secondTimestamp)
}
// Keep the nondeterministic ordering in storage
a.logger.Error("unable to parse activity log timestamps for partial client count",
"timestamp", months[i].Timestamp, "error", errOne, "timestamp", months[j].Timestamp, "error", errTwo)
return i < j
})
// Within each month sort everything by descending order of activity