Skip to content

Commit

Permalink
Rollup TSVB integration: Add test and fix warning text (elastic#56639)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Feb 5, 2020
1 parent 8df263b commit df90627
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export const IndexPattern = ({ fields, prefix, onChange, disabled, model: _model
})}
>
<EuiFieldText
data-test-subj="metricsIndexPatternInterval"
isInvalid={!intervalValidation.isValid}
disabled={disabled || isEntireTimeRangeActive(model, isTimeSeries)}
onChange={handleTextChange(intervalName, AUTO_INTERVAL)}
Expand All @@ -222,6 +223,7 @@ export const IndexPattern = ({ fields, prefix, onChange, disabled, model: _model
})}
>
<YesNo
data-test-subj="metricsDropLastBucket"
value={model[dropBucketName]}
name={dropBucketName}
onChange={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { EuiRadio, htmlIdGenerator } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

export function YesNo(props) {
const { name, value, disabled } = props;
const { name, value, disabled, 'data-test-subj': dataTestSubj } = props;
const handleChange = value => {
const { name } = props;
return () => {
Expand All @@ -38,6 +38,7 @@ export function YesNo(props) {
<div>
<EuiRadio
id={htmlId('yes')}
data-test-subj={`${dataTestSubj}-yes`}
label={
<FormattedMessage
id="visTypeTimeseries.yesButtonLabel"
Expand All @@ -55,6 +56,7 @@ export function YesNo(props) {
&emsp;
<EuiRadio
id={htmlId('no')}
data-test-subj={`${dataTestSubj}-no`}
label={
<FormattedMessage
id="visTypeTimeseries.noButtonLabel"
Expand Down
13 changes: 13 additions & 0 deletions test/functional/page_objects/visual_builder_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,19 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro
await PageObjects.header.waitUntilLoadingHasFinished();
}

public async setIntervalValue(value: string) {
const el = await testSubjects.find('metricsIndexPatternInterval');
await el.clearValue();
await el.type(value);
await PageObjects.header.waitUntilLoadingHasFinished();
}

public async setDropLastBucket(value: boolean) {
const option = await testSubjects.find(`metricsDropLastBucket-${value ? 'yes' : 'no'}`);
(await option.findByCssSelector('label')).click();
await PageObjects.header.waitUntilLoadingHasFinished();
}

public async selectIndexPatternTimeField(timeField: string) {
await retry.try(async () => {
await comboBox.clearInputField('metricsIndexPatternFieldsSelect');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const RollupPrompt = () => (
<p>
Kibana&apos;s support for rollup index patterns is in beta. You might encounter issues using
these patterns in saved searches, visualizations, and dashboards. They are not supported in
advanced features, such as TSVB, Timelion, and Machine Learning.
some advanced features, such as Timelion, and Machine Learning.
</p>
<p>
You can match a rollup index pattern against one rollup index and zero or more regular
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/functional/apps/rollup_job/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export default function({ loadTestFile }) {

loadTestFile(require.resolve('./rollup_jobs'));
loadTestFile(require.resolve('./hybrid_index_pattern'));
loadTestFile(require.resolve('./tsvb'));
});
}
105 changes: 105 additions & 0 deletions x-pack/test/functional/apps/rollup_job/tsvb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import datemath from '@elastic/datemath';
import expect from '@kbn/expect';
import mockRolledUpData from './hybrid_index_helper';

export default function({ getService, getPageObjects }) {
const es = getService('legacyEs');
const esArchiver = getService('esArchiver');
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects([
'common',
'settings',
'visualize',
'visualBuilder',
'timePicker',
]);

describe('tsvb integration', function() {
//Since rollups can only be created once with the same name (even if you delete it),
//we add the Date.now() to avoid name collision if you run the tests locally back to back.
const rollupJobName = `tsvb-test-rollup-job-${Date.now()}`;
const rollupSourceIndexName = 'rollup-source-data';
const rollupTargetIndexName = `rollup-target-data`;
const now = new Date();
const pastDates = [
datemath.parse('now-1m', { forceNow: now }),
datemath.parse('now-2m', { forceNow: now }),
datemath.parse('now-3m', { forceNow: now }),
];

before(async () => {
// load visualize to have an index pattern ready, otherwise visualize will redirect
await esArchiver.load('visualize/default');
});

it('create rollup tsvb', async () => {
//Create data for rollup job so it doesn't fail
await es.index({
index: rollupSourceIndexName,
body: {
'@timestamp': new Date().toISOString(),
},
});

await retry.try(async () => {
//Create a rollup for kibana to recognize
await es.transport.request({
path: `/_rollup/job/${rollupJobName}`,
method: 'PUT',
body: {
index_pattern: rollupSourceIndexName,
rollup_index: rollupTargetIndexName,
cron: '*/10 * * * * ?',
groups: {
date_histogram: {
fixed_interval: '1000ms',
field: '@timestamp',
time_zone: 'UTC',
},
},
timeout: '20s',
page_size: 1000,
},
});
});

await pastDates.map(async day => {
await es.index(mockRolledUpData(rollupJobName, rollupTargetIndexName, day));
});

await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisualBuilder();
await PageObjects.visualBuilder.checkVisualBuilderIsPresent();
await PageObjects.timePicker.openQuickSelectTimeMenu();
await testSubjects.click('superDatePickerCommonlyUsed_Last_24 hours');
await PageObjects.visualBuilder.clickMetric();
await PageObjects.visualBuilder.checkMetricTabIsPresent();
await PageObjects.visualBuilder.clickPanelOptions('metric');
await PageObjects.visualBuilder.setIndexPatternValue(rollupTargetIndexName);
await PageObjects.visualBuilder.setIntervalValue('1d');
await PageObjects.visualBuilder.setDropLastBucket(false);
await PageObjects.common.sleep(3000);
const newValue = await PageObjects.visualBuilder.getMetricValue();
expect(newValue).to.eql('3');
});

after(async () => {
// Delete the rollup job.
await es.transport.request({
path: `/_rollup/job/${rollupJobName}`,
method: 'DELETE',
});

await es.indices.delete({ index: rollupTargetIndexName });
await es.indices.delete({ index: rollupSourceIndexName });
await esArchiver.load('empty_kibana');
});
});
}

0 comments on commit df90627

Please sign in to comment.