diff --git a/docker-compose.yml b/docker-compose.yml index 6158df16d542f..38c27e56d1dfc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,13 +27,6 @@ services: - xpack.security.enabled=false ports: - "9200:9200" - pgbouncer: - image: z9pascal/pgbouncer-container:1.15-latest - environment: - - PG_ENV_POSTGRESQL_USER=pgbouncer - - PG_ENV_POSTGRESQL_PASS=pgbouncer - ports: - - "6432:6432" postgres: image: postgres:alpine environment: diff --git a/plugins/inputs/pgbouncer/pgbouncer_test.go b/plugins/inputs/pgbouncer/pgbouncer_test.go index 2c9500260078c..0e154bbe90bd7 100644 --- a/plugins/inputs/pgbouncer/pgbouncer_test.go +++ b/plugins/inputs/pgbouncer/pgbouncer_test.go @@ -5,19 +5,52 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/wait" "github.com/influxdata/telegraf/plugins/inputs/postgresql" "github.com/influxdata/telegraf/testutil" ) func TestPgBouncerGeneratesMetricsIntegration(t *testing.T) { - t.Skip("Skipping test, connection refused") + if testing.Short() { + t.Skip("Skipping integration test in short mode") + } + + backend := testutil.Container{ + Image: "postgres:alpine", + ExposedPorts: []string{"5432"}, + Env: map[string]string{ + "POSTGRES_HOST_AUTH_METHOD": "trust", + }, + WaitingFor: wait.ForLog("database system is ready to accept connections"), + } + err := backend.Start() + require.NoError(t, err, "failed to start container") + defer func() { + require.NoError(t, backend.Terminate(), "terminating container failed") + }() + + container := testutil.Container{ + Image: "z9pascal/pgbouncer-container:1.17.0-latest", + ExposedPorts: []string{"6432"}, + Env: map[string]string{ + "PG_ENV_POSTGRESQL_USER": "pgbouncer", + "PG_ENV_POSTGRESQL_PASS": "pgbouncer", + }, + WaitingFor: wait.ForListeningPort("6432"), + } + err = container.Start() + require.NoError(t, err, "failed to start container") + defer func() { + require.NoError(t, container.Terminate(), "terminating container failed") + }() p := &PgBouncer{ Service: postgresql.Service{ Address: fmt.Sprintf( - "host=%s user=pgbouncer password=pgbouncer dbname=pgbouncer port=6432 sslmode=disable", - testutil.GetLocalHost(), + "host=%s user=pgbouncer password=pgbouncer dbname=pgbouncer port=%s sslmode=disable", + container.Address, + container.Port, ), IsPgBouncer: true, },