2015-10-22 16:17:57 +00:00
|
|
|
package prometheus_client
|
|
|
|
|
|
|
|
import (
|
2015-10-28 22:19:13 +00:00
|
|
|
"testing"
|
|
|
|
|
2016-01-07 17:52:46 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2016-01-23 00:45:31 +00:00
|
|
|
"github.com/influxdb/influxdb/client/v2"
|
|
|
|
"github.com/influxdb/telegraf/plugins/inputs/prometheus"
|
|
|
|
"github.com/influxdb/telegraf/testutil"
|
2015-10-22 16:17:57 +00:00
|
|
|
)
|
|
|
|
|
2015-10-28 22:19:13 +00:00
|
|
|
var pTesting *PrometheusClient
|
2015-10-22 16:17:57 +00:00
|
|
|
|
|
|
|
func TestPrometheusWritePointEmptyTag(t *testing.T) {
|
2015-12-01 16:45:25 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
2015-10-28 22:19:13 +00:00
|
|
|
|
2015-10-22 16:17:57 +00:00
|
|
|
p := &prometheus.Prometheus{
|
2015-10-28 22:19:13 +00:00
|
|
|
Urls: []string{"http://localhost:9126/metrics"},
|
2015-10-22 16:17:57 +00:00
|
|
|
}
|
|
|
|
tags := make(map[string]string)
|
2015-11-11 00:05:28 +00:00
|
|
|
pt1, _ := client.NewPoint(
|
|
|
|
"test_point_1",
|
|
|
|
tags,
|
|
|
|
map[string]interface{}{"value": 0.0})
|
|
|
|
pt2, _ := client.NewPoint(
|
|
|
|
"test_point_2",
|
|
|
|
tags,
|
|
|
|
map[string]interface{}{"value": 1.0})
|
2015-10-22 16:17:57 +00:00
|
|
|
var points = []*client.Point{
|
2015-11-11 00:05:28 +00:00
|
|
|
pt1,
|
|
|
|
pt2,
|
2015-10-22 16:17:57 +00:00
|
|
|
}
|
|
|
|
require.NoError(t, pTesting.Write(points))
|
|
|
|
|
|
|
|
expected := []struct {
|
|
|
|
name string
|
|
|
|
value float64
|
|
|
|
tags map[string]string
|
|
|
|
}{
|
|
|
|
{"test_point_1", 0.0, tags},
|
|
|
|
{"test_point_2", 1.0, tags},
|
|
|
|
}
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
require.NoError(t, p.Gather(&acc))
|
|
|
|
for _, e := range expected {
|
2016-01-07 17:52:46 +00:00
|
|
|
acc.AssertContainsFields(t, "prometheus_"+e.name,
|
|
|
|
map[string]interface{}{"value": e.value})
|
2015-10-22 16:17:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrometheusWritePointTag(t *testing.T) {
|
2015-12-01 16:45:25 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
}
|
2015-10-28 22:19:13 +00:00
|
|
|
|
2015-10-22 16:17:57 +00:00
|
|
|
p := &prometheus.Prometheus{
|
2015-10-28 22:19:13 +00:00
|
|
|
Urls: []string{"http://localhost:9126/metrics"},
|
2015-10-22 16:17:57 +00:00
|
|
|
}
|
|
|
|
tags := make(map[string]string)
|
|
|
|
tags["testtag"] = "testvalue"
|
2015-11-11 00:05:28 +00:00
|
|
|
pt1, _ := client.NewPoint(
|
|
|
|
"test_point_3",
|
|
|
|
tags,
|
|
|
|
map[string]interface{}{"value": 0.0})
|
|
|
|
pt2, _ := client.NewPoint(
|
|
|
|
"test_point_4",
|
|
|
|
tags,
|
|
|
|
map[string]interface{}{"value": 1.0})
|
2015-10-22 16:17:57 +00:00
|
|
|
var points = []*client.Point{
|
2015-11-11 00:05:28 +00:00
|
|
|
pt1,
|
|
|
|
pt2,
|
2015-10-22 16:17:57 +00:00
|
|
|
}
|
|
|
|
require.NoError(t, pTesting.Write(points))
|
|
|
|
|
|
|
|
expected := []struct {
|
|
|
|
name string
|
|
|
|
value float64
|
|
|
|
}{
|
|
|
|
{"test_point_3", 0.0},
|
|
|
|
{"test_point_4", 1.0},
|
|
|
|
}
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
require.NoError(t, p.Gather(&acc))
|
|
|
|
for _, e := range expected {
|
2016-01-07 17:52:46 +00:00
|
|
|
acc.AssertContainsFields(t, "prometheus_"+e.name,
|
|
|
|
map[string]interface{}{"value": e.value})
|
2015-10-22 16:17:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-28 22:19:13 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
pTesting = &PrometheusClient{Listen: "localhost:9126"}
|
|
|
|
pTesting.Start()
|
|
|
|
}
|