Skip to content

Commit c5a8b87

Browse files
authored
Add one-time performance testing workflow (#1326)
1 parent e5fafd4 commit c5a8b87

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: One-time performance testing - 25th October 2023
2+
3+
# Run "At every 30th minute on day-of-month 25 in October"
4+
on:
5+
schedule:
6+
- cron: '*/30 * 25 10 *'
7+
8+
# Add some extra perms to comment on a PR
9+
permissions:
10+
pull-requests: write
11+
contents: read
12+
13+
jobs:
14+
run-perftests:
15+
# Run this on Delphi's self-hosted runner
16+
runs-on: self-hosted
17+
outputs:
18+
request_count: ${{ steps.output.outputs.request_count }}
19+
failure_count: ${{ steps.output.outputs.failure_count }}
20+
med_time: ${{ steps.output.outputs.med_time }}
21+
avg_time: ${{ steps.output.outputs.avg_time }}
22+
min_time: ${{ steps.output.outputs.min_time }}
23+
max_time: ${{ steps.output.outputs.max_time }}
24+
requests_per_sec: ${{ steps.output.outputs.requests_per_sec }}
25+
steps:
26+
- name: Set up WireGuard
27+
uses: egor-tensin/[email protected]
28+
with:
29+
endpoint: '${{ secrets.WG_PERF_ENDPOINT }}'
30+
endpoint_public_key: '${{ secrets.WG_PERF_ENDPOINT_PUBLIC_KEY }}'
31+
ips: '${{ secrets.WG_PERF_IPS }}'
32+
allowed_ips: '${{ secrets.WG_PERF_ALLOWED_IPS }}'
33+
private_key: '${{ secrets.WG_PERF_PRIVATE_KEY }}'
34+
- name: Clean files from previous runs
35+
uses: AutoModality/action-clean@v1
36+
- name: Check out repository
37+
uses: actions/checkout@v3
38+
# Previous step checks out default branch, so we check out the pull request's branch
39+
- name: Switch to PR branch
40+
run: |
41+
hub pr checkout ${{ github.event.issue.number }}
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
- name: Set up repository # mimics install.sh in the README except that delphi is cloned from the PR rather than main
45+
run: |
46+
cd ..
47+
rm -rf driver
48+
mkdir -p driver/repos/delphi
49+
cd driver/repos/delphi
50+
git clone https://github.com/cmu-delphi/operations
51+
git clone https://github.com/cmu-delphi/utils
52+
git clone https://github.com/cmu-delphi/flu-contest
53+
git clone https://github.com/cmu-delphi/nowcast
54+
cd ../../
55+
56+
cd ..
57+
cp -R delphi-epidata driver/repos/delphi/delphi-epidata
58+
cd -
59+
60+
ln -s repos/delphi/delphi-epidata/dev/local/Makefile
61+
- name: Build & run epidata
62+
run: |
63+
cd ../driver
64+
sudo make web sql="${{ secrets.DB_CONN_STRING }}" rate_limit="999999/second"
65+
sudo make redis
66+
- name: Check out delphi-admin
67+
uses: actions/checkout@v3
68+
with:
69+
repository: cmu-delphi/delphi-admin
70+
token: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
71+
path: delphi-admin
72+
- name: Build & run Locust
73+
continue-on-error: true # sometimes ~2-5 queries fail, we shouldn't end the run if that's the case
74+
run: |
75+
cd delphi-admin/load-testing/locust
76+
docker build -t locust .
77+
export CSV=v4-requests-small.csv
78+
touch output_stats.csv && chmod 666 output_stats.csv
79+
touch output_stats_history.csv && chmod 666 output_stats_history.csv
80+
touch output_failures.csv && chmod 666 output_failures.csv
81+
touch output_exceptions.csv && chmod 666 output_exceptions.csv
82+
docker run --net=host -v $PWD:/mnt/locust -e CSV="/mnt/locust/${CSV}" locust -f /mnt/locust/v4.py --host http://127.0.0.1:10080/ --users 10 --spawn-rate 1 --headless -i "$(cat ${CSV} | wc -l)" --csv=/mnt/locust/output
83+
- name: Produce output for summary
84+
id: output
85+
uses: jannekem/run-python-script-action@v1
86+
with:
87+
script: |
88+
import os
89+
90+
def write_string(name, value):
91+
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
92+
print(f'{name}={value}', file=fh)
93+
94+
def write_float(name, value):
95+
write_string(name, "{:.2f}".format(float(value)))
96+
97+
with open("delphi-admin/load-testing/locust/output_stats.csv", "r", encoding="utf-8", errors="ignore") as scraped:
98+
final_line = scraped.readlines()[-1].split(",")
99+
write_string('request_count', final_line[2])
100+
write_string('failure_count', final_line[3])
101+
write_float('med_time', final_line[4])
102+
write_float('avg_time', final_line[5])
103+
write_float('min_time', final_line[6])
104+
write_float('max_time', final_line[7])
105+
write_float('requests_per_sec', final_line[9])
106+
107+
- name: Archive results as artifacts
108+
uses: actions/upload-artifact@v3
109+
with:
110+
name: locust-output
111+
path: |
112+
delphi-admin/load-testing/locust/output_*.csv

0 commit comments

Comments
 (0)