Skip to content

Commit d376d9b

Browse files
committed
prometheus order for metric without labels fix
1 parent b490ccb commit d376d9b

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/Metrics/Exporter/PrometheusExporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function toString(string $prefix = '', array $labels = []): string
3535
$key .= '{' . implode(',', $rowLabels) . '}';
3636
}
3737

38-
$result[$key] = sprintf('%s %s', $key, $row['value']);
38+
$result[$key . '_'] = sprintf('%s %s', $key, $row['value']);
3939
}
4040

4141
ksort($result);

tests/Metrics/ExporterTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,22 @@ public function testMetricsOrder()
8787
$registry->set('todo', 1, ['queue' => 'web.bundle']);
8888
$registry->set('complete', 2, ['queue' => 'flow.promote']);
8989
$registry->set('todo', 3, ['queue' => 'space.housekeeping']);
90+
$registry->set('counter', 1);
9091

9192
$info = new Info();
9293
$info->set('todo', 'waiting');
9394
$info->set('complete', 'complete');
95+
$info->set('counter', 'example');
9496

9597
$string = (new PrometheusExporter($registry, $info))->toString();
9698

9799
$shouldbe = implode(PHP_EOL, [
98100
'# HELP complete complete',
99101
'# TYPE complete gauge',
100102
'complete{queue="flow.promote"} 2',
103+
'# HELP counter example',
104+
'# TYPE counter gauge',
105+
'counter 1',
101106
'# HELP todo waiting',
102107
'# TYPE todo gauge',
103108
'todo{queue="space.housekeeping"} 3',

0 commit comments

Comments
 (0)