|
| 1 | +echo "${_group}Bootstrapping seaweedfs (profiles)..." |
| 2 | + |
| 3 | +# The purpose of this file is to have both `sentry`-based containers and `vroom` use the same bucket for profiling. |
| 4 | +# Currently, we have a `sentry-vroom` volume which stores the profiling data. However, since version 25.10.0, |
| 5 | +# the behavior changed, and `vroomrs` now ingests profiles directly. Both services must share the same bucket, |
| 6 | +# but at the time of this writing, it's not possible because the `sentry-vroom` volume has ownership set to `vroom:vroom`. |
| 7 | +# This prevents the `sentry`-based containers from performing read/write operations on that volume. |
| 8 | +# |
| 9 | +# Therefore, this script should do the following: |
| 10 | +# 1. Check if there are any files inside the `sentry-vroom` volume. |
| 11 | +# 2. If (1) finds files, copy those files into a "profiles" bucket on SeaweedFS. |
| 12 | +# 3. Point `filestore-profiles` and vroom to the SeaweedFS "profiles" bucket. |
| 13 | + |
| 14 | +start_service_and_wait_ready seaweedfs |
| 15 | +$dc exec -e "HTTP_PROXY=${HTTP_PROXY:-}" -e "HTTPS_PROXY=${HTTPS_PROXY:-}" -e "NO_PROXY=${NO_PROXY:-}" -e "http_proxy=${http_proxy:-}" -e "https_proxy=${https_proxy:-}" -e "no_proxy=${no_proxy:-}" seaweedfs apk add --no-cache s3cmd |
| 16 | + |
| 17 | +bucket_list=$($s3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=localhost:8333 --host-bucket='localhost:8333/%(bucket)' ls) |
| 18 | + |
| 19 | +if [[ $(echo "$bucket_list" | tail -1 | awk '{print $3}') != 's3://profiles' ]]; then |
| 20 | + apply_config_changes_profiles=0 |
| 21 | + # Only touch if no existing profiles config is found |
| 22 | + if ! grep -q "filestore.profiles-backend" $SENTRY_CONFIG_YML; then |
| 23 | + if [[ -z "${APPLY_AUTOMATIC_CONFIG_UPDATES:-}" ]]; then |
| 24 | + echo |
| 25 | + echo "We are migrating the Profiles data directory from the 'sentry-vroom' volume to S3." |
| 26 | + echo "This migration will ensure profiles ingestion works correctly with the new 'vroomrs'" |
| 27 | + echo "and allows both 'sentry' and 'vroom' to transition smoothly." |
| 28 | + echo "To complete this, your sentry/config.yml file needs to be modified." |
| 29 | + echo "Would you like us to perform this modification automatically?" |
| 30 | + echo |
| 31 | + |
| 32 | + yn="" |
| 33 | + until [ ! -z "$yn" ]; do |
| 34 | + read -p "y or n? " yn |
| 35 | + case $yn in |
| 36 | + y | yes | 1) |
| 37 | + export apply_config_changes_profiles=1 |
| 38 | + echo |
| 39 | + echo -n "Thank you." |
| 40 | + ;; |
| 41 | + n | no | 0) |
| 42 | + export apply_config_changes_profiles=0 |
| 43 | + echo |
| 44 | + echo -n "Alright, you will need to update your sentry/config.yml file manually before running 'docker compose up'." |
| 45 | + ;; |
| 46 | + *) yn="" ;; |
| 47 | + esac |
| 48 | + done |
| 49 | + |
| 50 | + echo |
| 51 | + echo "To avoid this prompt in the future, use one of these flags:" |
| 52 | + echo |
| 53 | + echo " --apply-automatic-config-updates" |
| 54 | + echo " --no-apply-automatic-config-updates" |
| 55 | + echo |
| 56 | + echo "or set the APPLY_AUTOMATIC_CONFIG_UPDATES environment variable:" |
| 57 | + echo |
| 58 | + echo " APPLY_AUTOMATIC_CONFIG_UPDATES=1 to apply automatic updates" |
| 59 | + echo " APPLY_AUTOMATIC_CONFIG_UPDATES=0 to not apply automatic updates" |
| 60 | + echo |
| 61 | + sleep 5 |
| 62 | + fi |
| 63 | + |
| 64 | + if [[ "$APPLY_AUTOMATIC_CONFIG_UPDATES" == 1 || "$apply_config_changes_profiles" == 1 ]]; then |
| 65 | + profiles_config=$(sed -n '/filestore.profiles-backend/,/s3v4"/{p}' sentry/config.example.yml) |
| 66 | + echo "$profiles_config" >>$SENTRY_CONFIG_YML |
| 67 | + fi |
| 68 | + fi |
| 69 | + |
| 70 | + $s3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=localhost:8333 --host-bucket='localhost:8333/%(bucket)' mb s3://profiles |
| 71 | + |
| 72 | + # Check if there are files in the sentry-vroom volume |
| 73 | + vroom_files_count=$($dc exec vroom sh -c "find /var/vroom/sentry-profiles -type f | wc -l") |
| 74 | + if [[ "$vroom_files_count" -gt 0 ]]; then |
| 75 | + echo "Migrating $vroom_files_count files from 'sentry-vroom' volume to 'profiles' bucket on SeaweedFS..." |
| 76 | + |
| 77 | + # Use a temporary container to copy files from the volume to SeaweedFS |
| 78 | + $dc run --rm --no-deps -v sentry-vroom:/source -e "HTTP_PROXY=${HTTP_PROXY:-}" -e "HTTPS_PROXY=${HTTPS_PROXY:-}" -e "NO_PROXY=${NO_PROXY:-}" -e "http_proxy=${http_proxy:-}" -e "https_proxy=${https_proxy:-}" -e "no_proxy=${no_proxy:-}" seaweedfs sh -c ' |
| 79 | + apk add --no-cache s3cmd && |
| 80 | + s3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=localhost:8333 --host-bucket="localhost:8333/%(bucket)" sync /source/ s3://profiles/ |
| 81 | + ' |
| 82 | + |
| 83 | + echo "Migration completed." |
| 84 | + else |
| 85 | + echo "No files found in 'sentry-vroom' volume. Skipping files migration." |
| 86 | + fi |
| 87 | +else |
| 88 | + echo "'profiles' bucket already exists on SeaweedFS. Skipping creation." |
| 89 | +fi |
| 90 | + |
| 91 | +if [[ -z "${APPLY_AUTOMATIC_CONFIG_UPDATES:-}" || "$APPLY_AUTOMATIC_CONFIG_UPDATES" == 1 ]]; then |
| 92 | + lifecycle_policy=$( |
| 93 | + cat <<EOF |
| 94 | +<?xml version="1.0" encoding="UTF-8"?> |
| 95 | +<LifecycleConfiguration> |
| 96 | + <Rule> |
| 97 | + <ID>Sentry-Profiles-Rule</ID> |
| 98 | + <Status>Enabled</Status> |
| 99 | + <Filter></Filter> |
| 100 | + <Expiration> |
| 101 | + <Days>$SENTRY_EVENT_RETENTION_DAYS</Days> |
| 102 | + </Expiration> |
| 103 | + </Rule> |
| 104 | +</LifecycleConfiguration> |
| 105 | +EOF |
| 106 | + ) |
| 107 | + |
| 108 | + $dc exec seaweedfs sh -c "printf '%s' '$lifecycle_policy' > /tmp/profiles-lifecycle-policy.xml" |
| 109 | + $s3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=localhost:8333 --host-bucket='localhost:8333/%(bucket)' setlifecycle /tmp/profiles-lifecycle-policy.xml s3://profiles |
| 110 | + |
| 111 | + echo "Making sure the bucket lifecycle policy is all set up correctly..." |
| 112 | + $s3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=localhost:8333 --host-bucket='localhost:8333/%(bucket)' getlifecycle s3://profiles |
| 113 | +fi |
0 commit comments