Skip Menu |

This queue is for tickets about the Net-Prometheus CPAN distribution.

Report information
The Basics
Id: 127284
Status: resolved
Priority: 0/
Queue: Net-Prometheus

People
Owner: Nobody in particular
Requestors: orjan [...] ksat.no
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.06



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
A suggested quick fix can be found here: https://github.com/tyldum/net-prometheus/compare/master...rt-cpan-org-127284?diff=unified In essence the samples method will loop through all \%values, but there is no value for these gauges. This patch will set the value to undef and it will be populated on the first run.
Thanks. Now applied. -- Paul Evans