mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-11 03:31:26 +00:00
Add docker-compose and replication environment tests to the smoke-tests.
Use docker-compose and p2 to setup a replicated environment for each version of PostgreSQL we want to support. Still missing: key-specific tests to ensure each version doesn't lose metrics.
This commit is contained in:
parent
f554139279
commit
53ad0efbbb
4
Makefile
4
Makefile
@ -19,8 +19,8 @@ vet:
|
|||||||
test:
|
test:
|
||||||
go test -v .
|
go test -v .
|
||||||
|
|
||||||
test-integration:
|
test-integration: postgres_exporter
|
||||||
tests/test-smoke
|
tests/test-smoke ./postgres_exporter
|
||||||
|
|
||||||
# Do a self-contained docker build - we pull the official upstream container
|
# Do a self-contained docker build - we pull the official upstream container
|
||||||
# and do a self-contained build.
|
# and do a self-contained build.
|
||||||
|
7
tests/docker-postgres-replication/Dockerfile
Executable file
7
tests/docker-postgres-replication/Dockerfile
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
FROM postgres:9.6
|
||||||
|
MAINTAINER Daniel Dent (https://www.danieldent.com)
|
||||||
|
ENV PG_MAX_WAL_SENDERS 8
|
||||||
|
ENV PG_WAL_KEEP_SEGMENTS 8
|
||||||
|
COPY setup-replication.sh /docker-entrypoint-initdb.d/
|
||||||
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
RUN chmod +x /docker-entrypoint-initdb.d/setup-replication.sh /docker-entrypoint.sh
|
@ -9,6 +9,11 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
|
|||||||
done
|
done
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
|
|
||||||
|
# Read the absolute path to the exporter
|
||||||
|
postgres_exporter=$(readlink -f $1)
|
||||||
|
exporter_port=9187
|
||||||
|
$exporter_port=password
|
||||||
|
|
||||||
cd $DIR
|
cd $DIR
|
||||||
|
|
||||||
VERSIONS=( \
|
VERSIONS=( \
|
||||||
@ -29,9 +34,9 @@ smoketest_postgres() {
|
|||||||
local CUR_IMAGE=$IMAGE_NAME:$version
|
local CUR_IMAGE=$IMAGE_NAME:$version
|
||||||
|
|
||||||
echo "Test standalone cluster..."
|
echo "Test standalone cluster..."
|
||||||
docker run -d --name=$CONTAINER_NAME -e POSTGRES_PASSWORD=password -p 127.0.0.1:55432:5432 $CUR_IMAGE
|
CONTAINER_NAME=$(docker run -d -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -p 127.0.0.1:55432:5432 $CUR_IMAGE)
|
||||||
|
|
||||||
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME" EXIT INT TERM
|
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME; exit 1" EXIT INT TERM
|
||||||
|
|
||||||
local WAIT_START=$(date +%s)
|
local WAIT_START=$(date +%s)
|
||||||
while ! docker exec $CONTAINER_NAME bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
while ! docker exec $CONTAINER_NAME bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
||||||
@ -43,11 +48,11 @@ smoketest_postgres() {
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
DATA_SOURCE_NAME="postgresql://postgres:password@localhost:55432/?sslmode=disable" ./postgres_exporter &
|
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $postgres_exporter &
|
||||||
exporter_pid=$!
|
exporter_pid=$!
|
||||||
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid" EXIT INT TERM
|
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid; exit 1" EXIT INT TERM
|
||||||
local DAEMON_WAIT_START=$(date +%s)
|
local DAEMON_WAIT_START=$(date +%s)
|
||||||
while ! nc -z localhost 9113 ; do
|
while ! nc -z localhost $exporter_port ; do
|
||||||
echo "Waiting for exporter to start..."
|
echo "Waiting for exporter to start..."
|
||||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
||||||
echo "Timed out waiting for exporter!" 1>&2
|
echo "Timed out waiting for exporter!" 1>&2
|
||||||
@ -56,7 +61,7 @@ smoketest_postgres() {
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
wget -q -O - http://localhost:9113/metrics 1> /dev/null
|
wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
|
||||||
if [ "$?" != "0" ]; then
|
if [ "$?" != "0" ]; then
|
||||||
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
||||||
kill $exporter_pid
|
kill $exporter_pid
|
||||||
@ -69,7 +74,6 @@ smoketest_postgres() {
|
|||||||
trap - EXIT INT TERM
|
trap - EXIT INT TERM
|
||||||
|
|
||||||
echo "Test replicated cluster..."
|
echo "Test replicated cluster..."
|
||||||
postgres_exporter=$(readlink -f ./postgres_exporter)
|
|
||||||
old_pwd=$(pwd)
|
old_pwd=$(pwd)
|
||||||
cd docker-postgres-replication
|
cd docker-postgres-replication
|
||||||
|
|
||||||
@ -78,8 +82,8 @@ smoketest_postgres() {
|
|||||||
echo "Templating failed" 1>&2
|
echo "Templating failed" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
trap "docker-compose logs; docker-compose down ; docker-compose rm -v" EXIT INT TERM
|
trap "docker-compose logs; docker-compose down ; docker-compose rm -v; exit 1" EXIT INT TERM
|
||||||
docker-compose up -d --force-recreate --build
|
POSTGRES_PASSWORD=$POSTGRES_PASSWORD docker-compose up -d --force-recreate --build
|
||||||
|
|
||||||
master_container=$(docker-compose ps -q pg-master)
|
master_container=$(docker-compose ps -q pg-master)
|
||||||
slave_container=$(docker-compose ps -q pg-slave)
|
slave_container=$(docker-compose ps -q pg-slave)
|
||||||
@ -105,11 +109,11 @@ smoketest_postgres() {
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
DATA_SOURCE_NAME="postgresql://postgres:password@$master_ip:5432/?sslmode=disable" $postgres_exporter &
|
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $postgres_exporter &
|
||||||
exporter_pid=$!
|
exporter_pid=$!
|
||||||
trap "docker-compose logs; docker-compose down ; docker-compose rm -v ; kill $exporter_pid" EXIT INT TERM
|
trap "docker-compose logs; docker-compose down ; docker-compose rm -v ; kill $exporter_pid; exit 1" EXIT INT TERM
|
||||||
local DAEMON_WAIT_START=$(date +%s)
|
local DAEMON_WAIT_START=$(date +%s)
|
||||||
while ! nc -z localhost 9113 ; do
|
while ! nc -z localhost $exporter_port ; do
|
||||||
echo "Waiting for exporter to start..."
|
echo "Waiting for exporter to start..."
|
||||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
||||||
echo "Timed out waiting for exporter!" 1>&2
|
echo "Timed out waiting for exporter!" 1>&2
|
||||||
@ -118,7 +122,7 @@ smoketest_postgres() {
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
wget -q -O - http://localhost:9113/metrics 1> /dev/null
|
wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
|
||||||
if [ "$?" != "0" ]; then
|
if [ "$?" != "0" ]; then
|
||||||
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user