ci(atlasbot): emit per-test case result metrics for flaky tracking
This commit is contained in:
parent
abcb38a3f7
commit
4f8c77e7b5
@ -54,6 +54,39 @@ def _load_junit(path: Path) -> dict[str, int]:
|
|||||||
return totals
|
return totals
|
||||||
|
|
||||||
|
|
||||||
|
def _load_junit_cases(path: Path) -> list[tuple[str, str]]:
|
||||||
|
if not path.exists():
|
||||||
|
return []
|
||||||
|
|
||||||
|
tree = ET.parse(path)
|
||||||
|
root = tree.getroot()
|
||||||
|
suites: list[ET.Element]
|
||||||
|
if root.tag == "testsuite":
|
||||||
|
suites = [root]
|
||||||
|
elif root.tag == "testsuites":
|
||||||
|
suites = list(root.findall("testsuite"))
|
||||||
|
else:
|
||||||
|
suites = []
|
||||||
|
|
||||||
|
cases: list[tuple[str, str]] = []
|
||||||
|
for suite in suites:
|
||||||
|
for case in suite.findall("testcase"):
|
||||||
|
name = (case.attrib.get("name") or "").strip()
|
||||||
|
classname = (case.attrib.get("classname") or "").strip()
|
||||||
|
if not name:
|
||||||
|
continue
|
||||||
|
test_id = f"{classname}::{name}" if classname else name
|
||||||
|
status = "passed"
|
||||||
|
if case.find("failure") is not None:
|
||||||
|
status = "failed"
|
||||||
|
elif case.find("error") is not None:
|
||||||
|
status = "error"
|
||||||
|
elif case.find("skipped") is not None:
|
||||||
|
status = "skipped"
|
||||||
|
cases.append((test_id, status))
|
||||||
|
return cases
|
||||||
|
|
||||||
|
|
||||||
def _load_coverage_percent(path: Path) -> float:
|
def _load_coverage_percent(path: Path) -> float:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return 0.0
|
return 0.0
|
||||||
@ -183,6 +216,7 @@ def main() -> int:
|
|||||||
build_dir = Path(os.getenv("BUILD_DIR", "build"))
|
build_dir = Path(os.getenv("BUILD_DIR", "build"))
|
||||||
|
|
||||||
totals = _load_junit(junit_path)
|
totals = _load_junit(junit_path)
|
||||||
|
test_cases = _load_junit_cases(junit_path)
|
||||||
coverage_pct = _load_coverage_percent(coverage_path)
|
coverage_pct = _load_coverage_percent(coverage_path)
|
||||||
gate_rc = _load_gate_rc(gate_rc_path)
|
gate_rc = _load_gate_rc(gate_rc_path)
|
||||||
docs_rc = _load_gate_rc(docs_rc_path)
|
docs_rc = _load_gate_rc(docs_rc_path)
|
||||||
@ -226,8 +260,13 @@ def main() -> int:
|
|||||||
"# TYPE platform_quality_gate_source_lines_over_500_total gauge",
|
"# 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}',
|
f'platform_quality_gate_source_lines_over_500_total{{suite="{suite}"}} {source_lines_over_500}',
|
||||||
"# TYPE atlasbot_quality_gate_checks_total gauge",
|
"# TYPE atlasbot_quality_gate_checks_total gauge",
|
||||||
|
"# TYPE platform_quality_gate_test_case_result gauge",
|
||||||
]
|
]
|
||||||
) + "\n"
|
) + "\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(
|
payload += "\n".join(
|
||||||
f'atlasbot_quality_gate_checks_total{{suite="{suite}",check="{check_name}",result="{check_status}"}} 1'
|
f'atlasbot_quality_gate_checks_total{{suite="{suite}",check="{check_name}",result="{check_status}"}} 1'
|
||||||
for check_name, check_status in checks.items()
|
for check_name, check_status in checks.items()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user