mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-08 10:11:26 +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'
|
||||
# Make sure we have p2
|
||||
before_install:
|
||||
- wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
|
||||
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 &&
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
- sudo wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
|
||||
sudo chmod +x /usr/local/bin/p2
|
||||
- sudo wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.9.0-rc4/docker-compose-Linux-x86_64 &&
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
script:
|
||||
- make all
|
||||
|
13
README.md
13
README.md
@ -34,10 +34,15 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
|
||||
|
||||
### Flags
|
||||
|
||||
Name | Description
|
||||
-------------------|------------
|
||||
web.listen-address | Address to listen on for web interface and telemetry.
|
||||
web.telemetry-path | Path under which to expose metrics.
|
||||
* `web.listen-address`
|
||||
Address to listen on for web interface and telemetry.
|
||||
|
||||
* `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
|
||||
|
||||
|
@ -39,6 +39,10 @@ var (
|
||||
"dumpmaps", false,
|
||||
"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.
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM postgres:9.6
|
||||
FROM postgres:9.2
|
||||
MAINTAINER Daniel Dent (https://www.danieldent.com)
|
||||
ENV PG_MAX_WAL_SENDERS 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
|
||||
postgres_exporter=$(readlink -f $1)
|
||||
test_binary=$(readlink -f $2)
|
||||
exporter_port=9187
|
||||
$exporter_port=password
|
||||
exporter_password=password
|
||||
|
||||
cd $DIR
|
||||
|
||||
@ -25,6 +26,35 @@ VERSIONS=( \
|
||||
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() {
|
||||
local version=$1
|
||||
local CONTAINER_NAME=postgres_exporter-test-smoke
|
||||
@ -35,40 +65,22 @@ smoketest_postgres() {
|
||||
|
||||
echo "Test standalone cluster..."
|
||||
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
|
||||
wait_for_postgres $CONTAINER_NAME
|
||||
|
||||
local WAIT_START=$(date +%s)
|
||||
while ! docker exec $CONTAINER_NAME bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
||||
echo "Waiting for postgres to start..."
|
||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
||||
echo "Timed out waiting for postgres!" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $postgres_exporter &
|
||||
exporter_pid=$!
|
||||
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)
|
||||
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
|
||||
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $test_binary || exit $?
|
||||
# exporter_pid=$!
|
||||
# trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid; exit 1" EXIT INT TERM
|
||||
# wait_for_exporter
|
||||
#
|
||||
# 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 rm $CONTAINER_NAME
|
||||
trap - EXIT INT TERM
|
||||
@ -88,47 +100,21 @@ smoketest_postgres() {
|
||||
master_container=$(docker-compose ps -q pg-master)
|
||||
slave_container=$(docker-compose ps -q pg-slave)
|
||||
master_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $master_container)
|
||||
|
||||
local WAIT_START=$(date +%s)
|
||||
while ! docker exec $master_container bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
||||
echo "Waiting for postgres master to start..."
|
||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
||||
echo "Timed out waiting for postgres!" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
wait_for_postgres $master_container
|
||||
wait_for_postgres $slave_container
|
||||
|
||||
local WAIT_START=$(date +%s)
|
||||
while ! docker exec $slave_container bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
|
||||
echo "Waiting for postgres master to start..."
|
||||
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
|
||||
echo "Timed out waiting for postgres!" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $test_binary || exit $?
|
||||
# exporter_pid=$!
|
||||
# trap "docker-compose logs; docker-compose down ; docker-compose rm -v ; kill $exporter_pid; exit 1" EXIT INT TERM
|
||||
# wait_for_exporter
|
||||
|
||||
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
|
||||
# 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 rm -v
|
||||
|
Loading…
Reference in New Issue
Block a user