/
options.go
86 lines (64 loc) · 1.85 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package middleware
import (
"sort"
"github.com/prometheus/client_golang/prometheus"
)
// Options the options which will be used to create the middleware.
type Options struct {
HTTPMetricName string
HTTPMetricBuckets []float64
HTTPMetricUseNotNormalizedPaths bool
MetricsPath string
AdditionalHTTPMetricDefaultLabelsNames map[string]string
HTTPMetricDefaultLabelsNames map[string]string
Registry prometheus.Registerer
Blacklister Blacklister
}
func (o *Options) getHTTPMetricName() string {
if len(o.HTTPMetricName) == 0 {
return defaultHTTPMetricName
}
return o.HTTPMetricName
}
func (o *Options) getMetricsPath() string {
if len(o.MetricsPath) == 0 {
return defaultMetricsPath
}
return o.MetricsPath
}
func (o *Options) getHTTPMetricBuckets() []float64 {
if len(o.HTTPMetricBuckets) == 0 {
return defaultHTTPMetricBuckets
}
return o.HTTPMetricBuckets
}
func (o *Options) getLabelName(labelName string) string {
result, ok := o.HTTPMetricDefaultLabelsNames[labelName]
if !ok {
return defaultHTTPMetricDefaultLabelsNamesNames[labelName]
}
return result
}
func (o *Options) getHTTPMetricDefaultLabelNames() []string {
sorted := getSortedKeys(defaultHTTPMetricDefaultLabelsNamesNames)
result := make([]string, len(sorted))
for i, labelName := range sorted {
result[i] = o.getLabelName(labelName)
}
sort.Strings(result)
return result
}
func (o *Options) getAllHTTPMetricDefaultLabelsNames() []string {
labels := append(o.getHTTPMetricDefaultLabelNames(), getSortedKeys(o.AdditionalHTTPMetricDefaultLabelsNames)...)
sort.Strings(labels)
return labels
}
func (o *Options) getRegistry() prometheus.Registerer {
if o.Registry == nil {
return prometheus.DefaultRegisterer
}
return o.Registry
}
func (o *Options) getBlacklister() Blacklister {
return o.Blacklister
}