forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsul_test.go
More file actions
137 lines (114 loc) · 3.27 KB
/
Copy pathconsul_test.go
File metadata and controls
137 lines (114 loc) · 3.27 KB
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
package consul
import (
"testing"
"github.com/hashicorp/consul/api"
"github.com/influxdata/telegraf/testutil"
)
var sampleChecks = []*api.HealthCheck{
{
Node: "localhost",
CheckID: "foo.health123",
Name: "foo.health",
Status: "passing",
Notes: "lorem ipsum",
Output: "OK",
ServiceID: "foo.123",
ServiceName: "foo",
ServiceTags: []string{"bar", "env:sandbox", "tagkey:value:stillvalue"},
},
}
func TestGatherHealthCheck(t *testing.T) {
expectedFields := map[string]interface{}{
"check_name": "foo.health",
"status": "passing",
"passing": 1,
"critical": 0,
"warning": 0,
"service_id": "foo.123",
}
expectedTags := map[string]string{
"node": "localhost",
"service_name": "foo",
"check_id": "foo.health123",
"bar": "bar",
"env:sandbox": "env:sandbox",
"tagkey:value:stillvalue": "tagkey:value:stillvalue",
}
var acc testutil.Accumulator
consul := &Consul{}
consul.GatherHealthCheck(&acc, sampleChecks)
acc.AssertContainsTaggedFields(t, "consul_health_checks", expectedFields, expectedTags)
}
func TestGatherHealthCheckWithDelimitedTags(t *testing.T) {
expectedFields := map[string]interface{}{
"check_name": "foo.health",
"status": "passing",
"passing": 1,
"critical": 0,
"warning": 0,
"service_id": "foo.123",
}
expectedTags := map[string]string{
"node": "localhost",
"service_name": "foo",
"check_id": "foo.health123",
"bar": "bar",
"env": "sandbox",
"tagkey": "value:stillvalue",
}
var acc testutil.Accumulator
consul := &Consul{
TagDelimiter: ":",
}
consul.GatherHealthCheck(&acc, sampleChecks)
acc.AssertContainsTaggedFields(t, "consul_health_checks", expectedFields, expectedTags)
}
func TestGatherHealthCheckV2(t *testing.T) {
expectedFields := map[string]interface{}{
"passing": 1,
"critical": 0,
"warning": 0,
}
expectedTags := map[string]string{
"node": "localhost",
"check_id": "foo.health123",
"check_name": "foo.health",
"status": "passing",
"service_id": "foo.123",
"service_name": "foo",
"bar": "bar",
"env:sandbox": "env:sandbox",
"tagkey:value:stillvalue": "tagkey:value:stillvalue",
}
var acc testutil.Accumulator
consul := &Consul{
MetricVersion: 2,
}
consul.GatherHealthCheck(&acc, sampleChecks)
acc.AssertContainsTaggedFields(t, "consul_health_checks", expectedFields, expectedTags)
}
func TestGatherHealthCheckWithDelimitedTagsV2(t *testing.T) {
expectedFields := map[string]interface{}{
"passing": 1,
"critical": 0,
"warning": 0,
}
expectedTags := map[string]string{
"node": "localhost",
"check_id": "foo.health123",
"check_name": "foo.health",
"status": "passing",
"service_id": "foo.123",
"service_name": "foo",
"bar": "bar",
"env": "sandbox",
"tagkey": "value:stillvalue",
}
var acc testutil.Accumulator
consul := &Consul{
MetricVersion: 2,
TagDelimiter: ":",
}
consul.GatherHealthCheck(&acc, sampleChecks)
acc.AssertContainsTaggedFields(t, "consul_health_checks", expectedFields, expectedTags)
}