Debian Codegraph @

metric_options.go

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