client_golang icon indicating copy to clipboard operation
client_golang copied to clipboard

Rework Desc and ConstMetrics

Open beorn7 opened this issue 9 years ago • 4 comments

  • 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.

beorn7 avatar Aug 16 '16 16:08 beorn7

This should, after all, go into 0.10, as it will break a lot of code.

beorn7 avatar Aug 19 '16 21:08 beorn7

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

beorn7 avatar Oct 17 '16 13:10 beorn7

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.

brian-brazil avatar Dec 28 '16 11:12 brian-brazil

Note to self to consider #516 to make Desc's useful for generating documentation.

beorn7 avatar May 06 '19 22:05 beorn7