2016-06-01 10:02:28 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/api"
|
|
|
|
"github.com/influxdata/telegraf/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
var sampleChecks = []*api.HealthCheck{
|
|
|
|
&api.HealthCheck{
|
|
|
|
Node: "localhost",
|
|
|
|
CheckID: "foo.health123",
|
|
|
|
Name: "foo.health",
|
|
|
|
Status: "passing",
|
|
|
|
Notes: "lorem ipsum",
|
|
|
|
Output: "OK",
|
|
|
|
ServiceID: "foo.123",
|
|
|
|
ServiceName: "foo",
|
2018-05-17 21:24:51 +00:00
|
|
|
ServiceTags: []string{"bar", "env:sandbox", "tagkey:value:stillvalue"},
|
2016-06-01 10:02:28 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-10-23 19:31:27 +00:00
|
|
|
func TestGatherHealthCheck(t *testing.T) {
|
2016-06-01 10:02:28 +00:00
|
|
|
expectedFields := map[string]interface{}{
|
|
|
|
"check_name": "foo.health",
|
|
|
|
"status": "passing",
|
2017-01-29 00:47:25 +00:00
|
|
|
"passing": 1,
|
|
|
|
"critical": 0,
|
|
|
|
"warning": 0,
|
2016-06-01 10:02:28 +00:00
|
|
|
"service_id": "foo.123",
|
|
|
|
}
|
|
|
|
|
2018-05-17 21:24:51 +00:00
|
|
|
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",
|
|
|
|
}
|
|
|
|
|
2016-06-01 10:02:28 +00:00
|
|
|
expectedTags := map[string]string{
|
|
|
|
"node": "localhost",
|
|
|
|
"service_name": "foo",
|
2016-12-20 13:03:31 +00:00
|
|
|
"check_id": "foo.health123",
|
2018-05-17 21:24:51 +00:00
|
|
|
"bar": "bar",
|
|
|
|
"env": "sandbox",
|
|
|
|
"tagkey": "value:stillvalue",
|
2016-06-01 10:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
2018-05-17 21:24:51 +00:00
|
|
|
consul := &Consul{
|
|
|
|
TagDelimiter: ":",
|
|
|
|
}
|
2016-06-01 10:02:28 +00:00
|
|
|
consul.GatherHealthCheck(&acc, sampleChecks)
|
|
|
|
|
|
|
|
acc.AssertContainsTaggedFields(t, "consul_health_checks", expectedFields, expectedTags)
|
|
|
|
}
|