diff --git a/scripts/publish_test_metrics.py b/scripts/publish_test_metrics.py index 86e8bab..7741537 100755 --- a/scripts/publish_test_metrics.py +++ b/scripts/publish_test_metrics.py @@ -28,6 +28,12 @@ def _escape_label(value: str) -> str: return value.replace("\\", "\\\\").replace("\n", "\\n").replace('"', '\\"') +def _label_str(labels: dict[str, str]) -> str: + """Render Prometheus labels, omitting empty optional values.""" + parts = [f'{key}="{_escape_label(val)}"' for key, val in labels.items() if val] + return "{" + ",".join(parts) + "}" if parts else "" + + def _as_int(node: ET.Element, name: str) -> int: raw = node.attrib.get(name) or "0" try: @@ -219,6 +225,8 @@ def main() -> int: docs_rc_path = Path(os.getenv("QUALITY_GATE_DOCS_RC_PATH", "build/docs-naming.rc")) source_root = Path(os.getenv("SOURCE_ROOT", "atlasbot")) build_dir = Path(os.getenv("BUILD_DIR", "build")) + branch = os.getenv("BRANCH_NAME", os.getenv("GIT_BRANCH", "")) + build_number = os.getenv("BUILD_NUMBER", "") if not junit_path.exists(): junit_candidates = sorted(build_dir.glob("junit*.xml")) @@ -280,6 +288,8 @@ def main() -> int: f'platform_quality_gate_workspace_line_coverage_percent{{suite="{suite}"}} {coverage_pct:.3f}', "# TYPE platform_quality_gate_source_lines_over_500_total gauge", f'platform_quality_gate_source_lines_over_500_total{{suite="{suite}"}} {source_lines_over_500}', + "# TYPE platform_quality_gate_build_info gauge", + f'platform_quality_gate_build_info{_label_str({"suite": suite, "branch": branch, "build_number": build_number})} 1', "# TYPE atlasbot_quality_gate_checks_total gauge", "# TYPE platform_quality_gate_test_case_result gauge", ]