From fd83f45fb7f90437a43dd7542dc59388ba2b2a19 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 28 Nov 2023 11:06:04 +0100 Subject: [PATCH 1/6] Add tests for settings route --- .../index_management/lib/settings.api.ts | 31 +++++ .../index_management/settings.helpers.js | 20 --- .../{settings.js => settings.ts} | 5 +- .../services/index_management.ts | 4 + .../common/index_management/index.ts | 1 + .../common/index_management/settings.ts | 127 ++++++++++++++++++ 6 files changed, 165 insertions(+), 23 deletions(-) create mode 100644 x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts delete mode 100644 x-pack/test/api_integration/apis/management/index_management/settings.helpers.js rename x-pack/test/api_integration/apis/management/index_management/{settings.js => settings.ts} (95%) create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/index_management/settings.ts diff --git a/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts b/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts new file mode 100644 index 0000000000000..b1bf996cf36a5 --- /dev/null +++ b/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts @@ -0,0 +1,31 @@ +/* + * 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 { API_BASE_PATH } from '../constants'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export function settingsApi(getService: FtrProviderContext['getService']) { + const supertest = getService('supertest'); + + const getIndexSettings = (index: string) => + supertest + .get(`${API_BASE_PATH}/settings/${index}`) + .set('kbn-xsrf', 'xxx') + .set('x-elastic-internal-origin', 'xxx'); + + const updateIndexSettings = (index: string, settings: any) => + supertest + .put(`${API_BASE_PATH}/settings/${index}`) + .set('kbn-xsrf', 'xxx') + .set('x-elastic-internal-origin', 'xxx') + .send(settings); + + return { + getIndexSettings, + updateIndexSettings, + }; +} diff --git a/x-pack/test/api_integration/apis/management/index_management/settings.helpers.js b/x-pack/test/api_integration/apis/management/index_management/settings.helpers.js deleted file mode 100644 index 58573b1572fa8..0000000000000 --- a/x-pack/test/api_integration/apis/management/index_management/settings.helpers.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 { API_BASE_PATH } from './constants'; - -export const registerHelpers = ({ supertest }) => { - const getIndexSettings = (indexName) => supertest.get(`${API_BASE_PATH}/settings/${indexName}`); - - const updateIndexSettings = (indexName, settings) => - supertest.put(`${API_BASE_PATH}/settings/${indexName}`).set('kbn-xsrf', 'xxx').send(settings); - - return { - getIndexSettings, - updateIndexSettings, - }; -}; diff --git a/x-pack/test/api_integration/apis/management/index_management/settings.js b/x-pack/test/api_integration/apis/management/index_management/settings.ts similarity index 95% rename from x-pack/test/api_integration/apis/management/index_management/settings.js rename to x-pack/test/api_integration/apis/management/index_management/settings.ts index fbffc203cff58..eb31ef7b787e7 100644 --- a/x-pack/test/api_integration/apis/management/index_management/settings.js +++ b/x-pack/test/api_integration/apis/management/index_management/settings.ts @@ -8,14 +8,13 @@ import expect from '@kbn/expect'; import { indicesHelpers } from './lib/indices.helpers'; -import { registerHelpers } from './settings.helpers'; +import { settingsApi } from './lib/settings.api'; export default function ({ getService }) { const supertest = getService('supertest'); const { createIndex, deleteAllIndices } = indicesHelpers(getService); - - const { getIndexSettings, updateIndexSettings } = registerHelpers({ supertest }); + const { getIndexSettings, updateIndexSettings } = settingsApi(getService); describe('settings', () => { after(async () => await deleteAllIndices()); diff --git a/x-pack/test/api_integration/services/index_management.ts b/x-pack/test/api_integration/services/index_management.ts index 44d33752e4147..8f891a2b7fce4 100644 --- a/x-pack/test/api_integration/services/index_management.ts +++ b/x-pack/test/api_integration/services/index_management.ts @@ -9,6 +9,7 @@ import { FtrProviderContext } from '../ftr_provider_context'; import { indicesApi } from '../apis/management/index_management/lib/indices.api'; import { mappingsApi } from '../apis/management/index_management/lib/mappings.api'; import { indicesHelpers } from '../apis/management/index_management/lib/indices.helpers'; +import { settingsApi } from '../apis/management/index_management/lib/settings.api'; export function IndexManagementProvider({ getService }: FtrProviderContext) { return { @@ -19,5 +20,8 @@ export function IndexManagementProvider({ getService }: FtrProviderContext) { mappings: { api: mappingsApi(getService), }, + settings: { + api: settingsApi(getService), + }, }; } diff --git a/x-pack/test_serverless/api_integration/test_suites/common/index_management/index.ts b/x-pack/test_serverless/api_integration/test_suites/common/index_management/index.ts index e06aaf9225cfa..b376cc6a73ce9 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/index_management/index.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/index_management/index.ts @@ -15,5 +15,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./indices')); loadTestFile(require.resolve('./create_enrich_policies')); loadTestFile(require.resolve('./mappings')); + loadTestFile(require.resolve('./settings')); }); } diff --git a/x-pack/test_serverless/api_integration/test_suites/common/index_management/settings.ts b/x-pack/test_serverless/api_integration/test_suites/common/index_management/settings.ts new file mode 100644 index 0000000000000..219832a1f4c5d --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/index_management/settings.ts @@ -0,0 +1,127 @@ +/* + * 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 '@kbn/expect'; + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const indexManagementService = getService('indexManagement'); + + describe('settings', () => { + let getIndexSettings: typeof indexManagementService['settings']['api']['getIndexSettings']; + let updateIndexSettings: typeof indexManagementService['settings']['api']['updateIndexSettings']; + let createIndex: typeof indexManagementService['indices']['helpers']['createIndex']; + let deleteAllIndices: typeof indexManagementService['indices']['helpers']['deleteAllIndices']; + + before(async () => { + ({ + settings: { + api: { + getIndexSettings, + updateIndexSettings, + }, + }, + indices: { + helpers: { createIndex, deleteAllIndices }, + }, + } = indexManagementService); + }); + + after(async () => await deleteAllIndices()); + + it('should fetch an index settings', async () => { + const index = await createIndex(); + + const { body } = await getIndexSettings(index).expect(200); + + // Verify we fetch the corret index settings + expect(body.settings.index.provided_name).to.be(index); + + const expectedSettings = [ + 'max_inner_result_window', + 'unassigned', + 'max_terms_count', + 'lifecycle', + 'routing_partition_size', + 'max_docvalue_fields_search', + 'merge', + 'max_refresh_listeners', + 'max_regex_length', + 'load_fixed_bitset_filters_eagerly', + 'number_of_routing_shards', + 'write', + 'verified_before_close', + 'mapping', + 'source_only', + 'soft_deletes', + 'max_script_fields', + 'query', + 'format', + 'frozen', + 'sort', + 'priority', + 'codec', + 'max_rescore_window', + 'analyze', + 'gc_deletes', + 'max_ngram_diff', + 'translog', + 'auto_expand_replicas', + 'requests', + 'data_path', + 'highlight', + 'routing', + 'search', + 'fielddata', + 'default_pipeline', + 'max_slices_per_scroll', + 'shard', + 'xpack', + 'percolator', + 'allocation', + 'refresh_interval', + 'indexing', + 'compound_format', + 'blocks', + 'max_result_window', + 'store', + 'queries', + 'warmer', + 'max_shingle_diff', + 'query_string', + ]; + + // Make sure none of the settings have been removed from ES API + expectedSettings.forEach((setting) => { + try { + expect(body.defaults.index.hasOwnProperty(setting)).to.be(true); + } catch { + throw new Error(`Expected setting "${setting}" not found.`); + } + }); + }); + + it('should update an index settings', async () => { + const index = await createIndex(); + + const { body: body1 } = await getIndexSettings(index); + expect(body1.settings.index.number_of_replicas).to.be('1'); + + const settings = { + index: { + number_of_replicas: 2, + }, + }; + await updateIndexSettings(index, settings); + + const { body: body2 } = await getIndexSettings(index); + expect(body2.settings.index.number_of_replicas).to.be('2'); + }); + + }); +} From 36afc3bfada1864ade8c04bdf6c74b62de8a58de Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 28 Nov 2023 11:06:08 +0100 Subject: [PATCH 2/6] commit with @elastic email From d66ae2d3c8a419e78160e57d0261e833097e90db Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 28 Nov 2023 10:43:51 +0000 Subject: [PATCH 3/6] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../test_suites/common/index_management/settings.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x-pack/test_serverless/api_integration/test_suites/common/index_management/settings.ts b/x-pack/test_serverless/api_integration/test_suites/common/index_management/settings.ts index 219832a1f4c5d..d5cd93060737c 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/index_management/settings.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/index_management/settings.ts @@ -21,10 +21,7 @@ export default function ({ getService }: FtrProviderContext) { before(async () => { ({ settings: { - api: { - getIndexSettings, - updateIndexSettings, - }, + api: { getIndexSettings, updateIndexSettings }, }, indices: { helpers: { createIndex, deleteAllIndices }, @@ -122,6 +119,5 @@ export default function ({ getService }: FtrProviderContext) { const { body: body2 } = await getIndexSettings(index); expect(body2.settings.index.number_of_replicas).to.be('2'); }); - }); } From 5e58ca760635fa7b73486c8607953fbac0ec0dd9 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 28 Nov 2023 14:14:24 +0100 Subject: [PATCH 4/6] add missing type --- .../apis/management/index_management/settings.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/test/api_integration/apis/management/index_management/settings.ts b/x-pack/test/api_integration/apis/management/index_management/settings.ts index eb31ef7b787e7..573a0374e9c25 100644 --- a/x-pack/test/api_integration/apis/management/index_management/settings.ts +++ b/x-pack/test/api_integration/apis/management/index_management/settings.ts @@ -9,10 +9,9 @@ import expect from '@kbn/expect'; import { indicesHelpers } from './lib/indices.helpers'; import { settingsApi } from './lib/settings.api'; +import { FtrProviderContext } from '../../../ftr_provider_context'; -export default function ({ getService }) { - const supertest = getService('supertest'); - +export default function ({ getService }: FtrProviderContext) { const { createIndex, deleteAllIndices } = indicesHelpers(getService); const { getIndexSettings, updateIndexSettings } = settingsApi(getService); From f7817167349029773d8fd4dfdc054af42bb820c0 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 28 Nov 2023 16:02:21 +0100 Subject: [PATCH 5/6] Fix any type --- .../apis/management/index_management/lib/settings.api.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts b/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts index b1bf996cf36a5..666c1c227e395 100644 --- a/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts +++ b/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts @@ -7,6 +7,7 @@ import { API_BASE_PATH } from '../constants'; import { FtrProviderContext } from '../../../../ftr_provider_context'; +import { IndexSettings } from '@kbn/index-management-plugin/common' export function settingsApi(getService: FtrProviderContext['getService']) { const supertest = getService('supertest'); @@ -17,7 +18,7 @@ export function settingsApi(getService: FtrProviderContext['getService']) { .set('kbn-xsrf', 'xxx') .set('x-elastic-internal-origin', 'xxx'); - const updateIndexSettings = (index: string, settings: any) => + const updateIndexSettings = (index: string, settings: IndexSettings) => supertest .put(`${API_BASE_PATH}/settings/${index}`) .set('kbn-xsrf', 'xxx') From 264cd5998fdf133601fb92e4d71ea2c20b0d1e87 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 28 Nov 2023 16:12:59 +0100 Subject: [PATCH 6/6] Fix import order --- .../apis/management/index_management/lib/settings.api.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts b/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts index 666c1c227e395..67b3c275775c4 100644 --- a/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts +++ b/x-pack/test/api_integration/apis/management/index_management/lib/settings.api.ts @@ -5,9 +5,10 @@ * 2.0. */ +import { IndexSettings } from '@kbn/index-management-plugin/common'; + import { API_BASE_PATH } from '../constants'; import { FtrProviderContext } from '../../../../ftr_provider_context'; -import { IndexSettings } from '@kbn/index-management-plugin/common' export function settingsApi(getService: FtrProviderContext['getService']) { const supertest = getService('supertest');