Skip to content

Proxy dev

Proxy dev #2777

Workflow file for this run

---
# 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 "[email protected]"
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