metric_options.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package grpc_prometheus
  2. import (
  3. prom "github.com/prometheus/client_golang/prometheus"
  4. )
  5. // A CounterOption lets you add options to Counter metrics using With* funcs.
  6. type CounterOption func(*prom.CounterOpts)
  7. type counterOptions []CounterOption
  8. func (co counterOptions) apply(o prom.CounterOpts) prom.CounterOpts {
  9. for _, f := range co {
  10. f(&o)
  11. }
  12. return o
  13. }
  14. // WithConstLabels allows you to add ConstLabels to Counter metrics.
  15. func WithConstLabels(labels prom.Labels) CounterOption {
  16. return func(o *prom.CounterOpts) {
  17. o.ConstLabels = labels
  18. }
  19. }
  20. // A HistogramOption lets you add options to Histogram metrics using With*
  21. // funcs.
  22. type HistogramOption func(*prom.HistogramOpts)
  23. // WithHistogramBuckets allows you to specify custom bucket ranges for histograms if EnableHandlingTimeHistogram is on.
  24. func WithHistogramBuckets(buckets []float64) HistogramOption {
  25. return func(o *prom.HistogramOpts) { o.Buckets = buckets }
  26. }
  27. // WithHistogramConstLabels allows you to add custom ConstLabels to
  28. // histograms metrics.
  29. func WithHistogramConstLabels(labels prom.Labels) HistogramOption {
  30. return func(o *prom.HistogramOpts) {
  31. o.ConstLabels = labels
  32. }
  33. }