|
| 1 | +name: Performance Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + issue_comment: |
| 6 | + schedule: |
| 7 | + # don't know the timezone but it's daily at least |
| 8 | + - cron: '0 7 * * *' |
| 9 | + |
| 10 | +env: |
| 11 | + terraform_version: '0.15.3' |
| 12 | + |
| 13 | +jobs: |
| 14 | + perf: |
| 15 | + name: RPS, latency and flamegraphs |
| 16 | + runs-on: ubuntu-20.04 |
| 17 | + if: | |
| 18 | + github.event_name == 'schedule' || |
| 19 | + (github.event_name == 'pull_request' && startsWith(github.event.pull_request.title, 'perf(')) || |
| 20 | + (github.event_name == 'issue_comment' && github.event.action == 'created' && |
| 21 | + github.event.issue.pull_request && |
| 22 | + contains('["OWNER", "COLLABORATOR", "MEMBER"]', github.event.comment.author_association) && |
| 23 | + (startsWith(github.event.comment.body, '/perf') || startsWith(github.event.comment.body, '/flamegraph')) |
| 24 | + ) |
| 25 | +
|
| 26 | + steps: |
| 27 | + - name: Checkout Kong source code |
| 28 | + uses: actions/checkout@v2 |
| 29 | + # Fetch all history for all tags and branches |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Install OpenResty |
| 34 | + run: | |
| 35 | + sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates |
| 36 | + wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add - |
| 37 | + echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" | \ |
| 38 | + sudo tee /etc/apt/sources.list.d/openresty.list |
| 39 | + sudo apt-get update |
| 40 | + sudo apt install openresty |
| 41 | +
|
| 42 | + - name: Install Dependencies |
| 43 | + run: | |
| 44 | + wget https://luarocks.org/releases/luarocks-3.7.0.tar.gz -O - |tar zxvf - |
| 45 | + pushd luarocks-*/ |
| 46 | + ./configure --with-lua=/usr/local/openresty/luajit/ \ |
| 47 | + --lua-suffix=jit \ |
| 48 | + --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 |
| 49 | + sudo make install |
| 50 | + popd |
| 51 | +
|
| 52 | + # just need the lua files to let all imports happy |
| 53 | + # the CI won't actually run Kong locally |
| 54 | + git clone https://github.com/kong/lua-kong-nginx-module /tmp/lua-kong-nginx-module |
| 55 | + pushd /tmp/lua-kong-nginx-module |
| 56 | + sudo make LUA_LIB_DIR=/usr/local/share/lua/5.1/ install |
| 57 | + popd |
| 58 | +
|
| 59 | + # in Kong repository |
| 60 | + sudo apt install libyaml-dev -y |
| 61 | + sudo make dev |
| 62 | +
|
| 63 | + # terraform! |
| 64 | + wget https://releases.hashicorp.com/terraform/${{ env.terraform_version }}/terraform_${{ env.terraform_version }}_linux_amd64.zip |
| 65 | + unzip terraform_${{ env.terraform_version }}_linux_amd64.zip |
| 66 | + sudo mv terraform /usr/bin/ |
| 67 | +
|
| 68 | + - name: Choose perf suites |
| 69 | + id: choose_perf |
| 70 | + run: | |
| 71 | + suites=$(echo "${{ github.event.comment.body }}" | awk '{print $1}') |
| 72 | + tags=$(echo "${{ github.event.comment.body }}" | awk '{print $2}') |
| 73 | +
|
| 74 | + if [[ $suite == "/flamegraph" ]]; then |
| 75 | + suites="02-flamegraph" |
| 76 | + if [[ -z $tags ]]; then |
| 77 | + tags="simple" |
| 78 | + fi |
| 79 | + elif [[ $suite == "/flamegraph" ]]; then |
| 80 | + suites="01-rps" |
| 81 | + if [[ -z $tags ]]; then |
| 82 | + tags="baseline,single_route" |
| 83 | + fi |
| 84 | + else |
| 85 | + # if not specified by comment, run both |
| 86 | + suites="01-rps 02-flamegraph" |
| 87 | + if [[ -z $tags ]]; then |
| 88 | + tags="baseline,single_route,simple" |
| 89 | + fi |
| 90 | + fi |
| 91 | +
|
| 92 | + echo ::set-output name=suites::"$suites" |
| 93 | + echo ::set-output name=tags::"$tags" |
| 94 | +
|
| 95 | + - name: Run Tests |
| 96 | + env: |
| 97 | + PERF_TEST_VERSIONS: git:${{ github.sha }},git:master |
| 98 | + PERF_TEST_PACKET_PROJECT_ID: ${{ secrets.PERF_TEST_PACKET_PROJECT_ID }} |
| 99 | + PERF_TEST_PACKET_AUTH_TOKEN: ${{ secrets.PERF_TEST_PACKET_AUTH_TOKEN }} |
| 100 | + PERF_TEST_DRIVER: terraform |
| 101 | + run: | |
| 102 | + for suite in ${{ steps.choose_perf.outputs.suites }}; do |
| 103 | + bin/busted -o gtest spec/04-perf/$suite/ \ |
| 104 | + -t "${{ steps.choose_perf.outputs.tags }}" |
| 105 | + done |
| 106 | + |
| 107 | + - name: Teardown |
| 108 | + # Note: by default each job has if: ${{ success() }} |
| 109 | + if: always() |
| 110 | + env: |
| 111 | + PERF_TEST_VERSIONS: git:${{ github.sha }},git:master |
| 112 | + PERF_TEST_PACKET_PROJECT_ID: ${{ secrets.PERF_TEST_PACKET_PROJECT_ID }} |
| 113 | + PERF_TEST_PACKET_AUTH_TOKEN: ${{ secrets.PERF_TEST_PACKET_AUTH_TOKEN }} |
| 114 | + PERF_TEST_DRIVER: terraform |
| 115 | + PERF_TEST_TEARDOWN_ALL: "true" |
| 116 | + run: | |
| 117 | + bin/busted -o gtest spec/04-perf/99-teardown/ |
| 118 | +
|
| 119 | + - name: Save results |
| 120 | + uses: actions/upload-artifact@v2 |
| 121 | + with: |
| 122 | + name: rps-and-latency |
| 123 | + path: | |
| 124 | + output/result.txt |
| 125 | + retention-days: 31 |
| 126 | + |
| 127 | + - name: Save flamegrpahs |
| 128 | + uses: actions/upload-artifact@v2 |
| 129 | + with: |
| 130 | + name: flamegraphs |
| 131 | + path: | |
| 132 | + output/*.svg |
| 133 | + retention-days: 31 |
| 134 | + |
| 135 | + - name: Save error logs |
| 136 | + uses: actions/upload-artifact@v2 |
| 137 | + with: |
| 138 | + name: error_logs |
| 139 | + path: | |
| 140 | + output/*.log |
| 141 | + retention-days: 31 |
| 142 | + |
| 143 | + - name: Output |
| 144 | + id: output |
| 145 | + run: | |
| 146 | + if [[ "${{ steps.choose_perf.outputs.suites }}" =~ "02-flamegraph" ]]; then |
| 147 | + result="Please see Github Actions artifacts for flamegraphs. |
| 148 | +
|
| 149 | + " |
| 150 | + fi |
| 151 | +
|
| 152 | + result="${result}$(cat output/result.txt)" || true |
| 153 | +
|
| 154 | + # https://github.community/t/set-output-truncates-multiline-strings/16852/2 |
| 155 | + result="${result//'%'/'%25'}" |
| 156 | + result="${result//$'\n'/'%0A'}" |
| 157 | + result="${result//$'\r'/'%0D'}" |
| 158 | +
|
| 159 | + echo ::set-output name=result::"$result" |
| 160 | + |
| 161 | + - name: Comment |
| 162 | + if: | |
| 163 | + github.event_name == 'pull_request' || |
| 164 | + (github.event_name == 'issue_comment' && github.event.issue.pull_request) |
| 165 | + uses: actions-ecosystem/action-create-comment@v1 |
| 166 | + with: |
| 167 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 168 | + body: | |
| 169 | + ## :rocket: Performance test result |
| 170 | +
|
| 171 | + **Test Suite**: ${{ steps.choose_perf.outputs.suites }} (${{ steps.choose_perf.outputs.tags }}) |
| 172 | +
|
| 173 | + <details><summary>Click to expand</summary> |
| 174 | +
|
| 175 | + ``` |
| 176 | + ${{ steps.output.outputs.result }} |
| 177 | +
|
| 178 | + Kong error logs are also available in Github Actions artifacts. |
| 179 | + ``` |
| 180 | +
|
| 181 | + </details> |
| 182 | +
|
| 183 | + [Download Artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts) |
0 commit comments