Skip to content

Commit

Permalink
Set up staging to use sentry tracing for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed Sep 19, 2023
1 parent 5f2a879 commit d2f669f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
10 changes: 10 additions & 0 deletions ansible/_set_up_directories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
group: deploy
become: true

- name: Move .env file to shared directory
ansible.builtin.template:
src: "templates/dotenv.j2"
dest: "{{ project_root }}/shared/.env"
mode: "0755"
owner: deploy
group: deploy
become: true
when: update_dotenv is true

- name: Link .env to shared directory
ansible.builtin.file:
src: "{{ project_root }}/shared/.env"
Expand Down
3 changes: 3 additions & 0 deletions ansible/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
# is a workaround
update_front_end_deps: true

# create new dotenv file in shared directory (use when adding new env vars)
update_dotenv: true

supervisor_restart: true
supervisor_user: "deploy"

Expand Down
1 change: 1 addition & 0 deletions ansible/inventories/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ all:
supervisor_user: "deploy"
supervisor_gunicorn_app: "web_{{ tgwf_stage }}"
supervisor_worker_job: "worker_{{ tgwf_stage }}"
port: 9000

# you can set child groups too
children:
Expand Down
3 changes: 2 additions & 1 deletion ansible/inventories/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ all:
hosts:
app3.thegreenwebfoundation.org:
internal_ip: "10.0.0.6"
gunicorn_port: 10000
dramatiq_threads: 1
dramatiq_processes: 1

sentry_trace_rate: 1
vars:
tgwf_stage: "staging"
tgwf_domain_name: "admin-staging"
Expand Down
5 changes: 5 additions & 0 deletions ansible/templates/dotenv.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ EXPLORER_TOKEN="{{ lookup('env','EXPLORER_TOKEN') }}"
SECRET_KEY="{{ lookup('env','SECRET_KEY') }}"
DJANGO_SETTINGS_MODULE="{{ lookup('env','DJANGO_SETTINGS_MODULE') }}"
RABBITMQ_URL="{{ lookup('env', "RABBITMQ_URL") }}"


SENTRY_DSN="{{ lookup('env', "SENTRY_DSN") }}"
SENTRY_ENVIRONMENT="{{ lookup('env', "SENTRY_ENVIRONMENT") }}"
{% if sentry_sample_rate %}
SENTRY_SAMPLE_RATE = {{ sentry_sample_rate }}
{% endif %}

DOMAIN_SNAPSHOT_BUCKET = "{{ lookup('env', 'DOMAIN_SNAPSHOT_BUCKET') }}"
OBJECT_STORAGE_ENDPOINT = "{{ lookup('env', 'OBJECT_STORAGE_ENDPOINT') }}"
Expand Down
2 changes: 1 addition & 1 deletion ansible/templates/run_gunicorn.sh.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# supervisor can only control processes it started itself.
# So we need to use exec to replace the parent shell script process
# that starts pipenv
exec python -m pipenv run gunicorn greenweb.wsgi -b {{ internal_ip }}:$PORT -t 300 -c gunicorn.conf.py --statsd-host=10.0.0.2:9125 --statsd-prefix=member.app
exec python -m pipenv run gunicorn greenweb.wsgi -b {{ internal_ip }}:{{ gunicorn_port }} -t 300 -c gunicorn.conf.py --statsd-host=10.0.0.2:9125 --statsd-prefix=member.app
4 changes: 0 additions & 4 deletions ansible/templates/supervisor.gunicorn.conf.j2
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# {{ ansible_managed }}
# Last run: {{ template_run_date }}

[supervisord]
environment=LC_ALL='en_US.UTF-8',LANG='en_US.UTF-8'

[program:{{ supervisor_gunicorn_app }}]
directory=/var/www/{{ tgwf_domain_name }}.thegreenwebfoundation.org/current/
numprocs=1
command=bash ./run_gunicorn.sh
process_name=%(process_num)02d
environment=PORT=90%(process_num)02d
autostart=true
autorestart=true
stopsignal=QUIT
user={{ supervisor_user }}

stdout_logfile=%(program_name)s_%(process_num)02d_.log
stderr_logfile=%(program_name)s_%(process_num)02d_.error.log

0 comments on commit d2f669f

Please sign in to comment.