diff --git a/changelog/15259.txt b/changelog/15259.txt new file mode 100644 index 000000000..6ad0b2e40 --- /dev/null +++ b/changelog/15259.txt @@ -0,0 +1,3 @@ +```release-note:improvement +core/activity: Order month data in ascending order of timestamps +``` \ No newline at end of file diff --git a/vault/activity_log.go b/vault/activity_log.go index 4988262b5..22a9593f8 100644 --- a/vault/activity_log.go +++ b/vault/activity_log.go @@ -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