Skip to content

Commit

Permalink
feat(RHIDP-2178): Enable postgresql logging (#48)
Browse files Browse the repository at this point in the history
* Enable postgresql logging

This patch enables logging of long running queries in postgresql.

* Update Makefile

Co-authored-by: Pavel Macík <[email protected]>

* fix(RHIDP-2178): restart RHDH after DB is restarted with psql_debug

---------

Co-authored-by: Pavel Macík <[email protected]>
  • Loading branch information
yogananth-subramanian and pmacik authored Jul 20, 2024
1 parent 72296c2 commit a1e61ab
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ endif
@echo "Getting locust master log:"
kubectl logs --namespace $(LOCUST_NAMESPACE) -f -l performance-test-pod-name=$(SCENARIO)-test-master | tee load-test.log
date --utc -Ins>$(TMP_DIR)/benchmark-after
ifeq ($(RHDH_INSTALL_METHOD),helm)
oc exec rhdh-postgresql-primary-0 -n $(RHDH_NAMESPACE) -- sh -c 'cat /var/lib/pgsql/data/userdata/log/postgresql*.log'>postgresql.log
else
oc exec backstage-psql-developer-hub-0 -n $(RHDH_NAMESPACE) -- sh -c 'cat /var/lib/pgsql/data/userdata/log/postgresql*.log'>postgresql.log
endif
@echo "All done!!!"

## Run the scalability test
Expand Down
1 change: 1 addition & 0 deletions ci-scripts/collect-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ try_gather_file "${TMP_DIR}/create_group.log"
try_gather_file "${TMP_DIR}/create_user.log"
try_gather_file "${TMP_DIR}/get_token.log"
try_gather_file load-test.log
try_gather_file postgresql.log

PYTHON_VENV_DIR=.venv

Expand Down
30 changes: 30 additions & 0 deletions ci-scripts/rhdh-setup/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export KEYCLOAK_USER_PASS=${KEYCLOAK_USER_PASS:-$(mktemp -u XXXXXXXXXX)}
export AUTH_PROVIDER="${AUTH_PROVIDER:-''}"
export ENABLE_RBAC="${ENABLE_RBAC:-false}"

export PSQL_LOG="${PSQL_LOG:-true}"
export LOG_MIN_DURATION_STATEMENT="${LOG_MIN_DURATION_STATEMENT:-65}"
export LOG_MIN_DURATION_SAMPLE="${LOG_MIN_DURATION_SAMPLE:-50}"
export LOG_STATEMENT_SAMPLE_RATE="${LOG_STATEMENT_SAMPLE_RATE:-0.7}"

export INSTALL_METHOD=helm

TMP_DIR=$(readlink -m "${TMP_DIR:-.tmp}")
Expand Down Expand Up @@ -147,6 +152,7 @@ install() {
fi

backstage_install
psql_debug
setup_monitoring
}

Expand Down Expand Up @@ -284,6 +290,30 @@ install_rhdh_with_olm() {
wait_to_start deployment "backstage-developer-hub" 300 300
}

# shellcheck disable=SC2016,SC1001,SC2086
psql_debug() {
if [ "$INSTALL_METHOD" == "helm" ]; then
psql_db_ss="${RHDH_HELM_RELEASE_NAME}-postgresql-primary"
psql_db="${psql_db_ss}-0"
rhdh_deployment="${RHDH_HELM_RELEASE_NAME}-developer-hub"
elif [ "$INSTALL_METHOD" == "olm" ]; then
psql_db_ss=backstage-psql-developer-hub
psql_db="${psql_db_ss}-0"
rhdh_deployment=backstage-developer-hub
fi
if ${PSQL_LOG}; then
$clin exec "${psql_db}" -- sh -c "sed -i "s/^\s*#log_min_duration_statement.*/log_min_duration_statement=${LOG_MIN_DURATION_STATEMENT}/" /var/lib/pgsql/data/userdata/postgresql.conf "
$clin exec "${psql_db}" -- sh -c "sed -i "s/^\s*#log_min_duration_sample.*/log_min_duration_sample=${LOG_MIN_DURATION_SAMPLE}/" /var/lib/pgsql/data/userdata/postgresql.conf "
$clin exec "${psql_db}" -- sh -c "sed -i "s/^\s*#log_statement_sample_rate.*/log_statement_sample_rate=${LOG_STATEMENT_SAMPLE_RATE}/" /var/lib/pgsql/data/userdata/postgresql.conf "
fi
echo "Restarting RHDH DB..."
$clin exec "${psql_db}" -- sh -c 'pg_ctl -D $PGDATA restart -mf'
wait_to_start statefulset "$psql_db_ss" 300 300

echo "Restarting RHDH..."
$clin rollout restart deployment/"$rhdh_deployment"
wait_to_start deployment "$rhdh_deployment" 300 300
}
setup_monitoring() {
echo "Enabling user workload monitoring"
rm -f config.yaml
Expand Down

0 comments on commit a1e61ab

Please sign in to comment.