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

WIP: Store if registry was initialized #67

Open tback opened 6 years ago

tback commented 6 years ago

This code is a work in progress. I'm opening the pull request this early to learn if you'd accept this when it's done?

Prometheus Authors (Brian) recommend to create zero value for metrics known to exist in the future.

The usage pattern I want to enable is this:

$counter = $registry->registerCounter('namespace', 'metric', ['label_name']);
if(!$registry->initialized()){
    foreach($labelValues as $labelValue){
        $counter->incBy(0, [$labelValue]);
    }
}

Initialization is valid as for as long as the data exists in the storage adapter.

tback commented 6 years ago

It'd be great to know if this has a chance of getting accepted when it's done.

bracki commented 6 years ago

Would you mind adding a link to the post that describes the usage pattern you outlined above?

tback commented 6 years ago

There you go @bracki: https://www.robustperception.io/existential-issues-with-metrics/ https://prometheus.io/docs/practices/instrumentation/#avoid-missing-metrics

bracki commented 6 years ago

I read the blog post you mentioned. I would rather not add it. If you need to do it, it should be possible to do it on your own. In the example from the blog post a Java static initializer is used, which makes sure the code only runs once. I don't think we should fix the shortcomings of PHP within this library. It's more of a pattern than a feature.

tback commented 6 years ago

PHP doesn't provide a method to share data between requests out of the box. prometheus_client_php solves this shortcoming with storage adapters. Initializing metrics with 0 is a common usage pattern for prometheus and needs to share data between requests. Why is one inside the scope of this library, but the other one is not?