Skip to content

Commit

Permalink
Use the customMetric's formatter for pipeline aggregations (#11933)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevan authored and thomasneirynck committed Jul 19, 2017
1 parent 3c0c0ff commit 0ee63e6
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 7 deletions.
34 changes: 34 additions & 0 deletions src/ui/public/agg_types/__tests__/metrics/parent_pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('parent pipeline aggs', function () {
ngMock.inject(function (Private) {
const Vis = Private(VisProvider);
const indexPattern = Private(StubbedIndexPattern);
indexPattern.stubSetFieldFormat('bytes', 'bytes');
metricAgg = Private(metric.provider);

const params = settings || {
Expand All @@ -52,6 +53,12 @@ describe('parent pipeline aggs', function () {
type: metric.name,
schema: 'metric',
params
},
{
id: '3',
type: 'max',
params: { field: '@timestamp' },
schema: 'metric'
}
],
listeners: {}
Expand Down Expand Up @@ -137,6 +144,33 @@ describe('parent pipeline aggs', function () {
expect(aggDsl.parentAggs['2-metric'][metric.name].buckets_path).to.be('2-metric-metric');
});

it('should have correct formatter', function () {
init({
metricAgg: '3'
});
expect(metricAgg.getFormat(aggConfig).type.id).to.be('date');
});

it('should have correct customMetric nested formatter', function () {
init({
metricAgg: 'custom',
customMetric: {
id:'2-metric',
type: metric.name,
params: {
buckets_path: 'custom',
customMetric: {
id:'2-metric-metric',
type: 'max',
params: { field: 'bytes' },
schema: 'orderAgg'
}
},
schema: 'orderAgg'
}
});
expect(metricAgg.getFormat(aggConfig).type.id).to.be('bytes');
});
});
});

Expand Down
19 changes: 19 additions & 0 deletions src/ui/public/agg_types/__tests__/metrics/sibling_pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('sibling pipeline aggs', function () {
ngMock.inject(function (Private) {
const Vis = Private(VisProvider);
const indexPattern = Private(StubbedIndexPattern);
indexPattern.stubSetFieldFormat('bytes', 'bytes');
metricAgg = Private(metric.provider);

const params = settings || {
Expand Down Expand Up @@ -103,6 +104,24 @@ describe('sibling pipeline aggs', function () {
expect(aggDsl.parentAggs['2-bucket'].aggs['2-metric'].avg.field).to.equal('bytes');
});

it('should have correct formatter', function () {
init({
customMetric: {
id: '5',
type: 'avg',
schema: 'metric',
params: { field: 'bytes' },
},
customBucket: {
id: '6',
type: 'date_histogram',
schema: 'bucket',
params: { field: '@timestamp' },
}
});
expect(metricAgg.getFormat(aggConfig).type.id).to.be('bytes');
});

});
});

Expand Down
1 change: 1 addition & 0 deletions src/ui/public/agg_types/metrics/bucket_avg.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function AggTypesMetricsBucketAvgProvider(Private) {
params: [
...siblingPipelineHelper.params()
],
getFormat: siblingPipelineHelper.getFormat,
getValue: function (agg, bucket) {
const customMetric = agg.params.customMetric;
const scaleMetrics = customMetric.type && customMetric.type.isScalable();
Expand Down
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/bucket_max.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AggTypesMetricsBucketMaxProvider(Private) {
subtype: siblingPipelineHelper.subtype,
params: [
...siblingPipelineHelper.params()
]
],
getFormat: siblingPipelineHelper.getFormat
});
}
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/bucket_min.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AggTypesMetricsBucketMinProvider(Private) {
subtype: siblingPipelineHelper.subtype,
params: [
...siblingPipelineHelper.params()
]
],
getFormat: siblingPipelineHelper.getFormat
});
}
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/bucket_sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AggTypesMetricsBucketSumProvider(Private) {
subtype: siblingPipelineHelper.subtype,
params: [
...siblingPipelineHelper.params()
]
],
getFormat: siblingPipelineHelper.getFormat
});
}
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/cumulative_sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AggTypesMetricsCumulativeSumProvider(Private) {
makeLabel: agg => makeNestedLabel(agg, 'cumulative sum'),
params: [
...parentPipelineAggHelper.params()
]
],
getFormat: parentPipelineAggHelper.getFormat
});
}
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/derivative.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AggTypesMetricsDerivativeProvider(Private) {
makeLabel: agg => makeNestedLabel(agg, 'derivative'),
params: [
...parentPipelineAggHelper.params()
]
],
getFormat: parentPipelineAggHelper.getFormat
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export const ParentPipelineAggHelperProvider = function (Private) {
write: parentPipelineAggWritter
}
];
},
getFormat: function (agg) {
let subAgg;
if (agg.params.customMetric) {
subAgg = agg.params.customMetric;
} else {
subAgg = agg.vis.aggs.byId[agg.params.metricAgg];
}
return subAgg.type.getFormat(subAgg);
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export const SiblingPipelineAggHelperProvider = function (Private) {
write: siblingPipelineAggWritter
}
];
},
getFormat: function (agg) {
return agg.params.customMetric.type.getFormat(agg.params.customMetric);
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/moving_avg.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AggTypesMetricsMovingAvgProvider(Private) {
makeLabel: agg => makeNestedLabel(agg, 'moving avg'),
params: [
...parentPipelineAggHelper.params()
]
],
getFormat: parentPipelineAggHelper.getFormat
});
}
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/serial_diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AggTypesMetricsSerialDiffProvider(Private) {
makeLabel: agg => makeNestedLabel(agg, 'serial diff'),
params: [
...parentPipelineAggHelper.params()
]
],
getFormat: parentPipelineAggHelper.getFormat
});
}

0 comments on commit 0ee63e6

Please sign in to comment.