From 760332a8e4eadfbbcc80fec4601de6dc62609068 Mon Sep 17 00:00:00 2001 From: Joshua Kahn Date: Fri, 7 Jun 2019 10:12:09 -0400 Subject: [PATCH] Fix errant keys in Redis scripts The metric labels and command types were inappropriately specified as KEYS in the Redis scripts. This meant there was no way to avoid a `CROSSSLOT Keys in request don't hash to the same slot` error when using a Redis cluster that hashes keys to select a specific node. --- src/Prometheus/Storage/Redis.php | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index f38391b..9f25fe6 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -117,23 +117,23 @@ public function updateHistogram(array $data) unset($metaData['value']); unset($metaData['labelValues']); $this->redis->eval(<<toMetricKey($data), + self::$prefix . Histogram::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX, json_encode(array('b' => 'sum', 'labelValues' => $data['labelValues'])), json_encode(array('b' => $bucketToIncrease, 'labelValues' => $data['labelValues'])), - self::$prefix . Histogram::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX, $data['value'], json_encode($metaData), ), - 4 + 2 ); } @@ -145,30 +145,30 @@ public function updateGauge(array $data) unset($metaData['labelValues']); unset($metaData['command']); $this->redis->eval(<<toMetricKey($data), - $this->getRedisCommand($data['command']), self::$prefix . Gauge::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX, + $this->getRedisCommand($data['command']), json_encode($data['labelValues']), $data['value'], json_encode($metaData), ), - 4 + 2 ); } @@ -180,23 +180,23 @@ public function updateCounter(array $data) unset($metaData['labelValues']); unset($metaData['command']); $result = $this->redis->eval(<<toMetricKey($data), - $this->getRedisCommand($data['command']), self::$prefix . Counter::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX, + $this->getRedisCommand($data['command']), json_encode($data['labelValues']), $data['value'], json_encode($metaData), ), - 4 + 2 ); return $result; }