mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
parent
147352f2b4
commit
239020b24e
7 changed files with 66 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
|||
import { expect } from 'chai';
|
||||
import getSplits from '../../helpers/get_splits';
|
||||
|
||||
describe('getSplits(resp, series)', () => {
|
||||
describe('getSplits(resp, panel, series)', () => {
|
||||
|
||||
it('should return a splits for everything/filter group bys', () => {
|
||||
const resp = {
|
||||
|
@ -12,6 +12,7 @@ describe('getSplits(resp, series)', () => {
|
|||
}
|
||||
}
|
||||
};
|
||||
const panel = { type: 'timeseries' };
|
||||
const series = {
|
||||
id: 'SERIES',
|
||||
color: '#F00',
|
||||
|
@ -21,7 +22,7 @@ describe('getSplits(resp, series)', () => {
|
|||
{ id: 'SIBAGG', type: 'avg_bucket', field: 'AVG' }
|
||||
]
|
||||
};
|
||||
expect(getSplits(resp, series)).to.eql([
|
||||
expect(getSplits(resp, panel, series)).to.eql([
|
||||
{
|
||||
id: 'SERIES',
|
||||
label: 'Overall Average of Average of cpu',
|
||||
|
@ -32,6 +33,57 @@ describe('getSplits(resp, series)', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('should return a splits for terms group bys for top_n', () => {
|
||||
const resp = {
|
||||
aggregations: {
|
||||
SERIES: {
|
||||
buckets: [
|
||||
{
|
||||
key: 'example-01',
|
||||
timeseries: { buckets: [] },
|
||||
SIBAGG: { value: 1 }
|
||||
},
|
||||
{
|
||||
key: 'example-02',
|
||||
timeseries: { buckets: [] },
|
||||
SIBAGG: { value: 2 }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
const series = {
|
||||
id: 'SERIES',
|
||||
color: '#F00',
|
||||
split_mode: 'terms',
|
||||
terms_field: 'beat.hostname',
|
||||
terms_size: 10,
|
||||
metrics: [
|
||||
{ id: 'AVG', type: 'avg', field: 'cpu' },
|
||||
{ id: 'SIBAGG', type: 'avg_bucket', field: 'AVG' }
|
||||
]
|
||||
};
|
||||
const panel = { type: 'top_n' };
|
||||
expect(getSplits(resp, panel, series)).to.eql([
|
||||
{
|
||||
id: 'SERIES:example-01',
|
||||
key: 'example-01',
|
||||
label: 'example-01',
|
||||
color: '#FF0000',
|
||||
timeseries: { buckets: [] },
|
||||
SIBAGG: { value: 1 }
|
||||
},
|
||||
{
|
||||
id: 'SERIES:example-02',
|
||||
key: 'example-02',
|
||||
label: 'example-02',
|
||||
color: '#FF0000',
|
||||
timeseries: { buckets: [] },
|
||||
SIBAGG: { value: 2 }
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return a splits for terms group bys', () => {
|
||||
const resp = {
|
||||
aggregations: {
|
||||
|
@ -62,7 +114,8 @@ describe('getSplits(resp, series)', () => {
|
|||
{ id: 'SIBAGG', type: 'avg_bucket', field: 'AVG' }
|
||||
]
|
||||
};
|
||||
expect(getSplits(resp, series)).to.eql([
|
||||
const panel = { type: 'timeseries' };
|
||||
expect(getSplits(resp, panel, series)).to.eql([
|
||||
{
|
||||
id: 'SERIES:example-01',
|
||||
key: 'example-01',
|
||||
|
@ -109,7 +162,8 @@ describe('getSplits(resp, series)', () => {
|
|||
{ id: 'COUNT', type: 'count' },
|
||||
]
|
||||
};
|
||||
expect(getSplits(resp, series)).to.eql([
|
||||
const panel = { type: 'timeseries' };
|
||||
expect(getSplits(resp, panel, series)).to.eql([
|
||||
{
|
||||
id: 'SERIES:filter-1',
|
||||
key: 'filter-1',
|
||||
|
|
|
@ -4,7 +4,8 @@ import _ from 'lodash';
|
|||
import getLastMetric from './get_last_metric';
|
||||
import getSplitColors from './get_split_colors';
|
||||
import { formatKey } from './format_key';
|
||||
export default function getSplits(resp, series) {
|
||||
export default function getSplits(resp, panel, series) {
|
||||
const color = new Color(series.color);
|
||||
const metric = getLastMetric(series);
|
||||
if (_.has(resp, `aggregations.${series.id}.buckets`)) {
|
||||
const buckets = _.get(resp, `aggregations.${series.id}.buckets`);
|
||||
|
@ -14,7 +15,7 @@ export default function getSplits(resp, series) {
|
|||
return buckets.map(bucket => {
|
||||
bucket.id = `${series.id}:${bucket.key}`;
|
||||
bucket.label = formatKey(bucket.key, series);
|
||||
bucket.color = colors.shift();
|
||||
bucket.color = panel.type === 'top_n' ? color.hex() : colors.shift();
|
||||
return bucket;
|
||||
});
|
||||
}
|
||||
|
@ -31,7 +32,6 @@ export default function getSplits(resp, series) {
|
|||
}
|
||||
}
|
||||
|
||||
const color = new Color(series.color);
|
||||
const timeseries = _.get(resp, `aggregations.${series.id}.timeseries`);
|
||||
const mergeObj = {
|
||||
timeseries
|
||||
|
|
|
@ -8,7 +8,7 @@ export default function percentile(resp, panel, series) {
|
|||
const metric = getLastMetric(series);
|
||||
if (metric.type !== 'percentile') return next(results);
|
||||
|
||||
getSplits(resp, series).forEach((split) => {
|
||||
getSplits(resp, panel, series).forEach((split) => {
|
||||
metric.percentiles.forEach(percentile => {
|
||||
const label = (split.label) + ` (${percentile.value})`;
|
||||
const data = split.timeseries.buckets.map(bucket => {
|
||||
|
|
|
@ -6,7 +6,7 @@ export default function stdDeviationBands(resp, panel, series) {
|
|||
return next => results => {
|
||||
const metric = getLastMetric(series);
|
||||
if (metric.type === 'std_deviation' && metric.mode === 'band') {
|
||||
getSplits(resp, series).forEach((split) => {
|
||||
getSplits(resp, panel, series).forEach((split) => {
|
||||
const upper = split.timeseries.buckets.map(mapBucket(_.assign({}, metric, { mode: 'upper' })));
|
||||
const lower = split.timeseries.buckets.map(mapBucket(_.assign({}, metric, { mode: 'lower' })));
|
||||
results.push({
|
||||
|
|
|
@ -6,7 +6,7 @@ export default function stdDeviationSibling(resp, panel, series) {
|
|||
return next => results => {
|
||||
const metric = getLastMetric(series);
|
||||
if (metric.mode === 'band' && metric.type === 'std_deviation_bucket') {
|
||||
getSplits(resp, series).forEach((split) => {
|
||||
getSplits(resp, panel, series).forEach((split) => {
|
||||
|
||||
const mapBucketByMode = (mode) => {
|
||||
return bucket => {
|
||||
|
|
|
@ -13,7 +13,7 @@ export default function stdMetric(resp, panel, series) {
|
|||
}
|
||||
if (/_bucket$/.test(metric.type)) return next(results);
|
||||
const decoration = getDefaultDecoration(series);
|
||||
getSplits(resp, series).forEach((split) => {
|
||||
getSplits(resp, panel, series).forEach((split) => {
|
||||
const data = split.timeseries.buckets.map(mapBucket(metric));
|
||||
results.push({
|
||||
id: `${split.id}`,
|
||||
|
|
|
@ -10,7 +10,7 @@ export default function stdSibling(resp, panel, series) {
|
|||
if (metric.type === 'std_deviation_bucket' && metric.mode === 'band') return next(results);
|
||||
|
||||
const decoration = getDefaultDecoration(series);
|
||||
getSplits(resp, series).forEach((split) => {
|
||||
getSplits(resp, panel, series).forEach((split) => {
|
||||
const data = split.timeseries.buckets.map(bucket => {
|
||||
return [bucket.key, getSiblingAggValue(split, metric)];
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue