From b78512ca5950d6a0d8436f838ba90f3c944c37eb Mon Sep 17 00:00:00 2001 From: Jean-Christophe Cura Date: Thu, 14 Dec 2023 11:55:45 +0100 Subject: [PATCH 1/2] fix scrapping for redis < 4.0 This fix avoid an exception to bee thrown so scrapping fail for redis version < 4.0 Metrics will so only contains keys_group_count and not memory_usage tested on docker redis 3.2.4: (docker pull r900/redis:3.2.4) --- exporter/key_groups.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exporter/key_groups.go b/exporter/key_groups.go index 72bca1bf..5a94d123 100644 --- a/exporter/key_groups.go +++ b/exporter/key_groups.go @@ -173,7 +173,10 @@ for i=3,#ARGV do end end for i,key in ipairs(batch[2]) do - usage = redis.call("MEMORY", "USAGE", key) + local reply = redis.pcall("MEMORY", "USAGE", key) + if reply['err'] == nil then + usage = reply; + end group = nil for i=3,#ARGV do key_match_result = {string.find(key, ARGV[i])} From 1bc1b4584b122297aadb8ceb270376537f2fbe58 Mon Sep 17 00:00:00 2001 From: jcaspes Date: Fri, 15 Dec 2023 15:55:35 +0100 Subject: [PATCH 2/2] Fix bad error on type Was trying to index a number in case of success Better to check type to check if MEMORY USAGE command succeed, so use the result (key memory usage bytes) --- exporter/key_groups.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/key_groups.go b/exporter/key_groups.go index 5a94d123..0141255f 100644 --- a/exporter/key_groups.go +++ b/exporter/key_groups.go @@ -174,7 +174,7 @@ for i=3,#ARGV do end for i,key in ipairs(batch[2]) do local reply = redis.pcall("MEMORY", "USAGE", key) - if reply['err'] == nil then + if type(reply) == "number" then usage = reply; end group = nil