From b81421135df48e25a75909b84ea26b75116ab8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20=C3=81brah=C3=A1m?= Date: Tue, 29 Oct 2024 11:52:36 +0100 Subject: [PATCH] [EDR Workflows] Improve on unavailable shard exception flakiness in cypress (#197864) ## Summary The cypress task `cy.task('indexEndpointHosts')` sometimes throws `no_shard_available_action_exception`, when transforms are stopped. This looks like a temporary issue, and in other tests it is simply retried. This PR adds the retry logic for this type of error, and unskips some tests. closes #194135 closes #191914 ### Checklist Delete any items that are not applicable to this PR. - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed (cherry picked from commit db18039dc40bc0e994be666a83a28a0452a0c6e2) --- .../e2e/artifacts/artifacts_mocked_data.cy.ts | 3 +- .../plugin_handlers/endpoint_data_loader.ts | 44 ++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/cypress/e2e/artifacts/artifacts_mocked_data.cy.ts b/x-pack/plugins/security_solution/public/management/cypress/e2e/artifacts/artifacts_mocked_data.cy.ts index 6ab7979c46086..b5c41d1e66faf 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/e2e/artifacts/artifacts_mocked_data.cy.ts +++ b/x-pack/plugins/security_solution/public/management/cypress/e2e/artifacts/artifacts_mocked_data.cy.ts @@ -35,8 +35,7 @@ const loginWithoutAccess = (url: string) => { loadPage(url); }; -// Failing: See https://github.com/elastic/kibana/issues/191914 -describe.skip('Artifacts pages', { tags: ['@ess', '@serverless', '@skipInServerlessMKI'] }, () => { +describe('Artifacts pages', { tags: ['@ess', '@serverless', '@skipInServerlessMKI'] }, () => { let endpointData: ReturnTypeFromChainable | undefined; before(() => { diff --git a/x-pack/plugins/security_solution/public/management/cypress/support/plugin_handlers/endpoint_data_loader.ts b/x-pack/plugins/security_solution/public/management/cypress/support/plugin_handlers/endpoint_data_loader.ts index 76004f91ccb48..4b4e9adef0ec2 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/support/plugin_handlers/endpoint_data_loader.ts +++ b/x-pack/plugins/security_solution/public/management/cypress/support/plugin_handlers/endpoint_data_loader.ts @@ -10,6 +10,10 @@ import type { KbnClient } from '@kbn/test'; import pRetry from 'p-retry'; import { kibanaPackageJson } from '@kbn/repo-info'; import type { ToolingLog } from '@kbn/tooling-log'; +import { + RETRYABLE_TRANSIENT_ERRORS, + retryOnError, +} from '../../../../../common/endpoint/data_loaders/utils'; import { fetchFleetLatestAvailableAgentVersion } from '../../../../../common/endpoint/utils/fetch_fleet_version'; import { dump } from '../../../../../scripts/endpoint/common/utils'; import { STARTED_TRANSFORM_STATES } from '../../../../../common/constants'; @@ -158,18 +162,17 @@ const stopTransform = async ( ): Promise => { log.debug(`Stopping transform id: ${transformId}`); - await esClient.transform - .stopTransform({ - transform_id: `${transformId}*`, - force: true, - wait_for_completion: true, - allow_no_match: true, - }) - .catch((e) => { - Error.captureStackTrace(e); - log.verbose(dump(e, 8)); - throw e; - }); + await retryOnError( + () => + esClient.transform.stopTransform({ + transform_id: `${transformId}*`, + force: true, + wait_for_completion: true, + allow_no_match: true, + }), + RETRYABLE_TRANSIENT_ERRORS, + log + ); }; const startTransform = async ( @@ -177,9 +180,14 @@ const startTransform = async ( log: ToolingLog, transformId: string ): Promise => { - const transformsResponse = await esClient.transform.getTransformStats({ - transform_id: `${transformId}*`, - }); + const transformsResponse = await retryOnError( + () => + esClient.transform.getTransformStats({ + transform_id: `${transformId}*`, + }), + RETRYABLE_TRANSIENT_ERRORS, + log + ); log.verbose( `Transform status found for [${transformId}*] returned:\n${dump(transformsResponse)}` @@ -193,7 +201,11 @@ const startTransform = async ( log.debug(`Staring transform id: [${transform.id}]`); - return esClient.transform.startTransform({ transform_id: transform.id }); + return retryOnError( + () => esClient.transform.startTransform({ transform_id: transform.id }), + RETRYABLE_TRANSIENT_ERRORS, + log + ); }) ); };