Skip to content

Commit 5af9235

Browse files
Define an MTR JUnit reporter (client)
Standalone build step that checks for xml's files in the mtr log path and reports them back to the collector service. The collector service is running on the buildmaster as a docker container and its address is defined in the .env files This is not a critical client service so just warn on step failure. Common failures that can occur are: collector service is not available or the report is not a valid xml. If all MTR steps are successful then naturally there's no failure to report from the XML files so skip this step -> hasFailed(step)
1 parent 48687ec commit 5af9235

5 files changed

Lines changed: 131 additions & 2 deletions

File tree

configuration/builders/sequences/helpers.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from configuration.builders.infra.runtime import InContainer
55
from configuration.steps.base import StepOptions
66
from configuration.steps.commands.base import URL
7-
from configuration.steps.commands.mtr import MTRTest
7+
from configuration.steps.commands.mtr import MTRTest, MTRReporter
88
from configuration.steps.commands.util import (
99
CreateS3Bucket,
1010
DeleteS3Bucket,
@@ -270,6 +270,14 @@ def add_test_suites_steps(
270270
)
271271
)
272272

273+
steps.append(
274+
mtr_junit_reporter(
275+
step_wrapping_fn=lambda step: InContainer(
276+
docker_environment=config, step=step
277+
),
278+
)
279+
)
280+
273281
return steps
274282

275283

@@ -294,3 +302,23 @@ def save_mtr_logs(
294302
),
295303
),
296304
)
305+
306+
307+
def mtr_junit_reporter(
308+
step_wrapping_fn=lambda step: step,
309+
):
310+
return step_wrapping_fn(
311+
ShellStep(
312+
command=MTRReporter(
313+
directory=MTR_PATH_TO_SAVE_LOGS,
314+
),
315+
url=URL(
316+
url=f"{os.environ['BUILDMASTER_URL']}/cr",
317+
url_text="Check MTR JUnit results on CrossReference",
318+
),
319+
options=StepOptions(
320+
alwaysRun=True, doStepIf=(lambda step: hasFailed(step))
321+
),
322+
warn_on_fail=True,
323+
),
324+
)

configuration/steps/commands/mtr.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import os
2+
13
from pathlib import PurePath
24

35
from buildbot.plugins import util
4-
from configuration.steps.commands.base import Command
6+
from configuration.steps.commands.base import BashScriptCommand, Command
57
from configuration.steps.generators.mtr.generator import MTRGenerator
68

79

@@ -75,3 +77,24 @@ def _save_logs(self) -> str:
7577
find . -type f \( {patterns} \) -print0 | rsync -a --files-from=- --from0 ./ {self.save_logs_path}/
7678
exit 1
7779
"""
80+
81+
82+
class MTRReporter(BashScriptCommand):
83+
"""
84+
A command to transfer all the MTR JUnit test results to the mtr_junit_collector service.
85+
Attributes:
86+
directory (PurePath): The directory containing the MTR test results.
87+
"""
88+
89+
JUNIT_COLLECTOR_BASE_URL = os.environ.get("JUNIT_COLLECTOR_BASE_URL")
90+
91+
def __init__(self, directory: PurePath):
92+
base_url = self.JUNIT_COLLECTOR_BASE_URL
93+
branch = util.Interpolate("%(prop:branch)s")
94+
revision = util.Interpolate("%(prop:revision)s")
95+
platform = util.Interpolate("%(prop:buildnumber)s")
96+
bbnum = util.Interpolate("%(prop:buildnumber)s")
97+
dir = str(directory)
98+
99+
args = [base_url, branch, revision, platform, bbnum, dir]
100+
super().__init__(script_name="mtr_reporter.sh", args=args)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Input variables
6+
BASE_URL="$1" # e.g., 100.64.101.1:9990
7+
BRANCH="$2"
8+
REVISION="$3"
9+
PLATFORM="$4"
10+
BBNUM="$5"
11+
DIR="$6" # Directory containing .xml files
12+
13+
UPLOAD_URL="http://${BASE_URL}/upload-test-results/"
14+
HEALTH_URL="http://${BASE_URL}/health"
15+
16+
# Step 1: Health check before uploads
17+
echo "Checking service health at $HEALTH_URL..."
18+
if ! curl "$HEALTH_URL" \
19+
--max-time 5 \
20+
--retry 3 \
21+
--retry-max-time 0 \
22+
--retry-delay 5 \
23+
--retry-connrefused \
24+
--fail-with-body > /dev/null; then
25+
echo "Service health check failed. Aborting uploads."
26+
exit 1
27+
fi
28+
echo "Service is healthy. Proceeding with uploads."
29+
30+
# Step 2: Validate directory
31+
if [[ ! -d "$DIR" ]]; then
32+
echo "Error: directory '$DIR' does not exist"
33+
exit 1
34+
fi
35+
36+
# Step 3: Find XML files
37+
shopt -s nullglob
38+
XML_FILES=("$DIR"/*.xml)
39+
shopt -u nullglob
40+
41+
if [[ ${#XML_FILES[@]} -eq 0 ]]; then
42+
echo "Error: no .xml files found in directory '$DIR'"
43+
exit 1
44+
fi
45+
46+
# Step 4: Upload files and track failures
47+
ANY_FAILED=0
48+
49+
for FILE in "${XML_FILES[@]}"; do
50+
# Extract filename without extension for 'typ'
51+
BASENAME="$(basename "$FILE" .xml)"
52+
echo "Uploading $FILE (typ=$BASENAME)..."
53+
54+
if ! curl --max-time 120 --connect-timeout 10 --fail-with-body \
55+
-X POST "$UPLOAD_URL" \
56+
-F "branch=${BRANCH}" \
57+
-F "revision=${REVISION}" \
58+
-F "platform=${PLATFORM}" \
59+
-F "bbnum=${BBNUM}" \
60+
-F "typ=${BASENAME}" \
61+
-F "file=@${FILE};type=application/xml"; then
62+
echo "Upload failed for $FILE"
63+
ANY_FAILED=1
64+
else
65+
echo "Upload succeeded for $FILE"
66+
fi
67+
done
68+
69+
# Step 5: Final result
70+
if [[ $ANY_FAILED -ne 0 ]]; then
71+
echo "One or more uploads failed."
72+
exit 1
73+
else
74+
echo "All uploads succeeded."
75+
exit 0
76+
fi

docker-compose/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ TITLE='MariaDB CI'
22
TITLE_URL='https://github.com/MariaDB/server'
33
BUILDMASTER_URL='https://buildbot.mariadb.org/'
44
BUILDMASTER_WG_IP='100.64.100.1'
5+
JUNIT_COLLECTOR_BASE_URL='http://100.64.100.1:9990'
56
MQ_ROUTER_URL='ws://127.0.0.1:8080/ws'
67
MASTER_PACKAGES_DIR='/mnt/autofs/master_packages'
78
MASTER_CREDENTIALS_DIR='/srv/buildbot/master/master-credential-provider'

docker-compose/.env.dev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ TITLE='MariaDB CI (DEV)'
22
TITLE_URL='https://github.com/MariaDB/server'
33
BUILDMASTER_URL='https://buildbot.dev.mariadb.org/'
44
BUILDMASTER_WG_IP='100.64.101.1'
5+
JUNIT_COLLECTOR_BASE_URL='http://100.64.101.1:9990'
56
MQ_ROUTER_URL='ws://127.0.0.1:8080/ws'
67
MASTER_PACKAGES_DIR='/mnt/autofs/master_dev_packages'
78
MASTER_CREDENTIALS_DIR='/srv/buildbot/master/master-credential-provider'

0 commit comments

Comments
 (0)