forked from farcasterxyz/hub-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafanadash.cjs
55 lines (45 loc) · 1.58 KB
/
grafanadash.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* This is a custom linter that checks for the presence of a "datasource" property
* in the Grafana dashboard JSON file. If the property is present, it must be set
* to "Graphite". This is to ensure that the dashboard is not using any other
* datasource.
*
* It runs as a part of "yarn lint"
*/
const fs = require("fs");
const path = require("path");
module.exports = function grafana() {
const filePath = path.join(__dirname, "../grafana/grafana-dashboard.json");
function checkDataSource(lineArray) {
let lineNumber = 0;
for (const line of lineArray) {
lineNumber++;
// Check if the current line contains the undesired datasource entry
if (line.includes('"datasource":') && !line.replaceAll(" ", "").includes('"datasource":"Graphite"')) {
return lineNumber;
}
}
return null;
}
return new Promise((resolve, reject) => {
fs.readFile(filePath, "utf-8", (err, data) => {
if (err) {
console.error(`Error reading ${filePath}:`, err);
process.exit(1);
}
// Split the content into lines
const lineArray = data.split("\n");
const errorLine = checkDataSource(lineArray);
if (errorLine !== null) {
console.error(`line ${errorLine}: ${lineArray[errorLine - 1]}`);
console.error(`Error: "datasource" has to be "Graphite"`);
console.error(`Replace with: "datasource": "Graphite"`);
console.error(`Error: ${filePath}`);
process.exit(1);
} else {
console.log("✨ Grafana Dashboard linter passed");
resolve();
}
});
});
};