From 9a5b46436ea4f04e41fcd4ccd8b1447095847c5f Mon Sep 17 00:00:00 2001 From: Hridoy Roy Date: Tue, 3 May 2022 13:39:29 -0700 Subject: [PATCH] =?UTF-8?q?change=20ordering=20of=20activity=20log=20month?= =?UTF-8?q?=20data=20to=20sort=20by=20ascending=20order=E2=80=A6=20(#15259?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * change ordering of activity log month data to sort by ascending order of timestamp * changelog * changelog --- changelog/15259.txt | 3 +++ vault/activity_log.go | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 changelog/15259.txt 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