-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathbootstrap-s3-profiles.sh
More file actions
132 lines (118 loc) · 6.16 KB
/
Copy pathbootstrap-s3-profiles.sh
File metadata and controls
132 lines (118 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# The purpose of this file is to have both `sentry`-based containers and `vroom` use the same bucket for profiling.
# On pre-25.10.0, we have a `sentry-vroom` volume which stores the profiling data however, since this version,
# the behavior changed, and `vroomrs` now ingests profiles directly. Both services must share the same bucket,
# but at the time of this writing, it's not possible because the `sentry-vroom` volume has ownership set to `vroom:vroom`.
# This prevents the `sentry`-based containers from performing read/write operations on that volume.
#
# Therefore, this script should do the following:
# 1. Check if there are any files inside the `sentry-vroom` volume.
# 2. If (1) finds files, copy those files into a "profiles" bucket on SeaweedFS.
# 3. Point `filestore-profiles` and vroom to the SeaweedFS "profiles" bucket.
# Should only run when `$COMPOSE_PROFILES` is set to `feature-complete`
if [[ "$COMPOSE_PROFILES" == "feature-complete" ]]; then
echo "${_group}Bootstrapping seaweedfs (profiles)..."
start_service_and_wait_ready seaweedfs
$dcx seaweedfs apk add --no-cache s3cmd
s3cmd="$dc exec seaweedfs s3cmd"
bucket_list=$($s3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=localhost:8333 --host-bucket='localhost:8333/%(bucket)' ls)
if ! echo "$bucket_list" | grep -q "s3://profiles"; then
apply_config_changes_profiles=0
# Ensure `$SENTRY_CONFIG_YML` file exists
if [[ -f "$SENTRY_CONFIG_YML" ]]; then
# Only touch if no existing profiles config is found
if ! grep -q "filestore.profiles-backend" $SENTRY_CONFIG_YML; then
if [[ -z "${APPLY_AUTOMATIC_CONFIG_UPDATES:-}" ]]; then
echo
echo "We are migrating the Profiles data directory from the 'sentry-vroom' volume to SeaweedFS."
echo "This migration will ensure profiles ingestion works correctly with the new 'vroomrs'"
echo "and allows both 'sentry' and 'vroom' to transition smoothly."
echo "To complete this, your sentry/config.yml file needs to be modified."
echo "Would you like us to perform this modification automatically?"
echo
yn=""
until [ ! -z "$yn" ]; do
read -p "y or n? " yn
case $yn in
y | yes | 1)
export apply_config_changes_profiles=1
echo
echo -n "Thank you."
;;
n | no | 0)
export apply_config_changes_profiles=0
echo
echo -n "Alright, you will need to update your sentry/config.yml 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 || "$apply_config_changes_profiles" == 1 ]]; then
profiles_config=$(sed -n '/filestore.profiles-backend/,/s3v4"/{p}' sentry/config.example.yml)
echo "$profiles_config" >>$SENTRY_CONFIG_YML
fi
fi
fi
$s3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=localhost:8333 --host-bucket='localhost:8333/%(bucket)' mb s3://profiles
# Check if there are files in the sentry-vroom volume
start_service_and_wait_ready vroom
vroom_files_count=$($dc exec vroom sh -c "find /var/vroom/sentry-profiles -type f | wc -l")
if [[ "$vroom_files_count" -gt 0 ]]; then
echo "Migrating $vroom_files_count files from 'sentry-vroom' volume to 'profiles' bucket on SeaweedFS..."
# Use a temporary container to copy files from the volume to SeaweedFS
$dcx -u root vroom sh -c 'mkdir -p /var/lib/apt/lists/partial && apt-get update && apt-get install -y --no-install-recommends s3cmd'
$dc exec vroom sh -c 's3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=seaweedfs:8333 --host-bucket="seaweedfs:8333/%(bucket)" sync /var/vroom/sentry-profiles/ s3://profiles/'
echo "Migration completed."
else
echo "No files found in 'sentry-vroom' volume. Skipping files migration."
fi
else
echo "'profiles' bucket already exists on SeaweedFS. Skipping creation."
fi
if [[ -z "${APPLY_AUTOMATIC_CONFIG_UPDATES:-}" || "$APPLY_AUTOMATIC_CONFIG_UPDATES" == 1 ]]; then
lifecycle_policy=$(
cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration>
<Rule>
<ID>Sentry-Profiles-Rule</ID>
<Status>Enabled</Status>
<Filter></Filter>
<Expiration>
<Days>$SENTRY_EVENT_RETENTION_DAYS</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
EOF
)
$dc exec seaweedfs sh -c "printf '%s' '$lifecycle_policy' > /tmp/profiles-lifecycle-policy.xml"
setlifecycle_cmd="$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"
if ! timeout 60s sh -c "$setlifecycle_cmd"; then
echo
echo
echo "====== WARNING ======"
echo
echo "Applying the lifecycle policy for the 'profiles' bucket took too long or failed."
echo "This policy is important to ensure that old profiles are automatically deleted after $SENTRY_EVENT_RETENTION_DAYS days, which helps manage storage usage."
echo "Please run this command manually as soon as possible to set the lifecycle policy for the 'profiles' bucket:"
echo
echo " $setlifecycle_cmd"
echo
sleep 5
fi
timeout 30s $s3cmd --access_key=sentry --secret_key=sentry --no-ssl --region=us-east-1 --host=localhost:8333 --host-bucket='localhost:8333/%(bucket)' getlifecycle s3://profiles >/dev/null 2>&1 || true
fi
echo "${_endgroup}"
fi