fixing date_histogram to correctly work inside plugins without global time picker (#21955)

This commit is contained in:
Peter Pisljar 2018-08-22 12:42:28 +02:00 committed by GitHub
parent 4d9bc2f121
commit c38e948c2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 476 additions and 7 deletions

View file

@ -42,7 +42,7 @@ function getInterval(agg) {
}
function getBounds(vis) {
if (vis.API.timeFilter.isTimeRangeSelectorEnabled && vis.filters && vis.filters.timeRange) {
if (vis.filters && vis.filters.timeRange) {
return vis.API.timeFilter.calculateBounds(vis.filters.timeRange);
}
}

View file

@ -60,7 +60,7 @@ export default function ({ getService, getPageObjects }) {
expect(isApplyButtonEnabled).to.be(true);
});
it('should allow resseting changed params', async () => {
it('should allow reseting changed params', async () => {
await PageObjects.visualize.clickReset();
const interval = await PageObjects.visualize.getInputTypeParam('interval');
expect(interval).to.be('2000');

View file

@ -0,0 +1,177 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import expect from 'expect.js';
export default function ({ getService, getPageObjects }) {
const log = getService('log');
const retry = getService('retry');
const filterBar = getService('filterBar');
const renderable = getService('renderable');
const PageObjects = getPageObjects(['common', 'visualize', 'header']);
describe('data table with index without time filter', function indexPatternCreation() {
const vizName1 = 'Visualization DataTable without time filter';
before(async function () {
log.debug('navigateToApp visualize');
await PageObjects.visualize.navigateToNewVisualization();
log.debug('clickDataTable');
await PageObjects.visualize.clickDataTable();
log.debug('clickNewSearch');
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
log.debug('Bucket = Split Rows');
await PageObjects.common.sleep(500);
await PageObjects.visualize.clickBucket('Split Rows');
log.debug('Aggregation = Histogram');
await PageObjects.visualize.selectAggregation('Histogram');
log.debug('Field = bytes');
await PageObjects.visualize.selectField('bytes');
log.debug('Interval = 2000');
await PageObjects.visualize.setNumericInterval('2000');
await PageObjects.visualize.clickGo();
});
it('should allow applying changed params', async () => {
await PageObjects.visualize.setNumericInterval('1', { append: true });
const interval = await PageObjects.visualize.getInputTypeParam('interval');
expect(interval).to.be('20001');
const isApplyButtonEnabled = await PageObjects.visualize.isApplyEnabled();
expect(isApplyButtonEnabled).to.be(true);
});
it('should allow reseting changed params', async () => {
await PageObjects.visualize.clickReset();
const interval = await PageObjects.visualize.getInputTypeParam('interval');
expect(interval).to.be('2000');
});
it('should be able to save and load', async function () {
await PageObjects.visualize.saveVisualization(vizName1);
const pageTitle = await PageObjects.common.getBreadcrumbPageTitle();
log.debug(`Save viz page title is ${pageTitle}`);
expect(pageTitle).to.contain(vizName1);
await PageObjects.visualize.waitForVisualizationSavedToastGone();
await PageObjects.visualize.loadSavedVisualization(vizName1);
await PageObjects.visualize.waitForVisualization();
});
it('should have inspector enabled', async function () {
const spyToggleExists = await PageObjects.visualize.isInspectorButtonEnabled();
expect(spyToggleExists).to.be(true);
});
it('should show correct data', function () {
const expectedChartData = [
[ '0B', '2,088' ],
[ '1.953KB', '2,748' ],
[ '3.906KB', '2,707' ],
[ '5.859KB', '2,876' ],
[ '7.813KB', '2,863' ],
[ '9.766KB', '147' ],
[ '11.719KB', '148' ],
[ '13.672KB', '129' ],
[ '15.625KB', '161' ],
[ '17.578KB', '137' ]
];
return retry.try(async function () {
await PageObjects.visualize.openInspector();
const data = await PageObjects.visualize.getInspectorTableData();
await PageObjects.visualize.closeInspector();
log.debug(data);
expect(data).to.eql(expectedChartData);
});
});
it('should show correct data when using average pipeline aggregation', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
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();
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
await PageObjects.common.sleep(500);
await PageObjects.visualize.clickBucket('Split Rows');
await PageObjects.visualize.selectAggregation('Date Histogram');
await PageObjects.visualize.selectField('@timestamp');
await PageObjects.visualize.setInterval('Daily');
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
const data = await PageObjects.visualize.getTableVisData();
log.debug(data.split('\n'));
expect(data.trim().split('\n')).to.be.eql([
'2015-09-20', '4,757',
'2015-09-21', '4,614',
'2015-09-22', '4,633',
]);
});
it('should show correct data for a data table with date histogram', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
await PageObjects.common.sleep(500);
await PageObjects.visualize.clickBucket('Split Rows');
await PageObjects.visualize.selectAggregation('Date Histogram');
await PageObjects.visualize.selectField('@timestamp');
await PageObjects.visualize.setInterval('Daily');
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
const data = await PageObjects.visualize.getTableVisData();
expect(data.trim().split('\n')).to.be.eql([
'2015-09-20', '4,757',
'2015-09-21', '4,614',
'2015-09-22', '4,633',
]);
});
it('should correctly filter for applied time filter on the main timefield', async () => {
await filterBar.addFilter('@timestamp', 'is between', '2015-09-19', '2015-09-21');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const data = await PageObjects.visualize.getTableVisData();
expect(data.trim().split('\n')).to.be.eql([
'2015-09-20', '4,757',
]);
});
it('should correctly filter for pinned filters', async () => {
await filterBar.toggleFilterPinned('@timestamp');
await PageObjects.header.waitUntilLoadingHasFinished();
await renderable.waitForRender();
const data = await PageObjects.visualize.getTableVisData();
expect(data.trim().split('\n')).to.be.eql([
'2015-09-20', '4,757',
]);
});
});
}

View file

@ -37,7 +37,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.header.setAbsoluteRange('2017-01-01', '2017-01-02');
await PageObjects.visualize.clickVisEditorTab('controls');
await PageObjects.visualize.addInputControl();
await comboBox.set('indexPatternSelect-0', 'logstash');
await comboBox.set('indexPatternSelect-0', 'logstash- ');
await comboBox.set('fieldSelect-0', FIELD_NAME);
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
@ -190,7 +190,7 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.clickVisEditorTab('controls');
await PageObjects.visualize.addInputControl();
await comboBox.set('indexPatternSelect-0', 'logstash');
await comboBox.set('indexPatternSelect-0', 'logstash- ');
await comboBox.set('fieldSelect-0', 'geo.src');
await PageObjects.visualize.clickGo();
@ -233,11 +233,11 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.clickVisEditorTab('controls');
await PageObjects.visualize.addInputControl();
await comboBox.set('indexPatternSelect-0', 'logstash');
await comboBox.set('indexPatternSelect-0', 'logstash- ');
await comboBox.set('fieldSelect-0', 'geo.src');
await PageObjects.visualize.addInputControl();
await comboBox.set('indexPatternSelect-1', 'logstash');
await comboBox.set('indexPatternSelect-1', 'logstash- ');
await comboBox.set('fieldSelect-1', 'clientip');
await PageObjects.visualize.setSelectByOptionText('parentSelect-1', 'geo.src');

View file

@ -0,0 +1,275 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import expect from 'expect.js';
export default function ({ getService, getPageObjects }) {
const log = getService('log');
const retry = getService('retry');
const PageObjects = getPageObjects(['common', 'visualize', 'header']);
describe('vertical bar chart with index without time filter', function () {
const vizName1 = 'Visualization VerticalBarChart without time filter';
const initBarChart = async () => {
log.debug('navigateToApp visualize');
await PageObjects.visualize.navigateToNewVisualization();
log.debug('clickVerticalBarChart');
await PageObjects.visualize.clickVerticalBarChart();
await PageObjects.visualize.clickNewSearch(PageObjects.visualize.index.LOGSTASH_NON_TIME_BASED);
await PageObjects.common.sleep(500);
log.debug('Bucket = X-Axis');
await PageObjects.visualize.clickBucket('X-Axis');
log.debug('Aggregation = Date Histogram');
await PageObjects.visualize.selectAggregation('Date Histogram');
log.debug('Field = @timestamp');
await PageObjects.visualize.selectField('@timestamp');
await PageObjects.visualize.setCustomInterval('3h');
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.visualize.waitForVisualization();
};
before(initBarChart);
it('should save and load', async function () {
await PageObjects.visualize.saveVisualization(vizName1);
const pageTitle = await PageObjects.common.getBreadcrumbPageTitle();
log.debug(`Save viz page title is ${pageTitle}`);
expect(pageTitle).to.contain(vizName1);
await PageObjects.visualize.waitForVisualizationSavedToastGone();
await PageObjects.visualize.loadSavedVisualization(vizName1);
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.visualize.waitForVisualization();
});
it('should have inspector enabled', async function () {
const spyToggleExists = await PageObjects.visualize.isInspectorButtonEnabled();
expect(spyToggleExists).to.be(true);
});
it('should show correct chart', async function () {
const expectedChartValues = [37, 202, 740, 1437, 1371, 751, 188, 31, 42, 202, 683,
1361, 1415, 707, 177, 27, 32, 175, 707, 1408, 1355, 726, 201, 29
];
// Most recent failure on Jenkins usually indicates the bar chart is still being drawn?
// return arguments[0].getAttribute(arguments[1]);","args":[{"ELEMENT":"592"},"fill"]}] arguments[0].getAttribute is not a function
// try sleeping a bit before getting that data
await retry.try(async () => {
const data = await PageObjects.visualize.getBarChartData();
log.debug('data=' + data);
log.debug('data.length=' + data.length);
expect(data).to.eql(expectedChartValues);
});
});
it('should show correct data', async function () {
// this is only the first page of the tabular data.
const expectedChartData = [
['2015-09-20 00:00', '37'],
['2015-09-20 03:00', '202'],
['2015-09-20 06:00', '740'],
['2015-09-20 09:00', '1,437'],
['2015-09-20 12:00', '1,371'],
['2015-09-20 15:00', '751'],
['2015-09-20 18:00', '188'],
['2015-09-20 21:00', '31'],
['2015-09-21 00:00', '42'],
['2015-09-21 03:00', '202'],
[ '2015-09-21 06:00', '683' ],
[ '2015-09-21 09:00', '1,361' ],
[ '2015-09-21 12:00', '1,415' ],
[ '2015-09-21 15:00', '707' ],
[ '2015-09-21 18:00', '177' ],
[ '2015-09-21 21:00', '27' ],
[ '2015-09-22 00:00', '32' ],
[ '2015-09-22 03:00', '175' ],
[ '2015-09-22 06:00', '707' ],
[ '2015-09-22 09:00', '1,408' ],
];
await PageObjects.visualize.openInspector();
const data = await PageObjects.visualize.getInspectorTableData();
log.debug(data);
expect(data).to.eql(expectedChartData);
});
describe.skip('switch between Y axis scale types', () => {
before(initBarChart);
const axisId = 'ValueAxis-1';
it('should show ticks on selecting log scale', async () => {
await PageObjects.visualize.clickMetricsAndAxes();
await PageObjects.visualize.clickYAxisOptions(axisId);
await PageObjects.visualize.selectYAxisScaleType(axisId, 'log');
await PageObjects.visualize.clickYAxisAdvancedOptions(axisId);
await PageObjects.visualize.changeYAxisFilterLabelsCheckbox(axisId, false);
await PageObjects.visualize.clickGo();
const labels = await PageObjects.visualize.getYAxisLabels();
const expectedLabels = [
'2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '200',
'300', '500', '700', '1,000', '2,000', '3,000', '5,000', '7,000',
];
expect(labels).to.eql(expectedLabels);
});
it('should show filtered ticks on selecting log scale', async () => {
await PageObjects.visualize.changeYAxisFilterLabelsCheckbox(axisId, true);
await PageObjects.visualize.clickGo();
const labels = await PageObjects.visualize.getYAxisLabels();
const expectedLabels = [
'2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '200',
'300', '500', '700', '1,000', '2,000', '3,000', '5,000', '7,000',
];
expect(labels).to.eql(expectedLabels);
});
it('should show ticks on selecting square root scale', async () => {
await PageObjects.visualize.selectYAxisScaleType(axisId, 'square root');
await PageObjects.visualize.changeYAxisFilterLabelsCheckbox(axisId, false);
await PageObjects.visualize.clickGo();
const labels = await PageObjects.visualize.getYAxisLabels();
const expectedLabels = [
'0', '200', '400', '600', '800', '1,000', '1,200', '1,400', '1,600',
];
expect(labels).to.eql(expectedLabels);
});
it('should show filtered ticks on selecting square root scale', async () => {
await PageObjects.visualize.changeYAxisFilterLabelsCheckbox(axisId, true);
await PageObjects.visualize.clickGo();
const labels = await PageObjects.visualize.getYAxisLabels();
const expectedLabels = [
'200', '400', '600', '800', '1,000', '1,200', '1,400',
];
expect(labels).to.eql(expectedLabels);
});
it('should show ticks on selecting linear scale', async () => {
await PageObjects.visualize.selectYAxisScaleType(axisId, 'linear');
await PageObjects.visualize.changeYAxisFilterLabelsCheckbox(axisId, false);
await PageObjects.visualize.clickGo();
const labels = await PageObjects.visualize.getYAxisLabels();
log.debug(labels);
const expectedLabels = [
'0', '200', '400', '600', '800', '1,000', '1,200', '1,400', '1,600',
];
expect(labels).to.eql(expectedLabels);
});
it('should show filtered ticks on selecting linear scale', async () => {
await PageObjects.visualize.changeYAxisFilterLabelsCheckbox(axisId, true);
await PageObjects.visualize.clickGo();
const labels = await PageObjects.visualize.getYAxisLabels();
const expectedLabels = [
'200', '400', '600', '800', '1,000', '1,200', '1,400',
];
expect(labels).to.eql(expectedLabels);
});
});
describe('vertical bar with split series', function () {
before(initBarChart);
it('should show correct series', async function () {
await PageObjects.visualize.toggleOpenEditor(2, 'false');
await PageObjects.visualize.clickAddBucket();
await PageObjects.visualize.clickBucket('Split Series');
await PageObjects.visualize.selectAggregation('Terms');
await PageObjects.visualize.selectField('response.raw');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.common.sleep(1003);
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
const expectedEntries = ['200', '404', '503'];
const legendEntries = await PageObjects.visualize.getLegendEntries();
expect(legendEntries).to.eql(expectedEntries);
});
});
describe('vertical bar with multiple splits', function () {
before(initBarChart);
it('should show correct series', async function () {
await PageObjects.visualize.toggleOpenEditor(2, 'false');
await PageObjects.visualize.clickAddBucket();
await PageObjects.visualize.clickBucket('Split Series');
await PageObjects.visualize.selectAggregation('Terms');
await PageObjects.visualize.selectField('response.raw');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.visualize.toggleOpenEditor(3, 'false');
await PageObjects.visualize.clickAddBucket();
await PageObjects.visualize.clickBucket('Split Series');
await PageObjects.visualize.selectAggregation('Terms');
await PageObjects.visualize.selectField('machine.os');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.common.sleep(1003);
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
const expectedEntries = [
'200 - win 8', '200 - win xp', '200 - ios', '200 - osx', '200 - win 7',
'404 - ios', '503 - ios', '503 - osx', '503 - win 7', '503 - win 8',
'503 - win xp', '404 - osx', '404 - win 7', '404 - win 8', '404 - win xp'
];
const legendEntries = await PageObjects.visualize.getLegendEntries();
expect(legendEntries).to.eql(expectedEntries);
});
it('should show correct series when disabling first agg', async function () {
await PageObjects.visualize.toggleDisabledAgg(3);
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
const expectedEntries = [ 'win 8', 'win xp', 'ios', 'osx', 'win 7' ];
const legendEntries = await PageObjects.visualize.getLegendEntries();
expect(legendEntries).to.eql(expectedEntries);
});
});
describe('vertical bar with derivative', function () {
before(initBarChart);
it('should show correct series', async function () {
await PageObjects.visualize.toggleOpenEditor(2, 'false');
await PageObjects.visualize.toggleOpenEditor(1);
await PageObjects.visualize.selectAggregation('Derivative', 'metrics');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.common.sleep(1003);
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
const expectedEntries = [
'Derivative of Count'
];
const legendEntries = await PageObjects.visualize.getLegendEntries();
expect(legendEntries).to.eql(expectedEntries);
});
});
});
}

View file

@ -40,11 +40,13 @@ export default function ({ getService, loadTestFile }) {
loadTestFile(require.resolve('./_area_chart'));
loadTestFile(require.resolve('./_line_chart'));
loadTestFile(require.resolve('./_data_table'));
loadTestFile(require.resolve('./_data_table_nontimeindex'));
loadTestFile(require.resolve('./_pie_chart'));
loadTestFile(require.resolve('./_tag_cloud'));
loadTestFile(require.resolve('./_tile_map'));
loadTestFile(require.resolve('./_region_map'));
loadTestFile(require.resolve('./_vertical_bar_chart'));
loadTestFile(require.resolve('./_vertical_bar_chart_nontimeindex'));
loadTestFile(require.resolve('./_heatmap_chart'));
loadTestFile(require.resolve('./_point_series_options'));
loadTestFile(require.resolve('./_markdown_vis'));

View file

@ -35,6 +35,13 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
class VisualizePage {
get index() {
return {
LOGSTASH_TIME_BASED: 'logstash-*',
LOGSTASH_NON_TIME_BASED: 'logstash*'
};
}
async navigateToNewVisualization() {
log.debug('navigateToApp visualize new');
await PageObjects.common.navigateToUrl('visualize', 'new');
@ -353,7 +360,7 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
await find.clickByCssSelector('button[data-test-subj="toggleEditor"]');
}
async clickNewSearch(indexPattern = 'logstash-*') {
async clickNewSearch(indexPattern = this.index.LOGSTASH_TIME_BASED) {
await testSubjects.click(`paginatedListItem-${indexPattern}`);
await PageObjects.header.waitUntilLoadingHasFinished();
}
@ -541,6 +548,14 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
async setInterval(newValue) {
const input = await find.byCssSelector('select[ng-model="agg.params.interval"]');
await input.type(newValue);
await remote.pressKeys(Keys.RETURN);
}
async setCustomInterval(newValue) {
await this.setInterval('Custom');
const input = await find.byCssSelector('input[name="customInterval"]');
await input.clearValue();
await input.type(newValue);
}
async setNumericInterval(newValue, { append } = {}) {