-
Notifications
You must be signed in to change notification settings - Fork 18
383 lines (367 loc) · 15.6 KB
/
stdlib_workflow.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
name: Stdlib Workflow
on:
workflow_dispatch:
inputs:
repo-name:
description: >
Name of the repo containing tests. Repo should be in ballerina-platform org.
Example- module-ballerina-http
required: true
tests:
description: >
Array of test names
Example-["hello world","https_passthrough"]
required: false
zipURL:
description: 'Ballerina Zip Distribution URL'
required: false
clusterName:
description: 'Cluster name'
default: 'bal-perf-cluster-test'
required: false
dispatchType:
description: 'Repository dispatch type'
default: ''
required: false
branch:
description: 'Branch of the given repository'
default: ''
required: false
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17.0.7
- name: Setup outputs
id: write
run: |
testsInput='${{ github.event.inputs.tests }}'
branch='${{ github.event.inputs.branch }}'
if [[ -z $testsInput ]]; then
repoName=${{ github.event.inputs.repo-name }}
git clone https://github.com/ballerina-platform/$repoName
if [[ -z $repoName ]]; then
echo "Github repo should be in `ballerina-platform` org"
exit 1
fi
if [[ ! -z $branch ]]; then
(cd $repoName ; git checkout $branch)
fi
cd $repoName/load-tests
tests=$(ls -d */ | cut -f1 -d'/' | jq -R -s -c 'split("\n")[:-1]')
echo "::set-output name=test::${tests}"
else
tests=$(echo $testsInput | jq '.')
if [[ -z $tests ]]; then
echo "Invalid json array input for tests"
exit 1
fi
if [[ $tests == "[]" ]]; then
echo "Empty test case array"
exit 1
fi
tests=${tests//$'\n'/}
echo "::set-output name=test::${tests}"
fi
- name: AZURE LOGIN
uses: azure/login@v1
with:
creds: ${{secrets.AZURE_CREDENTIALS}}
- name: Create Cluster
env:
AZURE_APP_ID: ${{ secrets.AZURE_APP_ID }}
AZURE_APP_PASSWORD: ${{ secrets.AZURE_APP_PASSWORD }}
RESOURCE_GROUP: ${{ secrets.CLUSTER_RESOURCE_GROUP }}
run: |
az aks create \
--resource-group "${RESOURCE_GROUP}" \
--name "${{ github.event.inputs.clusterName }}" \
--service-principal "${AZURE_APP_ID}"\
--client-secret "${AZURE_APP_PASSWORD}" \
--node-vm-size "Standard_F4s_v2" \
--node-osdisk-size 256 \
--node-osdisk-type Managed \
--node-count 1 \
--location "eastus" \
--generate-ssh-keys
- name: Configure AKS
uses: azure/aks-set-context@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
cluster-name: '${{ github.event.inputs.clusterName }}'
resource-group: ${{ secrets.CLUSTER_RESOURCE_GROUP }}
- name: Deploy Niginx
run: |
# Create a namespace for your ingress resources
kubectl create namespace ingress-basic
# Add the ingress-nginx repository
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
# Use Helm to deploy an NGINX ingress controller
helm install nginx-ingress ingress-nginx/ingress-nginx \
--namespace ingress-basic \
--set controller.replicaCount=2 \
--set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
--set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \
--set controller.admissionWebhooks.patch.nodeSelector."beta\.kubernetes\.io/os"=linux
# Wait for ingress ip
kubectl get service nginx-ingress-ingress-nginx-controller --namespace ingress-basic -w \
-o 'go-template={{with .status.loadBalancer.ingress}}{{range .}}{{.ip}}{{"\n"}}{{end}}{{.err}}{{end}}' 2>/dev/null \
| head -n1
kubectl apply -f https://raw.githubusercontent.com/ballerina-platform/ballerina-performance-cloud/main/base-image/volumes.yaml
- name: Create results branch in target repo
id: branch
run: |
dispatchType='${{ github.event.inputs.dispatchType }}'
if [[ -z $dispatchType ]]; then
repoName=${{ github.event.inputs.repo-name }}
git clone https://ballerina-bot:${{ secrets.BALLERINA_BOT_TOKEN }}@github.com/ballerina-platform/"${repoName}" remote_repo
cd remote_repo
timestamp=$(date +%s -u)
branch_name="nightly-${timestamp}"
git checkout -b ${branch_name}
git push origin ${branch_name}
echo "::set-output name=branch-name::${branch_name}"
fi
outputs:
matrix: ${{ steps.write.outputs.test }}
branch-name: ${{ steps.branch.outputs.branch-name }}
run_test:
needs: setup
runs-on: ubuntu-latest
strategy:
max-parallel: 1
fail-fast: false
matrix:
test_name: ${{ fromJson(needs.setup.outputs.matrix) }}
payload: [50]
users: [60]
env:
TEST_NAME: "${{ matrix.test_name }}"
TEST_ROOT: "load-tests"
steps:
- uses: actions/checkout@v2
if: ${{ github.event.inputs.branch == '' }}
with:
repository: ballerina-platform/${{ github.event.inputs.repo-name }}
- uses: actions/checkout@v2
if: ${{ github.event.inputs.branch != '' }}
with:
repository: ballerina-platform/${{ github.event.inputs.repo-name }}
ref: ${{ github.event.inputs.branch }}
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Ballerina Build
if: ${{ github.event.inputs.zipURL == '' }}
uses: ballerina-platform/ballerina-action@nightly
env:
DOCKER_BUILDKIT: 0
WORKING_DIR: load-tests/${{ matrix.test_name }}/src
with:
args:
build
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17.0.7
- name: Ballerina Build from Distribution ZIP
if: ${{ github.event.inputs.zipURL != '' }}
run: |
export packageUser=ballerina-bot
curl -u $packageUser:${{ secrets.BALLERINA_BOT_TOKEN }} -L -o ballerina-dist.zip ${{ github.event.inputs.zipURL }}
mkdir ballerina-dist
unzip -q ballerina-dist.zip -d ballerina-dist
export DOCKER_BUILDKIT=0
export BAL_PATH=`pwd`/ballerina-dist
echo "var ${BAL_PATH}"
pushd load-tests/${TEST_NAME}/src
chmod +x $BAL_PATH/bin/bal
$BAL_PATH/bin/bal build
- name: Docker push
run: docker push ballerina/${TEST_NAME}:latest
- name: Copy artifacts
run: |
ls -ltr
cp -a ${TEST_ROOT}/${TEST_NAME}/src/target/kubernetes/${TEST_NAME}/. ${TEST_ROOT}/${TEST_NAME}/deployment/
- name: 'Install Kustomize'
run: |
curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
- name: 'Run Kustomize'
run: |
kustomize build ${TEST_ROOT}/${TEST_NAME}/deployment > ${TEST_ROOT}/${TEST_NAME}/final.yaml
- name: Configure AKS
uses: azure/aks-set-context@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
cluster-name: '${{ github.event.inputs.clusterName }}'
resource-group: ${{ secrets.CLUSTER_RESOURCE_GROUP }}
- name: Deploy artifacts
run: |
kubectl apply -f ${TEST_ROOT}/${TEST_NAME}/final.yaml
- name: Login via Az module
uses: azure/login@v1
with:
creds: ${{secrets.AZURE_CREDENTIALS}}
- name: Write values to outputs
id: write
run: |
echo "::set-output name=cluster-ip::$(kubectl get service nginx-ingress-ingress-nginx-controller --namespace ingress-basic -w \
-o 'go-template={{with .status.loadBalancer.ingress}}{{range .}}{{.ip}}{{"\n"}}{{end}}{{.err}}{{end}}' 2>/dev/null \
| head -n1)"
echo "::set-output name=scenario-name::${TEST_NAME}"
echo "::set-output name=vm-name::bal-perf-vm-`echo ${TEST_NAME} | tr '_' '-'`-${{ matrix.users }}-${{ matrix.payload }}-${{ GITHUB.RUN_NUMBER }}"
echo "::set-output name=git-token::${{ secrets.BALLERINA_BOT_TOKEN }}"
echo "::set-output name=space-id::${{ secrets.SPACE_ID }}"
echo "::set-output name=message-key::${{ secrets.MESSAGE_KEY }}"
echo "::set-output name=chat-token::${{ secrets.CHAT_TOKEN }}"
echo "::set-output name=dispatch-type::${{ github.event.inputs.dispatchType }}"
version_out=""
echo "::set-output name=version::${version_out}"
- name: Wait for VM instance
run: sleep 60s
shell: bash
- name: Wait for pods
run: |
kubectl wait --for=condition=ready pod -l load=true --timeout=10m || true
- name: Deploy Jmeter container
run: |
wget https://raw.githubusercontent.com/ballerina-platform/ballerina-performance-cloud/main/base-image/k8s.yaml
sed -i -e 's/<<CLUSTER_IP>>/${{ steps.write.outputs.cluster-ip }}/g' k8s.yaml
sed -i -e 's/<<REPO_NAME>>/${{ github.event.inputs.repo-name }}/g' k8s.yaml
sed -i -e 's/<<SCENARIO_NAME>>/${{ steps.write.outputs.scenario-name }}/g' k8s.yaml
sed -i -e 's/<<GITHUB_TOKEN>>/${{steps.write.outputs.git-token}}/g' k8s.yaml
sed -i -e 's/<<PAYLOAD_SIZE>>/${{ matrix.payload }}/g' k8s.yaml
sed -i -e 's/<<SPACE_ID>>/${{steps.write.outputs.space-id}}/g' k8s.yaml
sed -i -e 's/<<MESSAGE_KEY>>/${{steps.write.outputs.message-key}}/g' k8s.yaml
sed -i -e 's/<<CHAT_TOKEN>>/${{steps.write.outputs.chat-token}}/g' k8s.yaml
sed -i -e 's/<<DISPATCH_TYPE>>/${{steps.write.outputs.dispatch-type}}/g' k8s.yaml
sed -i -e 's/<<BRANCH_NAME>>/${{ needs.setup.outputs.branch-name }}/g' k8s.yaml
sed -i -e 's/<<CONCURRENT_USERS>>/${{ matrix.users }}/g' k8s.yaml
sed -i -e 's/<<VERSION>>/${{ steps.write.outputs.version }}/g' k8s.yaml
sed -i -e 's/<<BASE_BRANCH>>/${{ github.event.inputs.branch }}/g' k8s.yaml
kubectl apply -f k8s.yaml
echo "Waiting till the Jmeter job to finish"
attempt_num=1
until kubectl wait --for=condition=complete --timeout=2h job/jmeter-job
do
if ((attempt_num==3))
then
echo "Job waiting failed on the $attempt_num attempt and there are no more attempts left! Failing the workflow"
kubectl get jobs
kubectl get pods
kubectl logs job.batch/jmeter-job
exit 1
else
echo "Attempt $attempt_num failed! Trying again in 30 seconds..."
((attempt_num++))
sleep 30
kubectl get jobs
kubectl get pods
kubectl logs job.batch/jmeter-job
fi
done
kubectl logs job.batch/jmeter-job
- name: Pod logs
if: always()
run: |
kubectl logs -l logs=true
- name: Undeploy Kubernetes artifacts
if: always()
run: |
kubectl delete -f ${TEST_ROOT}/${TEST_NAME}/final.yaml
kubectl delete -f k8s.yaml
cleanup:
needs: [setup,run_test]
name: clean up
if: always()
runs-on: ubuntu-latest
steps:
- name: AZURE LOGIN
uses: azure/login@v1
with:
creds: ${{secrets.AZURE_CREDENTIALS}}
- name: Configure AKS
uses: azure/aks-set-context@v1
with:
creds: '${{ secrets.AZURE_CREDENTIALS }}'
cluster-name: '${{ github.event.inputs.clusterName }}'
resource-group: ${{ secrets.CLUSTER_RESOURCE_GROUP }}
- name: Deploy data collector pod
if: github.event.inputs.dispatchType != ''
shell: bash
run: |
kubectl apply -f https://raw.githubusercontent.com/ballerina-platform/ballerina-performance-cloud/main/base-image/notification.yaml
kubectl wait --for=condition=Ready pod/dataaccess
kubectl cp dataaccess:/data data/
DISPATCH_TYPE="${{ github.event.inputs.dispatchType }}"
BRANCH="${{ github.event.inputs.branch }}"
pushd data
if [ -z "$(ls -A ./)" ]; then
CONTENT=$(echo '{ "results": [] }' | jq )
else
CONTENT=$(for SCENARIO_NAME in *; do
STATUS="success"
SUMMARY_STRING=$(cat $SCENARIO_NAME/summary.csv)
ERROR_RATE=$(echo $SUMMARY_STRING | cut -d ',' -f10)
ERROR_RATE=$(echo $ERROR_RATE | sed 's/%//')
if [[ -z $BRANCH ]]; then
DATA_STRING=$( jq -n \
--arg status "$STATUS" \
--arg summary "$SUMMARY_STRING" \
--arg errorRate "$ERROR_RATE" \
--arg scenarioName "${SCENARIO_NAME}" \
'{ "name": $scenarioName, "status": $status, "result": $summary, "errorRate": $errorRate}' )
else
DATA_STRING=$( jq -n \
--arg status "$STATUS" \
--arg summary "$SUMMARY_STRING" \
--arg errorRate "$ERROR_RATE" \
--arg scenarioName "${SCENARIO_NAME}" \
--arg branch "${BRANCH}" \
'{ "name": $scenarioName, "status": $status, "branch": $branch,"result": $summary, "errorRate": $errorRate}' )
fi
echo $DATA_STRING
done | jq -n '.results |= [inputs]')
fi
echo "Complete scenario list from the inputs"
COMPLETE_LIST='${{ needs.setup.outputs.matrix }}'
echo $COMPLETE_LIST
REMAINING_LIST=$COMPLETE_LIST
for SCENARIO_NAME in *; do
REMAINING_LIST=$(echo $REMAINING_LIST | jq --arg SCENARIO $SCENARIO_NAME 'del(.[] | select(. == $SCENARIO))')
done
echo "Remaining scenario list after removing successful runs"
echo $REMAINING_LIST
while read i; do
SCENARIO=$(echo $i | tr -d '"')
CONTENT=$(echo $CONTENT | jq --arg SCENARIO $SCENARIO '.results += [{"name":$SCENARIO,"status": "failed"}]')
done <<<$(echo $REMAINING_LIST | jq -c '.[]')
echo $CONTENT
FINAL_PAYLOAD=$( jq -n \
--argjson content "${CONTENT}" \
--arg eventType "${DISPATCH_TYPE}" \
'{"event_type": $eventType, "client_payload": $content }' )
echo $FINAL_PAYLOAD
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.BALLERINA_BOT_TOKEN }}" \
--data "$FINAL_PAYLOAD" \
"https://api.github.com/repos/ballerina-platform/${{ github.event.inputs.repo-name }}/dispatches"
popd
- name: Cleaning up the cluster
if: always()
uses: azure/CLI@v1
with:
azcliversion: "agentazcliversion"
inlineScript: |
az group delete --name mc_${{ secrets.CLUSTER_RESOURCE_GROUP }}_${{ github.event.inputs.clusterName }}_eastus -y
az aks delete --name ${{ github.event.inputs.clusterName }} --resource-group ${{ secrets.CLUSTER_RESOURCE_GROUP }} -y