From 9e15badcb105598b75a7737d27588f42cdb801e1 Mon Sep 17 00:00:00 2001 From: jenkins Date: Mon, 20 Apr 2026 10:46:07 -0300 Subject: [PATCH] ci(atlasbot): fix test-case metric label escaping --- scripts/publish_test_metrics.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/publish_test_metrics.py b/scripts/publish_test_metrics.py index 1ec7ea8..445467b 100755 --- a/scripts/publish_test_metrics.py +++ b/scripts/publish_test_metrics.py @@ -23,6 +23,11 @@ from pathlib import Path QUALITY_SUCCESS_STATES = {"ok", "pass", "passed", "success", "compliant"} +def _escape_label(value: str) -> str: + """Escape Prometheus label values safely.""" + return value.replace("\\", "\\\\").replace("\n", "\\n").replace('"', '\\"') + + def _as_int(node: ET.Element, name: str) -> int: raw = node.attrib.get(name) or "0" try: @@ -270,6 +275,10 @@ def main() -> int: ) + "\n" else: payload += f'platform_quality_gate_test_case_result{{suite="{suite}",test="__no_test_cases__",status="skipped"}} 1\n' + payload += "\n".join( + f'platform_quality_gate_test_case_result{{suite="{suite}",test="{_escape_label(test_name)}",status="{_escape_label(test_status)}"}} 1' + for test_name, test_status in test_cases + ) + "\n" payload += "\n".join( f'atlasbot_quality_gate_checks_total{{suite="{suite}",check="{check_name}",result="{check_status}"}} 1' for check_name, check_status in checks.items()