|
| 1 | +name: Performance testing |
| 2 | + |
| 3 | +# Run when a PR comment is created (issues and PRs are considered the same entity in the GitHub API) |
| 4 | +on: |
| 5 | + issue_comment: |
| 6 | + types: [created] |
| 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 | + # Make sure 1. this is a PR, not an issue 2. it contains "/run performance test" anywhere in the body |
| 16 | + if: github.event.issue.pull_request && contains(github.event.comment.body, '/run performance test') |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + request_count: ${{ steps.output.outputs.request_count }} |
| 20 | + failure_count: ${{ steps.output.outputs.failure_count }} |
| 21 | + med_time: ${{ steps.output.outputs.med_time }} |
| 22 | + avg_time: ${{ steps.output.outputs.avg_time }} |
| 23 | + min_time: ${{ steps.output.outputs.min_time }} |
| 24 | + max_time: ${{ steps.output.outputs.max_time }} |
| 25 | + requests_per_sec: ${{ steps.output.outputs.requests_per_sec }} |
| 26 | + steps: |
| 27 | + - name: Set up WireGuard |
| 28 | + uses: egor-tensin/[email protected] |
| 29 | + with: |
| 30 | + endpoint: '${{ secrets.WG_PERF_ENDPOINT }}' |
| 31 | + endpoint_public_key: '${{ secrets.WG_PERF_ENDPOINT_PUBLIC_KEY }}' |
| 32 | + ips: '${{ secrets.WG_PERF_IPS }}' |
| 33 | + allowed_ips: '${{ secrets.WG_PERF_ALLOWED_IPS }}' |
| 34 | + private_key: '${{ secrets.WG_PERF_PRIVATE_KEY }}' |
| 35 | + - name: Check out repository |
| 36 | + uses: actions/checkout@v3 |
| 37 | + # Previous step checks out default branch, so we check out the pull request's branch |
| 38 | + - name: Switch to PR branch |
| 39 | + run: | |
| 40 | + hub pr checkout ${{ github.event.issue.number }} |
| 41 | + env: |
| 42 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + - name: Set up repository # mimics install.sh in the README except that delphi is cloned from the PR rather than main |
| 44 | + run: | |
| 45 | + cd .. |
| 46 | + mkdir -p driver/repos/delphi |
| 47 | + cd driver/repos/delphi |
| 48 | + git clone https://github.com/cmu-delphi/operations |
| 49 | + git clone https://github.com/cmu-delphi/utils |
| 50 | + git clone https://github.com/cmu-delphi/flu-contest |
| 51 | + git clone https://github.com/cmu-delphi/nowcast |
| 52 | + cd ../../ |
| 53 | +
|
| 54 | + cd .. |
| 55 | + cp -R delphi-epidata driver/repos/delphi/delphi-epidata |
| 56 | + cd - |
| 57 | +
|
| 58 | + ln -s repos/delphi/delphi-epidata/dev/local/Makefile |
| 59 | + - name: Build & run epidata |
| 60 | + run: | |
| 61 | + cd ../driver |
| 62 | + sudo make web sql="${{ secrets.DB_CONN_STRING }}" |
| 63 | + - name: Check out delphi-admin |
| 64 | + uses: actions/checkout@v3 |
| 65 | + with: |
| 66 | + repository: cmu-delphi/delphi-admin |
| 67 | + token: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }} |
| 68 | + path: delphi-admin |
| 69 | + - name: Build & run Locust |
| 70 | + continue-on-error: true # sometimes ~2-5 queries fail, we shouldn't end the run if that's the case |
| 71 | + run: | |
| 72 | + cd delphi-admin/load-testing/locust |
| 73 | + docker build -t locust . |
| 74 | + export CSV=v4-requests-small.csv |
| 75 | + touch output_stats.csv && chmod 666 output_stats.csv |
| 76 | + touch output_stats_history.csv && chmod 666 output_stats_history.csv |
| 77 | + touch output_failures.csv && chmod 666 output_failures.csv |
| 78 | + touch output_exceptions.csv && chmod 666 output_exceptions.csv |
| 79 | + 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 |
| 80 | + - name: Produce output for summary |
| 81 | + id: output |
| 82 | + uses: jannekem/run-python-script-action@v1 |
| 83 | + with: |
| 84 | + script: | |
| 85 | + import os |
| 86 | +
|
| 87 | + def write_string(name, value): |
| 88 | + with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: |
| 89 | + print(f'{name}={value}', file=fh) |
| 90 | +
|
| 91 | + def write_float(name, value): |
| 92 | + write_string(name, "{:.2f}".format(float(value))) |
| 93 | +
|
| 94 | + with open("delphi-admin/load-testing/locust/output_stats.csv", "r", encoding="utf-8", errors="ignore") as scraped: |
| 95 | + final_line = scraped.readlines()[-1].split(",") |
| 96 | + write_string('request_count', final_line[2]) |
| 97 | + write_string('failure_count', final_line[3]) |
| 98 | + write_float('med_time', final_line[4]) |
| 99 | + write_float('avg_time', final_line[5]) |
| 100 | + write_float('min_time', final_line[6]) |
| 101 | + write_float('max_time', final_line[7]) |
| 102 | + write_float('requests_per_sec', final_line[9]) |
| 103 | +
|
| 104 | + - name: Archive results as artifacts |
| 105 | + uses: actions/upload-artifact@v3 |
| 106 | + with: |
| 107 | + name: locust-output |
| 108 | + path: | |
| 109 | + delphi-admin/load-testing/locust/output_*.csv |
| 110 | +
|
| 111 | + comment-success: |
| 112 | + runs-on: ubuntu-latest |
| 113 | + if: success() |
| 114 | + needs: run-perftests |
| 115 | + steps: |
| 116 | + - name: Comment run results |
| 117 | + env: |
| 118 | + GITHUB_WORKFLOW_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 119 | + uses: actions/github-script@v5 |
| 120 | + with: |
| 121 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 122 | + script: | |
| 123 | + github.rest.issues.createComment({ |
| 124 | + issue_number: context.issue.number, |
| 125 | + owner: context.repo.owner, |
| 126 | + repo: context.repo.repo, |
| 127 | + body: `✅ Performance tests complete! Result summary: |
| 128 | + - Total requests: **${{ needs.run-perftests.outputs.request_count }}** |
| 129 | + - Total failures: **${{ needs.run-perftests.outputs.failure_count }}** |
| 130 | + - Min response time: **${{ needs.run-perftests.outputs.min_time }} ms** |
| 131 | + - Max response time: **${{ needs.run-perftests.outputs.max_time }} ms** |
| 132 | + - Average response time: **${{ needs.run-perftests.outputs.avg_time }} ms** |
| 133 | + - Median response time: **${{ needs.run-perftests.outputs.med_time }} ms** |
| 134 | + - Requests per second: **${{ needs.run-perftests.outputs.requests_per_sec }}** |
| 135 | + |
| 136 | + Click here to view full results: ${{ env.GITHUB_WORKFLOW_URL }}.` |
| 137 | + }) |
| 138 | + |
| 139 | + comment-failure: |
| 140 | + runs-on: ubuntu-latest |
| 141 | + if: failure() |
| 142 | + needs: run-perftests |
| 143 | + steps: |
| 144 | + - name: Comment run results |
| 145 | + env: |
| 146 | + GITHUB_WORKFLOW_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 147 | + uses: actions/github-script@v5 |
| 148 | + with: |
| 149 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 150 | + script: | |
| 151 | + github.rest.issues.createComment({ |
| 152 | + issue_number: context.issue.number, |
| 153 | + owner: context.repo.owner, |
| 154 | + repo: context.repo.repo, |
| 155 | + body: `❌ Performance tests failed! Click here to view full results: ${{ env.GITHUB_WORKFLOW_URL }}.` |
| 156 | + }) |
0 commit comments