-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
62 lines (58 loc) · 2.19 KB
/
index.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
'use strict';
let regression = require('./lib');
let R = require('ramda');
/**
* Generate regression candidate points by creating a new object with columns as
* keys, values as the object values, and merge with a base object containing
* tags and measurement name
* @param {Function} merger function which generates new object with base object of tags
* @param {String} name measurement name
* @param {Array} columns collection of object keys
* @param {Array} values collection of object values
* @returns {Array}
*/
let mergeColumnsWithValues = (merger, name, columns, values) => {
return R.map(R.pipe(
R.zipObj(columns),
merger,
R.merge(R.objOf('name', name))
), values);
};
/**
* Transform an InfluxDB query resultset into -> Array<{ value: Number }>
* @returns Array
*/
let transform = R.pipe(
R.prop('results'), // Each query has a single "results" property;
R.map(R.prop('series')), // Get all the series from results,
R.flatten, // Squish all the series together
R.map(R.converge(mergeColumnsWithValues, [ // Generate all the points per series by merging together:
R.pipe(R.prop('tags'), R.merge), // The tags for the series as the base of the new point,
R.prop('name'), // Set the name as the measurement name,
R.prop('columns'), // Use the columns as new keys in the object
R.prop('values') // And the values as the key-values to the columns
])),
R.flatten // Finally, squish all the points together across series into a single array
);
module.exports = (cli) => {
return cli
.command('regression')
.description('Pipe in an InfluxDB query result to search for performance regressions')
.action(function() {
/**
* Command flow:
* 1. Read the contents of stdin, parse as JSON
* 2. Transform the query results into a format understood by raptor-regression
* 3. Pass the formatted data to raptor-regression
* 4. Either output the regression results as JSON to the console,
* 5. Or output any errors encountered along the way
*/
return Promise
.resolve()
.then(cli.stdin)
.then(transform)
.then(regression)
.then(cli.JSON)
.catch(cli.exits);
});
};