Skip to content

Enable use of pg_stat_statement extension in local docker-compose and CI pipeline #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]*$'