forked from Kong/kong
-
Notifications
You must be signed in to change notification settings - Fork 0
341 lines (284 loc) · 11.4 KB
/
perf.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
name: Performance Test
on:
pull_request:
schedule:
# don't know the timezone but it's daily at least
- cron: '0 7 * * *'
env:
terraform_version: '1.2.4'
HAS_ACCESS_TO_GITHUB_TOKEN: ${{ github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') }}
BUILD_ROOT: ${{ github.workspace }}/bazel-bin/build
# only for pr
GHA_CACHE: ${{ github.event_name == 'pull_request' }}
jobs:
build-packages:
name: Build dependencies
runs-on: ubuntu-22.04
if: |
github.event_name == 'schedule' ||
(github.event_name == 'pull_request' && startsWith(github.event.pull_request.title, 'perf(')) ||
(github.event_name == 'issue_comment' && github.event.action == 'created' &&
github.event.issue.pull_request &&
contains('["OWNER", "COLLABORATOR", "MEMBER"]', github.event.comment.author_association) &&
(startsWith(github.event.comment.body, '/perf') || startsWith(github.event.comment.body, '/flamegraph'))
)
outputs:
cache-key: ${{ steps.cache-key.outputs.cache-key }}
steps:
- name: Checkout Kong source code
uses: actions/checkout@v4
- name: Generate cache key
id: cache-key
uses: ./.github/actions/build-cache-key
with:
prefix: perf
- name: Lookup build cache
id: cache-deps
uses: actions/cache@v4
with:
path: ${{ env.BUILD_ROOT }}
key: ${{ steps.cache-key.outputs.cache-key }}
- name: Install packages
if: steps.cache-deps.outputs.cache-hit != 'true'
run: sudo apt update && sudo apt install libyaml-dev valgrind libprotobuf-dev
- name: Build Kong
if: steps.cache-deps.outputs.cache-hit != 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
make build-kong
BUILD_PREFIX=$BUILD_ROOT/kong-dev
export PATH="$BUILD_PREFIX/bin:$BUILD_PREFIX/openresty/nginx/sbin:$BUILD_PREFIX/openresty/bin:$PATH"
chmod +rw -R $BUILD_PREFIX
nginx -V
ldd $(which nginx)
luarocks
- name: Bazel Outputs
uses: actions/upload-artifact@v3
if: failure()
with:
name: bazel-outputs
path: |
bazel-out/_tmp/actions
retention-days: 3
- name: Build Dev Kong dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
make install-dev-rocks
perf:
name: RPS, latency and flamegraphs
runs-on: ubuntu-22.04
needs: build-packages
permissions:
# required to send comment of graphs and results in the PR
pull-requests: write
if: |
github.event_name == 'schedule' ||
(github.event_name == 'pull_request' && startsWith(github.event.pull_request.title, 'perf(')) ||
(github.event_name == 'issue_comment' && github.event.action == 'created' &&
github.event.issue.pull_request &&
contains('["OWNER", "COLLABORATOR", "MEMBER"]', github.event.comment.author_association) &&
(startsWith(github.event.comment.body, '/perf') || startsWith(github.event.comment.body, '/flamegraph'))
)
# perf test can only run one at a time per repo for now
concurrency:
group: perf-ce
steps:
# set up mutex across CE and EE to avoid resource race
- name: Set up mutex
uses: ben-z/gh-action-mutex@9709ba4d8596ad4f9f8bbe8e0f626ae249b1b3ac # v1.0-alpha-6
with:
repository: "Kong/kong-perf-mutex-lock"
branch: "gh-mutex"
repo-token: ${{ secrets.PAT }}
- name: Checkout Kong source code
uses: actions/checkout@v4
with:
# Fetch all history for all tags and branches
fetch-depth: 0
- name: Load Cached Packages
id: cache-deps
if: env.GHA_CACHE == 'true'
uses: actions/cache@v4
with:
path: ${{ env.BUILD_ROOT }}
key: ${{ needs.build-packages.outputs.cache-key }}
- name: Install performance test Dependencies
run: |
# in Kong repository
sudo apt update && sudo apt install inkscape -y
# terraform!
wget https://releases.hashicorp.com/terraform/${{ env.terraform_version }}/terraform_${{ env.terraform_version }}_linux_amd64.zip
unzip terraform_${{ env.terraform_version }}_linux_amd64.zip
sudo mv terraform /usr/bin/
- name: Choose perf suites
id: choose_perf
run: |
suites="$(printf '%s' "${{ github.event.comment.body }}" | awk '{print $1}')"
tags="$(printf '%s' "${{ github.event.comment.body }}" | awk '{print $2}')"
if [[ $suite == "/flamegraph" ]]; then
suites="02-flamegraph"
if [[ -z $tags ]]; then
tags="simple"
fi
elif [[ $suite == "/perf" ]]; then
suites="01-rps"
if [[ -z $tags ]]; then
tags="baseline,single_route"
fi
else
# if not specified by comment, run both
suites="01-rps 02-flamegraph"
if [[ -z $tags ]]; then
tags="baseline,single_route,simple"
fi
fi
echo "suites=$suites" >> $GITHUB_OUTPUT
echo "tags=$tags" >> $GITHUB_OUTPUT
- uses: xt0rted/pull-request-comment-branch@d97294d304604fa98a2600a6e2f916a84b596dc7 # v1.4.1
id: comment-branch
if: github.event_name == 'issue_comment' && github.event.action == 'created'
- name: Find compared versions
id: compare_versions
run: |
pr_ref=$(echo "${{ github.event.pull_request.base.ref }}")
custom_vers="$(printf '%s' "${{ github.event.comment.body }}" | awk '{print $3}')"
if [[ ! -z "${pr_ref}" ]]; then
vers="git:${{ github.head_ref }},git:${pr_ref}"
elif [[ ! -z "${custom_vers}" ]]; then
vers="${custom_vers}"
elif [[ ! -z "${{ github.event.comment.body }}" ]]; then
vers="git:${{ steps.comment-branch.outputs.head_ref}},git:${{ steps.comment-branch.outputs.base_ref}}"
else # is cron job/on master
vers="git:master,git:origin/master~10,git:origin/master~50"
fi
echo $vers
echo "vers=$vers" >> $GITHUB_OUTPUT
- name: Run Tests
env:
PERF_TEST_VERSIONS: ${{ steps.compare_versions.outputs.vers }}
PERF_TEST_DRIVER: terraform
PERF_TEST_TERRAFORM_PROVIDER: bring-your-own
PERF_TEST_BYO_KONG_IP: ${{ secrets.PERF_TEST_BYO_KONG_IP }}
PERF_TEST_BYO_WORKER_IP: ${{ secrets.PERF_TEST_BYO_WORKER_IP }}
PERF_TEST_BYO_SSH_USER: gha
PERF_TEST_USE_DAILY_IMAGE: true
PERF_TEST_DISABLE_EXEC_OUTPUT: true
timeout-minutes: 180
run: |
export PERF_TEST_BYO_SSH_KEY_PATH=$(pwd)/ssh_key
echo "${{ secrets.PERF_TEST_BYO_SSH_KEY }}" > ${PERF_TEST_BYO_SSH_KEY_PATH}
chmod 600 ${PERF_TEST_BYO_SSH_KEY_PATH}
# setup tunnel for psql and admin port
ssh -o StrictHostKeyChecking=no -o TCPKeepAlive=yes -o ServerAliveInterval=10 \
-o ExitOnForwardFailure=yes -o ConnectTimeout=5 \
-L 15432:localhost:5432 -L 39001:localhost:39001 \
-i ${PERF_TEST_BYO_SSH_KEY_PATH} \
${PERF_TEST_BYO_SSH_USER}@${PERF_TEST_BYO_KONG_IP} tail -f /dev/null &
sleep 5
sudo iptables -t nat -I OUTPUT -p tcp --dport 5432 -d ${PERF_TEST_BYO_KONG_IP} -j DNAT --to 127.0.0.1:15432
sudo iptables -t nat -I OUTPUT -p tcp --dport 39001 -d ${PERF_TEST_BYO_KONG_IP} -j DNAT --to 127.0.0.1:39001
make dev # required to install other dependencies like bin/grpcurl
source ${{ env.BUILD_ROOT }}/kong-dev-venv.sh
for suite in ${{ steps.choose_perf.outputs.suites }}; do
# Run each test individually, ngx.pipe doesn't like to be imported twice
# maybe bin/busted --no-auto-insulate
for f in $(find "spec/04-perf/$suite/" -type f); do
bin/busted "$f" \
-t "${{ steps.choose_perf.outputs.tags }}"
done
done
- name: Teardown
# Note: by default each job has if: ${{ success() }}
if: always()
env:
PERF_TEST_VERSIONS: git:${{ github.sha }}
PERF_TEST_DRIVER: terraform
PERF_TEST_TERRAFORM_PROVIDER: bring-your-own
PERF_TEST_BYO_KONG_IP: ${{ secrets.PERF_TEST_BYO_KONG_IP }}
PERF_TEST_BYO_WORKER_IP: ${{ secrets.PERF_TEST_BYO_WORKER_IP }}
PERF_TEST_BYO_SSH_USER: gha
PERF_TEST_TEARDOWN_ALL: true
run: |
export PERF_TEST_BYO_SSH_KEY_PATH=$(pwd)/ssh_key
echo "${{ secrets.PERF_TEST_BYO_SSH_KEY }}" > ${PERF_TEST_BYO_SSH_KEY_PATH}
make dev # required to install other dependencies like bin/grpcurl
source ${{ env.BUILD_ROOT }}/kong-dev-venv.sh
bin/busted spec/04-perf/99-teardown/
rm -f ${PERF_TEST_BYO_SSH_KEY_PATH}
- name: Generate high DPI graphs
if: always()
run: |
for i in $(ls output/*.svg); do
inkscape --export-area-drawing --export-png="${i%.*}.png" --export-dpi=300 -b FFFFFF $i
done
- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: Generate plots
if: always()
run: |
cwd=$(pwd)
cd spec/helpers/perf/charts/
pip install -r requirements.txt
for i in $(ls ${cwd}/output/*.data.json); do
python ./charts.py $i -o "${cwd}/output/"
done
- name: Save results
uses: actions/upload-artifact@v3
if: always()
with:
name: perf-results
path: |
output/
!output/**/*.log
retention-days: 31
- name: Save error logs
uses: actions/upload-artifact@v3
if: always()
with:
name: error_logs
path: |
output/**/*.log
retention-days: 31
- name: Output
if: always()
id: output
run: |
if [[ "${{ steps.choose_perf.outputs.suites }}" =~ "02-flamegraph" ]]; then
result="Please see Github Actions artifacts for flamegraphs.
"
fi
result="${result}$(cat output/result.txt)" || true
# https://github.community/t/set-output-truncates-multiline-strings/16852/2
result="${result//'%'/'%25'}"
result="${result//$'\n'/'%0A'}"
result="${result//$'\r'/'%0D'}"
echo "result=$results" >> $GITHUB_OUTPUT
- name: Upload charts
if: always()
id: charts
uses: devicons/public-upload-to-imgur@352cf5f2805c692539a96cfe49a09669e6fca88e # v2.2.2
continue-on-error: true
with:
path: output/*.png
client_id: ${{ secrets.PERF_TEST_IMGUR_CLIENT_ID }}
- name: Comment
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' && github.event.issue.pull_request)
uses: actions-ecosystem/action-create-comment@e23bc59fbff7aac7f9044bd66c2dc0fe1286f80b # v1.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
body: |
## :rocket: Performance test result
**Test Suite**: ${{ steps.choose_perf.outputs.suites }} (${{ steps.choose_perf.outputs.tags }})
${{ join(fromJSON(steps.charts.outputs.markdown_urls), ' ') }}
<details><summary>Click to expand</summary>
```
${{ steps.output.outputs.result }}
Kong error logs are also available in Github Actions artifacts.
```
</details>
[Download Artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts) for detailed results and interactive SVG flamegraphs.