prometheus / client_golang

Prometheus instrumentation library for Go applications
https://pkg.go.dev/github.com/prometheus/client_golang
Apache License 2.0
5.36k stars 1.17k forks source link

Clarify Collector's Describe(): Returning all possible metrics required? When not? #140

Closed discordianfish closed 9 years ago

discordianfish commented 9 years ago

The Collector interface describes Describe() as:

Describe sends the super-set of all possible descriptors of metrics
collected by this Collector to the provided channel and returns once
the last descriptor has been sent.

In reality this often is hard to achieve, therefor we have lot of exporters (e.g graphite exporter) simply not doing that but returning just a subset of possible metric descriptors.

Even to me it's still unclear why this is necessary and how does it help with consistency given that it doesn't enforce the described requirements.

beorn7 commented 9 years ago

tl;dr: This is essentially a duplicate of https://github.com/prometheus/client_golang/issues/47

If you call prometheus.EnableCollectChecks(true), it will enforce the requirements. If you do not call it, the requirement is just a contract. Bug-free collectors must honor it, so we can save the scrape-time overhead of checking it.

Also, the whole reason for having Describe() is to check consistency upon registration time (i.e. when you start up your program) and not upon scrape time. Panicking upon startup is kind of acceptable while panicking upon touching an HTTP endpoint is not.

discordianfish commented 9 years ago

OH forgot about that. Thanks. I opened this because the author of heka-prometheus was confused about that and had crazy things in mind to workaround that.