Skip to content

Commit

Permalink
prometheus order for metric without labels fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Aug 18, 2021
1 parent b490ccb commit d376d9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Metrics/Exporter/PrometheusExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions tests/Metrics/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,22 @@ 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();

$shouldbe = implode(PHP_EOL, [
'# 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',
Expand Down

0 comments on commit d376d9b

Please sign in to comment.