-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics_test.go
93 lines (76 loc) · 1.93 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package metrics
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDimensionalOverride(t *testing.T) {
sub, env := subscribe(t)
defer sub.Unsubscribe()
env.AddDimension("global-val", 12)
env.AddDimension("metric-overide", "global-level")
env.AddDimension("instance-overide", "global-level")
sender := env.newMetric("thing.one", CounterType, DimMap{
"metric-val": 456,
"metric-overide": "metric-level",
"instance-overide": "metric-level",
})
sender.send(DimMap{
"instance-overide": "instance-level",
"instance-val": 789,
})
m := readOne(t, sub)
if assert.NotNil(t, m) {
assert.EqualValues(t, 5, len(m.Dims))
expected := DimMap{
"global-val": 12,
"metric-overide": "metric-level",
"instance-overide": "instance-level",
"metric-val": 456,
"instance-val": 789,
}
for k, v := range expected {
dimVal, exists := m.Dims[k]
assert.True(t, exists)
assert.EqualValues(t, v, dimVal)
}
assert.NotEqual(t, time.Time{}, m.Timestamp)
}
}
func TestSetTimestampCounter(t *testing.T) {
sub, env := subscribe(t)
defer sub.Unsubscribe()
ts := time.Now()
c := env.NewCounter("thingy", nil)
c.SetTimestamp(ts)
c.Count(nil)
m := readOne(t, sub)
if assert.NotNil(t, m) {
assert.EqualValues(t, ts.UnixNano(), m.Timestamp.UnixNano())
}
}
func TestSetTimestampTimer(t *testing.T) {
sub, env := subscribe(t)
defer sub.Unsubscribe()
ts := time.Now()
timer := env.NewTimer("thingy", nil)
timer.SetTimestamp(ts)
timer.Start()
timer.Stop(nil)
m := readOne(t, sub)
if assert.NotNil(t, m) {
assert.EqualValues(t, ts.UnixNano(), m.Timestamp.UnixNano())
}
}
func TestSetTimestampGauge(t *testing.T) {
sub, env := subscribe(t)
defer sub.Unsubscribe()
ts := time.Now()
g := env.NewGauge("thingy", nil)
g.SetTimestamp(ts)
g.Increment(nil)
m := readOne(t, sub)
if assert.NotNil(t, m) {
assert.EqualValues(t, ts.UnixNano(), m.Timestamp.UnixNano())
}
}