ci(pegasus): emit test-case status metrics for flaky-test tracking
This commit is contained in:
parent
f6fcadc52d
commit
2cf7fcba50
@ -8,6 +8,7 @@ Inputs:
|
|||||||
Outputs pushed:
|
Outputs pushed:
|
||||||
- platform_quality_gate_runs_total{suite="pegasus",status="ok|failed"}
|
- platform_quality_gate_runs_total{suite="pegasus",status="ok|failed"}
|
||||||
- pegasus_quality_gate_tests_total{suite="pegasus",result=*}
|
- pegasus_quality_gate_tests_total{suite="pegasus",result=*}
|
||||||
|
- platform_quality_gate_test_case_result{suite="pegasus",test=*,status=*}
|
||||||
- pegasus_quality_gate_coverage_percent{suite="pegasus"}
|
- pegasus_quality_gate_coverage_percent{suite="pegasus"}
|
||||||
- platform_quality_gate_workspace_line_coverage_percent{suite="pegasus"}
|
- platform_quality_gate_workspace_line_coverage_percent{suite="pegasus"}
|
||||||
- platform_quality_gate_source_lines_over_500_total{suite="pegasus"}
|
- platform_quality_gate_source_lines_over_500_total{suite="pegasus"}
|
||||||
@ -72,6 +73,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_backend_coverage_percent(path: Path) -> float:
|
def _load_backend_coverage_percent(path: Path) -> float:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return 0.0
|
return 0.0
|
||||||
@ -144,7 +178,7 @@ def _post_text(url: str, payload: str) -> None:
|
|||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
url,
|
url,
|
||||||
data=payload.encode("utf-8"),
|
data=payload.encode("utf-8"),
|
||||||
method="POST",
|
method="PUT",
|
||||||
headers={"Content-Type": "text/plain"},
|
headers={"Content-Type": "text/plain"},
|
||||||
)
|
)
|
||||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||||
@ -228,6 +262,7 @@ def main() -> int:
|
|||||||
|
|
||||||
b = _load_junit(backend_junit)
|
b = _load_junit(backend_junit)
|
||||||
f = _load_junit(frontend_junit)
|
f = _load_junit(frontend_junit)
|
||||||
|
test_cases = _load_junit_cases(backend_junit) + _load_junit_cases(frontend_junit)
|
||||||
totals = {
|
totals = {
|
||||||
"tests": b["tests"] + f["tests"],
|
"tests": b["tests"] + f["tests"],
|
||||||
"failures": b["failures"] + f["failures"],
|
"failures": b["failures"] + f["failures"],
|
||||||
@ -317,9 +352,14 @@ def main() -> int:
|
|||||||
"# TYPE pegasus_quality_gate_issues_total gauge",
|
"# TYPE pegasus_quality_gate_issues_total gauge",
|
||||||
f'pegasus_quality_gate_issues_total{{suite="{suite}"}} {len(gate_issues)}',
|
f'pegasus_quality_gate_issues_total{{suite="{suite}"}} {len(gate_issues)}',
|
||||||
"# TYPE pegasus_quality_gate_checks_total gauge",
|
"# TYPE pegasus_quality_gate_checks_total gauge",
|
||||||
|
"# TYPE platform_quality_gate_test_case_result gauge",
|
||||||
"# TYPE pegasus_quality_gate_build_info gauge",
|
"# TYPE pegasus_quality_gate_build_info gauge",
|
||||||
f"pegasus_quality_gate_build_info{_label_str(labels)} 1",
|
f"pegasus_quality_gate_build_info{_label_str(labels)} 1",
|
||||||
]
|
]
|
||||||
|
payload_lines.extend(
|
||||||
|
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
|
||||||
|
)
|
||||||
payload_lines.extend(
|
payload_lines.extend(
|
||||||
f'pegasus_quality_gate_checks_total{{suite="{suite}",check="{check_name}",result="{check_status}"}} 1'
|
f'pegasus_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