-
Notifications
You must be signed in to change notification settings - Fork 892
/
Copy pathmetrics_test.go
73 lines (56 loc) · 1.76 KB
/
metrics_test.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
package exporter
import (
"strings"
"testing"
"github.com/prometheus/client_golang/prometheus"
)
func TestSanitizeMetricName(t *testing.T) {
tsts := map[string]string{
"cluster_stats_messages_auth-req_received": "cluster_stats_messages_auth_req_received",
"cluster_stats_messages_auth_req_received": "cluster_stats_messages_auth_req_received",
}
for m, want := range tsts {
if got := sanitizeMetricName(m); got != want {
t.Errorf("sanitizeMetricName( %s ) error, want: %s, got: %s", m, want, got)
}
}
}
func TestRegisterConstHistogram(t *testing.T) {
exp := getTestExporter()
metricName := "foo"
ch := make(chan prometheus.Metric)
go func() {
exp.registerConstHistogram(ch, metricName, []string{"bar"}, 12, .24, map[float64]uint64{}, "test")
close(ch)
}()
for m := range ch {
if strings.Contains(m.Desc().String(), metricName) {
return
}
}
t.Errorf("Histogram was not registered")
}
func TestFindOrCreateMetricsDescriptionFindExisting(t *testing.T) {
exp := getTestExporter()
exp.metricDescriptions = map[string]*prometheus.Desc{}
metricName := "foo"
labels := []string{"1", "2"}
ret := exp.findOrCreateMetricDescription(metricName, labels)
ret2 := exp.findOrCreateMetricDescription(metricName, labels)
if ret == nil || ret2 == nil || ret != ret2 {
t.Errorf("Unexpected return values: (%v, %v)", ret, ret2)
}
if len(exp.metricDescriptions) != 1 {
t.Errorf("Unexpected metricDescriptions entry count.")
}
}
func TestFindOrCreateMetricsDescriptionCreateNew(t *testing.T) {
exp := getTestExporter()
exp.metricDescriptions = map[string]*prometheus.Desc{}
metricName := "foo"
labels := []string{"1", "2"}
ret := exp.findOrCreateMetricDescription(metricName, labels)
if ret == nil {
t.Errorf("Unexpected return value: %s", ret)
}
}