From 43cbad0aff0eb39cfb94cf219b97528941f97810 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Mon, 7 Aug 2023 15:59:11 +0200 Subject: [PATCH 01/15] [esArchiver] Do not perform SO migration on cleanup --- .../src/actions/empty_kibana_index.ts | 16 +++------------- packages/kbn-es-archiver/src/es_archiver.ts | 4 +--- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/packages/kbn-es-archiver/src/actions/empty_kibana_index.ts b/packages/kbn-es-archiver/src/actions/empty_kibana_index.ts index 2c23eec3ca2aa..42df7340c1853 100644 --- a/packages/kbn-es-archiver/src/actions/empty_kibana_index.ts +++ b/packages/kbn-es-archiver/src/actions/empty_kibana_index.ts @@ -8,25 +8,15 @@ import type { Client } from '@elastic/elasticsearch'; import { ToolingLog } from '@kbn/tooling-log'; -import { KbnClient } from '@kbn/test'; import { ALL_SAVED_OBJECT_INDICES } from '@kbn/core-saved-objects-server'; -import { migrateSavedObjectIndices, createStats, cleanSavedObjectIndices } from '../lib'; +import { createStats, cleanSavedObjectIndices } from '../lib'; -export async function emptyKibanaIndexAction({ - client, - log, - kbnClient, -}: { - client: Client; - log: ToolingLog; - kbnClient: KbnClient; -}) { +export async function emptyKibanaIndexAction({ client, log }: { client: Client; log: ToolingLog }) { const stats = createStats('emptyKibanaIndex', log); await cleanSavedObjectIndices({ client, stats, log }); - await migrateSavedObjectIndices(kbnClient); await client.indices.refresh({ index: ALL_SAVED_OBJECT_INDICES }); - ALL_SAVED_OBJECT_INDICES.forEach((indexPattern) => stats.createdIndex(indexPattern)); + return stats.toJSON(); } diff --git a/packages/kbn-es-archiver/src/es_archiver.ts b/packages/kbn-es-archiver/src/es_archiver.ts index 65de41148d8db..d5c989f080486 100644 --- a/packages/kbn-es-archiver/src/es_archiver.ts +++ b/packages/kbn-es-archiver/src/es_archiver.ts @@ -154,14 +154,12 @@ export class EsArchiver { } /** - * Delete any Kibana indices, and initialize the Kibana index as Kibana would do - * on startup. + * Cleanup saved object indices, preserving the space:default saved object. */ async emptyKibanaIndex() { return await emptyKibanaIndexAction({ client: this.client, log: this.log, - kbnClient: this.kbnClient, }); } From fc9e679f799649f0f77ae3a8dddd602c491bff03 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Tue, 8 Aug 2023 10:33:16 +0200 Subject: [PATCH 02/15] Unskip flaky suite --- .../plugin_functional/test_suites/core_plugins/applications.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/plugin_functional/test_suites/core_plugins/applications.ts b/test/plugin_functional/test_suites/core_plugins/applications.ts index df4ac37b96464..0145a84423b3c 100644 --- a/test/plugin_functional/test_suites/core_plugins/applications.ts +++ b/test/plugin_functional/test_suites/core_plugins/applications.ts @@ -49,8 +49,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide const navigateTo = async (path: string) => await browser.navigateTo(`${deployment.getHostPort()}${path}`); - // FLAKY: https://github.com/elastic/kibana/issues/127545 - describe.skip('ui applications', function describeIndexTests() { + describe('ui applications', function describeIndexTests() { before(async () => { await esArchiver.emptyKibanaIndex(); await PageObjects.common.navigateToApp('foo'); From c603793d69e21d25b8c90dd229869485c4827ad8 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Tue, 8 Aug 2023 15:54:35 +0200 Subject: [PATCH 03/15] Fix incorrect tests --- test/examples/search/warnings.ts | 1 + test/functional/services/common/browser.ts | 5 +++++ .../test_suites/core_plugins/applications.ts | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/examples/search/warnings.ts b/test/examples/search/warnings.ts index 24656ed68285c..c1c86863ad7a8 100644 --- a/test/examples/search/warnings.ts +++ b/test/examples/search/warnings.ts @@ -167,6 +167,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { // click "see full error" button in the toast const [openShardModalButton] = await testSubjects.findAll('openShardFailureModalBtn'); await openShardModalButton.click(); + await testSubjects.exists('shardFailureModalTitle'); const modalHeader = await testSubjects.find('shardFailureModalTitle'); expect(await modalHeader.getVisibleText()).to.be('2 of 4 shards failed'); // request diff --git a/test/functional/services/common/browser.ts b/test/functional/services/common/browser.ts index 393f093d54189..bdc0afb277148 100644 --- a/test/functional/services/common/browser.ts +++ b/test/functional/services/common/browser.ts @@ -70,6 +70,11 @@ class BrowserService extends FtrService { return await this.driver.manage().window().getRect(); } + public async getWindowInnerSize(): Promise<{ height: number; width: number }> { + const JS_GET_INNER_WIDTH = 'return { width: window.innerWidth, height: window.innerHeight };'; + return await this.driver.executeScript(JS_GET_INNER_WIDTH); + } + /** * Sets the dimensions of a window. * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Window.html diff --git a/test/plugin_functional/test_suites/core_plugins/applications.ts b/test/plugin_functional/test_suites/core_plugins/applications.ts index 0145a84423b3c..5af71ba799457 100644 --- a/test/plugin_functional/test_suites/core_plugins/applications.ts +++ b/test/plugin_functional/test_suites/core_plugins/applications.ts @@ -53,6 +53,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide before(async () => { await esArchiver.emptyKibanaIndex(); await PageObjects.common.navigateToApp('foo'); + await PageObjects.common.dismissBanner(); }); it('starts on home page', async () => { @@ -125,7 +126,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide expect(await testSubjects.exists('headerGlobalNav')).to.be(false); const wrapperHeight = await getAppWrapperHeight(); - const windowHeight = (await browser.getWindowSize()).height; + const windowHeight = (await browser.getWindowInnerSize()).height; expect(wrapperHeight).to.eql(windowHeight); }); @@ -135,7 +136,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide expect(await testSubjects.exists('headerGlobalNav')).to.be(true); const wrapperHeight = await getAppWrapperHeight(); - const windowHeight = (await browser.getWindowSize()).height; + const windowHeight = (await browser.getWindowInnerSize()).height; expect(wrapperHeight).to.be.below(windowHeight); }); }); From 0b9ba20752e8ffb511f355501cd39997a834b228 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Wed, 9 Aug 2023 10:53:23 +0200 Subject: [PATCH 04/15] Make sure we go to the right Dashboard page --- .../test/functional/apps/dashboard/group2/_async_dashboard.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts b/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts index 80354eda9eefd..b45934f122b1d 100644 --- a/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts +++ b/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts @@ -128,7 +128,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); it('should launch sample flights data set dashboard', async () => { - await appMenu.clickLink('Dashboard'); + appMenu.clickLink('Dashboard', { category: 'kibana', closeCollapsibleNav: true }); await PageObjects.dashboard.loadSavedDashboard('[Flights] Global Flight Dashboard'); await PageObjects.header.waitUntilLoadingHasFinished(); await PageObjects.timePicker.setCommonlyUsedTime('sample_data range'); From 1cdecea05bff24863fbec175e2abe99b4c88f20a Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Wed, 9 Aug 2023 11:15:59 +0200 Subject: [PATCH 05/15] Add missing await statement --- .../test/functional/apps/dashboard/group2/_async_dashboard.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts b/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts index b45934f122b1d..14eee5b11474c 100644 --- a/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts +++ b/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts @@ -128,7 +128,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); it('should launch sample flights data set dashboard', async () => { - appMenu.clickLink('Dashboard', { category: 'kibana', closeCollapsibleNav: true }); + await appMenu.clickLink('Dashboard', { category: 'kibana', closeCollapsibleNav: true }); await PageObjects.dashboard.loadSavedDashboard('[Flights] Global Flight Dashboard'); await PageObjects.header.waitUntilLoadingHasFinished(); await PageObjects.timePicker.setCommonlyUsedTime('sample_data range'); From 2d0ee3959cd2b0da722255efca2ac87c5ac00512 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Wed, 9 Aug 2023 15:36:35 +0200 Subject: [PATCH 06/15] Fix the clickLink() issues --- .../apps/dashboard/group2/_async_dashboard.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts b/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts index 14eee5b11474c..bf76152a459c4 100644 --- a/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts +++ b/x-pack/test/functional/apps/dashboard/group2/_async_dashboard.ts @@ -128,7 +128,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); it('should launch sample flights data set dashboard', async () => { - await appMenu.clickLink('Dashboard', { category: 'kibana', closeCollapsibleNav: true }); + await PageObjects.common.navigateToApp('dashboard'); await PageObjects.dashboard.loadSavedDashboard('[Flights] Global Flight Dashboard'); await PageObjects.header.waitUntilLoadingHasFinished(); await PageObjects.timePicker.setCommonlyUsedTime('sample_data range'); @@ -144,7 +144,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const hitCount = parseInt(await PageObjects.discover.getHitCount(), 10); expect(hitCount).to.be.greaterThan(0); }); - await appMenu.clickLink('Dashboard'); + await appMenu.clickLink('Dashboard', { + category: 'recentlyViewed', + closeCollapsibleNav: true, + }); await PageObjects.header.waitUntilLoadingHasFinished(); await renderable.waitForRender(); log.debug('Checking charts rendered'); @@ -157,7 +160,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const hitCount = parseInt(await PageObjects.discover.getHitCount(), 10); expect(hitCount).to.be.greaterThan(0); }); - await appMenu.clickLink('Dashboard'); + await appMenu.clickLink('Dashboard', { + category: 'recentlyViewed', + closeCollapsibleNav: true, + }); await PageObjects.header.waitUntilLoadingHasFinished(); await renderable.waitForRender(); log.debug('Checking charts rendered'); @@ -170,7 +176,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const hitCount = parseInt(await PageObjects.discover.getHitCount(), 10); expect(hitCount).to.be.greaterThan(0); }); - await appMenu.clickLink('Dashboard'); + await appMenu.clickLink('Dashboard', { + category: 'recentlyViewed', + closeCollapsibleNav: true, + }); await PageObjects.header.waitUntilLoadingHasFinished(); await renderable.waitForRender(); log.debug('Checking charts rendered'); From 04481ef885a6553afebcad78fd3e428bf96e1b2c Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Thu, 10 Aug 2023 19:29:08 +0200 Subject: [PATCH 07/15] Make sure we go to the right Dashboards page --- .../apps/dashboard/group2/dashboard_maps_by_value.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/test/functional/apps/dashboard/group2/dashboard_maps_by_value.ts b/x-pack/test/functional/apps/dashboard/group2/dashboard_maps_by_value.ts index d9a0062298eec..5503d1a08dc4e 100644 --- a/x-pack/test/functional/apps/dashboard/group2/dashboard_maps_by_value.ts +++ b/x-pack/test/functional/apps/dashboard/group2/dashboard_maps_by_value.ts @@ -60,7 +60,10 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { }); if (!saveToDashboard) { - await appsMenu.clickLink('Dashboard'); + await appsMenu.clickLink('Dashboard', { + category: 'kibana', + closeCollapsibleNav: true, + }); } } else { await PageObjects.maps.clickSaveAndReturnButton(); From 7ed084dfc7facb4dfd99f15fcd36b960ecdd6621 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Fri, 11 Aug 2023 17:38:34 +0200 Subject: [PATCH 08/15] Make sure `Download Report` popup is closed by each test --- x-pack/test/functional/apps/discover/reporting.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/test/functional/apps/discover/reporting.ts b/x-pack/test/functional/apps/discover/reporting.ts index 75fa7feb02057..60c28050383cf 100644 --- a/x-pack/test/functional/apps/discover/reporting.ts +++ b/x-pack/test/functional/apps/discover/reporting.ts @@ -35,6 +35,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const url = await PageObjects.reporting.getReportURL(60000); const res = await PageObjects.reporting.getResponse(url); + await PageObjects.reporting.clearToastNotifications(); + expect(res.status).to.equal(200); expect(res.get('content-type')).to.equal('text/csv; charset=utf-8'); return res; From da54bc95d0849a1ee8aa2e25c77d7a9d6776f381 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Mon, 28 Aug 2023 14:38:10 +0200 Subject: [PATCH 09/15] Clear toast notifications before generating / getting a report --- x-pack/test/functional/apps/discover/reporting.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/apps/discover/reporting.ts b/x-pack/test/functional/apps/discover/reporting.ts index 60c28050383cf..173869a85465f 100644 --- a/x-pack/test/functional/apps/discover/reporting.ts +++ b/x-pack/test/functional/apps/discover/reporting.ts @@ -29,14 +29,15 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }; const getReport = async () => { + // close any open notification toasts + await PageObjects.reporting.clearToastNotifications(); + await PageObjects.reporting.openCsvReportingPanel(); await PageObjects.reporting.clickGenerateReportButton(); const url = await PageObjects.reporting.getReportURL(60000); const res = await PageObjects.reporting.getResponse(url); - await PageObjects.reporting.clearToastNotifications(); - expect(res.status).to.equal(200); expect(res.get('content-type')).to.equal('text/csv; charset=utf-8'); return res; From c8c5f9a5bee2a32413737322d32058b4e8d20575 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Mon, 28 Aug 2023 17:05:19 +0200 Subject: [PATCH 10/15] Wait for the welcome interstitial to be fully visible (500ms) --- test/functional/page_objects/home_page.ts | 4 +++- test/functional/services/common/test_subjects.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/functional/page_objects/home_page.ts b/test/functional/page_objects/home_page.ts index ac942c70b5d90..61eb1f40c49e7 100644 --- a/test/functional/page_objects/home_page.ts +++ b/test/functional/page_objects/home_page.ts @@ -53,7 +53,9 @@ export class HomePageObject extends FtrService { } async isWelcomeInterstitialDisplayed() { - return await this.testSubjects.isDisplayed('homeWelcomeInterstitial'); + // give the interstitial enough time to fade in + await new Promise((resolve) => setTimeout(resolve, 500)); + return await this.testSubjects.isDisplayed('homeWelcomeInterstitial', 2000); } async isGuidedOnboardingLandingDisplayed() { diff --git a/test/functional/services/common/test_subjects.ts b/test/functional/services/common/test_subjects.ts index e54a1caa08d26..9cbce20b05068 100644 --- a/test/functional/services/common/test_subjects.ts +++ b/test/functional/services/common/test_subjects.ts @@ -285,9 +285,9 @@ export class TestSubjects extends FtrService { return await element.isEnabled(); } - public async isDisplayed(selector: string): Promise { + public async isDisplayed(selector: string, timeout?: number): Promise { this.log.debug(`TestSubjects.isDisplayed(${selector})`); - const element = await this.find(selector); + const element = await this.find(selector, timeout); return await element.isDisplayed(); } From d9b2ccf85f0e60d8b84aa8e3ca0960a9f4f56ecd Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Tue, 29 Aug 2023 15:24:00 +0200 Subject: [PATCH 11/15] Add more logging for failed requests at Kibana level --- .../http/core-http-router-server-internal/src/router.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/http/core-http-router-server-internal/src/router.ts b/packages/core/http/core-http-router-server-internal/src/router.ts index 617c810109138..df27263e34b33 100644 --- a/packages/core/http/core-http-router-server-internal/src/router.ts +++ b/packages/core/http/core-http-router-server-internal/src/router.ts @@ -200,6 +200,8 @@ export class Router Date: Tue, 29 Aug 2023 17:17:41 +0200 Subject: [PATCH 12/15] Update snapshots with latest logging enhancements --- .../integration_tests/http/router.test.ts | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/core/server/integration_tests/http/router.test.ts b/src/core/server/integration_tests/http/router.test.ts index 743624f2f46b3..25cd7104e72a3 100644 --- a/src/core/server/integration_tests/http/router.test.ts +++ b/src/core/server/integration_tests/http/router.test.ts @@ -576,11 +576,14 @@ describe('Handler', () => { 'An internal server error occurred. Check Kibana server logs for details.' ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` + Array [ Array [ - Array [ - [Error: unexpected error], - ], - ] + "500 Server Error - http://127.0.0.1:50107/", + ], + Array [ + [Error: unexpected error], + ], + ] `); }); @@ -616,6 +619,9 @@ describe('Handler', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50113/", + ], Array [ [Error: Unauthorized], ], @@ -638,6 +644,9 @@ describe('Handler', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50116/", + ], Array [ [Error: Unexpected result from Route Handler. Expected KibanaResponse, but given: string.], ], @@ -672,6 +681,17 @@ describe('Handler', () => { message: '[request query.page]: expected value of type [number] but got [string]', statusCode: 400, }); + + expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` + Array [ + Array [ + "400 Bad Request - http://127.0.0.1:50119/?page=one", + ], + Array [ + [Error: [request query.page]: expected value of type [number] but got [string]], + ], + ] + `); }); it('accept to receive an array payload', async () => { @@ -1144,6 +1164,9 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50185/", + ], Array [ [Error: expected 'location' header to be set], ], @@ -1550,6 +1573,9 @@ describe('Response factory', () => { }); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50239/", + ], Array [ [Error: Unexpected Http status code. Expected from 400 to 599, but given: 200], ], @@ -1619,6 +1645,9 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50248/", + ], Array [ [Error: expected 'location' header to be set], ], @@ -1759,6 +1788,9 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50266/", + ], Array [ [Error: expected error message to be provided], ], @@ -1785,6 +1817,9 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50269/", + ], Array [ [Error: expected error message to be provided], ], @@ -1810,6 +1845,9 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50272/", + ], Array [ [Error: options.statusCode is expected to be set. given options: undefined], ], @@ -1835,6 +1873,9 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ + Array [ + "500 Server Error - http://127.0.0.1:50275/", + ], Array [ [Error: Unexpected Http status code. Expected from 100 to 599, but given: 20.], ], From ea25549ddda103de58975deecfcd0e858ff9a8ae Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Wed, 30 Aug 2023 15:57:00 +0200 Subject: [PATCH 13/15] Update logged requests to NOT include the hostname --- .../src/router.ts | 18 +++++++++++---- .../integration_tests/http/router.test.ts | 22 +++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/core/http/core-http-router-server-internal/src/router.ts b/packages/core/http/core-http-router-server-internal/src/router.ts index df27263e34b33..5415e92ba272d 100644 --- a/packages/core/http/core-http-router-server-internal/src/router.ts +++ b/packages/core/http/core-http-router-server-internal/src/router.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { Request, ResponseToolkit } from '@hapi/hapi'; +import type { Request, ResponseToolkit, RequestQuery } from '@hapi/hapi'; import apm from 'elastic-apm-node'; import { isConfigSchema } from '@kbn/config-schema'; import type { Logger } from '@kbn/logging'; @@ -200,7 +200,7 @@ export class Router = T extends (first: any, ...rest: infer Params) => i type RequestHandlerEnhanced = WithoutHeadArgument< RequestHandler >; + +function toString(requestQuery?: RequestQuery): string { + const entries = Object.entries(requestQuery ?? {}); + + if (!entries?.length) { + return ''; + } + + return `?` + entries.map(([key, value]) => `${key}=${value}`).join('&'); +} diff --git a/src/core/server/integration_tests/http/router.test.ts b/src/core/server/integration_tests/http/router.test.ts index 25cd7104e72a3..f31fc70edb955 100644 --- a/src/core/server/integration_tests/http/router.test.ts +++ b/src/core/server/integration_tests/http/router.test.ts @@ -578,7 +578,7 @@ describe('Handler', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50107/", + "500 Server Error - /", ], Array [ [Error: unexpected error], @@ -620,7 +620,7 @@ describe('Handler', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50113/", + "500 Server Error - /", ], Array [ [Error: Unauthorized], @@ -645,7 +645,7 @@ describe('Handler', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50116/", + "500 Server Error - /", ], Array [ [Error: Unexpected result from Route Handler. Expected KibanaResponse, but given: string.], @@ -685,7 +685,7 @@ describe('Handler', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "400 Bad Request - http://127.0.0.1:50119/?page=one", + "400 Bad Request - /?page=one", ], Array [ [Error: [request query.page]: expected value of type [number] but got [string]], @@ -1165,7 +1165,7 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50185/", + "500 Server Error - /", ], Array [ [Error: expected 'location' header to be set], @@ -1574,7 +1574,7 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50239/", + "500 Server Error - /", ], Array [ [Error: Unexpected Http status code. Expected from 400 to 599, but given: 200], @@ -1646,7 +1646,7 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50248/", + "500 Server Error - /", ], Array [ [Error: expected 'location' header to be set], @@ -1789,7 +1789,7 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50266/", + "500 Server Error - /", ], Array [ [Error: expected error message to be provided], @@ -1818,7 +1818,7 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50269/", + "500 Server Error - /", ], Array [ [Error: expected error message to be provided], @@ -1846,7 +1846,7 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50272/", + "500 Server Error - /", ], Array [ [Error: options.statusCode is expected to be set. given options: undefined], @@ -1874,7 +1874,7 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ Array [ - "500 Server Error - http://127.0.0.1:50275/", + "500 Server Error - /", ], Array [ [Error: Unexpected Http status code. Expected from 100 to 599, but given: 20.], From fda01956121eaaf5607aee3717ee8f0d4a8da875 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Thu, 31 Aug 2023 15:15:08 +0200 Subject: [PATCH 14/15] Revert changes in router.ts (separate PR) --- .../src/router.ts | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/packages/core/http/core-http-router-server-internal/src/router.ts b/packages/core/http/core-http-router-server-internal/src/router.ts index 5415e92ba272d..617c810109138 100644 --- a/packages/core/http/core-http-router-server-internal/src/router.ts +++ b/packages/core/http/core-http-router-server-internal/src/router.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { Request, ResponseToolkit, RequestQuery } from '@hapi/hapi'; +import type { Request, ResponseToolkit } from '@hapi/hapi'; import apm from 'elastic-apm-node'; import { isConfigSchema } from '@kbn/config-schema'; import type { Logger } from '@kbn/logging'; @@ -200,8 +200,6 @@ export class Router = T extends (first: any, ...rest: infer Params) => i type RequestHandlerEnhanced = WithoutHeadArgument< RequestHandler >; - -function toString(requestQuery?: RequestQuery): string { - const entries = Object.entries(requestQuery ?? {}); - - if (!entries?.length) { - return ''; - } - - return `?` + entries.map(([key, value]) => `${key}=${value}`).join('&'); -} From e1d93c1c4a0881dd824007c7866876445a79ac29 Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Thu, 31 Aug 2023 16:48:12 +0200 Subject: [PATCH 15/15] Undo changes in router.test.ts --- .../integration_tests/http/router.test.ts | 49 ++----------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/src/core/server/integration_tests/http/router.test.ts b/src/core/server/integration_tests/http/router.test.ts index f31fc70edb955..743624f2f46b3 100644 --- a/src/core/server/integration_tests/http/router.test.ts +++ b/src/core/server/integration_tests/http/router.test.ts @@ -576,14 +576,11 @@ describe('Handler', () => { 'An internal server error occurred. Check Kibana server logs for details.' ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` - Array [ - Array [ - "500 Server Error - /", - ], Array [ - [Error: unexpected error], - ], - ] + Array [ + [Error: unexpected error], + ], + ] `); }); @@ -619,9 +616,6 @@ describe('Handler', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: Unauthorized], ], @@ -644,9 +638,6 @@ describe('Handler', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: Unexpected result from Route Handler. Expected KibanaResponse, but given: string.], ], @@ -681,17 +672,6 @@ describe('Handler', () => { message: '[request query.page]: expected value of type [number] but got [string]', statusCode: 400, }); - - expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` - Array [ - Array [ - "400 Bad Request - /?page=one", - ], - Array [ - [Error: [request query.page]: expected value of type [number] but got [string]], - ], - ] - `); }); it('accept to receive an array payload', async () => { @@ -1164,9 +1144,6 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: expected 'location' header to be set], ], @@ -1573,9 +1550,6 @@ describe('Response factory', () => { }); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: Unexpected Http status code. Expected from 400 to 599, but given: 200], ], @@ -1645,9 +1619,6 @@ describe('Response factory', () => { expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: expected 'location' header to be set], ], @@ -1788,9 +1759,6 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: expected error message to be provided], ], @@ -1817,9 +1785,6 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: expected error message to be provided], ], @@ -1845,9 +1810,6 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: options.statusCode is expected to be set. given options: undefined], ], @@ -1873,9 +1835,6 @@ describe('Response factory', () => { ); expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` Array [ - Array [ - "500 Server Error - /", - ], Array [ [Error: Unexpected Http status code. Expected from 100 to 599, but given: 20.], ],