Skip to content

Commit

Permalink
fixing error with average bucket pipeline aggregation (#21400)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Aug 1, 2018
1 parent 9894ade commit 71e7262
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/metrics/bucket_avg.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const bucketAvgMetricAgg = new MetricAggType({
const scaleMetrics = customMetric.type && customMetric.type.isScalable();

let value = bucket[agg.id] && bucket[agg.id].value;
if (scaleMetrics) {
if (scaleMetrics && agg.params.customBucket.type.name === 'date_histogram') {
const aggInfo = agg.params.customBucket.write();
value *= get(aggInfo, 'bucketInterval.scale', 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/vis/editors/default/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const defaultEditor = function ($rootScope, $compile) {

$scope.responseValueAggs = null;
try {
$scope.responseValueAggs = $scope.vis.aggs.getResponseAggs().filter(function (agg) {
$scope.responseValueAggs = $scope.state.aggs.getResponseAggs().filter(function (agg) {
return _.get(agg, 'schema.group') === 'metrics';
});
}
Expand Down
16 changes: 16 additions & 0 deletions test/functional/apps/visualize/_data_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ export default function ({ getService, getPageObjects }) {
});
});

it('should show correct data when using average pipeline aggregation', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
await PageObjects.visualize.clickNewSearch();
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
await PageObjects.visualize.clickAddMetric();
await PageObjects.visualize.clickBucket('Metric');
await PageObjects.visualize.selectAggregation('Average Bucket', 'metrics');
await PageObjects.visualize.selectAggregation('Terms', 'metrics', 'buckets');
await PageObjects.visualize.selectField('geo.src', 'metrics', 'buckets');
await PageObjects.visualize.clickGo();
const data = await PageObjects.visualize.getTableVisData();
log.debug(data.split('\n'));
expect(data.trim().split('\n')).to.be.eql(['14,004 1,412.6']);
});

it('should show correct data for a data table with date histogram', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
Expand Down
20 changes: 16 additions & 4 deletions test/functional/page_objects/visualize_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,14 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
await Promise.all(getChartTypesPromises);
}

async selectAggregation(myString, groupName = 'buckets') {
const selector = `[group-name="${groupName}"] vis-editor-agg-params:not(.ng-hide) .agg-select`;
async selectAggregation(myString, groupName = 'buckets', childAggregationType = null) {
const selector = `
[group-name="${groupName}"]
vis-editor-agg-params:not(.ng-hide)
${childAggregationType ? `vis-editor-agg-params[group-name="'${childAggregationType}'"]:not(.ng-hide)` : ''}
.agg-select
`;

await retry.try(async () => {
await find.clickByCssSelector(selector);
const input = await find.byCssSelector(`${selector} input.ui-select-search`);
Expand Down Expand Up @@ -483,8 +489,14 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
return await field.getVisibleText();
}

async selectField(fieldValue, groupName = 'buckets') {
const selector = `[group-name="${groupName}"] vis-editor-agg-params:not(.ng-hide) .field-select`;
async selectField(fieldValue, groupName = 'buckets', childAggregationType = null) {
const selector = `
[group-name="${groupName}"]
vis-editor-agg-params:not(.ng-hide)
${childAggregationType ? `vis-editor-agg-params[group-name="'${childAggregationType}'"]:not(.ng-hide)` : ''}
.field-select
`;

await retry.try(async () => {
await find.clickByCssSelector(selector);
const input = await find.byCssSelector(`${selector} input.ui-select-search`);
Expand Down

0 comments on commit 71e7262

Please sign in to comment.