-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpool_test.go
110 lines (90 loc) · 3.96 KB
/
pool_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package prometheusrunnerpool_test
import (
"strings"
"testing"
"github.com/cabify/prometheusrunnerpool"
"github.com/cabify/runnerpool"
"github.com/cabify/runnerpool/runnerpoolmock"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
)
const nl = "\n"
func TestObserver_Observe(t *testing.T) {
t.Run("reports metrics for one pool", func(t *testing.T) {
registry := prometheus.NewRegistry()
poolMock := &runnerpoolmock.Pool{}
poolMock.On("Stats").Return(runnerpool.Stats{
MaxWorkers: 4,
Workers: 3,
Acquired: 2,
Running: 1,
})
prometheusrunnerpool.Observe(registry, poolMock, "test_pool")
reader := strings.NewReader(`` +
`# HELP runnerpool_stats_max_workers_total Maximum amount of workers configured in the pool` + nl +
`# TYPE runnerpool_stats_max_workers_total gauge` + nl +
`runnerpool_stats_max_workers_total{pool_name="test_pool"} 4` + nl +
`# HELP runnerpool_stats_workers_total Total number of workers in the pool` + nl +
`# TYPE runnerpool_stats_workers_total gauge` + nl +
`runnerpool_stats_workers_total{pool_name="test_pool"} 3` + nl +
`# HELP runnerpool_stats_acquired_total Total number of workers acquired in the pool, they may or may not be running something` + nl +
`# TYPE runnerpool_stats_acquired_total gauge` + nl +
`runnerpool_stats_acquired_total{pool_name="test_pool"} 2` + nl +
`# HELP runnerpool_stats_running_total Total number of workers running a function in the pool` + nl +
`# TYPE runnerpool_stats_running_total gauge` + nl +
`runnerpool_stats_running_total{pool_name="test_pool"} 1` + nl,
)
err := testutil.GatherAndCompare(registry, reader,
"runnerpool_stats_max_workers_total",
"runnerpool_stats_workers_total",
"runnerpool_stats_acquired_total",
"runnerpool_stats_running_total",
)
assert.NoError(t, err)
})
t.Run("reports metrics for two pools", func(t *testing.T) {
registry := prometheus.NewRegistry()
firstPoolMock := &runnerpoolmock.Pool{}
firstPoolMock.On("Stats").Return(runnerpool.Stats{
MaxWorkers: 4,
Workers: 3,
Acquired: 2,
Running: 1,
})
secondPoolMock := &runnerpoolmock.Pool{}
secondPoolMock.On("Stats").Return(runnerpool.Stats{
MaxWorkers: 40,
Workers: 30,
Acquired: 20,
Running: 10,
})
prometheusrunnerpool.Observe(registry, firstPoolMock, "first_pool")
prometheusrunnerpool.Observe(registry, secondPoolMock, "second_pool")
reader := strings.NewReader(`` +
`# HELP runnerpool_stats_max_workers_total Maximum amount of workers configured in the pool` + nl +
`# TYPE runnerpool_stats_max_workers_total gauge` + nl +
`runnerpool_stats_max_workers_total{pool_name="first_pool"} 4` + nl +
`runnerpool_stats_max_workers_total{pool_name="second_pool"} 40` + nl +
`# HELP runnerpool_stats_workers_total Total number of workers in the pool` + nl +
`# TYPE runnerpool_stats_workers_total gauge` + nl +
`runnerpool_stats_workers_total{pool_name="first_pool"} 3` + nl +
`runnerpool_stats_workers_total{pool_name="second_pool"} 30` + nl +
`# HELP runnerpool_stats_acquired_total Total number of workers acquired in the pool, they may or may not be running something` + nl +
`# TYPE runnerpool_stats_acquired_total gauge` + nl +
`runnerpool_stats_acquired_total{pool_name="first_pool"} 2` + nl +
`runnerpool_stats_acquired_total{pool_name="second_pool"} 20` + nl +
`# HELP runnerpool_stats_running_total Total number of workers running a function in the pool` + nl +
`# TYPE runnerpool_stats_running_total gauge` + nl +
`runnerpool_stats_running_total{pool_name="first_pool"} 1` + nl +
`runnerpool_stats_running_total{pool_name="second_pool"} 10` + nl,
)
err := testutil.GatherAndCompare(registry, reader,
"runnerpool_stats_max_workers_total",
"runnerpool_stats_workers_total",
"runnerpool_stats_acquired_total",
"runnerpool_stats_running_total",
)
assert.NoError(t, err)
})
}