2015-10-14 07:15:39 +08:00
|
|
|
package zookeeper
|
|
|
|
|
|
|
|
|
|
import (
|
2022-05-26 03:51:38 +08:00
|
|
|
"fmt"
|
2015-10-14 07:15:39 +08:00
|
|
|
"testing"
|
|
|
|
|
|
2022-05-28 00:24:31 +08:00
|
|
|
"github.com/docker/go-connections/nat"
|
2015-10-14 07:15:39 +08:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-05-26 03:51:38 +08:00
|
|
|
"github.com/testcontainers/testcontainers-go/wait"
|
2021-11-18 22:22:43 +08:00
|
|
|
|
|
|
|
|
"github.com/influxdata/telegraf/testutil"
|
2015-10-14 07:15:39 +08:00
|
|
|
)
|
|
|
|
|
|
2021-01-27 02:06:12 +08:00
|
|
|
func TestZookeeperGeneratesMetricsIntegration(t *testing.T) {
|
2015-10-14 07:15:39 +08:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping integration test in short mode")
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-28 00:24:31 +08:00
|
|
|
servicePort := "2181"
|
2022-05-26 03:51:38 +08:00
|
|
|
container := testutil.Container{
|
|
|
|
|
Image: "zookeeper",
|
2022-05-28 00:24:31 +08:00
|
|
|
ExposedPorts: []string{servicePort},
|
2022-05-26 03:51:38 +08:00
|
|
|
Env: map[string]string{
|
|
|
|
|
"ZOO_4LW_COMMANDS_WHITELIST": "mntr",
|
|
|
|
|
},
|
2022-06-04 00:29:08 +08:00
|
|
|
WaitingFor: wait.ForAll(
|
|
|
|
|
wait.ForListeningPort(nat.Port(servicePort)),
|
|
|
|
|
wait.ForLog("ZooKeeper audit is disabled."),
|
|
|
|
|
),
|
2022-05-26 03:51:38 +08:00
|
|
|
}
|
|
|
|
|
err := container.Start()
|
|
|
|
|
require.NoError(t, err, "failed to start container")
|
|
|
|
|
defer func() {
|
|
|
|
|
require.NoError(t, container.Terminate(), "terminating container failed")
|
|
|
|
|
}()
|
|
|
|
|
|
2015-10-14 07:15:39 +08:00
|
|
|
z := &Zookeeper{
|
2022-05-26 03:51:38 +08:00
|
|
|
Servers: []string{
|
2022-05-28 00:24:31 +08:00
|
|
|
fmt.Sprintf("%s:%s", container.Address, container.Ports[servicePort]),
|
2022-05-26 03:51:38 +08:00
|
|
|
},
|
2015-10-14 07:15:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
2017-04-25 02:13:26 +08:00
|
|
|
require.NoError(t, acc.GatherError(z.Gather))
|
2015-10-14 07:15:39 +08:00
|
|
|
|
2015-10-17 06:13:32 +08:00
|
|
|
intMetrics := []string{
|
|
|
|
|
"max_latency",
|
|
|
|
|
"min_latency",
|
|
|
|
|
"packets_received",
|
|
|
|
|
"packets_sent",
|
|
|
|
|
"outstanding_requests",
|
|
|
|
|
"znode_count",
|
|
|
|
|
"watch_count",
|
|
|
|
|
"ephemerals_count",
|
|
|
|
|
"approximate_data_size",
|
|
|
|
|
"open_file_descriptor_count",
|
|
|
|
|
"max_file_descriptor_count",
|
|
|
|
|
}
|
2015-10-14 07:15:39 +08:00
|
|
|
|
|
|
|
|
for _, metric := range intMetrics {
|
2021-11-18 22:22:43 +08:00
|
|
|
require.True(t, acc.HasInt64Field("zookeeper", metric), metric)
|
2015-10-14 07:15:39 +08:00
|
|
|
}
|
2022-05-26 03:51:38 +08:00
|
|
|
|
|
|
|
|
// Currently we output floats as strings (see #8863), but the desired behavior is to have floats
|
|
|
|
|
require.True(t, acc.HasStringField("zookeeper", "avg_latency"), "avg_latency")
|
|
|
|
|
// require.True(t, acc.HasFloat64Field("zookeeper", "avg_latency"), "avg_latency")
|
2015-10-14 07:15:39 +08:00
|
|
|
}
|