[TSVB] Fix bucket paths to work with ES 6.0 and later (#15322)

* Fix bucket paths (and pretty up the file some)

* Fixing tests
This commit is contained in:
Chris Cowan 2017-12-12 09:52:10 -07:00
parent 605eea52f9
commit a7575a1dcd
2 changed files with 24 additions and 19 deletions

View file

@ -29,9 +29,11 @@ function extendStats(bucket) {
} }
function extendStatsBucket(bucket, metrics) { function extendStatsBucket(bucket, metrics) {
const bucketsPath = 'timeseries > ' + getBucketsPath(bucket.field, metrics); const bucketsPath = 'timeseries>' + getBucketsPath(bucket.field, metrics);
const body = { extended_stats_bucket: { buckets_path: bucketsPath } }; const body = { extended_stats_bucket: { buckets_path: bucketsPath } };
if (bucket.sigma) body.extended_stats_bucket.sigma = parseInt(bucket.sigma, 10); if (bucket.sigma) {
body.extended_stats_bucket.sigma = parseInt(bucket.sigma, 10);
}
return body; return body;
} }
@ -48,7 +50,7 @@ export default {
} }
}; };
}, },
static: (bucket) => { static: bucket => {
checkMetric(bucket, ['value']); checkMetric(bucket, ['value']);
return { return {
bucket_script: { bucket_script: {
@ -90,13 +92,15 @@ export default {
std_deviation_bucket: extendStatsBucket, std_deviation_bucket: extendStatsBucket,
variance_bucket: extendStatsBucket, variance_bucket: extendStatsBucket,
percentile: (bucket) => { percentile: bucket => {
checkMetric(bucket, ['type', 'field', 'percentiles']); checkMetric(bucket, ['type', 'field', 'percentiles']);
let percents = bucket.percentiles.filter(p => p.value != null).map(p => p.value); let percents = bucket.percentiles
.filter(p => p.value != null)
.map(p => p.value);
if (bucket.percentiles.some(p => p.mode === 'band')) { if (bucket.percentiles.some(p => p.mode === 'band')) {
percents = percents.concat(bucket.percentiles percents = percents.concat(
.filter(p => p.percentile) bucket.percentiles.filter(p => p.percentile).map(p => p.percentile)
.map(p => p.percentile)); );
} }
const agg = { const agg = {
percentiles: { percentiles: {
@ -117,7 +121,11 @@ export default {
} }
}; };
if (bucket.gap_policy) body.derivative.gap_policy = bucket.gap_policy; if (bucket.gap_policy) body.derivative.gap_policy = bucket.gap_policy;
if (bucket.unit) body.derivative.unit = /^([\d]+)([shmdwMy]|ms)$/.test(bucket.unit) ? bucket.unit : bucketSize; if (bucket.unit) {
body.derivative.unit = /^([\d]+)([shmdwMy]|ms)$/.test(bucket.unit)
? bucket.unit
: bucketSize;
}
return body; return body;
}, },
@ -131,7 +139,9 @@ export default {
} }
}; };
if (bucket.gap_policy) body.serial_diff.gap_policy = bucket.gap_policy; if (bucket.gap_policy) body.serial_diff.gap_policy = bucket.gap_policy;
if (bucket.lag) body.serial_diff.lag = /^([\d]+)$/.test(bucket.lag) ? bucket.lag : 0; if (bucket.lag) {
body.serial_diff.lag = /^([\d]+)$/.test(bucket.lag) ? bucket.lag : 0;
}
return body; return body;
}, },
@ -157,7 +167,9 @@ export default {
if (bucket.window) body.moving_avg.window = Number(bucket.window); if (bucket.window) body.moving_avg.window = Number(bucket.window);
if (bucket.minimize) body.moving_avg.minimize = Boolean(bucket.minimize); if (bucket.minimize) body.moving_avg.minimize = Boolean(bucket.minimize);
if (bucket.predict) body.moving_avg.predict = Number(bucket.predict); if (bucket.predict) body.moving_avg.predict = Number(bucket.predict);
if (bucket.settings) body.moving_avg.settings = parseSettings(bucket.settings); if (bucket.settings) {
body.moving_avg.settings = parseSettings(bucket.settings);
}
return body; return body;
}, },
@ -199,7 +211,4 @@ export default {
}; };
return body; return body;
} }
}; };

View file

@ -3,7 +3,6 @@ import { expect } from 'chai';
import sinon from 'sinon'; import sinon from 'sinon';
describe('siblingBuckets(req, panel, series)', () => { describe('siblingBuckets(req, panel, series)', () => {
let panel; let panel;
let series; let series;
let req; let req;
@ -54,15 +53,12 @@ describe('siblingBuckets(req, panel, series)', () => {
aggs: { aggs: {
'metric-2': { 'metric-2': {
extended_stats_bucket: { extended_stats_bucket: {
buckets_path: 'timeseries > metric-1' buckets_path: 'timeseries>metric-1'
} }
} }
} }
} }
} }
}); });
}); });
}); });