From f18705526255ce14ed3ad3eb67aff374f613d00e Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 23 Aug 2025 19:14:30 +0700 Subject: [PATCH 1/9] feat: install script to migrate sentry.conf.py config to use pgbouncer This PR may only be merged after https://github.com/getsentry/self-hosted/pull/3884 has been merged --- _unit-test/migrate-pgbouncer-test.sh | 199 +++++++++++++++++++++++++++ install/migrate-pgbouncer.sh | 44 ++++++ 2 files changed, 243 insertions(+) create mode 100755 _unit-test/migrate-pgbouncer-test.sh create mode 100644 install/migrate-pgbouncer.sh diff --git a/_unit-test/migrate-pgbouncer-test.sh b/_unit-test/migrate-pgbouncer-test.sh new file mode 100755 index 00000000000..2645a04ee7f --- /dev/null +++ b/_unit-test/migrate-pgbouncer-test.sh @@ -0,0 +1,199 @@ +#!/usr/bin/env bash + +source _unit-test/_test_setup.sh +source install/dc-detect-version.sh + +source install/ensure-files-from-examples.sh +cp $SENTRY_CONFIG_PY /tmp/sentry_conf_py + +export SETUP_PGBOUNCER_MIGRATION=1 + +# Declare expected content +expected_db_config=$( + cat <<'EOF' +DATABASES = { + "default": { + "ENGINE": "sentry.db.postgres", + "NAME": "postgres", + "USER": "postgres", + "PASSWORD": "", + "HOST": "pgbouncer", + "PORT": "", + } +} +EOF +) + +echo "Test 1 (pre 25.9.0 release)" +# Modify the `DATABASES = {` to the next `}` line, with: +# DATABASES = { +# "default": { +# "ENGINE": "sentry.db.postgres", +# "NAME": "postgres", +# "USER": "postgres", +# "PASSWORD": "", +# "HOST": "postgres", +# "PORT": "", +# } +# } + +# Create the replacement text in a temp file +cat >/tmp/sentry_conf_py_db_config <<'EOF' +DATABASES = { + "default": { + "ENGINE": "sentry.db.postgres", + "NAME": "postgres", + "USER": "postgres", + "PASSWORD": "", + "HOST": "postgres", + "PORT": "", + } +} +EOF + +# Replace the block +sed -i '/^DATABASES = {$/,/^}$/{ + /^DATABASES = {$/r /tmp/sentry_conf_py_db_config + d +}' $SENTRY_CONFIG_PY + +# Clean up +rm /tmp/sentry_conf_py_db_config + +source install/migrate-pgbouncer.sh + +# Extract actual content +actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' filename.py) + +# Compare +if [ "$actual_db_config" = "$expected_db_config" ]; then + echo "DATABASES section is correct" +else + echo "DATABASES section does not match" + echo "Expected:" + echo "$expected_db_config" + echo "Actual:" + echo "$actual_db_config" + exit 1 +fi + +# Reset the file +rm $SENTRY_CONFIG_PY +cp /tmp/sentry_conf_py $SENTRY_CONFIG_PY + +echo "Test 2 (post 25.9.0 release)" +# Modify the `DATABASES = {` to the next `}` line, with: +# DATABASES = { +# "default": { +# "ENGINE": "sentry.db.postgres", +# "NAME": "postgres", +# "USER": "postgres", +# "PASSWORD": "", +# "HOST": "pgbouncer", +# "PORT": "", +# } +# } + +# Create the replacement text in a temp file +cat >/tmp/sentry_conf_py_db_config <<'EOF' +DATABASES = { + "default": { + "ENGINE": "sentry.db.postgres", + "NAME": "postgres", + "USER": "postgres", + "PASSWORD": "", + "HOST": "pgbouncer", + "PORT": "", + } +} +EOF + +# Replace the block +sed -i '/^DATABASES = {$/,/^}$/{ + /^DATABASES = {$/r /tmp/sentry_conf_py_db_config + d +}' $SENTRY_CONFIG_PY + +# Clean up +rm /tmp/sentry_conf_py_db_config + +source install/migrate-pgbouncer.sh + +# Extract actual content +actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' filename.py) + +# Compare +if [ "$actual_db_config" = "$expected_db_config" ]; then + echo "DATABASES section is correct" +else + echo "DATABASES section does not match" + echo "Expected:" + echo "$expected_db_config" + echo "Actual:" + echo "$actual_db_config" + exit 1 +fi + +# Reset the file +rm $SENTRY_CONFIG_PY +cp /tmp/sentry_conf_py $SENTRY_CONFIG_PY + +echo "Test 3 (custom postgres config)" +# Modify the `DATABASES = {` to the next `}` line, with: +# DATABASES = { +# "default": { +# "ENGINE": "sentry.db.postgres", +# "NAME": "postgres", +# "USER": "sentry", +# "PASSWORD": "sentry", +# "HOST": "postgres.internal", +# "PORT": "5432", +# } +# } + +# Create the replacement text in a temp file +cat >/tmp/sentry_conf_py_db_config <<'EOF' +DATABASES = { + "default": { + "ENGINE": "sentry.db.postgres", + "NAME": "postgres", + "USER": "sentry", + "PASSWORD": "sentry", + "HOST": "postgres.internal", + "PORT": "5432", + } +} +EOF + +# Replace the block +sed -i '/^DATABASES = {$/,/^}$/{ + /^DATABASES = {$/r /tmp/sentry_conf_py_db_config + d +}' $SENTRY_CONFIG_PY + +# Clean up +rm /tmp/sentry_conf_py_db_config + +source install/migrate-pgbouncer.sh + +# Extract actual content +actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' filename.py) + +# THe file should NOT be modified +if [ "$actual_db_config" = "$expected_db_config" ]; then + echo "DATABASES section SHOULD NOT be modified" + echo "Expected:" + echo "$expected_db_config" + echo "Actual:" + echo "$actual_db_config" + exit 1 +else + echo "DATABASES section is correct" +fi + +# Remove the file +rm $SENTRY_CONFIG_PY /tmp/sentry_conf_py + +export SETUP_PGBOUNCER_MIGRATION=0 + +report_success diff --git a/install/migrate-pgbouncer.sh b/install/migrate-pgbouncer.sh new file mode 100644 index 00000000000..25c3e0a9733 --- /dev/null +++ b/install/migrate-pgbouncer.sh @@ -0,0 +1,44 @@ +# Guard this file behind SETUP_PGBOUNCER_MIGRATION +if [ "$SETUP_PGBOUNCER_MIGRATION" == "1" ]; then + echo "${_group}Migrating Postgres config to PGBouncer..." + # If users has this EXACT configuration on their `sentry.conf.py` file: + # ```python + # DATABASES = { + # "default": { + # "ENGINE": "sentry.db.postgres", + # "NAME": "postgres", + # "USER": "postgres", + # "PASSWORD": "", + # "HOST": "postgres", + # "PORT": "", + # } + # } + # ``` + # We need to migrate it to this configuration: + # ```python + # DATABASES = { + # "default": { + # "ENGINE": "sentry.db.postgres", + # "NAME": "postgres", + # "USER": "postgres", + # "PASSWORD": "", + # "HOST": "pgbouncer", + # "PORT": "", + # } + # } + # ``` + + # Found this from https://stackoverflow.com/a/2686705/3153224 + if pcregrep -M '^DATABASES[[:space:]]*=[[:space:]]*{\n[[:space:]]*"default"[[:space:]]*:[[:space:]]*{\n[[:space:]]*"ENGINE"[[:space:]]*:[[:space:]]*"sentry.db.postgres",\n[[:space:]]*"NAME"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"USER"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"PASSWORD"[[:space:]]*:[[:space:]]*"",\n[[:space:]]*"HOST"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"PORT"[[:space:]]*:[[:space:]]*"",\n[[:space:]]*}\n[[:space:]]*}' "$SENTRY_CONFIG_PY"; then + echo "Migrating $SENTRY_CONFIG_PY to use PGBouncer" + sed -i 's/"HOST": "postgres"/"HOST": "pgbouncer"/' "$SENTRY_CONFIG_PY" + echo "Migrated $SENTRY_CONFIG_PY to use PGBouncer" + # See if we already have pgbouncer set. If it is, then we just say "ok you're good". + elif pcregrep -M '^DATABASES[[:space:]]*=[[:space:]]*{\n[[:space:]]*"default"[[:space:]]*:[[:space:]]*{\n[[:space:]]*"ENGINE"[[:space:]]*:[[:space:]]*"sentry.db.postgres",\n[[:space:]]*"NAME"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"USER"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"PASSWORD"[[:space:]]*:[[:space:]]*"",\n[[:space:]]*"HOST"[[:space:]]*:[[:space:]]*"pgbouncer",\n[[:space:]]*"PORT"[[:space:]]*:[[:space:]]*"",\n[[:space:]]*}\n[[:space:]]*}' "$SENTRY_CONFIG_PY"; then + echo "Found pgbouncer in $SENTRY_CONFIG_PY, I'm assuming you're good! :)" + else + echo "⚠️ You don't have standard configuration for Postgres in $SENTRY_CONFIG_PY, skipping pgbouncer migration. I'm assuming you know what you're doing." + fi + + echo "${_endgroup}" +fi From b2cb6f400f3b4b21629b6ca0362da4d02e659945 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 23 Aug 2025 19:16:50 +0700 Subject: [PATCH 2/9] feat: try to use standard grep and sed --- install/migrate-pgbouncer.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/install/migrate-pgbouncer.sh b/install/migrate-pgbouncer.sh index 25c3e0a9733..e8aa21fafd8 100644 --- a/install/migrate-pgbouncer.sh +++ b/install/migrate-pgbouncer.sh @@ -28,13 +28,11 @@ if [ "$SETUP_PGBOUNCER_MIGRATION" == "1" ]; then # } # ``` - # Found this from https://stackoverflow.com/a/2686705/3153224 - if pcregrep -M '^DATABASES[[:space:]]*=[[:space:]]*{\n[[:space:]]*"default"[[:space:]]*:[[:space:]]*{\n[[:space:]]*"ENGINE"[[:space:]]*:[[:space:]]*"sentry.db.postgres",\n[[:space:]]*"NAME"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"USER"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"PASSWORD"[[:space:]]*:[[:space:]]*"",\n[[:space:]]*"HOST"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"PORT"[[:space:]]*:[[:space:]]*"",\n[[:space:]]*}\n[[:space:]]*}' "$SENTRY_CONFIG_PY"; then + if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "postgres"'; then echo "Migrating $SENTRY_CONFIG_PY to use PGBouncer" sed -i 's/"HOST": "postgres"/"HOST": "pgbouncer"/' "$SENTRY_CONFIG_PY" echo "Migrated $SENTRY_CONFIG_PY to use PGBouncer" - # See if we already have pgbouncer set. If it is, then we just say "ok you're good". - elif pcregrep -M '^DATABASES[[:space:]]*=[[:space:]]*{\n[[:space:]]*"default"[[:space:]]*:[[:space:]]*{\n[[:space:]]*"ENGINE"[[:space:]]*:[[:space:]]*"sentry.db.postgres",\n[[:space:]]*"NAME"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"USER"[[:space:]]*:[[:space:]]*"postgres",\n[[:space:]]*"PASSWORD"[[:space:]]*:[[:space:]]*"",\n[[:space:]]*"HOST"[[:space:]]*:[[:space:]]*"pgbouncer",\n[[:space:]]*"PORT"[[:space:]]*:[[:space:]]*"",\n[[:space:]]*}\n[[:space:]]*}' "$SENTRY_CONFIG_PY"; then + elif sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "pgbouncer"'; then echo "Found pgbouncer in $SENTRY_CONFIG_PY, I'm assuming you're good! :)" else echo "⚠️ You don't have standard configuration for Postgres in $SENTRY_CONFIG_PY, skipping pgbouncer migration. I'm assuming you know what you're doing." From 9d34a36f41b8fd5d591871cf256679f60b22ed01 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 23 Aug 2025 19:20:56 +0700 Subject: [PATCH 3/9] fix: wrong file name to assert --- _unit-test/migrate-pgbouncer-test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_unit-test/migrate-pgbouncer-test.sh b/_unit-test/migrate-pgbouncer-test.sh index 2645a04ee7f..53b8993fa43 100755 --- a/_unit-test/migrate-pgbouncer-test.sh +++ b/_unit-test/migrate-pgbouncer-test.sh @@ -63,7 +63,7 @@ rm /tmp/sentry_conf_py_db_config source install/migrate-pgbouncer.sh # Extract actual content -actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' filename.py) +actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' $SENTRY_CONFIG_PY) # Compare if [ "$actual_db_config" = "$expected_db_config" ]; then @@ -120,7 +120,7 @@ rm /tmp/sentry_conf_py_db_config source install/migrate-pgbouncer.sh # Extract actual content -actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' filename.py) +actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' $SENTRY_CONFIG_PY) # Compare if [ "$actual_db_config" = "$expected_db_config" ]; then @@ -177,7 +177,7 @@ rm /tmp/sentry_conf_py_db_config source install/migrate-pgbouncer.sh # Extract actual content -actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' filename.py) +actual_db_config=$(sed -n '/^DATABASES = {$/,/^}$/p' $SENTRY_CONFIG_PY) # THe file should NOT be modified if [ "$actual_db_config" = "$expected_db_config" ]; then From 9f593663b20ba040f8985ce2cfbf3bbca8a06c8a Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 23 Aug 2025 20:19:54 +0700 Subject: [PATCH 4/9] feat: remove flag guard --- _unit-test/migrate-pgbouncer-test.sh | 4 -- install/migrate-pgbouncer.sh | 77 +++++++++++++--------------- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/_unit-test/migrate-pgbouncer-test.sh b/_unit-test/migrate-pgbouncer-test.sh index 53b8993fa43..923fb560605 100755 --- a/_unit-test/migrate-pgbouncer-test.sh +++ b/_unit-test/migrate-pgbouncer-test.sh @@ -6,8 +6,6 @@ source install/dc-detect-version.sh source install/ensure-files-from-examples.sh cp $SENTRY_CONFIG_PY /tmp/sentry_conf_py -export SETUP_PGBOUNCER_MIGRATION=1 - # Declare expected content expected_db_config=$( cat <<'EOF' @@ -194,6 +192,4 @@ fi # Remove the file rm $SENTRY_CONFIG_PY /tmp/sentry_conf_py -export SETUP_PGBOUNCER_MIGRATION=0 - report_success diff --git a/install/migrate-pgbouncer.sh b/install/migrate-pgbouncer.sh index e8aa21fafd8..440caeba1ff 100644 --- a/install/migrate-pgbouncer.sh +++ b/install/migrate-pgbouncer.sh @@ -1,42 +1,39 @@ -# Guard this file behind SETUP_PGBOUNCER_MIGRATION -if [ "$SETUP_PGBOUNCER_MIGRATION" == "1" ]; then - echo "${_group}Migrating Postgres config to PGBouncer..." - # If users has this EXACT configuration on their `sentry.conf.py` file: - # ```python - # DATABASES = { - # "default": { - # "ENGINE": "sentry.db.postgres", - # "NAME": "postgres", - # "USER": "postgres", - # "PASSWORD": "", - # "HOST": "postgres", - # "PORT": "", - # } - # } - # ``` - # We need to migrate it to this configuration: - # ```python - # DATABASES = { - # "default": { - # "ENGINE": "sentry.db.postgres", - # "NAME": "postgres", - # "USER": "postgres", - # "PASSWORD": "", - # "HOST": "pgbouncer", - # "PORT": "", - # } - # } - # ``` +echo "${_group}Migrating Postgres config to PGBouncer..." +# If users has this EXACT configuration on their `sentry.conf.py` file: +# ```python +# DATABASES = { +# "default": { +# "ENGINE": "sentry.db.postgres", +# "NAME": "postgres", +# "USER": "postgres", +# "PASSWORD": "", +# "HOST": "postgres", +# "PORT": "", +# } +# } +# ``` +# We need to migrate it to this configuration: +# ```python +# DATABASES = { +# "default": { +# "ENGINE": "sentry.db.postgres", +# "NAME": "postgres", +# "USER": "postgres", +# "PASSWORD": "", +# "HOST": "pgbouncer", +# "PORT": "", +# } +# } +# ``` - if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "postgres"'; then - echo "Migrating $SENTRY_CONFIG_PY to use PGBouncer" - sed -i 's/"HOST": "postgres"/"HOST": "pgbouncer"/' "$SENTRY_CONFIG_PY" - echo "Migrated $SENTRY_CONFIG_PY to use PGBouncer" - elif sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "pgbouncer"'; then - echo "Found pgbouncer in $SENTRY_CONFIG_PY, I'm assuming you're good! :)" - else - echo "⚠️ You don't have standard configuration for Postgres in $SENTRY_CONFIG_PY, skipping pgbouncer migration. I'm assuming you know what you're doing." - fi - - echo "${_endgroup}" +if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "postgres"'; then + echo "Migrating $SENTRY_CONFIG_PY to use PGBouncer" + sed -i 's/"HOST": "postgres"/"HOST": "pgbouncer"/' "$SENTRY_CONFIG_PY" + echo "Migrated $SENTRY_CONFIG_PY to use PGBouncer" +elif sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "pgbouncer"'; then + echo "Found pgbouncer in $SENTRY_CONFIG_PY, I'm assuming you're good! :)" +else + echo "⚠️ You don't have standard configuration for Postgres in $SENTRY_CONFIG_PY, skipping pgbouncer migration. I'm assuming you know what you're doing." fi + +echo "${_endgroup}" From 6f7a21720b82211ffb0aeaa52046dba381f44156 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Fri, 5 Sep 2025 20:36:43 +0700 Subject: [PATCH 5/9] feat: apply config file modification behind a consent flag --- install/migrate-pgbouncer.sh | 47 +++++++++++++++++++++++++++++++++--- install/parse-cli.sh | 7 ++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/install/migrate-pgbouncer.sh b/install/migrate-pgbouncer.sh index 440caeba1ff..d142262eb19 100644 --- a/install/migrate-pgbouncer.sh +++ b/install/migrate-pgbouncer.sh @@ -27,9 +27,50 @@ echo "${_group}Migrating Postgres config to PGBouncer..." # ``` if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "postgres"'; then - echo "Migrating $SENTRY_CONFIG_PY to use PGBouncer" - sed -i 's/"HOST": "postgres"/"HOST": "pgbouncer"/' "$SENTRY_CONFIG_PY" - echo "Migrated $SENTRY_CONFIG_PY to use PGBouncer" + if [[ -z "${APPLY_AUTOMATIC_CONFIG_UPDATES:-}" ]]; then + echo + echo "We want to add PGBouncer to your Compose stack, and that would mean" + echo "you will need to modify your sentry.conf.py file contents." + echo "Do you want us to do it automatically for you?" + echo + + yn="" + until [ ! -z "$yn" ]; do + read -p "y or n? " yn + case $yn in + y | yes | 1) + export APPLY_AUTOMATIC_CONFIG_UPDATES=1 + echo + echo -n "Thank you." + ;; + n | no | 0) + export APPLY_AUTOMATIC_CONFIG_UPDATES=0 + echo + echo -n "Alright, you will need to update your sentry.conf.py file manually before running 'docker compose up'." + ;; + *) yn="" ;; + esac + done + + echo + echo "To avoid this prompt in the future, use one of these flags:" + echo + echo " --apply-automatic-config-updates" + echo " --no-apply-automatic-config-updates" + echo + echo "or set the APPLY_AUTOMATIC_CONFIG_UPDATES environment variable:" + echo + echo " APPLY_AUTOMATIC_CONFIG_UPDATES=1 to apply automatic updates" + echo " APPLY_AUTOMATIC_CONFIG_UPDATES=0 to not apply automatic updates" + echo + sleep 5 + fi + + if [[ "$APPLY_AUTOMATIC_CONFIG_UPDATES" == 1 ]]; then + echo "Migrating $SENTRY_CONFIG_PY to use PGBouncer" + sed -i 's/"HOST": "postgres"/"HOST": "pgbouncer"/' "$SENTRY_CONFIG_PY" + echo "Migrated $SENTRY_CONFIG_PY to use PGBouncer" + fi elif sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "pgbouncer"'; then echo "Found pgbouncer in $SENTRY_CONFIG_PY, I'm assuming you're good! :)" else diff --git a/install/parse-cli.sh b/install/parse-cli.sh index b342033ca08..6b9da063723 100644 --- a/install/parse-cli.sh +++ b/install/parse-cli.sh @@ -31,6 +31,10 @@ Options: self-hosted instance upstream to Sentry. --container-engine-podman Use podman as the container engine. + --apply-automatic-config-updates + Apply automatic config file updates. + --no-apply-automatic-config-updates + Do not apply automatic config file updates. EOF } @@ -49,6 +53,7 @@ SKIP_COMMIT_CHECK="${SKIP_COMMIT_CHECK:-}" REPORT_SELF_HOSTED_ISSUES="${REPORT_SELF_HOSTED_ISSUES:-}" SKIP_SSE42_REQUIREMENTS="${SKIP_SSE42_REQUIREMENTS:-}" CONTAINER_ENGINE_PODMAN="${CONTAINER_ENGINE_PODMAN:-}" +APPLY_AUTOMATIC_CONFIG_UPDATES="${APPLY_AUTOMATIC_CONFIG_UPDATES:-}" while (($#)); do case "$1" in @@ -71,6 +76,8 @@ while (($#)); do --no-report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=0 ;; --skip-sse42-requirements) SKIP_SSE42_REQUIREMENTS=1 ;; --container-engine-podman) CONTAINER_ENGINE_PODMAN=1 ;; + --apply-automatic-config-updates) APPLY_AUTOMATIC_CONFIG_UPDATES=1 ;; + --no-apply-automatic-config-updates) APPLY_AUTOMATIC_CONFIG_UPDATES=0 ;; --) ;; *) echo "Unexpected argument: $1. Use --help for usage information." From 70b6acc84990ad2ecaf498ecfb3d2bda9c538860 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 6 Sep 2025 06:14:08 +0700 Subject: [PATCH 6/9] fix(test): set flag to apply automatic upgrade --- _unit-test/migrate-pgbouncer-test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_unit-test/migrate-pgbouncer-test.sh b/_unit-test/migrate-pgbouncer-test.sh index 923fb560605..b78ee633c04 100755 --- a/_unit-test/migrate-pgbouncer-test.sh +++ b/_unit-test/migrate-pgbouncer-test.sh @@ -5,6 +5,8 @@ source install/dc-detect-version.sh source install/ensure-files-from-examples.sh cp $SENTRY_CONFIG_PY /tmp/sentry_conf_py +# Set the flag to apply automatic updates +export APPLY_AUTOMATIC_CONFIG_UPDATES=1 # Declare expected content expected_db_config=$( From 43d4fe38a5466c6b9ff959e9eeb1651293f85c60 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 9 Sep 2025 20:24:17 +0700 Subject: [PATCH 7/9] chore: apply grammatical fixes Co-authored-by: Burak Yigit Kaya --- install/migrate-pgbouncer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install/migrate-pgbouncer.sh b/install/migrate-pgbouncer.sh index d142262eb19..ef290834883 100644 --- a/install/migrate-pgbouncer.sh +++ b/install/migrate-pgbouncer.sh @@ -29,9 +29,9 @@ echo "${_group}Migrating Postgres config to PGBouncer..." if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "postgres"'; then if [[ -z "${APPLY_AUTOMATIC_CONFIG_UPDATES:-}" ]]; then echo - echo "We want to add PGBouncer to your Compose stack, and that would mean" + echo "We added PGBouncer to the default Compose stack, and to use that" echo "you will need to modify your sentry.conf.py file contents." - echo "Do you want us to do it automatically for you?" + echo "Do you want us to make this change automatically for you?" echo yn="" @@ -46,7 +46,7 @@ if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "pos n | no | 0) export APPLY_AUTOMATIC_CONFIG_UPDATES=0 echo - echo -n "Alright, you will need to update your sentry.conf.py file manually before running 'docker compose up'." + echo -n "Alright, you will need to update your sentry.conf.py file manually before running 'docker compose up' or remove the `pgbouncer` service if you don't want to use that." ;; *) yn="" ;; esac From 41428816fe0f60305d676c30ee2a5391bf38cf48 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Tue, 9 Sep 2025 20:56:57 +0700 Subject: [PATCH 8/9] feat: provide link to pgbouncer PR and respect SKIP_USER_PROMPT --- install/migrate-pgbouncer.sh | 3 ++- install/parse-cli.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/install/migrate-pgbouncer.sh b/install/migrate-pgbouncer.sh index ef290834883..6e8fe395d43 100644 --- a/install/migrate-pgbouncer.sh +++ b/install/migrate-pgbouncer.sh @@ -46,7 +46,7 @@ if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "pos n | no | 0) export APPLY_AUTOMATIC_CONFIG_UPDATES=0 echo - echo -n "Alright, you will need to update your sentry.conf.py file manually before running 'docker compose up' or remove the `pgbouncer` service if you don't want to use that." + echo -n "Alright, you will need to update your sentry.conf.py file manually before running 'docker compose up' or remove the $(pgbouncer) service if you don't want to use that." ;; *) yn="" ;; esac @@ -75,6 +75,7 @@ elif sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "p echo "Found pgbouncer in $SENTRY_CONFIG_PY, I'm assuming you're good! :)" else echo "⚠️ You don't have standard configuration for Postgres in $SENTRY_CONFIG_PY, skipping pgbouncer migration. I'm assuming you know what you're doing." + echo " For more information about PGBouncer, refer to https://github.com/getsentry/self-hosted/pull/3884" fi echo "${_endgroup}" diff --git a/install/parse-cli.sh b/install/parse-cli.sh index 6b9da063723..aec899c6398 100644 --- a/install/parse-cli.sh +++ b/install/parse-cli.sh @@ -45,6 +45,7 @@ depwarn() { if [ ! -z "${SKIP_USER_PROMPT:-}" ]; then depwarn "SKIP_USER_PROMPT variable" "SKIP_USER_CREATION" SKIP_USER_CREATION="${SKIP_USER_PROMPT}" + APPLY_AUTOMATIC_CONFIG_UPDATES="${SKIP_USER_PROMPT}" fi SKIP_USER_CREATION="${SKIP_USER_CREATION:-}" From 7ffe5823215e6e851deb799e5b89138da236be22 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Fri, 12 Sep 2025 07:23:05 +0700 Subject: [PATCH 9/9] feat: don't pollute APPLY_AUTOMATIC_CONFIG_UPDATES flag I hope this change won't be troublesome for the S3 Seaweed PR --- install/migrate-pgbouncer.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install/migrate-pgbouncer.sh b/install/migrate-pgbouncer.sh index 6e8fe395d43..8c698c72d92 100644 --- a/install/migrate-pgbouncer.sh +++ b/install/migrate-pgbouncer.sh @@ -27,6 +27,7 @@ echo "${_group}Migrating Postgres config to PGBouncer..." # ``` if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "postgres"'; then + apply_config_changes_pgbouncer=0 if [[ -z "${APPLY_AUTOMATIC_CONFIG_UPDATES:-}" ]]; then echo echo "We added PGBouncer to the default Compose stack, and to use that" @@ -39,12 +40,12 @@ if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "pos read -p "y or n? " yn case $yn in y | yes | 1) - export APPLY_AUTOMATIC_CONFIG_UPDATES=1 + export apply_config_changes_pgbouncer=1 echo echo -n "Thank you." ;; n | no | 0) - export APPLY_AUTOMATIC_CONFIG_UPDATES=0 + export apply_config_changes_pgbouncer=0 echo echo -n "Alright, you will need to update your sentry.conf.py file manually before running 'docker compose up' or remove the $(pgbouncer) service if you don't want to use that." ;; @@ -66,7 +67,7 @@ if sed -n '/^DATABASES = {$/,/^}$/p' "$SENTRY_CONFIG_PY" | grep -q '"HOST": "pos sleep 5 fi - if [[ "$APPLY_AUTOMATIC_CONFIG_UPDATES" == 1 ]]; then + if [[ "$APPLY_AUTOMATIC_CONFIG_UPDATES" == 1 || "$apply_config_changes_pgbouncer" == 1 ]]; then echo "Migrating $SENTRY_CONFIG_PY to use PGBouncer" sed -i 's/"HOST": "postgres"/"HOST": "pgbouncer"/' "$SENTRY_CONFIG_PY" echo "Migrated $SENTRY_CONFIG_PY to use PGBouncer"