Skip to content

Commit c596bdf

Browse files
committed
test: add script to convert perf metrics to prometheus format
1 parent 9aca0c2 commit c596bdf

File tree

5 files changed

+81
-26
lines changed

5 files changed

+81
-26
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ jobs:
324324
needs: smokeTests
325325
if: always()
326326
steps:
327+
- name: Checkout repository
328+
uses: actions/checkout@v4
329+
327330
- name: Download all smoke tests artifacts
328331
uses: actions/download-artifact@v4
329332
with:
@@ -343,6 +346,11 @@ jobs:
343346
platform=Linux
344347
" > environment.properties
345348
349+
- name: Convert metrics JSON to Prometheus format
350+
working-directory: './packages/e2e-tests/tools/'
351+
run: |
352+
./convert_metrics_to_prometheus.sh "${{ github.workflow }}" "${{ github.run_id }}" ../../../metrics
353+
346354
- name: Publish allure report to S3
347355
uses: andrcuns/[email protected]
348356
if: always()

.github/workflows/e2e-tests-linux-split.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ jobs:
193193
# when cancelling job always() will prevent step from being cancelled and we don't want process results in this case
194194
if: ${{ success() || failure() }}
195195
steps:
196+
- name: Checkout repository
197+
uses: actions/checkout@v4
198+
196199
- name: Download all artifacts
197200
uses: actions/download-artifact@v4
198201
with:
@@ -212,6 +215,11 @@ jobs:
212215
tags=${{ needs.setup.outputs.tags }}
213216
" > environment.properties
214217
218+
- name: Convert metrics JSON to Prometheus format
219+
working-directory: './packages/e2e-tests/tools/'
220+
run: |
221+
./convert_metrics_to_prometheus.sh "${{ github.workflow }}" "${{ github.run_id }}" ../../../artifacts/metrics
222+
215223
- name: Publish allure report to S3
216224
uses: andrcuns/[email protected]
217225
env:

packages/e2e-tests/tools/convertChromeExtToSafari.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
JOB=${1:-}
6+
INSTANCE=${2:-}
7+
METRICS_DIR=${3:-metrics}
8+
9+
if [[ -z "$JOB" || -z "$INSTANCE" ]]; then
10+
echo "Usage: $0 <job> <instance> [metrics_dir]"
11+
echo " job - GitHub workflow name"
12+
echo " instance - GitHub run ID"
13+
echo " metrics_dir - (optional) Directory containing JSON metrics files (default: metrics)"
14+
exit 1
15+
fi
16+
17+
OUTPUT_FILE="$METRICS_DIR/prometheus.txt"
18+
19+
if [[ ! -d "$METRICS_DIR" ]]; then
20+
echo "Metrics directory '$METRICS_DIR' does not exist."
21+
exit 0
22+
fi
23+
24+
shopt -s nullglob
25+
FILES=("$METRICS_DIR"/*.json)
26+
27+
# Filter out the output file from being processed
28+
FILES=("${FILES[@]/$OUTPUT_FILE}")
29+
30+
if [[ ${#FILES[@]} -eq 0 ]]; then
31+
echo "No JSON files found in '$METRICS_DIR'."
32+
exit 0
33+
fi
34+
35+
> "$OUTPUT_FILE"
36+
37+
for file in "${FILES[@]}"; do
38+
if [[ ! -s "$file" ]]; then
39+
echo "Skipping empty file: $file"
40+
continue
41+
fi
42+
43+
filename=$(basename "$file")
44+
scenario_id="${filename%%-chrome-usage.json}"
45+
scenario_name=$(jq -r '.scenarioName // empty' "$file")
46+
data_length=$(jq '.data | length' "$file")
47+
48+
echo "# Metrics from $filename" >> "$OUTPUT_FILE"
49+
50+
if [[ "$data_length" -eq 0 ]]; then
51+
echo "e2e_cpu_seconds_total{scenario_name=\"$scenario_name\",scenario_id=\"$scenario_id\",job=\"$JOB\",instance=\"$INSTANCE\"} 0" >> "$OUTPUT_FILE"
52+
echo "e2e_memory_rss_bytes{scenario_name=\"$scenario_name\",scenario_id=\"$scenario_id\",job=\"$JOB\",instance=\"$INSTANCE\"} 0" >> "$OUTPUT_FILE"
53+
else
54+
jq -c '.data[]' "$file" | while read -r entry; do
55+
timestamp=$(echo "$entry" | jq -r '.timestamp')
56+
cpu=$(echo "$entry" | jq -r '.cpu')
57+
memory=$(echo "$entry" | jq -r '.memory')
58+
59+
echo "e2e_cpu_seconds_total{scenario_name=\"$scenario_name\",scenario_id=\"$scenario_id\",job=\"$JOB\",instance=\"$INSTANCE\",timestamp=\"$timestamp\"} $cpu" >> "$OUTPUT_FILE"
60+
echo "e2e_memory_rss_bytes{scenario_name=\"$scenario_name\",scenario_id=\"$scenario_id\",job=\"$JOB\",instance=\"$INSTANCE\",timestamp=\"$timestamp\"} $memory" >> "$OUTPUT_FILE"
61+
done
62+
fi
63+
done
64+
65+
echo "Metrics converted to Prometheus format: $OUTPUT_FILE"

packages/e2e-tests/tools/openSafariExtension.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)