-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathstats_test.go
144 lines (109 loc) · 3.32 KB
/
stats_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package templar
import (
"net/http"
"testing"
"time"
"github.com/amir/raidman"
"github.com/stretchr/testify/require"
"github.com/vektra/neko"
)
func TestStatsdOutput(t *testing.T) {
n := neko.Start(t)
var (
output *StatsdOutput
client MockStatsdClient
)
n.CheckMock(&client.Mock)
n.Setup(func() {
output = NewStatsdOutput(&client)
})
n.It("emits stats about a request on start", func() {
req, err := http.NewRequest("GET", "http://google.com/foo/bar", nil)
require.NoError(t, err)
client.On("Incr", "templar.request.method.GET", int64(1)).Return(nil)
client.On("Incr", "templar.request.host.google.com", int64(1)).Return(nil)
client.On("Incr", "templar.request.url.google.com-foo-bar", int64(1)).Return(nil)
client.On("GaugeDelta", "templar.requests.active", int64(1)).Return(nil)
output.StartRequest(req)
})
n.It("emits stats about a request on end", func() {
req, err := http.NewRequest("GET", "http://google.com/foo/bar", nil)
require.NoError(t, err)
t := 1 * time.Second
client.On("GaugeDelta", "templar.requests.active", int64(-1)).Return(nil)
client.On("PrecisionTiming",
"templar.request.url.google.com-foo-bar", t).Return(nil)
output.Emit(req, t)
})
n.It("emits stats when a request times out", func() {
req, err := http.NewRequest("GET", "http://google.com/foo/bar", nil)
require.NoError(t, err)
t := 5 * time.Second
client.On("Incr", "templar.timeout.host.google.com", int64(1)).Return(nil)
client.On("Incr", "templar.timeout.url.google.com-foo-bar", int64(1)).Return(nil)
output.RequestTimeout(req, t)
})
n.Meow()
}
func TestRiemannOutput(t *testing.T) {
n := neko.Start(t)
var (
output *RiemannOutput
client MockRiemannClient
)
n.CheckMock(&client.Mock)
n.Setup(func() {
output = NewRiemannOutput(&client)
})
n.It("emits stats about a request on start", func() {
req, err := http.NewRequest("GET", "http://google.com/foo/bar", nil)
require.NoError(t, err)
attributes := make(map[string]string)
attributes["method"] = "GET"
attributes["host"] = "google.com"
attributes["path"] = "/foo/bar"
var event = &raidman.Event{
State: "ok",
Service: "templar request",
Metric: 1,
Attributes: attributes,
}
client.On("Send", event).Return(nil)
output.StartRequest(req)
})
n.It("emits stats about a request on end", func() {
req, err := http.NewRequest("GET", "http://google.com/foo/bar", nil)
require.NoError(t, err)
t := 1 * time.Second
attributes := make(map[string]string)
attributes["method"] = "GET"
attributes["host"] = "google.com"
attributes["path"] = "/foo/bar"
var event = &raidman.Event{
State: "ok",
Service: "templar response",
Metric: 1000.0,
Attributes: attributes,
}
client.On("Send", event).Return(nil)
output.Emit(req, t)
})
n.It("emits stats when a request times out", func() {
req, err := http.NewRequest("GET", "http://google.com/foo/bar", nil)
require.NoError(t, err)
t := 5 * time.Second
attributes := make(map[string]string)
attributes["method"] = "GET"
attributes["host"] = "google.com"
attributes["path"] = "/foo/bar"
var event = &raidman.Event{
State: "warning",
Service: "templar timeout",
Metric: 5000.0,
Attributes: attributes,
}
client.On("Send", event).Return(nil)
output.RequestTimeout(req, t)
})
n.Meow()
}