Skip to content

Commit 2024c54

Browse files
committed
ci: compare CPU and memory usage between stable and PR DWO deployments (#1477)
- Deploy stable DevWorkspace Operator only on main branch - Capture CPU and memory usage via `kubectl top` for both deployments - Normalize and compare CPU/Memory metrics with configurable thresholds - Fail CI if resource usage increases beyond acceptable limits Signed-off-by: Rohan Kumar <[email protected]>
1 parent cf4c38d commit 2024c54

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#
2+
# Copyright (c) 2019-2025 Red Hat, Inc.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
name: DWO CPU Memory Regression Check
17+
18+
on:
19+
pull_request:
20+
branches: [ main ]
21+
22+
env:
23+
DWO_NAMESPACE_STABLE: devworkspace-controller-stable
24+
DWO_NAMESPACE_PR: devworkspace-controller-pr
25+
MEM_THRESHOLD: 100
26+
CPU_THRESHOLD: 50
27+
28+
jobs:
29+
test-on-minikube:
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
kubernetes: [v1.33.0]
35+
steps:
36+
- name: Setup Minikube-Kubernetes
37+
uses: manusa/actions-setup-minikube@b589f2d61bf96695c546929c72b38563e856059d # v2.14.0
38+
with:
39+
minikube version: 'v1.35.0'
40+
kubernetes version: ${{ matrix.kubernetes }}
41+
github token: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Install and Enable Minikube addons metrics-server
44+
run: |
45+
minikube addons enable metrics-server
46+
kubectl rollout status deployment/metrics-server -n kube-system --timeout=300s
47+
48+
- name: Install and Wait for cert-manager to be ready
49+
run: |
50+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.2/cert-manager.yaml
51+
kubectl rollout status deployment/cert-manager -n cert-manager --timeout=300s
52+
53+
- name: Enable and Wait for Ingress addon
54+
run: |
55+
minikube addons enable ingress
56+
kubectl rollout status deployment/ingress-nginx-controller -n ingress-nginx --timeout=300s
57+
58+
- name: Set up Go 1.x
59+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
60+
with:
61+
go-version: 1.23.6
62+
63+
- name: Clone DevWorkspace Operator main repo
64+
run: |
65+
git clone https://github.com/devfile/devworkspace-operator.git /tmp/devworkspace-operator-main
66+
cd /tmp/devworkspace-operator-main
67+
68+
- name: Deploy DevWorkspace Operator (stable)
69+
run: |
70+
cd /tmp/devworkspace-operator-main
71+
export DWO_IMG=quay.io/devfile/devworkspace-controller:next
72+
export NAMESPACE=$DWO_NAMESPACE_STABLE
73+
make install
74+
kubectl rollout status deployment/devworkspace-controller-manager -n $DWO_NAMESPACE_STABLE --timeout=300s
75+
sleep 100
76+
kubectl top pod --no-headers -n $DWO_NAMESPACE_STABLE $(kubectl get pods -n $DWO_NAMESPACE_STABLE -l app.kubernetes.io/name=devworkspace-controller -o jsonpath='{.items[0].metadata.name}') > /tmp/stable-metrics.txt
77+
make uninstall
78+
79+
- name: Check out code into the Go module directory
80+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
81+
82+
- name: Build DevWorkspace Operator from PR
83+
run: |
84+
export DWO_IMG=ttl.sh/devworkspace-operator:15m
85+
export NAMESPACE=$DWO_NAMESPACE_PR
86+
make docker
87+
88+
- name: Deploy DevWorkspace Operator from PR to Minikube
89+
run: |
90+
export DWO_IMG=ttl.sh/devworkspace-operator:15m
91+
export NAMESPACE=$DWO_NAMESPACE_PR
92+
make install
93+
kubectl get pods -n $DWO_NAMESPACE_PR
94+
kubectl rollout status deployment/devworkspace-controller-manager -n $DWO_NAMESPACE_PR --timeout=300s
95+
sleep 100
96+
kubectl get pods -n $DWO_NAMESPACE_PR
97+
kubectl describe pods -n $DWO_NAMESPACE_PR
98+
99+
- name: Save DevWorkspace Operator pods metrics
100+
run: |
101+
kubectl top pod --no-headers -n $DWO_NAMESPACE_PR $(kubectl get pods -n $DWO_NAMESPACE_PR -l app.kubernetes.io/name=devworkspace-controller -o jsonpath='{.items[0].metadata.name}') > /tmp/pr-metrics.txt
102+
cat /tmp/pr-metrics.txt
103+
104+
- name: Compare CPU usage
105+
run: |
106+
convert_cpu() {
107+
echo "${1%m}"
108+
}
109+
110+
CPU1=$(cat /tmp/stable-metrics.txt | awk '{print $2}')
111+
CPU2=$(cat /tmp/pr-metrics.txt | awk '{print $2}')
112+
113+
CPU1_INT=$(convert_cpu $CPU1)
114+
CPU2_INT=$(convert_cpu $CPU2)
115+
116+
CPU_DIFF=$(( CPU2_INT - CPU1_INT ))
117+
118+
echo "CPU stable pod: ${CPU1_INT}m"
119+
echo "CPU PR pod: ${CPU2_INT}m"
120+
echo "CPU difference: ${CPU_DIFF}m"
121+
122+
if (( CPU_DIFF > CPU_THRESHOLD )); then
123+
echo "❌ CPU usage increased by more than ${CPU_THRESHOLD}m"
124+
exit 1
125+
fi
126+
echo "✅ CPU usage within threshold."
127+
128+
- name: Compare Memory usage
129+
run: |
130+
convert_mem() {
131+
val=$1
132+
if [[ $val == *Ki ]]; then
133+
echo $(( ${val%Ki} / 1024 ))
134+
elif [[ $val == *Mi ]]; then
135+
echo ${val%Mi}
136+
elif [[ $val == *Gi ]]; then
137+
echo $(( ${val%Gi} * 1024 ))
138+
else
139+
echo 0
140+
fi
141+
}
142+
143+
MEM1=$(cat /tmp/stable-metrics.txt | awk '{print $3}')
144+
MEM2=$(cat /tmp/pr-metrics.txt | awk '{print $3}')
145+
146+
MEM1_INT=$(convert_mem $MEM1)
147+
MEM2_INT=$(convert_mem $MEM2)
148+
149+
MEM_DIFF=$(( MEM2_INT - MEM1_INT ))
150+
151+
echo "Memory stable pod: ${MEM1_INT}Mi"
152+
echo "Memory PR pod: ${MEM2_INT}Mi"
153+
echo "Memory difference: ${MEM_DIFF}Mi"
154+
155+
if (( MEM_DIFF > MEM_THRESHOLD )); then
156+
echo "❌ Memory usage increased by more than ${MEM_THRESHOLD}Mi"
157+
exit 1
158+
fi
159+
echo "✅ Memory usage within threshold."

0 commit comments

Comments
 (0)