From 41b124d528e96df720d92ef83b467d7da04eb148 Mon Sep 17 00:00:00 2001 From: Rachel Shen Date: Fri, 8 Sep 2023 08:20:45 -0600 Subject: [PATCH] [Fix] Load sample data in serverless (#165157) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Closes #165114 Closes https://github.com/elastic/kibana/issues/165368 Unable to create sample data index "kibana_sample_data_flights", error: illegal_argument_exception Root causes: illegal_argument_exception: Settings [index.auto_expand_replicas,index.number_of_shards] are not available when running in serverless mode Screenshot 2023-08-30 at 11 21 03 AM found in [logs](https://overview.qa.cld.elstc.co/s/appex/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:60000),time:(from:'2023-08-30T16:48:55.621Z',to:'2023-08-30T18:27:14.583Z'))&_a=(columns:!(),filters:!(),grid:(columns:(request_method.keyword:(width:814))),hideAggregatedPreview:!f,index:'2e3efa6b-bb9e-48a7-a1b5-af690e556a6b',interval:auto,query:(language:kuery,query:'kubernetes.labels.k8s_elastic_co%2Fproject-id:%20%22d660f827d17a4e3f9662d473461c099c%22%20'),sort:!(!('@timestamp',desc)),viewMode:aggregated)) in the message field when filtering by project by kubernetes.labels.k8s_elastic_co/project-id: "d660f827d17a4e3f9662d473461c099c" - [x] TODO set up FTR that should have caught this to confirm this fix works in serverless environments (based off the home page object) --------- Co-authored-by: Sébastien Loix --- .../sample_data/sample_data_installer.test.ts | 10 +++++++-- .../sample_data/sample_data_installer.ts | 4 +--- .../test_suites/common/sample_data.ts | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 x-pack/test_serverless/functional/test_suites/common/sample_data.ts diff --git a/src/plugins/home/server/services/sample_data/sample_data_installer.test.ts b/src/plugins/home/server/services/sample_data/sample_data_installer.test.ts index af3108ddafce9..361a9c74c0090 100644 --- a/src/plugins/home/server/services/sample_data/sample_data_installer.test.ts +++ b/src/plugins/home/server/services/sample_data/sample_data_installer.test.ts @@ -159,8 +159,14 @@ describe('SampleDataInstaller', () => { expect(esClient.asCurrentUser.indices.create).toHaveBeenCalledWith({ index: 'kibana_sample_data_test_single_data_index', body: { - settings: { index: { number_of_shards: 1, auto_expand_replicas: '0-1' } }, - mappings: { properties: { someField: { type: 'keyword' } } }, + mappings: { + properties: { + someField: { type: 'keyword' }, + }, + }, + settings: { + index: {}, + }, }, }); }); diff --git a/src/plugins/home/server/services/sample_data/sample_data_installer.ts b/src/plugins/home/server/services/sample_data/sample_data_installer.ts index 958f952fdd5a1..3f165a4a0e219 100644 --- a/src/plugins/home/server/services/sample_data/sample_data_installer.ts +++ b/src/plugins/home/server/services/sample_data/sample_data_installer.ts @@ -155,13 +155,13 @@ export class SampleDataInstaller { private async installDataIndex(dataset: SampleDatasetSchema, dataIndex: DataIndexSchema) { const index = createIndexName(dataset.id, dataIndex.id); + try { if (dataIndex.isDataStream) { const request = { name: index, body: { template: { - settings: { number_of_shards: 1, auto_expand_replicas: '0-1' }, mappings: { properties: dataIndex.fields }, }, index_patterns: [index], @@ -180,8 +180,6 @@ export class SampleDataInstaller { settings: { index: { ...dataIndex.indexSettings, - number_of_shards: 1, - auto_expand_replicas: '0-1', }, }, mappings: { properties: dataIndex.fields }, diff --git a/x-pack/test_serverless/functional/test_suites/common/sample_data.ts b/x-pack/test_serverless/functional/test_suites/common/sample_data.ts new file mode 100644 index 0000000000000..a127ce0ee3e1d --- /dev/null +++ b/x-pack/test_serverless/functional/test_suites/common/sample_data.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from 'expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getPageObjects }: FtrProviderContext) { + const PageObjects = getPageObjects(['settings', 'common', 'header', 'home']); + + describe('Sample data in serverless', function () { + it('Sample data loads', async () => { + await PageObjects.home.addSampleDataSet('ecommerce'); + const ecommerce = await PageObjects.home.isSampleDataSetInstalled('ecommerce'); + expect(ecommerce).toBe(true); + }); + }); +}