Skip to content

Commit 0ee4ffa

Browse files
committed
experimental debug output for debugging performance issues
1 parent ab29854 commit 0ee4ffa

File tree

4 files changed

+87
-20
lines changed

4 files changed

+87
-20
lines changed

clowder_init.sh

+18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11
#!/bin/sh
22

3+
logtime "start clowder_init..."
4+
echo "start clowder_init.sh" | tee -a $LOGPATH
5+
36
if [[ -z "${ACG_CONFIG}" ]]; then
7+
logtime "export PG_BOUNCER_LISTEN_PORT..."
48
export PG_BOUNCER_LISTEN_PORT="5432"
59
else
10+
logtime "export DB_NAME..."
611
export DB_NAME="`cat $ACG_CONFIG | jq -r '.database.name // empty'`"
12+
logtime "export DB_HOST..."
713
export DB_HOST="`cat $ACG_CONFIG | jq -r '.database.hostname // empty'`"
14+
logtime "export DB_PORT..."
815
export DB_PORT="`cat $ACG_CONFIG | jq -r '.database.port // empty'`"
16+
logtime "export DB_USER..."
917
export DB_USER="`cat $ACG_CONFIG | jq -r '.database.username // empty'`"
18+
logtime "export DB_PASSWORD..."
1019
export DB_PASSWORD="`cat $ACG_CONFIG | jq -r '.database.password // empty'`"
20+
logtime "export DB_SSLMODE..."
1121
export DB_SSLMODE="`cat $ACG_CONFIG | jq -r '.database.sslMode // empty'`"
22+
logtime "export DB_CAFILE..."
1223
export DB_CAFILE="/etc/pgbouncer/rdsca.cert"
24+
logtime "export PG_BOUNCER_LISTEN_PORT..."
1325
export PG_BOUNCER_LISTEN_PORT="`cat $ACG_CONFIG | jq -r '.webPort'`"
1426

27+
logtime "db_cert=..."
1528
db_cert="`cat $ACG_CONFIG | jq -r '.database.rdsCa // empty'`"
1629
>${DB_CAFILE}
1730
if [[ -n "${db_cert}" ]]; then
31+
logtime "echo db_cert to DB_CAFILE..."
1832
echo "${db_cert}" > ${DB_CAFILE}
33+
logtime "unset db_cert..."
1934
unset db_cert
2035
fi
2136

2237
[[ -z "${DB_PORT}" ]] && DB_PORT="5432"
2338
fi
39+
40+
logtime "exit clowder_init..."
41+
echo "exit clowder_init.sh" | tee -a $LOGPATH

entrypoint.sh

+32-15
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,66 @@
11
#!/bin/sh
22

3+
PID="$$"
4+
LOGPATH=/tmp/log-entrypoint-"$PID"
5+
6+
function logtime() {
7+
echo "$(date --iso-8601=ns)" | tee -a $LOGPATH
8+
}
9+
10+
logtime
311
source /clowder_init.sh
12+
logtime
413

514
set -e
615

716
function check_svc_status() {
817
local SVC_NAME=$1 SVC_PORT=$2
918

10-
[[ $# -lt 2 ]] && echo "Error: Usage: check_svc_status svc_name svc_port" && exit 1
19+
[[ $# -lt 2 ]] && echo "Error: Usage: check_svc_status svc_name svc_port" | tee -a $LOGPATH && exit 1
1120

1221
while true; do
13-
echo "${LOGPREFIX} Checking ${SVC_NAME}:$SVC_PORT status ..."
22+
logtime
23+
echo "${LOGPREFIX} Checking ${SVC_NAME}:$SVC_PORT status ..." | tee -a $LOGPATH
1424
ncat ${SVC_NAME} ${SVC_PORT} < /dev/null && break
15-
sleep 5
25+
logtime
26+
echo "not ready yet" | tee -a $LOGPATH
27+
sleep 1
1628
done
29+
logtime
1730
echo "${LOGPREFIX} ${SVC_NAME}:${SVC_PORT} - accepting connections"
1831
}
1932

33+
2034
if [[ -n "${ACG_CONFIG}" ]]; then
2135
export LOGPREFIX="Clowder Init:"
22-
echo "${LOGPREFIX} Running in a clowder environment"
36+
echo "${LOGPREFIX} Running in a clowder environment" | tee -a $LOGPATH
2337

24-
echo "${LOGPREFIX} Database name: ${DB_NAME}"
25-
echo "${LOGPREFIX} Database host: ${DB_HOST}"
26-
echo "${LOGPREFIX} Database port: ${DB_PORT}"
27-
echo "${LOGPREFIX} PG Bouncer port: ${PG_BOUNCER_LISTEN_PORT}"
38+
echo "${LOGPREFIX} Database name: ${DB_NAME}" | tee -a $LOGPATH
39+
echo "${LOGPREFIX} Database host: ${DB_HOST}" | tee -a $LOGPATH
40+
echo "${LOGPREFIX} Database port: ${DB_PORT}" | tee -a $LOGPATH
41+
echo "${LOGPREFIX} PG Bouncer port: ${PG_BOUNCER_LISTEN_PORT}" | tee -a $LOGPATH
2842
if [[ -n "${DB_SSLMODE}" ]]; then
29-
echo "${LOGPREFIX} Database SSL Mode: ${DB_SSLMODE}"
43+
echo "${LOGPREFIX} Database SSL Mode: ${DB_SSLMODE}" | tee -a $LOGPATH
3044
fi
3145
if [[ -s "${DB_CAFILE}" ]]; then
32-
echo "${LOGPREFIX} Database CA File: ${DB_CAFILE}"
46+
echo "${LOGPREFIX} Database CA File: ${DB_CAFILE}" | tee -a $LOGPATH
3347
fi
3448

35-
[[ -z "${DB_HOST}" ]] && echo "${LOGPREFIX} Error: Missing Database configuration" && exit 1
49+
[[ -z "${DB_HOST}" ]] && echo "${LOGPREFIX} Error: Missing Database configuration" | tee -a $LOGPATH && exit 1
3650

3751
# Wait for the database to be ready
38-
echo "${LOGPREFIX} Waiting for database readiness ..."
52+
echo "${LOGPREFIX} Waiting for database readiness ..." | tee -a $LOGPATH
3953
check_svc_status $DB_HOST $DB_PORT
4054
fi
4155

4256
PG_CONFIG_DIR=/etc/pgbouncer
4357

58+
logtime
4459
# md5 and write the password
4560
pass="md5$(echo -n "$DB_PASSWORD$DB_USER" | md5sum | cut -f 1 -d ' ')"
4661
echo "\"$DB_USER\" \"$pass\"" >> ${PG_CONFIG_DIR}/userlist.txt
47-
echo "Wrote authentication credentials to ${PG_CONFIG_DIR}/userlist.txt"
62+
logtime
63+
echo "Wrote authentication credentials to ${PG_CONFIG_DIR}/userlist.txt" | tee -a $LOGPATH
4864

4965
# pgbouncer config
5066
printf "\
@@ -72,7 +88,8 @@ if [[ -s "${DB_CAFILE}" ]]; then
7288
echo "server_tls_ca_file=${DB_CAFILE}" >> ${PG_CONFIG_DIR}/pgbouncer.ini
7389
fi
7490

75-
echo "Wrote pgbouncer config to ${PG_CONFIG_DIR}/pgbouncer.ini"
91+
logtime
92+
echo "Wrote pgbouncer config to ${PG_CONFIG_DIR}/pgbouncer.ini" | tee -a $LOGPATH
7693

77-
echo "Starting $*..."
94+
echo "Starting $*..." | tee -a $LOGPATH
7895
exec "$@"

probe-liveness.sh

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
#!/bin/bash
22

3+
PID="$$"
4+
LOGPATH=/tmp/log-liveness-"$PID"
5+
6+
function logtime() {
7+
echo "$(date --iso-8601=ns) $1" | tee -a $LOGPATH
8+
}
9+
10+
11+
exec {BASH_XTRACEFD}>>$LOGPATH
12+
#set -x
13+
14+
15+
logtime "before clowder init"
316
source /clowder_init.sh
417

5-
/usr/pgsql-14/bin/pg_isready -h localhost -p ${PG_BOUNCER_LISTEN_PORT} -U "${DB_USER}" | grep "accepting connections"
6-
exit $?
18+
logtime "before pg_isready"
19+
/usr/pgsql-14/bin/pg_isready -h localhost -p ${PG_BOUNCER_LISTEN_PORT} -U "${DB_USER}" | grep "accepting connections" | tee -a $LOGPATH
20+
RESULT=$?
21+
logtime "after pg_isready"
22+
echo "result was $RESULT" | tee -a $LOGPATH
23+
exit $RESULT
724

probe-readiness.sh

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
#!/bin/bash
22

3+
function logtime() {
4+
echo "$(date --iso-8601=ns) $1" | tee -a $LOGPATH
5+
}
6+
7+
8+
PID="$$"
9+
LOGPATH=/tmp/log-readiness-"$PID"
10+
11+
exec {BASH_XTRACEFD}>>$LOGPATH
12+
#set -x
13+
314
# Note: host and port should remain localhost and ${PG_BOUNCER_LISTEN_PORT}
415
# because that represents the location of pgbouncer itself, not the
516
# remote psql server that would have $DB_HOST:$DB_PORT.
6-
717
source /clowder_init.sh
818

19+
logtime "before psql select"
920
PGPASSWORD="$DB_PASSWORD" /usr/pgsql-14/bin/psql \
1021
-h localhost -p ${PG_BOUNCER_LISTEN_PORT} -U "${DB_USER}" -d "${DB_NAME}" \
1122
-c "select 1 as psql_is_ready" 2>/dev/null \
12-
| grep "psql_is_ready"
13-
exit $?
23+
| grep "psql_is_ready" | tee -a $LOGPATH
24+
RESULT=$?
25+
26+
logtime "psql finished"
27+
echo "result was $RESULT" | tee -a $LOGPATH
28+
exit $RESULT
1429

0 commit comments

Comments
 (0)