Skip to content

Commit 175686d

Browse files
committed
Use the gocheck binary to run Postgres matrix tests.
1 parent 045ae96 commit 175686d

File tree

5 files changed

+71
-76
lines changed

5 files changed

+71
-76
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ go:
66
- '1.7'
77
# Make sure we have p2
88
before_install:
9-
- wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
10-
chmod +x /usr/local/bin/p2
11-
- wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.9.0-rc4/docker-compose-Linux-x86_64 &&
12-
chmod +x /usr/local/bin/docker-compose
9+
- sudo wget -O /usr/local/bin/p2 https://github.com/wrouesnel/p2cli/releases/download/r4/p2 &&
10+
sudo chmod +x /usr/local/bin/p2
11+
- sudo wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.9.0-rc4/docker-compose-Linux-x86_64 &&
12+
sudo chmod +x /usr/local/bin/docker-compose
1313

1414
script:
1515
- make all

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
3434

3535
### Flags
3636

37-
Name | Description
38-
-------------------|------------
39-
web.listen-address | Address to listen on for web interface and telemetry.
40-
web.telemetry-path | Path under which to expose metrics.
37+
* `web.listen-address`
38+
Address to listen on for web interface and telemetry.
39+
40+
* `web.telemetry-path`
41+
Path under which to expose metrics.
42+
43+
* `config.expect-replication-stats`
44+
The target database has replication turned on - log errors when
45+
replication stats are missing.
4146

4247
### Setting the Postgres server's data source name
4348

postgres_exporter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ var (
3939
"dumpmaps", false,
4040
"Do not run, simply dump the maps.",
4141
)
42+
expectReplicationStats = flag.Bool(
43+
"config.expect-replication-stats", false,
44+
"The target database has replication configured, log missing replication stats as an error.",
45+
)
4246
)
4347

4448
// Metric name parts.

tests/docker-postgres-replication/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM postgres:9.6
1+
FROM postgres:9.2
22
MAINTAINER Daniel Dent (https://www.danieldent.com)
33
ENV PG_MAX_WAL_SENDERS 8
44
ENV PG_WAL_KEEP_SEGMENTS 8

tests/test-smoke

Lines changed: 53 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
1111

1212
# Read the absolute path to the exporter
1313
postgres_exporter=$(readlink -f $1)
14+
test_binary=$(readlink -f $2)
1415
exporter_port=9187
15-
$exporter_port=password
16+
exporter_password=password
1617

1718
cd $DIR
1819

@@ -25,50 +26,61 @@ VERSIONS=( \
2526
9.6 \
2627
)
2728

28-
smoketest_postgres() {
29-
local version=$1
30-
local CONTAINER_NAME=postgres_exporter-test-smoke
31-
local TIMEOUT=30
32-
local IMAGE_NAME=postgres
33-
34-
local CUR_IMAGE=$IMAGE_NAME:$version
35-
36-
echo "Test standalone cluster..."
37-
CONTAINER_NAME=$(docker run -d -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -p 127.0.0.1:55432:5432 $CUR_IMAGE)
38-
39-
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME; exit 1" EXIT INT TERM
40-
29+
wait_for_postgres() {
30+
local CONTAINER_NAME=$1
31+
if [ -z $CONTAINER_NAME ]; then
32+
echo "No container name specified." 1>&2
33+
exit 1
34+
fi
4135
local WAIT_START=$(date +%s)
36+
echo "Waiting for postgres to start..."
4237
while ! docker exec $CONTAINER_NAME bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
43-
echo "Waiting for postgres to start..."
4438
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
4539
echo "Timed out waiting for postgres!" 1>&2
4640
exit 1
4741
fi
4842
sleep 1
49-
done
43+
done
44+
}
5045

51-
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $postgres_exporter &
52-
exporter_pid=$!
53-
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid; exit 1" EXIT INT TERM
46+
wait_for_exporter() {
5447
local DAEMON_WAIT_START=$(date +%s)
48+
echo "Waiting for exporter to start..."
5549
while ! nc -z localhost $exporter_port ; do
56-
echo "Waiting for exporter to start..."
57-
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
50+
if [ $(( $(date +%s) - $DAEMON_WAIT_START )) -gt $TIMEOUT ]; then
5851
echo "Timed out waiting for exporter!" 1>&2
5952
exit 1
6053
fi
6154
sleep 1
6255
done
56+
}
6357

64-
wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
65-
if [ "$?" != "0" ]; then
66-
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
67-
kill $exporter_pid
68-
exit 1
69-
fi
58+
smoketest_postgres() {
59+
local version=$1
60+
local CONTAINER_NAME=postgres_exporter-test-smoke
61+
local TIMEOUT=30
62+
local IMAGE_NAME=postgres
63+
64+
local CUR_IMAGE=$IMAGE_NAME:$version
65+
66+
echo "Test standalone cluster..."
67+
CONTAINER_NAME=$(docker run -d -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -p 127.0.0.1:55432:5432 $CUR_IMAGE)
68+
trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME; exit 1" EXIT INT TERM
69+
wait_for_postgres $CONTAINER_NAME
7070

71-
kill $exporter_pid
71+
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@localhost:55432/?sslmode=disable" $test_binary || exit $?
72+
# exporter_pid=$!
73+
# trap "docker logs $CONTAINER_NAME ; docker kill $CONTAINER_NAME ; docker rm $CONTAINER_NAME ; kill $exporter_pid; exit 1" EXIT INT TERM
74+
# wait_for_exporter
75+
#
76+
# wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
77+
# if [ "$?" != "0" ]; then
78+
# echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
79+
# kill $exporter_pid
80+
# exit 1
81+
# fi
82+
#
83+
# kill $exporter_pid
7284
docker kill $CONTAINER_NAME
7385
docker rm $CONTAINER_NAME
7486
trap - EXIT INT TERM
@@ -88,47 +100,21 @@ smoketest_postgres() {
88100
master_container=$(docker-compose ps -q pg-master)
89101
slave_container=$(docker-compose ps -q pg-slave)
90102
master_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $master_container)
91-
92-
local WAIT_START=$(date +%s)
93-
while ! docker exec $master_container bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
94-
echo "Waiting for postgres master to start..."
95-
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
96-
echo "Timed out waiting for postgres!" 1>&2
97-
exit 1
98-
fi
99-
sleep 1
100-
done
101-
102-
local WAIT_START=$(date +%s)
103-
while ! docker exec $slave_container bash -c "psql -U postgres -c \"select 'running'\" > /dev/null 2>&1 " ; do
104-
echo "Waiting for postgres master to start..."
105-
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
106-
echo "Timed out waiting for postgres!" 1>&2
107-
exit 1
108-
fi
109-
sleep 1
110-
done
103+
wait_for_postgres $master_container
104+
wait_for_postgres $slave_container
111105

112-
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $postgres_exporter &
113-
exporter_pid=$!
114-
trap "docker-compose logs; docker-compose down ; docker-compose rm -v ; kill $exporter_pid; exit 1" EXIT INT TERM
115-
local DAEMON_WAIT_START=$(date +%s)
116-
while ! nc -z localhost $exporter_port ; do
117-
echo "Waiting for exporter to start..."
118-
if [ $(( $(date +%s) - $WAIT_START )) -gt $TIMEOUT ]; then
119-
echo "Timed out waiting for exporter!" 1>&2
120-
exit 1
121-
fi
122-
sleep 1
123-
done
124-
125-
wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
126-
if [ "$?" != "0" ]; then
127-
echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
128-
exit 1
129-
fi
106+
DATA_SOURCE_NAME="postgresql://postgres:$POSTGRES_PASSWORD@$master_ip:5432/?sslmode=disable" $test_binary || exit $?
107+
# exporter_pid=$!
108+
# trap "docker-compose logs; docker-compose down ; docker-compose rm -v ; kill $exporter_pid; exit 1" EXIT INT TERM
109+
# wait_for_exporter
130110

131-
kill $exporter_pid
111+
# wget -q -O - http://localhost:$exporter_port/metrics 1> /dev/null
112+
# if [ "$?" != "0" ]; then
113+
# echo "Failed on postgres $version ($DOCKER_IMAGE)" 1>&2
114+
# exit 1
115+
# fi
116+
#
117+
# kill $exporter_pid
132118

133119
docker-compose down
134120
docker-compose rm -v

0 commit comments

Comments
 (0)