From 581de325e5a3e6bdc9623492733becdea67371d2 Mon Sep 17 00:00:00 2001 From: roggervalf Date: Tue, 10 Sep 2024 08:04:35 -0500 Subject: [PATCH] fix(metrics): differentiate points in different minutes to be more accurate --- lib/commands/includes/collectMetrics.lua | 2 +- test/test_metrics.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/commands/includes/collectMetrics.lua b/lib/commands/includes/collectMetrics.lua index a2a4a0cb3..cccba14d2 100644 --- a/lib/commands/includes/collectMetrics.lua +++ b/lib/commands/includes/collectMetrics.lua @@ -19,7 +19,7 @@ local function collectMetrics(metaKey, dataPointsList, maxDataPoints, timestamp) return end - local N = math.min(math.floor((timestamp - prevTS) / 60000), tonumber(maxDataPoints)) + local N = math.min(math.floor(timestamp / 60000) - math.floor(prevTS / 60000), tonumber(maxDataPoints)) if N > 0 then local delta = count - rcall("HGET", metaKey, "prevCount") diff --git a/test/test_metrics.js b/test/test_metrics.js index 5a8aaffed..fb063ee46 100644 --- a/test/test_metrics.js +++ b/test/test_metrics.js @@ -34,6 +34,8 @@ describe('metrics', () => { ONE_MINUTE, ONE_MINUTE, ONE_MINUTE * 3, + ONE_SECOND * 70, + ONE_SECOND * 50, ONE_HOUR, ONE_MINUTE ]; @@ -100,6 +102,8 @@ describe('metrics', () => { '0', '0', '1', + '1', + '1', '0', '0', '1',