Jimdo / prometheus_client_php

Prometheus instrumentation library for PHP applications
https://prometheus.io/docs/concepts/metric_types/
Apache License 2.0
281 stars 213 forks source link

Labels are creating duplicated metrics #74

Closed kekko1212 closed 6 years ago

kekko1212 commented 6 years ago

I noticed that registering 2 different countrers (different namespaces and names) with 2 different labels creates a weird situation where metrics are messed up.

Here's how I register the 2 counters:

Counter 1

$counter = $this->metricsClient->getOrRegisterCounter(
    'oosm',
    'successful_login_total',
    'Total of successful login',
    ['role']
);

$roles = $event->getUser()->getRoles();
foreach ($roles as $role) {
    $counter->inc([$role]);
}

Counter 2

$counter = $this->metricsClient->getOrRegisterCounter(
    'oosm',
    'location_put_offline_total',
    'Total of location put offline',
    ['location_name']
);
$counter->inc([$event->getLocationName()]);

When I hit both this counters, the metric endpoint is returning:

# HELP oosm_location_put_offline_total Total of location put offline 
# TYPE oosm_location_put_offline_total counter 
oosm_location_put_offline_total{location_name="Springfield Avenue"} 1    <---- Ok

# HELP oosm_successful_login_total Total of successful login
# TYPE oosm_successful_login_total counter 

oosm_location_put_offline_total{role="Springfield Avenue"} 1    <---- This is wrong!
oosm_successful_login_total{role="ADMINISTRATOR"} 2    <---- Ok

Could be related to: #34 ?

PHP version: 7.1.13

kekko1212 commented 6 years ago

I found the issue, it was on the wrapper I wrote for the library. Sorry.