mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-23 07:25:28 +00:00
Use the gocheck binary to run Postgres matrix tests.
This commit is contained in:
parent
045ae96430
commit
175686dc0f
@ -6,10 +6,10 @@ go:
|
|||||||
- '1.7'
|
- '1.7'
|
||||||
# Make sure we have p2
|
# Make sure we have p2
|
||||||
before_install:
|
before_install:
|
||||||
- wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
|
- sudo wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
|
||||||
chmod +x /usr/local/bin/p2
|
sudo chmod +x /usr/local/bin/p2
|
||||||
- wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.9.0-rc4/docker-compose-Linux-x86_64 &&
|
- sudo wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.9.0-rc4/docker-compose-Linux-x86_64 &&
|
||||||
chmod +x /usr/local/bin/docker-compose
|
sudo chmod +x /usr/local/bin/docker-compose
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- make all
|
- make all
|
||||||
|
13
README.md
13
README.md
@ -34,10 +34,15 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
|
|||||||
|
|
||||||
### Flags
|
### Flags
|
||||||
|
|
||||||
Name | Description
|
* `web.listen-address`
|
||||||
-------------------|------------
|
Address to listen on for web interface and telemetry.
|
||||||
web.listen-address | Address to listen on for web interface and telemetry.
|
|
||||||
web.telemetry-path | Path under which to expose metrics.
|
* `web.telemetry-path`
|
||||||
|
Path under which to expose metrics.
|
||||||
|
|
||||||
|
* `config.expect-replication-stats`
|
||||||
|
The target database has replication turned on - log errors when
|
||||||
|
replication stats are missing.
|
||||||
|
|
||||||
### Setting the Postgres server's data source name
|
### Setting the Postgres server's data source name
|
||||||
|
|
||||||
|
@ -39,6 +39,10 @@ var (
|
|||||||
"dumpmaps", false,
|
"dumpmaps", false,
|
||||||
"Do not run, simply dump the maps.",
|
"Do not run, simply dump the maps.",
|
||||||
)
|
)
|
||||||
|
expectReplicationStats = flag.Bool(
|
||||||
|
"config.expect-replication-stats", false,
|
||||||
|
"The target database has replication configured, log missing replication stats as an error.",
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Metric name parts.
|
// Metric name parts.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM postgres:9.6
|
FROM postgres:9.2
|
||||||
MAINTAINER Daniel Dent (https://www.danieldent.com)
|
MAINTAINER Daniel Dent (https://www.danieldent.com)
|
||||||
ENV PG_MAX_WAL_SENDERS 8
|
ENV PG_MAX_WAL_SENDERS 8
|
||||||
ENV PG_WAL_KEEP_SEGMENTS 8
|
ENV PG_WAL_KEEP_SEGMENTS 8
|
||||||
|
130
tests/test-smoke
130
tests/test-smoke
@ -11,8 +11,9 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|||||||
|
|
||||||
# Read the absolute path to the exporter
|
# Read the absolute path to the exporter
|
||||||
postgres_exporter=$(readlink -f $1)
|
postgres_exporter=$(readlink -f $1)
|
||||||
|
test_binary=$(readlink -f $2)
|
||||||
exporter_port=9187
|
exporter_port=9187
|
||||||
$exporter_port=password
|
exporter_password=password
|
||||||
|
|
||||||
cd $DIR
|
cd $DIR
|
||||||
|
|
||||||
@ -25,6 +26,35 @@ VERSIONS=( \
|
|||||||
9.6 \
|
9.6 \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
wait_for_postgres() {
|
||||||
|
local CONTAINER_NAME=$1
|
||||||
|
if [ -z $CONTAINER_NAME ]; then
|
||||||
|
echo "No container name specified." 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
local WAIT_START=$(date +%s)
|
||||||
|
echo "Waiting for postgres to start..."
|
||||||
|
while ! docker exec $CONTAINER_NAME bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
||||||
|
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
||||||
|
echo "Timed out waiting for postgres!" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for_exporter() {
|
||||||
|
local DAEMON_WAIT_START=$(date +%s)
|
||||||
|
echo "Waiting for exporter to start..."
|
||||||
|
while ! nc -z localhost $exporter_port ; do
|
||||||
|
if [ $(( $(date +%s) - $DAEMON_WAIT_START )) -gt $TIMEOUT ]; then
|
||||||
|
echo "Timed out waiting for exporter!" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
smoketest_postgres() {
|
smoketest_postgres() {
|
||||||
local version=$1
|
local version=$1
|
||||||
local CONTAINER_NAME=postgres_exporter-test-smoke
|
local CONTAINER_NAME=postgres_exporter-test-smoke
|
||||||
@ -35,40 +65,22 @@ smoketest_postgres() {
|
|||||||
|
|
||||||
echo "Test standalone cluster..."
|
echo "Test standalone cluster..."
|
||||||
CONTAINER_NAME=$(docker run -d -e POSTGRES_PASSWORD=$POSTGRES_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 1" EXIT INT TERM
|
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME; exit 1" EXIT INT TERM
|
||||||
|
wait_for_postgres $CONTAINER_NAME
|
||||||
|
|
||||||
local WAIT_START=$(date +%s)
|
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $test_binary || exit $?
|
||||||
while ! docker exec $CONTAINER_NAME bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
# exporter_pid=$!
|
||||||
echo "Waiting for postgres to start..."
|
# trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid; exit 1" EXIT INT TERM
|
||||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
# wait_for_exporter
|
||||||
echo "Timed out waiting for postgres!" 1>&2
|
#
|
||||||
exit 1
|
# wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
|
||||||
fi
|
# if [ "$?" != "0" ]; then
|
||||||
sleep 1
|
# echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
||||||
done
|
# kill $exporter_pid
|
||||||
|
# exit 1
|
||||||
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $postgres_exporter &
|
# fi
|
||||||
exporter_pid=$!
|
#
|
||||||
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid; exit 1" EXIT INT TERM
|
# kill $exporter_pid
|
||||||
local DAEMON_WAIT_START=$(date +%s)
|
|
||||||
while ! nc -z localhost $exporter_port ; do
|
|
||||||
echo "Waiting for exporter to start..."
|
|
||||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
|
||||||
echo "Timed out waiting for exporter!" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
|
|
||||||
if [ "$?" != "0" ]; then
|
|
||||||
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
|
||||||
kill $exporter_pid
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
kill $exporter_pid
|
|
||||||
docker kill $CONTAINER_NAME
|
docker kill $CONTAINER_NAME
|
||||||
docker rm $CONTAINER_NAME
|
docker rm $CONTAINER_NAME
|
||||||
trap - EXIT INT TERM
|
trap - EXIT INT TERM
|
||||||
@ -88,47 +100,21 @@ smoketest_postgres() {
|
|||||||
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)
|
||||||
master_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $master_container)
|
master_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $master_container)
|
||||||
|
wait_for_postgres $master_container
|
||||||
|
wait_for_postgres $slave_container
|
||||||
|
|
||||||
local WAIT_START=$(date +%s)
|
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $test_binary || exit $?
|
||||||
while ! docker exec $master_container bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
# exporter_pid=$!
|
||||||
echo "Waiting for postgres master to start..."
|
# trap "docker-compose logs; docker-compose down ; docker-compose rm -v ; kill $exporter_pid; exit 1" EXIT INT TERM
|
||||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
# wait_for_exporter
|
||||||
echo "Timed out waiting for postgres!" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
local WAIT_START=$(date +%s)
|
# wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
|
||||||
while ! docker exec $slave_container bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
# if [ "$?" != "0" ]; then
|
||||||
echo "Waiting for postgres master to start..."
|
# echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
||||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
# exit 1
|
||||||
echo "Timed out waiting for postgres!" 1>&2
|
# fi
|
||||||
exit 1
|
#
|
||||||
fi
|
# kill $exporter_pid
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $postgres_exporter &
|
|
||||||
exporter_pid=$!
|
|
||||||
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)
|
|
||||||
while ! nc -z localhost $exporter_port ; do
|
|
||||||
echo "Waiting for exporter to start..."
|
|
||||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
|
||||||
echo "Timed out waiting for exporter!" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
|
|
||||||
if [ "$?" != "0" ]; then
|
|
||||||
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
kill $exporter_pid
|
|
||||||
|
|
||||||
docker-compose down
|
docker-compose down
|
||||||
docker-compose rm -v
|
docker-compose rm -v
|
||||||
|
Loading…
Reference in New Issue
Block a user