Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Backport. Use the customMetric's formatter for pipeline aggregations (#11933) #13018

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion src/ui/public/agg_types/metrics/bucket_avg.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function AggTypesMetricsBucketAvgProvider(Private) {
subtype: siblingPipelineHelper.subtype,
params: [
...siblingPipelineHelper.params()
]
],
getFormat: siblingPipelineHelper.getFormat
});
}
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
});
}