forked from kobtea/dummy_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_exporter_test.go
82 lines (66 loc) · 1.31 KB
/
dummy_exporter_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
74
75
76
77
78
79
80
81
82
package main
import (
"strconv"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/TheoBrigitte/prometheus-dummy-exporter/pkg/collector"
"github.com/TheoBrigitte/prometheus-dummy-exporter/pkg/config"
)
func TestCollect(t *testing.T) {
conf := config.New()
c, err := collector.New(conf)
if err != nil {
t.Fatal(err)
}
ch := make(chan prometheus.Metric)
go func(ch chan prometheus.Metric) {
for range ch {
}
}(ch)
c.Collect(ch)
close(ch)
}
func BenchmarkCollect(b *testing.B) {
alice := config.Metric{
Name: "alice",
Type: config.MetricTypeGauge,
Size: 500000,
Labels: map[string][]string{},
}
addLabels(&alice)
bob := config.Metric{
Name: "bob",
Type: config.MetricTypeCounter,
Size: 500000,
Labels: map[string][]string{},
}
addLabels(&bob)
conf := &config.Config{
Metrics: []config.Metric{
alice, bob,
},
}
c, err := collector.New(conf)
if err != nil {
b.Fatal(err)
}
ch := make(chan prometheus.Metric)
go func(ch chan prometheus.Metric) {
for range ch {
}
}(ch)
b.ResetTimer()
for range b.N {
c.Collect(ch)
}
close(ch)
}
func addLabels(m *config.Metric) {
for i := 0; i < 10; i++ {
is := strconv.Itoa(i)
key := "l" + is
for j := 0; j < 10; j++ {
m.Labels[key] = append(m.Labels[key], "l"+is+strconv.Itoa(j))
}
}
}