Subject: | BUG: Setting labels on gauge metrics with set_function, render no result |
Date: | Wed, 3 Oct 2018 11:34:20 +0000 |
To: | "bug-Net-Prometheus [...] rt.cpan.org" <bug-Net-Prometheus [...] rt.cpan.org> |
From: | Ørjan Pettersen <orjan [...] ksat.no> |
By the looks of it, it seems like you have to call the set method before the set_function method to be able to set a label to a gauge metric.
It's not documented in the help text. Is this the intended usage, or is this a bug?
Example code:
#!/usr/bin/env perl
use Net::Prometheus;
use Data::Dumper;
my $client = Net::Prometheus->new;
my $g = $client->new_gauge(name => "Test", help => "Test help", labels => ['Color']);
$g->set_function('Red', sub { 13 });
print $client->render;
The result(shortened) is as follows:
# HELP Test Test help
# TYPE Test gauge
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.02
.
.
It's suppose to be a metric below #TYPE Test gauge.
If I change the code with this:
my $g = $client->new_gauge(name => "Test", help => "Test help", labels => ['Color']);
$g->set('Red', 1);
$g->set_function('Red', sub { 13 });
The new result(shortened) is as follows:
# HELP Test Test help
# TYPE Test gauge
Test{Color="Red"} 13
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.02
.
.
Net::Prometheus v.0.05
Perl v5.26.1
Ubuntu 18.04.1 LTS
Kind regards
Ørjan Pettersen