ci: preserve atlasbot quality gauges in pushgateway
This commit is contained in:
parent
dfbe46b0f8
commit
d78ffc7221
90
Jenkinsfile
vendored
90
Jenkinsfile
vendored
@ -179,96 +179,6 @@ spec:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
success {
|
|
||||||
container('tester') {
|
|
||||||
sh '''
|
|
||||||
set -euo pipefail
|
|
||||||
export QUALITY_STATUS=ok
|
|
||||||
python - <<'PY'
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
suite = os.environ.get("SUITE_NAME", "atlasbot")
|
|
||||||
status = os.environ.get("QUALITY_STATUS", "failed")
|
|
||||||
gateway = os.environ.get("PUSHGATEWAY_URL", "http://platform-quality-gateway.monitoring.svc.cluster.local:9091").rstrip("/")
|
|
||||||
text = urllib.request.urlopen(f"{gateway}/metrics", timeout=10).read().decode("utf-8", errors="replace")
|
|
||||||
|
|
||||||
def counter(name: str) -> float:
|
|
||||||
pattern = re.compile(
|
|
||||||
rf'^platform_quality_gate_runs_total\\{{[^}}]*job="platform-quality-ci"[^}}]*suite="{re.escape(suite)}"[^}}]*status="{name}"[^}}]*\\}}\\s+([0-9]+(?:\\.[0-9]+)?)$',
|
|
||||||
re.M,
|
|
||||||
)
|
|
||||||
match = pattern.search(text)
|
|
||||||
return float(match.group(1)) if match else 0.0
|
|
||||||
|
|
||||||
ok = counter("ok")
|
|
||||||
failed = counter("failed")
|
|
||||||
if status == "ok":
|
|
||||||
ok += 1
|
|
||||||
else:
|
|
||||||
failed += 1
|
|
||||||
payload = (
|
|
||||||
"# TYPE platform_quality_gate_runs_total counter\\n"
|
|
||||||
f'platform_quality_gate_runs_total{{suite="{suite}",status="ok"}} {int(ok)}\\n'
|
|
||||||
f'platform_quality_gate_runs_total{{suite="{suite}",status="failed"}} {int(failed)}\\n'
|
|
||||||
)
|
|
||||||
req = urllib.request.Request(
|
|
||||||
f"{gateway}/metrics/job/platform-quality-ci/suite/{suite}",
|
|
||||||
data=payload.encode("utf-8"),
|
|
||||||
method="POST",
|
|
||||||
headers={"Content-Type": "text/plain"},
|
|
||||||
)
|
|
||||||
urllib.request.urlopen(req, timeout=10).read()
|
|
||||||
PY
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
failure {
|
|
||||||
container('tester') {
|
|
||||||
sh '''
|
|
||||||
set -euo pipefail
|
|
||||||
export QUALITY_STATUS=failed
|
|
||||||
python - <<'PY'
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
suite = os.environ.get("SUITE_NAME", "atlasbot")
|
|
||||||
status = os.environ.get("QUALITY_STATUS", "failed")
|
|
||||||
gateway = os.environ.get("PUSHGATEWAY_URL", "http://platform-quality-gateway.monitoring.svc.cluster.local:9091").rstrip("/")
|
|
||||||
text = urllib.request.urlopen(f"{gateway}/metrics", timeout=10).read().decode("utf-8", errors="replace")
|
|
||||||
|
|
||||||
def counter(name: str) -> float:
|
|
||||||
pattern = re.compile(
|
|
||||||
rf'^platform_quality_gate_runs_total\\{{[^}}]*job="platform-quality-ci"[^}}]*suite="{re.escape(suite)}"[^}}]*status="{name}"[^}}]*\\}}\\s+([0-9]+(?:\\.[0-9]+)?)$',
|
|
||||||
re.M,
|
|
||||||
)
|
|
||||||
match = pattern.search(text)
|
|
||||||
return float(match.group(1)) if match else 0.0
|
|
||||||
|
|
||||||
ok = counter("ok")
|
|
||||||
failed = counter("failed")
|
|
||||||
if status == "ok":
|
|
||||||
ok += 1
|
|
||||||
else:
|
|
||||||
failed += 1
|
|
||||||
payload = (
|
|
||||||
"# TYPE platform_quality_gate_runs_total counter\\n"
|
|
||||||
f'platform_quality_gate_runs_total{{suite="{suite}",status="ok"}} {int(ok)}\\n'
|
|
||||||
f'platform_quality_gate_runs_total{{suite="{suite}",status="failed"}} {int(failed)}\\n'
|
|
||||||
)
|
|
||||||
req = urllib.request.Request(
|
|
||||||
f"{gateway}/metrics/job/platform-quality-ci/suite/{suite}",
|
|
||||||
data=payload.encode("utf-8"),
|
|
||||||
method="POST",
|
|
||||||
headers={"Content-Type": "text/plain"},
|
|
||||||
)
|
|
||||||
urllib.request.urlopen(req, timeout=10).read()
|
|
||||||
PY
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
always {
|
always {
|
||||||
script {
|
script {
|
||||||
if (fileExists('build.env')) {
|
if (fileExists('build.env')) {
|
||||||
|
|||||||
@ -8,6 +8,8 @@ Outputs:
|
|||||||
- platform_quality_gate_runs_total{suite="atlasbot",status="ok|failed"}
|
- platform_quality_gate_runs_total{suite="atlasbot",status="ok|failed"}
|
||||||
- atlasbot_quality_gate_tests_total{suite="atlasbot",result=*}
|
- atlasbot_quality_gate_tests_total{suite="atlasbot",result=*}
|
||||||
- atlasbot_quality_gate_coverage_percent{suite="atlasbot"}
|
- atlasbot_quality_gate_coverage_percent{suite="atlasbot"}
|
||||||
|
- platform_quality_gate_workspace_line_coverage_percent{suite="atlasbot"}
|
||||||
|
- platform_quality_gate_source_lines_over_500_total{suite="atlasbot"}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@ -61,6 +63,19 @@ def _load_coverage_percent(path: Path) -> float:
|
|||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
|
def _count_source_lines_over_500(root: Path) -> int:
|
||||||
|
if not root.exists():
|
||||||
|
return 0
|
||||||
|
over = 0
|
||||||
|
for path in root.rglob("*.py"):
|
||||||
|
if not path.is_file():
|
||||||
|
continue
|
||||||
|
line_count = sum(1 for _ in path.open("r", encoding="utf-8"))
|
||||||
|
if line_count > 500:
|
||||||
|
over += 1
|
||||||
|
return over
|
||||||
|
|
||||||
|
|
||||||
def _read_text(url: str) -> str:
|
def _read_text(url: str) -> str:
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(url, timeout=10) as resp:
|
with urllib.request.urlopen(url, timeout=10) as resp:
|
||||||
@ -109,9 +124,11 @@ def main() -> int:
|
|||||||
|
|
||||||
junit_path = Path(os.getenv("JUNIT_PATH", "build/junit.xml"))
|
junit_path = Path(os.getenv("JUNIT_PATH", "build/junit.xml"))
|
||||||
coverage_path = Path(os.getenv("COVERAGE_PATH", "build/coverage.json"))
|
coverage_path = Path(os.getenv("COVERAGE_PATH", "build/coverage.json"))
|
||||||
|
source_root = Path(os.getenv("SOURCE_ROOT", "atlasbot"))
|
||||||
|
|
||||||
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_lines_over_500(source_root)
|
||||||
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 +152,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