This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
reports.js
333 lines (298 loc) · 9.31 KB
/
reports.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
'use strict';
var debug = require('debug')(__filename.slice(__dirname.length + 1));
var util = require('./crater-util');
var crateIndex = require('./crate-index');
var Promise = require('promise');
var db = require('./crater-db');
var assert = require('assert');
var dist = require('./rust-dist');
function createToolchainReport(toolchain, dbctx, config) {
return db.getResults(dbctx, toolchain).then(function(results) {
return results.map(function(result) {
result.registryUrl = makeRegistryUrl(result.crateName);
result.inspectorLink = makeInspectorLink(result.taskId);
return result;
});
}).then(function(results) {
return sortByPopularity(results, config);
}).then(function(results) {
// Partition into successful results and failful results
var successes = [];
var failures = [];
results.forEach(function(result) {
if (result.status == "success") {
successes.push(result);
} else if (result.status == "failure") {
failures.push(result);
}
});
return getRootFailures(failures, config).then(function(rootFailures) {
var nonRootFailures = getNonRootFailures(failures, rootFailures);
return {
toolchain: toolchain,
successes: successes,
failures: failures,
rootFailures: rootFailures,
nonRootFailures: nonRootFailures
};
});
});
}
function createComparisonReport(fromToolchain, toToolchain, dbctx, config) {
var statuses = calculateStatuses(dbctx, fromToolchain, toToolchain);
return statuses.then(function(statuses) {
return sortByPopularity(statuses, config);
}).then(function(statuses) {
var statusSummary = calculateStatusSummary(statuses);
var regressions = extractWithStatus(statuses, "regressed");
var rootRegressions = getRootFailures(regressions, config);
return rootRegressions.then(function(rootRegressions) {
var nonRootRegressions = getNonRootFailures(regressions, rootRegressions);
var working = extractWithStatus(statuses, "working");
var broken = extractWithStatus(statuses, "broken");
var fixed = extractWithStatus(statuses, "fixed");
return {
fromToolchain: fromToolchain,
toToolchain: toToolchain,
statuses: statuses,
statusSummary: statusSummary,
regressions: regressions,
rootRegressions: rootRegressions,
nonRootRegressions: nonRootRegressions,
working: working,
broken: broken,
fixed: fixed
};
});
});
}
/**
* Returns a promise of the data for a 'weekly report'.
*/
function createWeeklyReport(date, dbctx, config) {
return createCurrentReport(date, config).then(function(currentReport) {
var stableToolchain = null;
if (currentReport.stable) {
stableToolchain = { channel: "stable", archiveDate: currentReport.stable };
}
var betaToolchain = null;
if (currentReport.beta) {
betaToolchain = { channel: "beta", archiveDate: currentReport.beta };
}
var nightlyToolchain = null;
if (currentReport.nightly) {
nightlyToolchain = { channel: "nightly", archiveDate: currentReport.nightly };
}
var betaReport = createComparisonReport(stableToolchain, betaToolchain, dbctx, config);
return betaReport.then(function(betaReport) {
var nightlyReport = createComparisonReport(betaToolchain, nightlyToolchain, dbctx, config);
return nightlyReport.then(function(nightlyReport) {
return {
date: date,
currentReport: currentReport,
beta: betaReport,
nightly: nightlyReport
};
});
});
});
}
/**
* Returns promise of array of `{ crateName, crateVers, status }`,
* where `status` is either 'working', 'broken', 'regressed',
* 'fixed'.
*/
function calculateStatuses(dbctx, fromToolchain, toToolchain) {
if (fromToolchain == null || toToolchain == null) {
return new Promise(function(resolve, reject) { resolve([]); });
}
return db.getResultPairs(dbctx, fromToolchain, toToolchain).then(function(buildResults) {
return buildResults.map(function(buildResult) {
var status = null;
if (buildResult.from.status == "success" && buildResult.to.status == "success") {
status = "working";
} else if (buildResult.from.status == "failure" && buildResult.to.status == "failure") {
status = "broken";
} else if (buildResult.from.status == "success" && buildResult.to.status == "failure") {
status = "regressed";
} else if (buildResult.from.status == "failure" && buildResult.to.status == "success") {
status = "fixed";
} else {
status = "unknown";
}
// Just modify the intermediate result
buildResult.status = status;
buildResult.from.inspectorLink = makeInspectorLink(buildResult.from.taskId);
buildResult.to.inspectorLink = makeInspectorLink(buildResult.to.taskId);
buildResult.registryUrl = makeRegistryUrl(buildResult.crateName);
return buildResult;
});
});
}
function sortByPopularity(statuses, config) {
return crateIndex.loadCrates(config).then(function(crates) {
var popMap = crateIndex.getPopularityMap(crates);
var sorted = statuses.slice();
sorted.sort(function(a, b) {
var aPop = popMap[a.crateName];
var bPop = popMap[b.crateName];
if (aPop == bPop) { return 0; }
if (aPop < bPop) { return 1; }
if (aPop > bPop) { return -1; }
});
return sorted;
});
}
function calculateStatusSummary(statuses) {
var working = 0;
var broken = 0;
var regressed = 0;
var fixed = 0;
var unknown = 0;
statuses.forEach(function(status) {
if (status.status == "working") {
working += 1;
} else if (status.status == "broken") {
broken += 1;
} else if (status.status == "regressed") {
regressed += 1;
} else if (status.status == "fixed") {
fixed += 1;
} else {
assert(status.status == "unknown");
unknown += 1;
}
});
return {
working: working,
broken: broken,
regressed: regressed,
fixed: fixed,
unknown: unknown
};
}
function extractWithStatus(statuses, needed) {
var result = [];
statuses.forEach(function(status) {
if (status.status == needed) {
result.push(status);
}
});
return result;
}
function getRootFailures(regressions, config) {
var regressionMap = {};
regressions.forEach(function(r) {
regressionMap[r.crateName] = r;
});
return crateIndex.loadCrates(config).then(function(crates) {
var dag = crateIndex.getDag(crates);
var independent = [];
regressions.forEach(function(reg) {
var isIndependent = true;
var depStack = dag[reg.crateName];
if (depStack == null) {
// No info about this crate? Happens in the test suite.
debug("no deps for " + reg.crateName);
}
while (depStack && depStack.length != 0 && isIndependent) {
var nextDep = depStack.pop();
if (regressionMap[nextDep]) {
debug(reg.crateName + " depends on regressed " + nextDep);
isIndependent = false;
}
if (dag[nextDep]) {
depStack.concat(dag[nextDep]);
}
}
if (isIndependent) {
debug(reg.crateName + " is an independent regression");
independent.push(reg);
}
});
return independent;
});
}
function getNonRootFailures(regs, rootRegs) {
var rootRegMap = {};
rootRegs.forEach(function(r) {
rootRegMap[r.crateName] = r;
});
var dependent = []
regs.forEach(function(reg) {
if (!rootRegMap[reg.crateName]) {
dependent.push(reg);
}
});
return dependent;
}
/**
* Returns a promise of a report on the current nightly/beta/stable revisions.
*/
function createCurrentReport(date, config) {
return dist.getAvailableToolchains(config).then(function(toolchains) {
var currentNightlyDate = null;
toolchains.nightly.forEach(function(toolchainDate) {
if (toolchainDate <= date) {
currentNightlyDate = toolchainDate;
}
});
var currentBetaDate = null;
toolchains.beta.forEach(function(toolchainDate) {
if (toolchainDate <= date) {
currentBetaDate = toolchainDate;
}
});
var currentStableDate = null;
toolchains.stable.forEach(function(toolchainDate) {
if (toolchainDate <= date) {
currentStableDate = toolchainDate;
}
});
return {
nightly: currentNightlyDate,
beta: currentBetaDate,
stable: currentStableDate
};
});
}
function createPopularityReport(config) {
return crateIndex.loadCrates(config).then(function(crates) {
var popMap = crateIndex.getPopularityMap(crates);
return crates.map(function(crate) {
return {
crateName: crate.name,
registryUrl: makeRegistryUrl(crate.name),
pop: popMap[crate.name]
};
});
}).then(function(crates) {
var map = {}
return crates.filter(function(crate) {
if (map[crate.crateName]) {
return false;
} else {
map[crate.crateName] = crate;
return true;
}
});
}).then(function(crates) {
return sortByPopularity(crates, config);
});
}
function makeRegistryUrl(name) {
return "https://crates.io/crates/" + name;
}
function makeInspectorLink(taskId) {
var inspectorRoot = "https://tools.taskcluster.net/task-inspector/#";
return inspectorRoot + taskId;
}
function createScoreboardReport(toolchain, config) {
return
}
exports.createWeeklyReport = createWeeklyReport;
exports.createCurrentReport = createCurrentReport;
exports.createComparisonReport = createComparisonReport;
exports.createPopularityReport = createPopularityReport;
exports.createScoreboardReport = createScoreboardReport;
exports.createToolchainReport = createToolchainReport;