quality: publish platform gauges for atlasbot
This commit is contained in:
parent
dfbe46b0f8
commit
6484d24c82
@ -18,6 +18,9 @@ import urllib.request
|
|||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
SOURCE_SCAN_ROOTS = ("atlasbot", "scripts", "tests")
|
||||||
|
SOURCE_EXTENSIONS = {".py", ".sh"}
|
||||||
|
|
||||||
|
|
||||||
def _as_int(node: ET.Element, name: str) -> int:
|
def _as_int(node: ET.Element, name: str) -> int:
|
||||||
raw = node.attrib.get(name) or "0"
|
raw = node.attrib.get(name) or "0"
|
||||||
@ -101,7 +104,25 @@ def _post_text(url: str, payload: str) -> None:
|
|||||||
raise RuntimeError(f"push failed status={resp.status}")
|
raise RuntimeError(f"push failed status={resp.status}")
|
||||||
|
|
||||||
|
|
||||||
|
def _count_source_files_over_limit(repo_root: Path, max_lines: int = 500) -> int:
|
||||||
|
count = 0
|
||||||
|
for rel_root in SOURCE_SCAN_ROOTS:
|
||||||
|
base = repo_root / rel_root
|
||||||
|
if not base.exists():
|
||||||
|
continue
|
||||||
|
for path in base.rglob("*"):
|
||||||
|
if not path.is_file():
|
||||||
|
continue
|
||||||
|
if path.suffix not in SOURCE_EXTENSIONS:
|
||||||
|
continue
|
||||||
|
lines = len(path.read_text(encoding="utf-8", errors="ignore").splitlines())
|
||||||
|
if lines > max_lines:
|
||||||
|
count += 1
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
|
repo_root = Path(__file__).resolve().parents[1]
|
||||||
suite = os.getenv("SUITE_NAME", "atlasbot")
|
suite = os.getenv("SUITE_NAME", "atlasbot")
|
||||||
pushgateway_url = os.getenv(
|
pushgateway_url = os.getenv(
|
||||||
"PUSHGATEWAY_URL", "http://platform-quality-gateway.monitoring.svc.cluster.local:9091"
|
"PUSHGATEWAY_URL", "http://platform-quality-gateway.monitoring.svc.cluster.local:9091"
|
||||||
@ -112,6 +133,7 @@ def main() -> int:
|
|||||||
|
|
||||||
totals = _load_junit(junit_path)
|
totals = _load_junit(junit_path)
|
||||||
coverage_pct = _load_coverage_percent(coverage_path)
|
coverage_pct = _load_coverage_percent(coverage_path)
|
||||||
|
source_lines_over_500 = _count_source_files_over_limit(repo_root, max_lines=500)
|
||||||
passed = max(totals["tests"] - totals["failures"] - totals["errors"] - totals["skipped"], 0)
|
passed = max(totals["tests"] - totals["failures"] - totals["errors"] - totals["skipped"], 0)
|
||||||
outcome = "ok" if totals["tests"] > 0 and totals["failures"] == 0 and totals["errors"] == 0 else "failed"
|
outcome = "ok" if totals["tests"] > 0 and totals["failures"] == 0 and totals["errors"] == 0 else "failed"
|
||||||
|
|
||||||
@ -135,6 +157,10 @@ def main() -> int:
|
|||||||
f'atlasbot_quality_gate_tests_total{{suite="{suite}",result="skipped"}} {totals["skipped"]}',
|
f'atlasbot_quality_gate_tests_total{{suite="{suite}",result="skipped"}} {totals["skipped"]}',
|
||||||
"# TYPE atlasbot_quality_gate_coverage_percent gauge",
|
"# TYPE atlasbot_quality_gate_coverage_percent gauge",
|
||||||
f'atlasbot_quality_gate_coverage_percent{{suite="{suite}"}} {coverage_pct:.3f}',
|
f'atlasbot_quality_gate_coverage_percent{{suite="{suite}"}} {coverage_pct:.3f}',
|
||||||
|
"# TYPE platform_quality_gate_workspace_line_coverage_percent gauge",
|
||||||
|
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}',
|
||||||
]
|
]
|
||||||
) + "\n"
|
) + "\n"
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user