diff --git a/Jenkinsfile b/Jenkinsfile index 9e38bdb..0816667 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -83,6 +83,8 @@ spec: METRICS_PREFIX = 'ariadne_ci' VM_IMPORT_URL = 'http://victoria-metrics-single-server.monitoring.svc.cluster.local:8428/api/v1/import/prometheus' REPO_NAME = 'ariadne' + SUITE_NAME = 'ariadne' + PUSHGATEWAY_URL = 'http://platform-quality-gateway.monitoring.svc.cluster.local:9091' } options { disableConcurrentBuilds() @@ -103,6 +105,7 @@ spec: sh(script: ''' set -euo pipefail mkdir -p build +python -m pip install --no-cache-dir -r requirements-dev.txt python -m ruff check ariadne --select C90,PLR python -m slipcover \ --json \ @@ -193,6 +196,96 @@ python -c "import json; payload=json.load(open('build/coverage.json', encoding=' } 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", "ariadne") +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", "ariadne") +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 { script { if (fileExists('build/junit.xml')) {