From 116cd9d1708bb698f704689f388c2001361978ef Mon Sep 17 00:00:00 2001 From: Davis McPhee Date: Fri, 8 Nov 2024 17:34:35 -0400 Subject: [PATCH] Fix missing params from search strategy polling requests causing validation errors in tests (#199539) ## Summary This PR fixes an issue introduced in #196962 where search strategy polling requests sent from some integration tests were missing necessary body parameters, resulting in validation errors and test failures. This issue was not caught by CI in the original PR because it only occurs when a search request runs slow enough to return partial results (and therefore requires polling), which is not common in test runs. Fixes #199537 Fixes #199499 Fixes #199460 Fixes #199449 Fixes #199412 Fixes #199410 Fixes #199394 Fixes #199379 Fixes #199372 Fixes #199363 Fixes #199541 Fixes #199446 Fixes #199433 Fixes #199432 Fixes #199381 Fixes #199369 Fixes #199364 Flaky test runner x200: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7362. ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels) - [ ] This will appear in the **Release Notes** and follow the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --- .../services/search.ts | 2 +- .../common/utils/parse_b_fetch.ts | 15 --------------- x-pack/test/common/services/search_secure.ts | 15 +++------------ .../tests/network_dns.ts | 3 +-- .../tests/network_top_n_flow.ts | 3 +-- .../shared/services/search_secure.ts | 15 +++------------ 6 files changed, 9 insertions(+), 44 deletions(-) delete mode 100644 x-pack/test/apm_api_integration/common/utils/parse_b_fetch.ts diff --git a/packages/kbn-ftr-common-functional-services/services/search.ts b/packages/kbn-ftr-common-functional-services/services/search.ts index c087f1d8bb913..2c9e0f558a365 100644 --- a/packages/kbn-ftr-common-functional-services/services/search.ts +++ b/packages/kbn-ftr-common-functional-services/services/search.ts @@ -73,7 +73,7 @@ export class SearchService extends FtrService { .post(`${spaceUrl}/internal/search/${strategy}/${body.id}`) .set('kbn-xsrf', 'true') .set(ELASTIC_HTTP_VERSION_HEADER, '1') - .send() + .send(options) .expect(200); expect(resp.body.isRunning).equal(false); return resp.body as T; diff --git a/x-pack/test/apm_api_integration/common/utils/parse_b_fetch.ts b/x-pack/test/apm_api_integration/common/utils/parse_b_fetch.ts deleted file mode 100644 index 79ea70f7199f9..0000000000000 --- a/x-pack/test/apm_api_integration/common/utils/parse_b_fetch.ts +++ /dev/null @@ -1,15 +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 request from 'superagent'; - -export function parseBfetchResponse(resp: request.Response): Array> { - return resp.text - .trim() - .split('\n') - .map((item) => JSON.parse(item)); -} diff --git a/x-pack/test/common/services/search_secure.ts b/x-pack/test/common/services/search_secure.ts index 93654fddd611a..f46e9e57ef275 100644 --- a/x-pack/test/common/services/search_secure.ts +++ b/x-pack/test/common/services/search_secure.ts @@ -9,20 +9,12 @@ // but with the ability to provide custom auth import expect from '@kbn/expect'; -import request from 'superagent'; import type { IEsSearchResponse } from '@kbn/search-types'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { BFETCH_ROUTE_VERSION_LATEST } from '@kbn/bfetch-plugin/common'; import { SupertestWithoutAuthProviderType } from '@kbn/ftr-common-functional-services'; import { FtrService } from '../ftr_provider_context'; -const parseBfetchResponse = (resp: request.Response): Array> => { - return resp.text - .trim() - .split('\n') - .map((item) => JSON.parse(item)); -}; - const getSpaceUrlPrefix = (spaceId?: string): string => { return spaceId && spaceId !== 'default' ? `/s/${spaceId}` : ``; }; @@ -114,11 +106,10 @@ export class SearchSecureService extends FtrService { .set('kbn-xsrf', 'true') .set('x-elastic-internal-origin', 'Kibana') .set(ELASTIC_HTTP_VERSION_HEADER, BFETCH_ROUTE_VERSION_LATEST) - .send() + .send(options) .expect(200); - const [parsedResponse] = parseBfetchResponse(resp); - expect(parsedResponse.result.isRunning).equal(false); - return parsedResponse.result; + expect(resp.body.isRunning).equal(false); + return resp.body; }); return result as T; diff --git a/x-pack/test/security_solution_api_integration/test_suites/explore/network/trial_license_complete_tier/tests/network_dns.ts b/x-pack/test/security_solution_api_integration/test_suites/explore/network/trial_license_complete_tier/tests/network_dns.ts index fd6009c82df09..cab4ee31744f6 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/explore/network/trial_license_complete_tier/tests/network_dns.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/explore/network/trial_license_complete_tier/tests/network_dns.ts @@ -21,8 +21,7 @@ export default function ({ getService }: FtrProviderContextWithSpaces) { const esArchiver = getService('esArchiver'); const utils = getService('securitySolutionUtils'); - // Failing: See https://github.com/elastic/kibana/issues/199372 - describe.skip('Network DNS', () => { + describe('Network DNS', () => { let supertest: TestAgent; let search: SearchService; describe('With packetbeat', () => { diff --git a/x-pack/test/security_solution_api_integration/test_suites/explore/network/trial_license_complete_tier/tests/network_top_n_flow.ts b/x-pack/test/security_solution_api_integration/test_suites/explore/network/trial_license_complete_tier/tests/network_top_n_flow.ts index 4c316e774ebbd..31eabe76ee0e1 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/explore/network/trial_license_complete_tier/tests/network_top_n_flow.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/explore/network/trial_license_complete_tier/tests/network_top_n_flow.ts @@ -25,8 +25,7 @@ export default function ({ getService }: FtrProviderContextWithSpaces) { const esArchiver = getService('esArchiver'); const utils = getService('securitySolutionUtils'); - // FLAKY: https://github.com/elastic/kibana/issues/199363 - describe.skip('Network Top N Flow', () => { + describe('Network Top N Flow', () => { let supertest: TestAgent; let search: SearchService; describe('With filebeat', () => { diff --git a/x-pack/test_serverless/shared/services/search_secure.ts b/x-pack/test_serverless/shared/services/search_secure.ts index 7db246dc4ccdf..f0130203dd9b9 100644 --- a/x-pack/test_serverless/shared/services/search_secure.ts +++ b/x-pack/test_serverless/shared/services/search_secure.ts @@ -10,19 +10,11 @@ import expect from '@kbn/expect'; import { GenericFtrService } from '@kbn/test'; -import request from 'superagent'; import type { IEsSearchResponse } from '@kbn/search-types'; import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { SupertestWithoutAuthProviderType } from '@kbn/ftr-common-functional-services'; import { FtrProviderContext } from '../../functional/ftr_provider_context'; -const parseBfetchResponse = (resp: request.Response): Array> => { - return resp.text - .trim() - .split('\n') - .map((item) => JSON.parse(item)); -}; - export interface SendOptions { supertestWithoutAuth: SupertestWithoutAuthProviderType; apiKeyHeader: { Authorization: string }; @@ -108,11 +100,10 @@ export class SearchSecureService extends GenericFtrService { .set('kbn-xsrf', 'true') .set('x-elastic-internal-origin', 'Kibana') .set(ELASTIC_HTTP_VERSION_HEADER, '1') - .send() + .send(options) .expect(200); - const [parsedResponse] = parseBfetchResponse(resp); - expect(parsedResponse.result.isRunning).equal(false); - return parsedResponse.result; + expect(resp.body.isRunning).equal(false); + return resp.body; }); return result as T;