From a50b97fb2382213c88f65bc7317caa792c3c0750 Mon Sep 17 00:00:00 2001 From: "Joey F. Poon" Date: Mon, 11 Dec 2023 08:59:53 -0800 Subject: [PATCH] [Security Solution] fix endpoint list + metadata api FTR tests (#170489) --- .../fleet/server/services/epm/elasticsearch/retry.ts | 3 +++ .../common/endpoint/utils/package_v2.ts | 9 +++++++-- .../apps/endpoint/endpoint_list.ts | 3 +-- .../apps/endpoint/responder.ts | 3 ++- .../security_solution_endpoint/services/endpoint.ts | 11 +++++++++-- .../apis/metadata.ts | 3 +-- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/retry.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/retry.ts index 773ed7273d885..32d0c9e23fb78 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/retry.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/retry.ts @@ -17,7 +17,10 @@ const retryResponseStatuses = [ 410, // Gone ]; +const retryMessages = ['no_shard_available_action_exception']; + const isRetryableError = (e: any, additionalResponseStatuses: number[] = []) => + retryMessages.some((msg) => e.message.includes(msg)) || e instanceof EsErrors.NoLivingConnectionsError || e instanceof EsErrors.ConnectionError || e instanceof EsErrors.TimeoutError || diff --git a/x-pack/plugins/security_solution/common/endpoint/utils/package_v2.ts b/x-pack/plugins/security_solution/common/endpoint/utils/package_v2.ts index 926949bf9cd7f..fffa55ccbe514 100644 --- a/x-pack/plugins/security_solution/common/endpoint/utils/package_v2.ts +++ b/x-pack/plugins/security_solution/common/endpoint/utils/package_v2.ts @@ -7,7 +7,12 @@ import semverLte from 'semver/functions/lte'; -const MIN_ENDPOINT_PACKAGE_V2_VERSION = '8.12.0'; +function parseSemver(semver: string) { + return semver.includes('-') ? semver.substring(0, semver.indexOf('-')) : semver; +} + +const MIN_ENDPOINT_PACKAGE_V2_VERSION = '8.13.0'; export function isEndpointPackageV2(version: string) { - return semverLte(MIN_ENDPOINT_PACKAGE_V2_VERSION, version); + const parsedVersion = parseSemver(version); + return semverLte(MIN_ENDPOINT_PACKAGE_V2_VERSION, parsedVersion); } diff --git a/x-pack/test/security_solution_endpoint/apps/endpoint/endpoint_list.ts b/x-pack/test/security_solution_endpoint/apps/endpoint/endpoint_list.ts index c1eed560a2142..f1edd7a45800c 100644 --- a/x-pack/test/security_solution_endpoint/apps/endpoint/endpoint_list.ts +++ b/x-pack/test/security_solution_endpoint/apps/endpoint/endpoint_list.ts @@ -117,8 +117,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await pageObjects.endpoint.navigateToEndpointList(); }); - // FLAKY: https://github.com/elastic/kibana/issues/170357 - describe.skip('when there is data,', () => { + describe('when there is data,', () => { before(async () => { indexedData = await endpointTestResources.loadEndpointData({ numHosts: 3 }); await pageObjects.endpoint.navigateToEndpointList(); diff --git a/x-pack/test/security_solution_endpoint/apps/endpoint/responder.ts b/x-pack/test/security_solution_endpoint/apps/endpoint/responder.ts index bcc3177846d37..6f00806e67c05 100644 --- a/x-pack/test/security_solution_endpoint/apps/endpoint/responder.ts +++ b/x-pack/test/security_solution_endpoint/apps/endpoint/responder.ts @@ -82,7 +82,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { ); }; - describe('Response Actions Responder', function () { + // FLAKY: https://github.com/elastic/kibana/issues/153071 + describe.skip('Response Actions Responder', function () { targetTags(this, ['@ess', '@serverless']); let indexedData: IndexedHostsAndAlertsResponse; diff --git a/x-pack/test/security_solution_endpoint/services/endpoint.ts b/x-pack/test/security_solution_endpoint/services/endpoint.ts index 1372ffe0139fd..b4b5e5aef96bf 100644 --- a/x-pack/test/security_solution_endpoint/services/endpoint.ts +++ b/x-pack/test/security_solution_endpoint/services/endpoint.ts @@ -9,6 +9,7 @@ import { errors } from '@elastic/elasticsearch'; import { Client } from '@elastic/elasticsearch'; +import { AGENTS_INDEX } from '@kbn/fleet-plugin/common'; import { metadataCurrentIndexPattern, metadataTransformPrefix, @@ -94,7 +95,7 @@ export class EndpointTestResources extends FtrService { * @param [options.enableFleetIntegration=true] When set to `true`, Fleet data will also be loaded (ex. Integration Policies, Agent Policies, "fake" Agents) * @param [options.generatorSeed='seed`] The seed to be used by the data generator. Important in order to ensure the same data is generated on very run. * @param [options.waitUntilTransformed=true] If set to `true`, the data loading process will wait until the endpoint hosts metadata is processed by the transform - * @param [options.waitTimeout=60000] If waitUntilTransformed=true, number of ms to wait until timeout + * @param [options.waitTimeout=120000] If waitUntilTransformed=true, number of ms to wait until timeout * @param [options.customIndexFn] If provided, will use this function to generate and index data instead */ async loadEndpointData( @@ -116,7 +117,7 @@ export class EndpointTestResources extends FtrService { enableFleetIntegration = true, generatorSeed = 'seed', waitUntilTransformed = true, - waitTimeout = 60000, + waitTimeout = 120000, customIndexFn, } = options; @@ -197,6 +198,12 @@ export class EndpointTestResources extends FtrService { await this.retry.waitForWithTimeout(`endpoint hosts in ${index}`, timeout, async () => { try { + if (index === METADATA_UNITED_INDEX) { + // United metadata transform occasionally can't find docs in .fleet-agents. + // Running a search on the index first eliminates this issue. + // Replacing the search with a refresh does not resolve flakiness. + await this.esClient.search({ index: AGENTS_INDEX }); + } const searchResponse = await this.esClient.search({ index, size, diff --git a/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts b/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts index 3ac6c83938c14..0e118cf88e4b9 100644 --- a/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts +++ b/x-pack/test/security_solution_endpoint_api_int/apis/metadata.ts @@ -47,8 +47,7 @@ export default function ({ getService }: FtrProviderContext) { const endpointTestResources = getService('endpointTestResources'); const log = getService('log'); - // Failing: See https://github.com/elastic/kibana/issues/151854 - describe.skip('test metadata apis', function () { + describe('test metadata apis', function () { targetTags(this, ['@ess', '@serverless']); describe('list endpoints GET route', () => {