Skip to content

Commit

Permalink
[8.16] [EDR Workflows] Improve on unavailable shard exception flakine…
Browse files Browse the repository at this point in the history
…ss in cypress (#197864) (#198137)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[EDR Workflows] Improve on unavailable shard exception flakiness in
cypress (#197864)](#197864)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Gergő
Ábrahám","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-29T10:52:36Z","message":"[EDR
Workflows] Improve on unavailable shard exception flakiness in cypress
(#197864)\n\n## Summary\r\n\r\nThe cypress task
`cy.task('indexEndpointHosts')` sometimes
throws\r\n`no_shard_available_action_exception`, when transforms are
stopped. This\r\nlooks like a temporary issue, and in other tests it is
simply retried.\r\n\r\nThis PR adds the retry logic for this type of
error, and unskips some\r\ntests.\r\n\r\ncloses #194135\r\ncloses
#191914\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n- [x] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"db18039dc40bc0e994be666a83a28a0452a0c6e2","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Defend
Workflows","v8.16.0","backport:version","v8.17.0"],"title":"[EDR
Workflows] Improve on unavailable shard exception flakiness in
cypress","number":197864,"url":"https://github.com/elastic/kibana/pull/197864","mergeCommit":{"message":"[EDR
Workflows] Improve on unavailable shard exception flakiness in cypress
(#197864)\n\n## Summary\r\n\r\nThe cypress task
`cy.task('indexEndpointHosts')` sometimes
throws\r\n`no_shard_available_action_exception`, when transforms are
stopped. This\r\nlooks like a temporary issue, and in other tests it is
simply retried.\r\n\r\nThis PR adds the retry logic for this type of
error, and unskips some\r\ntests.\r\n\r\ncloses #194135\r\ncloses
#191914\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n- [x] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"db18039dc40bc0e994be666a83a28a0452a0c6e2"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197864","number":197864,"mergeCommit":{"message":"[EDR
Workflows] Improve on unavailable shard exception flakiness in cypress
(#197864)\n\n## Summary\r\n\r\nThe cypress task
`cy.task('indexEndpointHosts')` sometimes
throws\r\n`no_shard_available_action_exception`, when transforms are
stopped. This\r\nlooks like a temporary issue, and in other tests it is
simply retried.\r\n\r\nThis PR adds the retry logic for this type of
error, and unskips some\r\ntests.\r\n\r\ncloses #194135\r\ncloses
#191914\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n- [x] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"db18039dc40bc0e994be666a83a28a0452a0c6e2"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Gergő Ábrahám <[email protected]>
  • Loading branch information
kibanamachine and gergoabraham authored Oct 30, 2024
1 parent 678244f commit b7c8696
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof indexEndpointHosts> | undefined;

before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -158,28 +162,32 @@ const stopTransform = async (
): Promise<void> => {
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 (
esClient: Client,
log: ToolingLog,
transformId: string
): Promise<void> => {
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)}`
Expand All @@ -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
);
})
);
};
Expand Down

0 comments on commit b7c8696

Please sign in to comment.