You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-08-09 15:42:47 +03:00
Improve support code quality.
This commit is contained in:
@@ -88,7 +88,7 @@ if [ "$1" = 'postgres' ]; then
|
||||
: ${POSTGRES_DB:=$POSTGRES_USER}
|
||||
export POSTGRES_USER POSTGRES_DB
|
||||
|
||||
psql=( psql -v ON_ERROR_STOP=1 )
|
||||
psql=( "psql" "-v" "ON_ERROR_STOP=1" )
|
||||
|
||||
if [ "$POSTGRES_DB" != 'postgres' ]; then
|
||||
"${psql[@]}" --username postgres <<-EOSQL
|
||||
|
@@ -23,7 +23,7 @@ echo "Test Binary: $test_binary" 1>&2
|
||||
[ -z "$postgres_exporter" ] && echo "Missing exporter binary" && exit 1
|
||||
[ -z "$test_binary" ] && echo "Missing test binary" && exit 1
|
||||
|
||||
cd $DIR
|
||||
cd "$DIR" || exit 1
|
||||
|
||||
VERSIONS=( \
|
||||
9.1 \
|
||||
@@ -48,7 +48,8 @@ wait_for_postgres(){
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local wait_start=$(date +%s)
|
||||
local wait_start
|
||||
wait_start=$(date +%s) || exit 1
|
||||
echo "Waiting for postgres to start listening..."
|
||||
while ! pg_isready --host=$ip --port=$port &> /dev/null; do
|
||||
if [ $(( $(date +%s) - $wait_start )) -gt $TIMEOUT ]; then
|
||||
@@ -60,7 +61,8 @@ wait_for_postgres(){
|
||||
}
|
||||
|
||||
wait_for_exporter() {
|
||||
local wait_start=$(date +%s)
|
||||
local wait_start
|
||||
wait_start=$(date +%s) || exit 1
|
||||
echo "Waiting for exporter to start..."
|
||||
while ! nc -z localhost $exporter_port ; do
|
||||
if [ $(( $(date +%s) - $wait_start )) -gt $TIMEOUT ]; then
|
||||
@@ -101,8 +103,7 @@ smoketest_postgres() {
|
||||
wait_for_exporter
|
||||
|
||||
# Dump the metrics to a file.
|
||||
wget -q -O - http://localhost:$exporter_port/metrics 1> $METRICS_DIR/.metrics.single.$version.prom
|
||||
if [ "$?" != "0" ]; then
|
||||
if wget -q -O - http://localhost:$exporter_port/metrics 1> "$METRICS_DIR/.metrics.single.$version.prom" ; then
|
||||
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
||||
kill $exporter_pid
|
||||
exit 1
|
||||
@@ -124,35 +125,34 @@ smoketest_postgres() {
|
||||
echo "Replicated Postgres $version"
|
||||
echo "#######################"
|
||||
old_pwd=$(pwd)
|
||||
cd docker-postgres-replication
|
||||
cd docker-postgres-replication || exit 1
|
||||
|
||||
VERSION=$version p2 -t Dockerfile.p2 -o Dockerfile
|
||||
if [ "$?" != "0" ]; then
|
||||
if VERSION="$version" p2 -t Dockerfile.p2 -o Dockerfile ; then
|
||||
echo "Templating failed" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
trap "docker-compose logs; docker-compose down ; docker-compose rm -v; exit 1" EXIT INT TERM
|
||||
local compose_cmd="POSTGRES_PASSWORD=$POSTGRES_PASSWORD docker-compose up -d --force-recreate --build"
|
||||
echo "Compose Cmd: $compose_cmd"
|
||||
eval $compose_cmd
|
||||
eval "$compose_cmd"
|
||||
|
||||
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)
|
||||
slave_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $slave_container)
|
||||
master_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$master_container")
|
||||
slave_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$slave_container")
|
||||
echo "Got master IP: $master_ip"
|
||||
wait_for_postgres $master_ip 5432
|
||||
wait_for_postgres $slave_ip 5432
|
||||
wait_for_postgres "$master_ip" 5432
|
||||
wait_for_postgres "$slave_ip" 5432
|
||||
|
||||
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $test_binary || exit $?
|
||||
|
||||
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $postgres_exporter --log.level=debug --web.listen-address=:$exporter_port &
|
||||
exporter_pid=$!
|
||||
# shellcheck disable=SC2064
|
||||
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> $METRICS_DIR/.metrics.replicated.$version.prom
|
||||
if [ "$?" != "0" ]; then
|
||||
if wget -q -O - http://localhost:$exporter_port/metrics 1> "$METRICS_DIR/.metrics.replicated.$version.prom" ; then
|
||||
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -162,15 +162,15 @@ smoketest_postgres() {
|
||||
docker-compose rm -v
|
||||
trap - EXIT INT TERM
|
||||
|
||||
cd $old_pwd
|
||||
cd "$old_pwd" || exit 1
|
||||
}
|
||||
|
||||
# Start pulling the docker images in advance
|
||||
for version in ${VERSIONS[@]}; do
|
||||
docker pull postgres:$version > /dev/null &
|
||||
for version in "${VERSIONS[@]}"; do
|
||||
docker pull "postgres:$version" > /dev/null &
|
||||
done
|
||||
|
||||
for version in ${VERSIONS[@]}; do
|
||||
for version in "${VERSIONS[@]}"; do
|
||||
echo "Testing postgres version $version"
|
||||
smoketest_postgres $version
|
||||
smoketest_postgres "$version"
|
||||
done
|
||||
|
Reference in New Issue
Block a user