forked from stripe/veneur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker_test.go
80 lines (63 loc) · 1.76 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
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 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")
}