Skip to content

feat(profiling): Run profiling on self-hosted #2154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
17ac35b
feat(profiling): Run profiling on self-hosted
phacops May 17, 2023
d919885
Run profiles and functions Snuba consumers
phacops May 17, 2023
7f82276
Fix typo in variable name
May 17, 2023
0cc8b66
Run profiles consumer
phacops May 17, 2023
e01c431
Enable profiling in the UI
phacops May 17, 2023
d608f0c
Add an external volume to store profiles
phacops May 17, 2023
a006a3a
Create sentry-vroom volume
phacops May 18, 2023
8aa571c
Add missing Kafka broker environment variables
phacops May 18, 2023
c47f62f
Bump vroom image version on new release
phacops May 23, 2023
4564d44
Move ingest-profiles right below the rest of the consumers
phacops May 23, 2023
36daec3
Hard code Snuba host variable
phacops May 23, 2023
d079095
Fix storage name for functions
phacops May 24, 2023
90dffe1
update create docker volumes unit test
hubertdeng123 May 24, 2023
ce11a29
apparently v comes before z in the alphabet
hubertdeng123 May 24, 2023
591d48d
Use nightly tag like other images
phacops May 25, 2023
35e98ad
Add a test to create and retrieve a profile
phacops May 25, 2023
35eeb82
Fix profile path
phacops May 25, 2023
1b85e47
Set the actual right path
phacops May 25, 2023
6ffa0a5
Remove local DSN and rename file since it's not valid JSON
phacops May 30, 2023
f4e4c0a
Adjust curl command to send data from file as binary to preserve new …
phacops May 30, 2023
9861b63
Make the test profile thinner
phacops May 30, 2023
419cdc1
Get the profile ID from the test profile file
phacops May 30, 2023
d5997b9
Make vroom volume not external
phacops May 30, 2023
58838d7
Use a common path for curl and jq call and fix content type
phacops May 31, 2023
9e28cef
Move environment variable to a vroom-specific location
phacops May 31, 2023
a540847
Add vroom as a default service
phacops May 31, 2023
40198e9
Set the proper environment variable for vroom service in web
phacops May 31, 2023
a49a5ed
Remove exposing the port as it's not needed for other containers to r…
Jun 2, 2023
a701258
Add comments to make it explicit what those volumes are and how they …
phacops Jun 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SENTRY_IMAGE=getsentry/sentry:nightly
SNUBA_IMAGE=getsentry/snuba:nightly
RELAY_IMAGE=getsentry/relay:nightly
SYMBOLICATOR_IMAGE=getsentry/symbolicator:nightly
VROOM_IMAGE=getsentry/vroom:nightly
WAL2JSON_VERSION=latest
HEALTHCHECK_INTERVAL=30s
HEALTHCHECK_TIMEOUT=60s
Expand Down
5 changes: 5 additions & 0 deletions _integration-test/fixtures/envelope-with-profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"event_id":"66578634d48d433db0ad52882d1efe5b","sent_at":"2023-05-17T14:54:31.057Z","sdk":{"name":"sentry.javascript.node","version":"7.46.0"},"trace":{"environment":"production","transaction":"fib: sourcemaps here","public_key":"05ab86aebbe14a24bcab62caa839cf27","trace_id":"33321bfbd5304bcc9663d1b53b08f84e","sample_rate":"1"}}
{"type":"transaction"}
{"contexts":{"profile":{"profile_id":"e73aaf1f29b24812be60132f32d09f92"},"trace":{"op":"test","span_id":"b38f2b24537c3858","trace_id":"33321bfbd5304bcc9663d1b53b08f84e"},"runtime":{"name":"node","version":"v16.16.0"},"app":{"app_start_time":"2023-05-17T14:54:27.678Z","app_memory":57966592},"os":{"kernel_version":"22.3.0","name":"macOS","version":"13.2","build":"22D49"},"device":{"boot_time":"2023-05-12T15:08:41.047Z","arch":"arm64","memory_size":34359738368,"free_memory":6861651968,"processor_count":10,"cpu_description":"Apple M1 Pro","processor_frequency":24},"culture":{"locale":"en-US","timezone":"America/New_York"}},"spans":[],"start_timestamp":1684335267.744,"tags":{},"timestamp":1684335271.033,"transaction":"fib: sourcemaps here","type":"transaction","transaction_info":{"source":"custom"},"platform":"node","server_name":"TK6G745PW1.local","event_id":"66578634d48d433db0ad52882d1efe5b","environment":"production","sdk":{"integrations":["InboundFilters","FunctionToString","Console","Http","OnUncaughtException","OnUnhandledRejection","ContextLines","LocalVariables","Context","Modules","RequestData","LinkedErrors","ProfilingIntegration"],"name":"sentry.javascript.node","version":"7.46.0","packages":[{"name":"npm:@sentry/node","version":"7.46.0"}]},"debug_meta":{"images":[]},"modules":{}}
{"type":"profile"}
{"event_id":"e73aaf1f29b24812be60132f32d09f92","timestamp":"2023-05-17T14:54:27.744Z","platform":"node","version":"1","release":"","environment":"production","runtime":{"name":"node","version":"16.16.0"},"os":{"name":"darwin","version":"22.3.0","build_number":"Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000"},"device":{"locale":"en_US.UTF-8","model":"arm64","manufacturer":"Darwin","architecture":"arm64","is_emulator":false},"debug_meta":{"images":[]},"profile":{"samples":[{"stack_id":0,"thread_id":"0","elapsed_since_start_ns":125000},{"stack_id":0,"thread_id":"0","elapsed_since_start_ns":13958000}],"frames":[{"lineno":14129,"colno":17,"function":"startProfiling","abs_path":"/Users/jonasbadalic/code/node-profiler/lib/index.js"}],"stacks":[[0]],"thread_metadata":{"0":{"name":"main"}}},"transaction":{"name":"fib: sourcemaps here","id":"66578634d48d433db0ad52882d1efe5b","trace_id":"33321bfbd5304bcc9663d1b53b08f84e","active_thread_id":"0"}}
12 changes: 12 additions & 0 deletions _integration-test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ $dcr --no-deps web python3 /etc/sentry/test-custom-ca-roots.py
source _integration-test/custom-ca-roots/teardown.sh
echo "${_endgroup}"

echo "${_group}Test that profiling work ..."
echo "Sending a test profile..."
PROFILE_FIXTURE_PATH="$(git rev-parse --show-toplevel)/_integration-test/fixtures/envelope-with-profile"
curl -sf --data-binary @$PROFILE_FIXTURE_PATH -H 'Content-Type: application/x-sentry-envelope' -H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=$SENTRY_KEY, sentry_client=test-bash/0.1" "$SENTRY_TEST_HOST/api/$PROJECT_ID/envelope/" -o /dev/null

printf "Getting the test profile back"
PROFILE_ID="$(jq -r -n --slurpfile profile $PROFILE_FIXTURE_PATH '$profile[4].event_id')"
PROFILE_PATH="api/0/projects/sentry/sentry/profiling/raw_profiles/$PROFILE_ID/"
timeout 60 bash -c 'until $(sentry_api_request "$PROFILE_PATH" -Isf -X GET -o /dev/null); do printf '.'; sleep 0.5; done'
echo " got it!"
echo "${_endgroup}"

# Table formatting based on https://stackoverflow.com/a/39144364
COMPOSE_PS_OUTPUT=$(docker compose ps --format json | jq -r \
'.[] |
Expand Down
2 changes: 0 additions & 2 deletions _unit-test/create-docker-volumes-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ before=$(get_volumes)

test "$before" == "" || test "$before" == "$expected_volumes"

source install/create-docker-volumes.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this was ever duplicated even after looking through the file history, and tests seem to be passing fine without it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe testing for duplicate volume creation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was to make sure trying to create volumes over and over again does not error. I think, since we run the whole installation twice now, this is redundant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, safe to remove then

source install/create-docker-volumes.sh
source install/create-docker-volumes.sh

after=$(get_volumes)
Expand Down
32 changes: 30 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ x-sentry-defaults: &sentry_defaults
<<: *depends_on-default
symbolicator:
<<: *depends_on-default
vroom:
<<: *depends_on-default
entrypoint: "/etc/sentry/entrypoint.sh"
command: ["run", "web"]
environment:
PYTHONUSERBASE: "/data/custom-packages"
SENTRY_CONF: "/etc/sentry"
SNUBA: "http://snuba-api:1218"
VROOM: "http://vroom:8085"
# Force everything to use the system CA bundle
# This is mostly needed to support installing custom CA certs
# This one is used by botocore
Expand Down Expand Up @@ -283,6 +286,12 @@ services:
snuba-subscription-consumer-transactions:
<<: *snuba_defaults
command: subscriptions-scheduler-executor --dataset transactions --entity transactions --auto-offset-reset=latest --no-strict-offset-reset --consumer-group=snuba-transactions-subscriptions-consumers --followed-consumer-group=transactions_group --delay-seconds=60 --schedule-ttl=60 --stale-threshold-seconds=900
snuba-profiling-profiles-consumer:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay, more snuba containers! Let's add another strike to getsentry/snuba#1670

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm counting 36 containers total. This is somewhat frightening.

<<: *snuba_defaults
command: consumer --storage profiles --auto-offset-reset=latest --max-batch-time-ms 1000 --no-strict-offset-reset
snuba-profiling-functions-consumer:
<<: *snuba_defaults
command: consumer --storage functions_raw --auto-offset-reset=latest --max-batch-time-ms 1000 --no-strict-offset-reset
symbolicator:
<<: *restart_policy
image: "$SYMBOLICATOR_IMAGE"
Expand Down Expand Up @@ -329,10 +338,12 @@ services:
ingest-replay-recordings:
<<: *sentry_defaults
command: run ingest-replay-recordings
ingest-profiles:
<<: *sentry_defaults
command: run ingest-profiles --no-strict-offset-reset
post-process-forwarder-errors:
<<: *sentry_defaults
command: run post-process-forwarder --entity errors

post-process-forwarder-transactions:
<<: *sentry_defaults
command: run post-process-forwarder --entity transactions --commit-log-topic=snuba-transactions-commit-log --synchronize-commit-group transactions_group
Expand Down Expand Up @@ -384,6 +395,19 @@ services:
<<: *depends_on-healthy
web:
<<: *depends_on-healthy
vroom:
<<: *restart_policy
image: "$VROOM_IMAGE"
environment:
SENTRY_KAFKA_BROKERS_PROFILING: "kafka:9092"
SENTRY_KAFKA_BROKERS_OCCURRENCES: "kafka:9092"
SENTRY_BUCKET_PROFILES: file://localhost//var/lib/sentry-profiles
SENTRY_SNUBA_HOST: "http://snuba-api:1218"
volumes:
- sentry-vroom:/var/lib/sentry-profiles
depends_on:
kafka:
<<: *depends_on-healthy
volumes:
# These store application data that should persist across restarts.
sentry-data:
Expand All @@ -400,8 +424,12 @@ volumes:
external: true
sentry-symbolicator:
external: true

# This volume stores profiles and should be persisted.
# Not being external will still persist data across restarts.
# It won't persist if someone does a docker compose down -v.
sentry-vroom:
# These store ephemeral data that needn't persist across restarts.
# That said, volumes will be persisted across restarts until they are deleted.
sentry-secrets:
sentry-smtp:
sentry-nginx-cache:
Expand Down
2 changes: 1 addition & 1 deletion install/create-kafka-topics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ echo "${_group}Creating additional Kafka topics ..."
# NOTE: This step relies on `kafka` being available from the previous `snuba-api bootstrap` step
# XXX(BYK): We cannot use auto.create.topics as Confluence and Apache hates it now (and makes it very hard to enable)
EXISTING_KAFKA_TOPICS=$($dcr -T kafka kafka-topics --list --bootstrap-server kafka:9092 2>/dev/null)
NEEDED_KAFKA_TOPICS="ingest-attachments ingest-transactions ingest-events ingest-replay-recordings"
NEEDED_KAFKA_TOPICS="ingest-attachments ingest-transactions ingest-events ingest-replay-recordings profiles"
for topic in $NEEDED_KAFKA_TOPICS; do
if ! echo "$EXISTING_KAFKA_TOPICS" | grep -wq $topic; then
$dcr kafka kafka-topics --create --topic $topic --bootstrap-server kafka:9092
Expand Down
2 changes: 1 addition & 1 deletion scripts/bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NEW_VERSION="$2"
WAL2JSON_VERSION=${WAL2JSON_VERSION:-$(curl -s "https://api.github.com/repos/getsentry/wal2json/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')}

sed -i -e "s/^WAL2JSON_VERSION=\([^:]\+\):.\+\$/WAL2JSON_VERSION=\1:$WAL2JSON_VERSION/" .env
sed -i -e "s/^\(SENTRY\|SNUBA\|RELAY\|SYMBOLICATOR\)_IMAGE=\([^:]\+\):.\+\$/\1_IMAGE=\2:$NEW_VERSION/" .env
sed -i -e "s/^\(SENTRY\|SNUBA\|RELAY\|SYMBOLICATOR|VROOM\)_IMAGE=\([^:]\+\):.\+\$/\1_IMAGE=\2:$NEW_VERSION/" .env
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should consider making this a blocklist now since almost all images get updated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, I think this is a reasonable refactor but let's not put the burden on @phacops in this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2207 ftr, missing escape of the | led to a corrupt 23.6.0 release. 🐭

sed -i -e "s/^\# Self-Hosted Sentry .*/# Self-Hosted Sentry $NEW_VERSION/" README.md
sed -i -e "s/\(Change Date:\s*\)[-0-9]\+\$/\\1$(date +'%Y-%m-%d' -d '3 years')/" LICENSE

Expand Down
1 change: 1 addition & 0 deletions sentry/sentry.conf.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def get_internal_network():
"organizations:performance-view",
"organizations:advanced-search",
"organizations:session-replay",
"organizations:profiling",
"projects:custom-inbound-filters",
"projects:data-forwarding",
"projects:discard-groups",
Expand Down