Skip to content

Commit 56c3e24

Browse files
authored
Enable use of pg_stat_statement extension in local docker-compose and CI pipeline (#510)
For testing support in #300 Note, do to lack of support for adjusting CMD args in service container launching (actions/runner#2139), we basically have to manage starting the container via `docker compose` ourselves. Luckily there are scripts for that already, and this way the CI environment should match the local dev experience as well.
1 parent aac5c87 commit 56c3e24

File tree

4 files changed

+68
-17
lines changed

4 files changed

+68
-17
lines changed

.github/workflows/maven.yml

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ jobs:
8686
name: benchbase-${{matrix.profile}}
8787
path: target/benchbase-${{matrix.profile}}.tgz
8888

89+
# Needed for running a customized service containers using docker/*/up.sh scripts.
90+
# See postgres example below.
91+
# https://github.com/actions/runner/issues/2139
92+
- name: Package docker-compose configs
93+
if: ${{ matrix.profile == 'postgres' }}
94+
run: |
95+
tar czvpf docker-compose-${{matrix.profile}}.tar.gz docker/${{matrix.profile}}-latest
96+
97+
- name: Upload docker-compose configs
98+
if: ${{ matrix.profile == 'postgres' }}
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: docker-compose-${{matrix.profile}}
102+
path: docker-compose-${{matrix.profile}}.tar.gz
103+
89104
## ----------------------------------------------------------------------------------
90105
## SQLITE
91106
## ----------------------------------------------------------------------------------
@@ -406,21 +421,25 @@ jobs:
406421
fail-fast: false
407422
matrix:
408423
benchmark: [ 'auctionmark', 'epinions', 'hyadapt', 'noop', 'otmetrics', 'resourcestresser', 'seats', 'sibench', 'smallbank', 'tatp', 'templated', 'tpcc', 'tpcc-with-reconnects', 'tpch', 'twitter', 'voter', 'wikipedia', 'ycsb' ]
409-
services:
410-
postgres: # https://hub.docker.com/_/postgres
411-
image: postgres:latest
412-
env:
413-
POSTGRES_DB: benchbase
414-
POSTGRES_USER: admin
415-
POSTGRES_PASSWORD: password
416-
options: >-
417-
--health-cmd pg_isready
418-
--health-interval 10s
419-
--health-timeout 5s
420-
--health-retries 5
421-
ports:
422-
- 5432:5432
423424
steps:
425+
# Note: we download just the docker-compose scripts/configs rather than the
426+
# whole source code repo for better testing.
427+
- name: Download artifact
428+
uses: actions/download-artifact@v4
429+
with:
430+
name: docker-compose-postgres
431+
432+
- name: Extract docker-compose artifacts
433+
run: |
434+
tar xvzf docker-compose-postgres.tar.gz
435+
436+
# Use docker-compose to start the postgres service so we can modify the
437+
# command line args to include extensions.
438+
# https://github.com/actions/runner/issues/2139
439+
- name: Start custom postgres service
440+
run: |
441+
./docker/postgres-latest/up.sh --quiet-pull postgres
442+
424443
- name: Download artifact
425444
uses: actions/download-artifact@v4
426445
with:
@@ -472,6 +491,10 @@ jobs:
472491
./scripts/check_latest_benchmark_results.sh $results_benchmark
473492
./scripts/check_histogram_results.sh results/histograms.json $ERRORS_THRESHOLD
474493
494+
- name: Stop custom postgres service
495+
run: |
496+
./docker/postgres-latest/down.sh
497+
475498
## ----------------------------------------------------------------------------------
476499
## COCKROACHDB
477500
## ----------------------------------------------------------------------------------

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ build/
5555
# vim swap files
5656
.*.swp
5757

58-
.env
58+
.env
59+
60+
docker-compose-*.tar.gz

docker/postgres-latest/docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ services:
66
container_name: postgres
77
hostname: postgres
88
image: postgres:alpine
9-
command: postgres -N 500
9+
command: postgres -N 500 -c shared_preload_libraries=pg_stat_statements
1010
environment:
1111
POSTGRES_USER: admin
1212
POSTGRES_PASSWORD: password
1313
POSTGRES_DB: benchbase
1414
ports:
1515
- "5432:5432"
16+
healthcheck:
17+
test: pg_isready
18+
interval: 10s
19+
timeout: 5s
20+
retries: 5
21+
start_period: 30s
1622

1723
postgres-ui:
1824
container_name: postgres-ui

docker/postgres-latest/up.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,24 @@ set -eu
44
scriptdir=$(dirname "$(readlink -f "$0")")
55
cd "$scriptdir/"
66

7-
docker compose up -d
7+
services="$@"
8+
9+
docker compose up -d $services
10+
11+
# Wait until ready
12+
for i in {1..5}; do
13+
if docker exec postgres pg_isready && sleep 2 && docker exec postgres pg_isready; then
14+
break
15+
else
16+
sleep 5
17+
fi
18+
done
19+
20+
function run_psql_in_docker() {
21+
set -x
22+
docker exec --env PGPASSWORD=password postgres psql -h localhost -U admin benchbase --csv -c "$@"
23+
set +x
24+
}
25+
26+
run_psql_in_docker "CREATE EXTENSION IF NOT EXISTS pg_stat_statements"
27+
run_psql_in_docker "SELECT COUNT(*) FROM pg_stat_statements" | egrep '^[1-9][0-9]*$'

0 commit comments

Comments
 (0)