From 142a34bf5fc4441e7524705c9a1aaba9e10bc323 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 4 Dec 2023 12:08:15 +0100 Subject: [PATCH] [Search profiler] Add serverless api tests (#172157) --- .../apis/searchprofiler/searchprofiler.ts | 5 +- .../common/search_profiler/index.ts | 16 +++++ .../common/search_profiler/search_profiler.ts | 59 +++++++++++++++++++ .../common_configs/config.group1.ts | 1 + .../search/common_configs/config.group1.ts | 1 + .../security/common_configs/config.group1.ts | 1 + 6 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/search_profiler/index.ts create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/search_profiler/search_profiler.ts diff --git a/x-pack/test/api_integration/apis/searchprofiler/searchprofiler.ts b/x-pack/test/api_integration/apis/searchprofiler/searchprofiler.ts index ab96505414648..9a0c4546a2e7b 100644 --- a/x-pack/test/api_integration/apis/searchprofiler/searchprofiler.ts +++ b/x-pack/test/api_integration/apis/searchprofiler/searchprofiler.ts @@ -10,11 +10,10 @@ import { FtrProviderContext } from '../../ftr_provider_context'; const API_BASE_PATH = '/api/searchprofiler'; -// Flaky https://github.com/elastic/kibana/issues/97954 export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - describe.skip('Profile', () => { + describe('Profile', () => { it('should return profile results for a valid index', async () => { const payload = { index: '_all', @@ -46,7 +45,7 @@ export default function ({ getService }: FtrProviderContext) { }; const { body } = await supertest - .post(`${API_BASE_PATH}/execute`) + .post(`${API_BASE_PATH}/profile`) .set('kbn-xsrf', 'xxx') .set('Content-Type', 'application/json;charset=UTF-8') .send(payloadWithInvalidIndex) diff --git a/x-pack/test_serverless/api_integration/test_suites/common/search_profiler/index.ts b/x-pack/test_serverless/api_integration/test_suites/common/search_profiler/index.ts new file mode 100644 index 0000000000000..1df060c658629 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/search_profiler/index.ts @@ -0,0 +1,16 @@ +/* + * 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 { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('Search profiler APIs', function () { + this.tags(['esGate']); + + loadTestFile(require.resolve('./search_profiler')); + }); +} diff --git a/x-pack/test_serverless/api_integration/test_suites/common/search_profiler/search_profiler.ts b/x-pack/test_serverless/api_integration/test_suites/common/search_profiler/search_profiler.ts new file mode 100644 index 0000000000000..45d515dff4883 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/search_profiler/search_profiler.ts @@ -0,0 +1,59 @@ +/* + * 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'; + +const API_BASE_PATH = '/api/searchprofiler'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + const svlCommonApi = getService('svlCommonApi'); + + describe('Profile', () => { + it('should return profile results for a valid index', async () => { + const payload = { + index: '_all', + query: { + query: { + match_all: {}, + }, + }, + }; + + const { body } = await supertest + .post(`${API_BASE_PATH}/profile`) + .set(svlCommonApi.getInternalRequestHeader()) + .set('Content-Type', 'application/json;charset=UTF-8') + .send(payload) + .expect(200); + + expect(body.ok).to.eql(true); + }); + + it('should return error for invalid index', async () => { + const payloadWithInvalidIndex = { + index: 'index_does_not_exist', + query: { + query: { + match_all: {}, + }, + }, + }; + + const { body } = await supertest + .post(`${API_BASE_PATH}/profile`) + .set(svlCommonApi.getInternalRequestHeader()) + .set('Content-Type', 'application/json;charset=UTF-8') + .send(payloadWithInvalidIndex) + .expect(404); + + expect(body.error).to.eql('Not Found'); + }); + }); +} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts index 00fd283b0fbd1..9a0ce57eda101 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts @@ -23,6 +23,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/platform_security'), require.resolve('../../common/scripts_tests'), require.resolve('../../common/search_oss'), + require.resolve('../../common/search_profiler'), require.resolve('../../common/search_xpack'), require.resolve('../../common/core'), require.resolve('../../common/reporting'), diff --git a/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts index 5a1834f91b7a1..1d83268723ddb 100644 --- a/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts @@ -23,6 +23,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/platform_security'), require.resolve('../../common/scripts_tests'), require.resolve('../../common/search_oss'), + require.resolve('../../common/search_profiler'), require.resolve('../../common/search_xpack'), require.resolve('../../common/core'), require.resolve('../../common/reporting'), diff --git a/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts index 87c5ea8b32ffe..8fcab232142fa 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts @@ -23,6 +23,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/platform_security'), require.resolve('../../common/scripts_tests'), require.resolve('../../common/search_oss'), + require.resolve('../../common/search_profiler'), require.resolve('../../common/search_xpack'), require.resolve('../../common/core'), require.resolve('../../common/reporting'),