-
Notifications
You must be signed in to change notification settings - Fork 2
163 lines (145 loc) · 6.88 KB
/
make-a-change.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
---
# make change in demo branch that effects cpu performance
name: Proxy dev
on:
workflow_dispatch:
inputs:
performanceIssue:
description: 'Performance Issue'
required: true
default: 'random'
type: choice
options:
- cpu
- connections
- query
- random
- baseline
schedule:
## At minute 10, 30, 50 past every hour
#- cron: '10,30,50 * * * *'
## At minute 10 past every 2nd hour from 8h to 16h AMS time (6-14 UTC)
- cron: '10 6-14/2 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout afterburner repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: demo
# needed to trigger CICD build with later push with PAT
persist-credentials: false
- name: Make a change
run: |
# default is random, inputs.performanceIssues is empty when run from scheduler
issueSelected=${{ inputs.performanceIssue }}
issueSelected=${issueSelected:-random}
# seed RANDOM to prevent same sequences
RANDOM=$(date +'%s' | cut -b6-10)
cpu_java_file=afterburner-java/src/main/java/io/perfana/afterburner/controller/CpuBurner.java
prop_file=afterburner-java/src/main/resources/application.properties
query_file=afterburner-java/src/main/java/io/perfana/afterburner/mybatis/EmployeeMapper.java
echo check if performance issue patterns are present
if grep -q "some variation: is more fun" "$cpu_java_file"; then
echo cpu issue found
cpuIssue=1
else
echo cpu issue not found
cpuIssue=0
fi
if grep -q "afterburner.remote.call.httpclient.connections.max=2" "$prop_file"; then
echo connection pool issue found
connectionPoolIssue=1
else
echo connection pool issue not found
connectionPoolIssue=0
fi
if grep -q "SELECT MAX(to_date) FROM salaries" "$query_file"; then
echo query issue found
queryIssue=1
else
echo query issue not found
queryIssue=0
fi
if [[ $cpuIssue -eq 0 && $connectionPoolIssue -eq 0 && $queryIssue -eq 0 ]]; then
isIssuePresent=0
else
isIssuePresent=1
fi
if [[ $isIssuePresent -eq 0 && "$issueSelected" != "baseline" ]]; then
echo "There are NO performance issues found, and the issue selected is '${issueSelected}' so maybe we want to introduce a performance issue..."
### `issue` : indicates the type of issue to introduce
### `mod_run` : when issue==random, run only every run % 2 build.
current_run=${{ github.run_number }}
mod_run=0
if [[ "$issueSelected" == "random" ]]; then
issue=$(( RANDOM % 3 ))
mod_run=$(( current_run % 4 )) # run once every 4 builds
elif [[ "$issueSelected" == "cpu" ]]; then
issue=0
elif [[ "$issueSelected" == "connections" ]]; then
issue=1
elif [[ "$issueSelected" == "query" ]]; then
issue=2
fi
echo "mod_run: $mod_run and issueSelected: '$issueSelected'"
if [[ $mod_run -eq 0 ]]; then #### mod_run is default 0, only 'random' might set it to something different
if [[ $issue -eq 0 ]]; then
echo "generate cpu issue"
commit_message="make matrix calculation more variable"
sed -i 's/no variation: is no fun/some variation: is more fun/g' $cpu_java_file
sed -i 's/int funSize = matrixSize/int funSize = (int) (matrixSize \* (1.0 + (random.nextDouble() \* 3.3)))/g' $cpu_java_file
elif [[ $issue -eq 1 ]]; then
echo "generate connection pool issue"
commit_message="use default httpclient connection pool size"
sed -i 's/afterburner.remote.call.httpclient.connections.max=60/afterburner.remote.call.httpclient.connections.max=2/g' $prop_file
elif [[ $issue -eq 2 ]]; then
echo "generate query issue"
commit_message="remove duplicates per salary"
sed -i "s/) limit 200;/ AND s.to_date = (SELECT MAX(to_date) FROM salaries WHERE emp_no = em.emp_no)) limit 200;/" $query_file
else
echo "WARN: current random mod 3 is $issue, this is not expected"
fi
else # mod_run was != 0, so code change is skipped altogether. Force one anyhow.
echo "Making a safe (no-op) change.."
if grep -q "magic matrix" "$cpu_java_file"; then
sed -i "s/magic matrix/magik matrix/" $cpu_java_file
else
sed -i "s/magik matrix/magic matrix/" $cpu_java_file
fi
commit_message="changed the text"
fi
else
echo "Found performance issue(s) to fix: cpuIssue: $cpuIssue, connectionPoolIssue: $connectionPoolIssue, queryIssue $queryIssue"
# reset issue into a fix
if [ $cpuIssue -eq 1 ]; then
echo cpu issue is found, now fix it
commit_message="make cpu more efficient "
sed -i 's/some variation: is more fun/no variation: is no fun/g' $cpu_java_file
sed -i 's/int funSize = (int) (matrixSize \* (1.0 + (random.nextDouble() \* 3.3)))/int funSize = matrixSize/g' $cpu_java_file
fi
if [ $connectionPoolIssue -eq 1 ]; then
echo connection pool issue is found, now fix it
commit_message="${commit_message}tune http connection pool size"
sed -i 's/afterburner.remote.call.httpclient.connections.max=2/afterburner.remote.call.httpclient.connections.max=60/g' $prop_file
fi
if [ $queryIssue -eq 1 ]; then
echo query issue is found, now fix it
commit_message="${commit_message}fix performance issue: revert remove duplicates per salary"
sed -i "s/ AND s.to_date = (SELECT MAX(to_date) FROM salaries WHERE emp_no = em.emp_no)) limit 200;/) limit 200;/" $query_file
fi
fi
echo "commit_message=$commit_message" >> $GITHUB_ENV
- name: Commit files
run: |
git config --local user.email "action@github.com"
git config --local user.name "Proxy Developer"
git commit -m "Proxy Dev: $commit_message" -a
# needed to trigger demo build: use explicit other PAT
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT_GITHUB }}
branch: demo