-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathperf_send.mjs
More file actions
63 lines (52 loc) · 1.44 KB
/
perf_send.mjs
File metadata and controls
63 lines (52 loc) · 1.44 KB
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
57
58
59
60
61
62
63
import fs from 'fs/promises';
import util from 'util';
const API_PATH = 'https://performance-monitoring-api.corp.mongodb.com/raw_perf_results';
const resultFile = process.argv[2];
if (resultFile == null) {
throw new Error('Must specify result file');
}
// Get expansions
const {
execution,
requester,
project,
task_id,
task_name,
revision_order_id,
build_variant: variant,
version_id: version
} = process.env;
const orderSplit = revision_order_id?.split('_');
const order = Number(orderSplit ? orderSplit[orderSplit.length - 1] : undefined);
if (!Number.isInteger(order)) throw new Error(`Failed to parse integer from order, revision_order_id=${revision_order_id}`);
const results = JSON.parse(await fs.readFile(resultFile, 'utf8'));
const body = {
id: {
project,
version,
variant,
order,
task_name,
task_id,
execution,
mainline: requester === 'commit'
},
results
};
const resp = await fetch(API_PATH, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body: JSON.stringify(body)
});
const responseText = await resp.text();
let jsonResponse = null;
try {
jsonResponse = JSON.parse(responseText)
} catch (cause) {
console.log('Failed to parse json response', cause);
}
console.log(resp.statusText, util.inspect(jsonResponse ?? responseText, { depth: Infinity }));
if (jsonResponse.message == null) throw new Error("Didn't get success message");