From d376d9bb8fa5a451afe94a6b31dd3428fd495405 Mon Sep 17 00:00:00 2001 From: dmitry krokhin Date: Wed, 18 Aug 2021 18:01:18 +0300 Subject: [PATCH] prometheus order for metric without labels fix --- src/Metrics/Exporter/PrometheusExporter.php | 2 +- tests/Metrics/ExporterTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Metrics/Exporter/PrometheusExporter.php b/src/Metrics/Exporter/PrometheusExporter.php index af6e092..a3bb27d 100644 --- a/src/Metrics/Exporter/PrometheusExporter.php +++ b/src/Metrics/Exporter/PrometheusExporter.php @@ -35,7 +35,7 @@ public function toString(string $prefix = '', array $labels = []): string $key .= '{' . implode(',', $rowLabels) . '}'; } - $result[$key] = sprintf('%s %s', $key, $row['value']); + $result[$key . '_'] = sprintf('%s %s', $key, $row['value']); } ksort($result); diff --git a/tests/Metrics/ExporterTest.php b/tests/Metrics/ExporterTest.php index 6cead30..d357a8a 100644 --- a/tests/Metrics/ExporterTest.php +++ b/tests/Metrics/ExporterTest.php @@ -87,10 +87,12 @@ public function testMetricsOrder() $registry->set('todo', 1, ['queue' => 'web.bundle']); $registry->set('complete', 2, ['queue' => 'flow.promote']); $registry->set('todo', 3, ['queue' => 'space.housekeeping']); + $registry->set('counter', 1); $info = new Info(); $info->set('todo', 'waiting'); $info->set('complete', 'complete'); + $info->set('counter', 'example'); $string = (new PrometheusExporter($registry, $info))->toString(); @@ -98,6 +100,9 @@ public function testMetricsOrder() '# HELP complete complete', '# TYPE complete gauge', 'complete{queue="flow.promote"} 2', + '# HELP counter example', + '# TYPE counter gauge', + 'counter 1', '# HELP todo waiting', '# TYPE todo gauge', 'todo{queue="space.housekeeping"} 3',