Skip to content

Commit

Permalink
Enable use of pg_stat_statement extension in local docker-compose and…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
bpkroth authored May 13, 2024
1 parent aac5c87 commit 56c3e24
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 17 deletions.
51 changes: 37 additions & 14 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ jobs:
name: benchbase-${{matrix.profile}}
path: target/benchbase-${{matrix.profile}}.tgz

# Needed for running a customized service containers using docker/*/up.sh scripts.
# See postgres example below.
# https://github.com/actions/runner/issues/2139
- name: Package docker-compose configs
if: ${{ matrix.profile == 'postgres' }}
run: |
tar czvpf docker-compose-${{matrix.profile}}.tar.gz docker/${{matrix.profile}}-latest
- name: Upload docker-compose configs
if: ${{ matrix.profile == 'postgres' }}
uses: actions/upload-artifact@v4
with:
name: docker-compose-${{matrix.profile}}
path: docker-compose-${{matrix.profile}}.tar.gz

## ----------------------------------------------------------------------------------
## SQLITE
## ----------------------------------------------------------------------------------
Expand Down Expand Up @@ -406,21 +421,25 @@ jobs:
fail-fast: false
matrix:
benchmark: [ 'auctionmark', 'epinions', 'hyadapt', 'noop', 'otmetrics', 'resourcestresser', 'seats', 'sibench', 'smallbank', 'tatp', 'templated', 'tpcc', 'tpcc-with-reconnects', 'tpch', 'twitter', 'voter', 'wikipedia', 'ycsb' ]
services:
postgres: # https://hub.docker.com/_/postgres
image: postgres:latest
env:
POSTGRES_DB: benchbase
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
# Note: we download just the docker-compose scripts/configs rather than the
# whole source code repo for better testing.
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: docker-compose-postgres

- name: Extract docker-compose artifacts
run: |
tar xvzf docker-compose-postgres.tar.gz
# Use docker-compose to start the postgres service so we can modify the
# command line args to include extensions.
# https://github.com/actions/runner/issues/2139
- name: Start custom postgres service
run: |
./docker/postgres-latest/up.sh --quiet-pull postgres
- name: Download artifact
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -472,6 +491,10 @@ jobs:
./scripts/check_latest_benchmark_results.sh $results_benchmark
./scripts/check_histogram_results.sh results/histograms.json $ERRORS_THRESHOLD
- name: Stop custom postgres service
run: |
./docker/postgres-latest/down.sh
## ----------------------------------------------------------------------------------
## COCKROACHDB
## ----------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ build/
# vim swap files
.*.swp

.env
.env

docker-compose-*.tar.gz
8 changes: 7 additions & 1 deletion docker/postgres-latest/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ services:
container_name: postgres
hostname: postgres
image: postgres:alpine
command: postgres -N 500
command: postgres -N 500 -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
POSTGRES_DB: benchbase
ports:
- "5432:5432"
healthcheck:
test: pg_isready
interval: 10s
timeout: 5s
retries: 5
start_period: 30s

postgres-ui:
container_name: postgres-ui
Expand Down
22 changes: 21 additions & 1 deletion docker/postgres-latest/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,24 @@ set -eu
scriptdir=$(dirname "$(readlink -f "$0")")
cd "$scriptdir/"

docker compose up -d
services="$@"

docker compose up -d $services

# Wait until ready
for i in {1..5}; do
if docker exec postgres pg_isready && sleep 2 && docker exec postgres pg_isready; then
break
else
sleep 5
fi
done

function run_psql_in_docker() {
set -x
docker exec --env PGPASSWORD=password postgres psql -h localhost -U admin benchbase --csv -c "$@"
set +x
}

run_psql_in_docker "CREATE EXTENSION IF NOT EXISTS pg_stat_statements"
run_psql_in_docker "SELECT COUNT(*) FROM pg_stat_statements" | egrep '^[1-9][0-9]*$'

0 comments on commit 56c3e24

Please sign in to comment.