client_golang
client_golang copied to clipboard
Rework Desc and ConstMetrics
- Desc needs to also include bucket layout and type.
- Desc creation needs to be easier. Consider creating a Desc from an Opts instance, give it a Desc() method. Give Desc a method AddLabelNames.
- Remove NewInvalidDesc, not needed anywhere (especially with the option of not returning a Desc in Describe at all).
- ConstMetric creation can then be streamlined: no type parameter needed anymore. Could also take Opts directly but that has a higher performance cost as a Desc has some things precalculated. Needs vetting.
- There is probably no need for hashing within Desc. It has the risk of hash collisions, and it is not really in the critical path, so it can as well use strings as keys.
This should, after all, go into 0.10, as it will break a lot of code.
With the bucket layout in the Desc, validating the bucket layout can be part of validating the Desc, i.e. invalid bucket layouts will show up at registration time. Currently, a panic is triggered during NewHistogram (which is OK) but in a HistogramVec only at the point a new histogram element in the histogram vector is created, i.e. during the WithLabels etc. call. That's sometimes hard to spot, especially if it occurs in the HTTP serving path where panics are recovered by the HTTP library. @stuartnelson3 FYI
I'd suggest a look at https://github.com/prometheus/client_python#custom-collectors CounterMetricFamily and friends that Python/Java has. It makes the simple cases really easy for custom collectors.
Note to self to consider #516 to make Desc's useful for generating documentation.