Skip to content

Commit

Permalink
Functional test for create a logdb index (elastic#204788)
Browse files Browse the repository at this point in the history
Part of elastic#203716
## Summary

* Functional test for verifying that users can create indices using the
“logsdb” index mode via the Kibana interface (Stateful and serverless).
* Functional test for verifying that users can upgrade a logs data
stream that is using a “standard” index mode to a data stream using
“logsdb” index mode. (Stateful and serverless).
* Functional test for verifying that users can downgrade a data stream
that is using a “logsdb” index mode to a data stream using “standard”
index mode. (Stateful and serverless).
* Functional test for verifying that users can upgrade a data stream
that is using a “time series” index mode to a data stream using “logsdb”
index mode. (Stateful and serverless).
* Functional test for verifying that users can downgrade a data stream
that is using a “logsdb” index mode to a data stream using “time series”
index mode. (Stateful and serverless).

The rollover operation has not been tested since is not expected to
happen automatically. See [this
comment](elastic#203716 (comment)).
  • Loading branch information
SoniaSanzV authored Dec 30, 2024
1 parent a3858a3 commit 34341e5
Show file tree
Hide file tree
Showing 9 changed files with 466 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function getFieldsMeta(esDocsBase: string) {
{
value: STANDARD_INDEX_MODE,
inputDisplay: indexModeLabels[STANDARD_INDEX_MODE],
'data-test-subj': 'index_mode_standard',
dropdownDisplay: (
<Fragment>
<strong>{indexModeLabels[STANDARD_INDEX_MODE]}</strong>
Expand All @@ -122,6 +123,7 @@ function getFieldsMeta(esDocsBase: string) {
{
value: TIME_SERIES_MODE,
inputDisplay: indexModeLabels[TIME_SERIES_MODE],
'data-test-subj': 'index_mode_time_series',
dropdownDisplay: (
<Fragment>
<strong>{indexModeLabels[TIME_SERIES_MODE]}</strong>
Expand All @@ -134,6 +136,7 @@ function getFieldsMeta(esDocsBase: string) {
{
value: LOGSDB_INDEX_MODE,
inputDisplay: indexModeLabels[LOGSDB_INDEX_MODE],
'data-test-subj': 'index_mode_logsdb',
dropdownDisplay: (
<Fragment>
<strong>{indexModeLabels[LOGSDB_INDEX_MODE]}</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export const TemplateDetailsContent = ({
defaultMessage: 'Edit',
}),
icon: 'pencil',
'data-test-subj': 'editIndexTemplateButton',
onClick: () => editTemplate(templateName, isLegacy),
disabled: isCloudManaged,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const security = getService('security');
const testSubjects = getService('testSubjects');

enum INDEX_MODE {
STANDARD = 'Standard',
LOGSDB = 'LogsDB',
TIME_SERIES = 'Time series',
}

const TEST_DS_NAME_1 = 'test-ds-1';
const TEST_DS_NAME_2 = 'test-ds-2';
const TEST_DATA_STREAM_NAMES = [TEST_DS_NAME_1, TEST_DS_NAME_2];
Expand Down Expand Up @@ -132,6 +138,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await es.indices.deleteIndexTemplate({
name: `logsdb_index_template`,
});
await testSubjects.click('reloadButton');
});
});

Expand Down Expand Up @@ -224,5 +231,171 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
});
});

describe('Modify data streams index mode', () => {
const TEST_DS_NAME = 'test-ds';
const setIndexModeTemplate = async (settings: object) => {
await es.indices.putIndexTemplate({
name: `index_template_${TEST_DS_NAME}`,
index_patterns: [TEST_DS_NAME],
data_stream: {},
template: {
settings,
},
});
await es.indices.createDataStream({
name: TEST_DS_NAME,
});
await testSubjects.click('reloadButton');
};

const verifyIndexModeIsOrigin = async (indexModeName: string) => {
// Open details flyout of data stream
await pageObjects.indexManagement.clickDataStreamNameLink(TEST_DS_NAME);
// Check that index mode detail exists and its label is origin
expect(await testSubjects.exists('indexModeDetail')).to.be(true);
expect(await testSubjects.getVisibleText('indexModeDetail')).to.be(indexModeName);
// Close flyout
await testSubjects.click('closeDetailsButton');
// Navigate to the templates tab
await pageObjects.indexManagement.changeTabs('templatesTab');
await pageObjects.header.waitUntilLoadingHasFinished();
// Edit template
await pageObjects.indexManagement.clickIndexTemplateNameLink(
`index_template_${TEST_DS_NAME}`
);
await testSubjects.click('manageTemplateButton');
await testSubjects.click('editIndexTemplateButton');

// Verify index mode is origin
expect(await testSubjects.getVisibleText('indexModeField')).to.be(indexModeName);
};

const changeIndexMode = async (indexModeSelector: string) => {
// Modify index mode
await testSubjects.click('indexModeField');
await testSubjects.click(indexModeSelector);
};

const verifyModeHasBeenChanged = async (indexModeName: string) => {
expect(await testSubjects.getVisibleText('indexModeValue')).to.be(indexModeName);

// Click update template
await pageObjects.indexManagement.clickNextButton();

// Verify index mode and close detail tab
expect(await testSubjects.getVisibleText('indexModeValue')).to.be(indexModeName);
await testSubjects.click('closeDetailsButton');

// Navigate to the data streams tab
await pageObjects.indexManagement.changeTabs('data_streamsTab');
await pageObjects.header.waitUntilLoadingHasFinished();

// Open data stream
await pageObjects.indexManagement.clickDataStreamNameLink(TEST_DS_NAME);
// Check that index mode detail exists and its label is destination index mode
expect(await testSubjects.exists('indexModeDetail')).to.be(true);
expect(await testSubjects.getVisibleText('indexModeDetail')).to.be(indexModeName);
// Close flyout
await testSubjects.click('closeDetailsButton');
};

afterEach(async () => {
await log.debug('Cleaning up created data stream');

try {
await es.indices.deleteDataStream({ name: TEST_DS_NAME });
await es.indices.deleteIndexTemplate({
name: `index_template_${TEST_DS_NAME}`,
});
} catch (e) {
log.debug('Error deleting test data stream');
throw e;
}
});

it('allows to upgrade data stream from standard to logsdb index mode', async () => {
await setIndexModeTemplate({
mode: 'standard',
});
await verifyIndexModeIsOrigin(INDEX_MODE.STANDARD);

await changeIndexMode('index_mode_logsdb');
// Navigate to the last step of the wizard
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');

await verifyModeHasBeenChanged(INDEX_MODE.LOGSDB);
});

it('allows to downgrade data stream from logsdb to standard index mode', async () => {
await setIndexModeTemplate({
mode: 'logsdb',
});
await verifyIndexModeIsOrigin(INDEX_MODE.LOGSDB);

await changeIndexMode('index_mode_standard');
// Navigate to the last step of the wizard
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');

await verifyModeHasBeenChanged(INDEX_MODE.STANDARD);
});

it('allows to upgrade data stream from time series to logsdb index mode', async () => {
await setIndexModeTemplate({
mode: 'time_series',
routing_path: 'test',
});
await verifyIndexModeIsOrigin(INDEX_MODE.TIME_SERIES);

await changeIndexMode('index_mode_logsdb');

await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
// Modify Index settings
await testSubjects.setValue('kibanaCodeEditor', '{}', {
clearWithKeyboard: true,
});
// Navigate to the last step of the wizard
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');

await verifyModeHasBeenChanged(INDEX_MODE.LOGSDB);
});

it('allows to downgrade data stream from logsdb to time series index mode', async () => {
await setIndexModeTemplate({
mode: 'logsdb',
});
await verifyIndexModeIsOrigin(INDEX_MODE.LOGSDB);

await changeIndexMode('index_mode_time_series');

await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
// Modify Index settings
await testSubjects.setValue(
'kibanaCodeEditor',
JSON.stringify({ index: { mode: 'time_series', routing_path: 'test' } }),
{
clearWithKeyboard: true,
}
);
// Navigate to the last step of the wizard
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');

await verifyModeHasBeenChanged(INDEX_MODE.TIME_SERIES);
});
});
});
};
1 change: 1 addition & 0 deletions x-pack/test/functional/apps/index_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export default ({ loadTestFile }: FtrProviderContext) => {
loadTestFile(require.resolve('./enrich_policies_tab'));
loadTestFile(require.resolve('./create_enrich_policy'));
loadTestFile(require.resolve('./data_streams_tab'));
loadTestFile(require.resolve('./index_templates_tab'));
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';

export default ({ loadTestFile }: FtrProviderContext) => {
describe('Index Management: index templates tab', function () {
loadTestFile(require.resolve('./create_index_template'));
loadTestFile(require.resolve('./index_template_tab'));
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,29 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const log = getService('log');
const security = getService('security');
const testSubjects = getService('testSubjects');
const es = getService('es');

const INDEX_TEMPLATE_NAME = `test-index-template`;
const INDEX_TEMPLATE_NAME = `test-index-template-name`;

describe('Create index template', function () {
describe('Index template tab', function () {
before(async () => {
await log.debug('Navigating to the index templates tab');
await security.testUser.setRoles(['index_management_user']);
await pageObjects.common.navigateToApp('indexManagement');
// Navigate to the data streams tab
// Navigate to the templates tab
await pageObjects.indexManagement.changeTabs('templatesTab');
await pageObjects.header.waitUntilLoadingHasFinished();
// Click create template button
await testSubjects.click('createTemplateButton');
});

afterEach(async () => {
await es.indices.deleteIndexTemplate({
name: INDEX_TEMPLATE_NAME,
});
await testSubjects.click('reloadButton');
});

it('can create an index template with data retention', async () => {
// Complete required fields from step 1
await testSubjects.setValue('nameField', INDEX_TEMPLATE_NAME);
Expand All @@ -46,6 +54,36 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await testSubjects.click('nextButton');

expect(await testSubjects.getVisibleText('lifecycleValue')).to.be('7 hours');

// Click Create template
await pageObjects.indexManagement.clickNextButton();
// Close detail tab
await testSubjects.click('closeDetailsButton');
});

it('can create an index template with logsdb index mode', async () => {
await testSubjects.click('createTemplateButton');
// Fill out required fields
await testSubjects.setValue('nameField', INDEX_TEMPLATE_NAME);
await testSubjects.setValue('indexPatternsField', 'logsdb-test-index-pattern');

await testSubjects.click('indexModeField');
await testSubjects.click('index_mode_logsdb');

// Navigate to the last step of the wizard
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');
await testSubjects.click('nextButton');

expect(await testSubjects.exists('indexModeTitle')).to.be(true);
expect(await testSubjects.getVisibleText('indexModeValue')).to.be('LogsDB');

// Click Create template
await pageObjects.indexManagement.clickNextButton();
// Close detail tab
await testSubjects.click('closeDetailsButton');
});
});
};
4 changes: 4 additions & 0 deletions x-pack/test/functional/page_objects/index_management_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export function IndexManagementPageProvider({ getService }: FtrProviderContext)
await testSubjects.click('bulkEditDataRetentionButton');
},

async clickIndexTemplateNameLink(name: string): Promise<void> {
await find.clickByLinkText(name);
},

async clickDataStreamNameLink(name: string): Promise<void> {
await find.clickByLinkText(name);
},
Expand Down
Loading

0 comments on commit 34341e5

Please sign in to comment.