forked from stripe/veneur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker_test.go
113 lines (92 loc) · 2.56 KB
/
worker_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
111
112
113
package veneur
import (
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stripe/veneur/samplers"
)
func TestWorker(t *testing.T) {
w := NewWorker(1, nil, logrus.New())
m := samplers.UDPMetric{
MetricKey: samplers.MetricKey{
Name: "a.b.c",
Type: "counter",
},
Value: 1.0,
Digest: 12345,
SampleRate: 1.0,
}
w.ProcessMetric(&m)
wm := w.Flush()
assert.Len(t, wm.counters, 1, "Number of flushed metrics")
nometrics := w.Flush()
assert.Len(t, nometrics.counters, 0, "Should flush no metrics")
}
func TestWorkerLocal(t *testing.T) {
w := NewWorker(1, nil, logrus.New())
m := samplers.UDPMetric{
MetricKey: samplers.MetricKey{
Name: "a.b.c",
Type: "histogram",
},
Value: 1.0,
Digest: 12345,
SampleRate: 1.0,
Scope: samplers.LocalOnly,
}
w.ProcessMetric(&m)
wm := w.Flush()
assert.Len(t, wm.localHistograms, 1, "number of local histograms")
assert.Len(t, wm.histograms, 0, "number of global histograms")
}
func TestWorkerGlobal(t *testing.T) {
w := NewWorker(1, nil, logrus.New())
gc := samplers.UDPMetric{
MetricKey: samplers.MetricKey{
Name: "a.b.c",
Type: "counter",
},
Value: 1.0,
Digest: 12345,
SampleRate: 1.0,
Scope: samplers.GlobalOnly,
}
w.ProcessMetric(&gc)
gg := samplers.UDPMetric{
MetricKey: samplers.MetricKey{
Name: "b.c.a",
Type: "gauge",
},
Value: 1.0,
Digest: 12346,
SampleRate: 1.0,
Scope: samplers.GlobalOnly,
}
w.ProcessMetric(&gg)
assert.Equal(t, 1, len(w.wm.globalGauges), "should have 1 global gauge")
assert.Equal(t, 0, len(w.wm.gauges), "should have no normal gauges")
assert.Equal(t, 1, len(w.wm.globalCounters), "should have 1 global counter")
assert.Equal(t, 0, len(w.wm.counters), "should have no local counters")
}
func TestWorkerImportSet(t *testing.T) {
w := NewWorker(1, nil, logrus.New())
testset := samplers.NewSet("a.b.c", nil)
testset.Sample("foo", 1.0)
testset.Sample("bar", 1.0)
jsonMetric, err := testset.Export()
assert.NoError(t, err, "should have exported successfully")
w.ImportMetric(jsonMetric)
wm := w.Flush()
assert.Len(t, wm.sets, 1, "number of flushed sets")
}
func TestWorkerImportHistogram(t *testing.T) {
w := NewWorker(1, nil, logrus.New())
testhisto := samplers.NewHist("a.b.c", nil)
testhisto.Sample(1.0, 1.0)
testhisto.Sample(2.0, 1.0)
jsonMetric, err := testhisto.Export()
assert.NoError(t, err, "should have exported successfully")
w.ImportMetric(jsonMetric)
wm := w.Flush()
assert.Len(t, wm.histograms, 1, "number of flushed histograms")
}