Skip to content

Commit

Permalink
Add logsdb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SoniaSanzV committed Dec 27, 2024
1 parent 04ff8aa commit 7b1ec6d
Show file tree
Hide file tree
Showing 9 changed files with 430 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 @@ -132,6 +132,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await es.indices.deleteIndexTemplate({
name: `logsdb_index_template`,
});
await browser.refresh();
});
});

Expand Down Expand Up @@ -224,5 +225,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 browser.refresh();
};

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('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('LogsDB');
});

it('allows to downgrade data stream from logsdb to standard index mode', async () => {
await setIndexModeTemplate({
mode: 'logsdb',
});
await verifyIndexModeIsOrigin('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('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('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('LogsDB');
});

it('allows to downgrade data stream from logsdb to time series index mode', async () => {
await setIndexModeTemplate({
mode: 'logsdb',
});
await verifyIndexModeIsOrigin('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('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,30 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const log = getService('log');
const security = getService('security');
const testSubjects = getService('testSubjects');
const es = getService('es');
const browser = getService('browser');

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 browser.refresh();
});

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 +55,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 7b1ec6d

Please sign in to comment.