Skip to content

Commit

Permalink
Limit retries during metabase init script (#42)
Browse files Browse the repository at this point in the history
* Update values file example and docs

* Adjust retries/timeout for metabase hook script

* Move hook scripts to bash shell

* Refactor kafkaconnector names
  • Loading branch information
teddyphreak authored Jul 1, 2023
1 parent be979eb commit 4d5337d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ This is an example values definition for replicating pagila db:
```
metabase:
admin:
email: [email protected]
password: dataplane
email: [email protected]
ingress:
enabled: true
className: nginx-private
hostName: metabase.nephelai.io
enabled: true
className: nginx-private
hostName: metabase.nephelai.io
cdc:
postgres:
- hostname: pagilahost
port: 5432
id: pagila
dbname: pagila
signaling: True
exclude:
- "public.staff"
partitions:
- source: "public.payment.*"
sink: "payment"
strimzi:
connect:
secret: "metabase-pagila-db"
Expand Down
28 changes: 24 additions & 4 deletions charts/dataplane/templates/metabase/hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,46 @@ spec:
key: password

command:
- "sh"
- "bash"
- "-c"
- >-
set -ex
echo "[$(date -Iseconds)] [INFO] [metabase-setup] waiting for metabase service";
retries=10;
until \
curl -s \
-H "X-Forwarded-Host: $MB_SITE_URL" \
-H "X-Forwarded-Proto: $MB_SITE_PROTO" \
http://{{ $svcName }}:{{ $svcPort }}/ -o /dev/null; do
echo "[$(date -Iseconds)] [INFO] [metabase-setup] waiting for metabase service";
sleep 10;
if (( retries > 0 )); then
retries=$(( retries - 1 ));
sleep 30;
else
echo "[$(date -Iseconds)] [ERROR] [metabase-setup] metabase service failed to start";
exit 1;
fi
done;
echo "[$(date -Iseconds)] [INFO] [metabase-setup] retrieve metabase setup token";
retries=10;
until [[ ${setup_token:-""} != "" ]]; do
setup_token=$(curl -s -X GET \
-H "X-Forwarded-Host: $MB_SITE_URL" \
-H "X-Forwarded-Proto: $MB_SITE_PROTO" \
http://{{ $svcName }}:{{ $svcPort }}/api/session/properties | jq '.["setup-token"]' -r);
if (( retries > 0 )); then
retries=$(( retries - 1 ));
sleep 30;
else
echo "[$(date -Iseconds)] [ERROR] [metabase-setup] unable to retrieve metabase setup token";
exit 1;
fi
done;
retries=10;
response_code="";
echo "[$(date -Iseconds)] [INFO] [metabase-setup] initial metabase setup start";
response_header=$(mktemp);
until [[ "$response_code" == "200" || "$response_code" == "403" || "$retries" == "0" ]]; do
until [[ "$response_code" == "200" || "$response_code" == "403" ]]; do
response_body=$(curl -s -D $response_header -X POST \
-H "Content-Type: application/json" \
-H "X-Forwarded-Host: $MB_SITE_URL" \
Expand Down Expand Up @@ -119,7 +134,12 @@ spec:
}" \
http://{{ $svcName }}:{{ $svcPort }}/api/setup);
response_code=$(cat $response_header | grep ^HTTP | awk '{print $2}');
retries=$(($retries - 1));
if (( retries > 0 )); then
retries=$(( retries - 1 ));
else
echo "[$(date -Iseconds)] [ERROR] [metabase-setup] unable to initialize metabase";
exit 1;
fi
if [[ "$response_code" != "200" && "$response_code" != "403" ]]; then
echo "$response_body (response_code=$response_code)";
sleep 30;
Expand Down
2 changes: 1 addition & 1 deletion charts/dataplane/templates/registry/hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
resources:
{{- toYaml .Values.util.resources | nindent 12 }}
command:
- "sh"
- "bash"
- "-c"
- >-
until curl -s http://{{ $svcName }}:{{ $svcPort }}/ -o /dev/null; do
Expand Down
2 changes: 1 addition & 1 deletion charts/dataplane/templates/strimzi/connector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{{- range $db := .Values.cdc.postgres }}
{{- $dbId := required "database id is required" $db.id }}
{{- $dbConnectorName := lower (printf "%s-%s-%s" $fullName $dbId $db.dbname) }}
{{- $dbConnectorName := lower (printf "%s-%s" $fullName $dbId) }}
{{- $dbSlotName := $dbConnectorName | replace "-" "_" }}
{{- $exclude := list }}
{{- $include := list }}
Expand Down
9 changes: 4 additions & 5 deletions values.minimal.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
---
metabase:
admin:
email: [email protected]
password: dataplane
email: [email protected]
ingress:
enabled: true
className: nginx-private
hostName: metabase.nephelai.io
enabled: true
className: nginx-private
hostName: metabase.nephelai.io
cdc:
postgres:
- hostname: pagilahost
Expand Down

0 comments on commit 4d5337d

Please sign in to comment.