-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathsubmit-bench-data.js
56 lines (44 loc) Β· 1.51 KB
/
submit-bench-data.js
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
56
const fs = require(`fs`);
const https = require(`https`);
const path = require(`path`);
const packageManager = process.argv[2];
const testName = process.argv[3];
const benchDir = process.argv[4];
const entries = fs.readdirSync(benchDir);
const BENCHMARK = /^bench-(.*)\.json$/;
const benchmarkEntries = entries.filter(entry => {
return entry.match(BENCHMARK);
});
// We round down at the nearest hour so that all tests
// make their reports at roughly the same time
const now = Math.floor(Date.now() / 1000);
const roundedNow = now - (now % 3600);
const series = [];
for (const entry of benchmarkEntries) {
const subtestName = entry.match(BENCHMARK)[1];
const data = JSON.parse(fs.readFileSync(path.join(benchDir, entry), `utf8`));
const points = [[roundedNow, data.results[0].mean]];
series.push({
metric: `perftest.duration`,
type: `gauge`,
tags: [`pm:${packageManager}`, `test:${testName}`, `subtest:${subtestName}`, `iteration:4`],
points: points.map(([timestamp, value]) => [timestamp, value]),
});
}
if (process.env.DD_API_KEY) {
const data = JSON.stringify({series}, null, 2);
const req = https.request(`https://api.datadoghq.eu/api/v1/series?api_key=${process.env.DD_API_KEY}`, {
method: `POST`,
headers: {
[`Content-Type`]: `application/json`,
},
}, res => {
console.log(`Data submitted; received status ${res.statusCode}`);
res.resume();
});
req.on(`error`, e => {
console.error(`problem with request: ${e.message}`);
});
req.write(data);
req.end();
}