From 7cb670e1bf9560a24de3da52427b4f6b6152a59a Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Tue, 10 Sep 2024 06:36:40 -0600 Subject: [PATCH] fix(metrics): differentiate points in different minutes to be more accurate (#2766) (python) --- src/commands/includes/collectMetrics.lua | 2 +- tests/test_metrics.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commands/includes/collectMetrics.lua b/src/commands/includes/collectMetrics.lua index 8cfd25a4fe..96d777ded5 100644 --- a/src/commands/includes/collectMetrics.lua +++ b/src/commands/includes/collectMetrics.lua @@ -17,7 +17,7 @@ local function collectMetrics(metaKey, dataPointsList, maxDataPoints, 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/tests/test_metrics.ts b/tests/test_metrics.ts index a83a9ae3fa..6433afc8b2 100644 --- a/tests/test_metrics.ts +++ b/tests/test_metrics.ts @@ -66,6 +66,8 @@ describe('metrics', function () { ONE_MINUTE, ONE_MINUTE, ONE_MINUTE * 3, + ONE_SECOND * 70, + ONE_SECOND * 50, ONE_HOUR, ONE_MINUTE, ]; @@ -132,6 +134,8 @@ describe('metrics', function () { '0', '0', '1', + '1', + '1', '0', '0', '1',