Skip to content
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

ci: enable exception replay in Django profile job [backport 2.17] #11958

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .github/workflows/django-overhead-profile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
DD_PROFILING_ENABLED: "1"
DD_PROFILING_STACK_V2_ENABLED: ${{ matrix.stack_v2 }}
DD_PROFILING_OUTPUT_PPROF: ${{ github.workspace }}/prefix/artifacts/ddtrace_profile
DD_EXCEPTION_REPLAY_ENABLED: "1"
defaults:
run:
working-directory: ddtrace
Expand Down
10 changes: 10 additions & 0 deletions scripts/profiles/django-simple/k6-exc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import http from 'k6/http';

export const options = {
duration: '60s',
vus: 100,
};

export default function () {
const res = http.get('http://127.0.0.1:8080/polls/123/results/');
}
3 changes: 1 addition & 2 deletions scripts/profiles/django-simple/k6-load.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
duration: '60s',
vus: 100,
};

export default function () {
const res = http.get('http://127.0.0.1:8000/accounts/signup/');
const res = http.get('http://127.0.0.1:8080/polls/123/vote/');
}
100 changes: 62 additions & 38 deletions scripts/profiles/django-simple/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,83 @@ AUSTIN_EXPOSURE=5 # sec

test -f ${PREFIX}/gunicorn.pid && (kill -9 `cat ${PREFIX}/gunicorn.pid` ; sleep 3) || rm -f ${PREFIX}/gunicorn.pid
pkill k6 || true
test -d ${PREFIX}/artifacts && rm -rf ${PREFIX}/artifacts || mkdir -p ${PREFIX}/artifacts
pkill -9 -f uwsgi || true
test -d ${PREFIX}/artifacts && rm -rf ${PREFIX}/artifacts
mkdir -p ${PREFIX}/artifacts

sudo echo "sudo OK"

sudo rm -f ${PREFIX}/uwsgi.pid

function profile_with_load {
name=${1}
scenario=${2}

echo "- profiling for ${name}"

sleep 3
${PREFIX}/k6*/k6 run --quiet scripts/profiles/django-simple/k6-load.js &
echo "Starting load"
${PREFIX}/k6*/k6 run --quiet scripts/profiles/django-simple/k6-${scenario}.js &
sleep 2
sudo `which austin` -bsCi ${AUSTIN_INTERVAL} -o ${PREFIX}/artifacts/${name}.mojo -p `cat ${PREFIX}/gunicorn.pid` -x ${AUSTIN_EXPOSURE}
LC_ALL=C sed -i 's|/home/runner/work/dd-trace-py/dd-trace-py/ddtrace/||g' ${PREFIX}/artifacts/${name}.mojo
echo "Attaching Austin to $(cat ${PREFIX}/uwsgi.pid)"
sudo `which austin` -bsCi ${AUSTIN_INTERVAL} -o ${PREFIX}/artifacts/${scenario}_${name}.mojo -p `cat ${PREFIX}/uwsgi.pid` -x ${AUSTIN_EXPOSURE}
LC_ALL=C sed -i 's|/home/runner/work/dd-trace-py/dd-trace-py/ddtrace/||g' ${PREFIX}/artifacts/${scenario}_${name}.mojo
echo "Stopping load"
pkill k6
}

source ${PREFIX}/bin/activate

export DJANGO_SETTINGS_MODULE="config.settings.production"
export DJANGO_ALLOWED_HOSTS="127.0.0.1"
export DJANGO_SECRET_KEY="SECRET_KEY"
export DATABASE_URL="sqlite:///django.db"
export DJANGO_ALLOWED_HOSTS="127.0.0.1"
export DEVELOPMENT_MODE=True

# Tag traces with HTTP headers to benchmark the related code
export DD_TRACE_HEADER_TAGS="User-Agent:http.user_agent,Referer:http.referer,Content-Type:http.content_type,Etag:http.etag"

# Baseline
pushd ${PREFIX}/trace-examples/python/django/django-simple
gunicorn config.wsgi --pid ${PREFIX}/gunicorn.pid > /dev/null &
echo "Done"
popd
profile_with_load "baseline"
kill $(cat ${PREFIX}/gunicorn.pid)

pushd ${PREFIX}/trace-examples/python/django/django-simple
ddtrace-run gunicorn config.wsgi --pid ${PREFIX}/gunicorn.pid > /dev/null &
popd
profile_with_load "head"
kill $(cat ${PREFIX}/gunicorn.pid)

sudo chown -R $(id -u):$(id -g) ${PREFIX}/artifacts/*

echo -n "Converting MOJO to Austin ... "
mojo2austin ${PREFIX}/artifacts/head.mojo ${PREFIX}/artifacts/head.austin.tmp
mojo2austin ${PREFIX}/artifacts/baseline.mojo ${PREFIX}/artifacts/baseline.austin.tmp
echo "[done]"

echo -n "Diffing ... "
python scripts/diff.py \
${PREFIX}/artifacts/head.austin.tmp \
${PREFIX}/artifacts/baseline.austin.tmp \
${PREFIX}/artifacts/baseline_head.diff
echo "[done]"

rm ${PREFIX}/artifacts/*.austin.tmp

head -n 25 ${PREFIX}/artifacts/baseline_head.diff.top

function run_scenario {
scenario=${1}

echo "Running scenario ${scenario}"

# Baseline
pushd ${PREFIX}/trace-examples/python/django/sample-django
uwsgi --http :8080 --enable-threads --module mysite.wsgi --pidfile ${PREFIX}/uwsgi.pid 2> /dev/null &
echo "Done"
popd
profile_with_load "baseline" ${scenario}
echo "Stopping uwsgi"
uwsgi --stop ${PREFIX}/uwsgi.pid
pkill -9 -f uwsgi || true

pushd ${PREFIX}/trace-examples/python/django/sample-django
uwsgi --http :8080 --enable-threads --module mysite.wsgi --pidfile ${PREFIX}/uwsgi.pid --import=ddtrace.bootstrap.sitecustomize 2> /dev/null &
popd
profile_with_load "head" ${scenario}
echo "Stopping uwsgi"
uwsgi --stop ${PREFIX}/uwsgi.pid
pkill -9 -f uwsgi || true

sudo chown -R $(id -u):$(id -g) ${PREFIX}/artifacts/*

echo -n "Converting MOJO to Austin ... "
mojo2austin ${PREFIX}/artifacts/${scenario}_head.mojo ${PREFIX}/artifacts/${scenario}_head.austin.tmp
mojo2austin ${PREFIX}/artifacts/${scenario}_baseline.mojo ${PREFIX}/artifacts/${scenario}_baseline.austin.tmp
echo "[done]"

echo -n "Diffing ... "
python scripts/diff.py \
${PREFIX}/artifacts/${scenario}_head.austin.tmp \
${PREFIX}/artifacts/${scenario}_baseline.austin.tmp \
${PREFIX}/artifacts/${scenario}_baseline_head.diff
echo "[done]"

rm ${PREFIX}/artifacts/*.austin.tmp

head -n 25 ${PREFIX}/artifacts/${scenario}_baseline_head.diff.top
}


run_scenario "load"
run_scenario "exc"
10 changes: 4 additions & 6 deletions scripts/profiles/django-simple/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ PREFIX=${1}
AUSTIN_VERSION="3.6"
K6_VERSION="0.26.2"

export DJANGO_SETTINGS_MODULE="config.settings.production"
export DJANGO_ALLOWED_HOSTS="127.0.0.1"
export DJANGO_SECRET_KEY="SECRET_KEY"
export DATABASE_URL="sqlite:///django.db"

# Clean up existing installation
Expand All @@ -26,12 +24,12 @@ source ${PREFIX}/bin/activate
pip install pip --upgrade

# Install the application
git clone https://github.com/DataDog/trace-examples.git ${PREFIX}/trace-examples
test -d ${PREFIX}/trace-examples || git clone -b sample-django --single-branch https://github.com/DataDog/trace-examples.git ${PREFIX}/trace-examples
pushd ${PREFIX}/trace-examples/
git checkout origin/django-simple
pushd python/django/django-simple
pip install -r requirements/production.txt
pushd python/django/sample-django
pip install -r requirements.txt
python manage.py migrate
python manage.py collectstatic
popd
popd

Expand Down
Loading