Skip to content

Commit 0aa70f2

Browse files
committed
e2e: updated test.stats and add a script to update stats automatically
1 parent 21aeadc commit 0aa70f2

2 files changed

Lines changed: 207 additions & 6 deletions

File tree

stackgres-k8s/e2e/test.stats

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
autoscaling:268
12
availability:217
23
backup:631
34
backupconf-removal:19
5+
catchup-from-backup-storage:187
6+
cert-manager-integration:173
47
cluster-api-info:28
58
connectivity:246
69
custom-annotations:146
710
custom-labels:107
8-
dbops-major-version-upgrade:868
11+
dbops-major-version-upgrade:635
912
dbops-major-version-upgrade-link-an-clone:559
13+
dbops-major-version-upgrade-link-and-clone:489
14+
dbops-major-version-upgrade-primary-not-first:319
1015
dbops-major-version-upgrade-timeout-and-repeat:494
1116
dbops-minor-version-upgrade:629
1217
dbops-pgbench:469
1318
dbops-repack:394
14-
dbops-restart:896
19+
dbops-restart:684
20+
dbops-restart-after-upgrade:764
1521
dbops-restart-failed:240
1622
dbops-restart-timeout-and-repeat:446
17-
dbops-security-upgrade:1306
23+
dbops-restart-with-failed-pod:151
24+
dbops-security-upgrade:1596
25+
dbops-security-upgrade-olm:1317
1826
dbops-vacuum:364
1927
default-cr:129
2028
default-mutator:272
@@ -39,7 +47,9 @@ operator-dbops-restart-api:70
3947
operator-dbops-vacuum-api:71
4048
operator-demo:523
4149
operator-distributedlogs-api:72
50+
operator-helm:594
4251
operator-namespace-api:15
52+
operator-olm:1065
4353
operator-pgconfig-api:176
4454
operator-pgpooling-api:195
4555
operator-profile-api:169
@@ -52,17 +62,26 @@ pod-node-affinity:45
5262
pod-nodeselectors:37
5363
pod-tolerations:45
5464
profile-removal:23
65+
prometheus-integration:391
5566
prometheus-integration-default:442
56-
prometheus-no-label-filtering:458
57-
reconciliation-ignore:96
67+
prometheus-no-label-filtering:361
68+
reconciliation-ignore:75
5869
regression:146
5970
reinstall:449
6071
replication:297
6172
restore:555
6273
scale-up-and-down:446
6374
service-conf:177
6475
service-conf-distributed-logs:85
76+
sharded-backup-citus:1034
77+
sharded-cluster-shardingsphere:634
78+
sharded-dbops-resharding-citus:206
79+
sharded-dbops-restart-ddp:238
6580
sql-scripts:217
6681
ssl:230
82+
standby-from-cluster:280
83+
standby-from-storage:170
84+
stream-to-pglambda:750
6785
switchover-and-backup:528
68-
ui:463
86+
sync-replication:364
87+
ui:1468
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6+
PROJECT_DIR="../../$SCRIPT_DIR"
7+
GLAB="${GLAB:-$PROJECT_DIR/stackgres-k8s/ci/utils/glabw}"
8+
TARGET_DIR="$SCRIPT_DIR/target"
9+
STATS_FILE="$SCRIPT_DIR/test.stats"
10+
ARTIFACT_ZIP="/tmp/job_artifact_$$.zip"
11+
COLLECTED_DURATIONS="/tmp/collected_durations_$$.txt"
12+
TEMP_STATS="/tmp/temp_stats_$$.txt"
13+
14+
usage() {
15+
echo "Usage: $0 <pipeline_id>"
16+
echo ""
17+
echo "Updates test.stats file with test durations from CI/CD pipeline artifacts."
18+
echo ""
19+
echo "Arguments:"
20+
echo " pipeline_id GitLab pipeline ID to fetch artifacts from"
21+
echo ""
22+
echo "Requirements:"
23+
echo " - Docker installed"
24+
exit 1
25+
}
26+
27+
# Get duration for a test from collected durations file
28+
get_collected_duration() {
29+
local test_name="$1"
30+
grep "^${test_name}:" "$COLLECTED_DURATIONS" 2>/dev/null | cut -d: -f2 | head -1
31+
}
32+
33+
# Check if test exists in collected durations
34+
has_collected_duration() {
35+
local test_name="$1"
36+
grep -q "^${test_name}:" "$COLLECTED_DURATIONS" 2>/dev/null
37+
}
38+
39+
# Get duration for a test from stats file
40+
get_stat_duration() {
41+
local test_name="$1"
42+
local file="$2"
43+
grep "^${test_name}:" "$file" 2>/dev/null | cut -d: -f2 | head -1
44+
}
45+
46+
# Clean up target directory
47+
clean_target() {
48+
rm -rf "$TARGET_DIR"
49+
}
50+
51+
# Cleanup on exit
52+
cleanup() {
53+
rm -f "$ARTIFACT_ZIP" "$COLLECTED_DURATIONS" "$TEMP_STATS"
54+
}
55+
trap cleanup EXIT
56+
57+
if [ -z "$1" ]; then
58+
usage
59+
fi
60+
61+
PIPELINE_ID="$1"
62+
63+
if ! "$GLAB" auth status > /dev/null 2>&1; then
64+
echo "Error: glab is not authenticated. Run '$GLAB auth login' first."
65+
exit 1
66+
fi
67+
68+
# Initialize collected durations file
69+
: > "$COLLECTED_DURATIONS"
70+
71+
echo "Fetching e2e job IDs from pipeline $PIPELINE_ID..."
72+
73+
# Get all e2e job IDs including retried ones
74+
e2e_jobs=$("$GLAB" api "projects/:id/pipelines/${PIPELINE_ID}/jobs?per_page=100&include_retried=true" 2>/dev/null \
75+
| jq -r '.[] | select(.name | contains("e2e")) | .id')
76+
77+
if [ -z "$e2e_jobs" ]; then
78+
echo "Error: No e2e jobs found in pipeline $PIPELINE_ID"
79+
exit 1
80+
fi
81+
82+
total_jobs=$(echo "$e2e_jobs" | wc -l | tr -d ' ')
83+
echo "Found $total_jobs e2e jobs"
84+
echo ""
85+
86+
current=0
87+
for job_id in $e2e_jobs; do
88+
current=$((current + 1))
89+
echo "[$current/$total_jobs] Processing job ID: $job_id"
90+
91+
# Clean target directory
92+
clean_target
93+
94+
# Download artifacts
95+
rm -f "$ARTIFACT_ZIP"
96+
if ! "$GLAB" api "projects/:id/jobs/${job_id}/artifacts" 2>/dev/null > "$ARTIFACT_ZIP"; then
97+
echo " Failed to download artifacts"
98+
continue
99+
fi
100+
101+
# Check if it's a valid zip file
102+
if ! file "$ARTIFACT_ZIP" | grep -q "Zip archive"; then
103+
echo " No valid artifacts"
104+
continue
105+
fi
106+
107+
# Extract artifacts
108+
if ! unzip -o "$ARTIFACT_ZIP" -d "$SCRIPT_DIR/../.." > /dev/null 2>&1; then
109+
echo " Failed to extract artifacts"
110+
continue
111+
fi
112+
113+
# Find duration files with matching success files
114+
found=0
115+
for duration_file in "$TARGET_DIR"/*.duration; do
116+
if [ -f "$duration_file" ]; then
117+
test_name=$(basename "$duration_file" .duration)
118+
success_file="$TARGET_DIR/${test_name}.success"
119+
120+
if [ -f "$success_file" ]; then
121+
duration=$(tr -d '[:space:]' < "$duration_file")
122+
if [ -n "$duration" ]; then
123+
# Only update if not already set (first match wins - latest run)
124+
if ! has_collected_duration "$test_name"; then
125+
echo "${test_name}:${duration}" >> "$COLLECTED_DURATIONS"
126+
echo " Found: $test_name -> $duration"
127+
found=$((found + 1))
128+
fi
129+
fi
130+
fi
131+
fi
132+
done
133+
echo " Total found in this job: $found"
134+
done
135+
136+
# Clean up target directory
137+
clean_target
138+
139+
echo ""
140+
echo "=== Updating $STATS_FILE ==="
141+
142+
# Copy existing stats to temp file, or create empty
143+
if [ -f "$STATS_FILE" ]; then
144+
cp "$STATS_FILE" "$TEMP_STATS"
145+
else
146+
: > "$TEMP_STATS"
147+
fi
148+
149+
existing_count=$(wc -l < "$TEMP_STATS" | tr -d ' ')
150+
echo "Existing entries: $existing_count"
151+
152+
# Update stats with collected durations
153+
updated=0
154+
added=0
155+
collected_count=$(wc -l < "$COLLECTED_DURATIONS" | tr -d ' ')
156+
157+
while IFS=: read -r name duration; do
158+
if [ -n "$name" ]; then
159+
old_duration=$(get_stat_duration "$name" "$TEMP_STATS")
160+
if [ -z "$old_duration" ]; then
161+
echo " Added: $name -> $duration"
162+
echo "${name}:${duration}" >> "$TEMP_STATS"
163+
added=$((added + 1))
164+
elif [ "$old_duration" != "$duration" ]; then
165+
echo " Updated: $name: $old_duration -> $duration"
166+
sed -i "s/^${name}:.*/${name}:${duration}/" "$TEMP_STATS"
167+
updated=$((updated + 1))
168+
fi
169+
fi
170+
done < "$COLLECTED_DURATIONS"
171+
172+
# Write sorted output to test.stats
173+
sort "$TEMP_STATS" > "$STATS_FILE"
174+
175+
final_count=$(wc -l < "$STATS_FILE" | tr -d ' ')
176+
177+
echo ""
178+
echo "Summary:"
179+
echo " Tests collected from pipeline: $collected_count"
180+
echo " New tests added: $added"
181+
echo " Tests updated: $updated"
182+
echo " Total entries in test.stats: $final_count"

0 commit comments

Comments
 (0)