Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.13] [kbn-ftr-common-functional-services] extend retry service (#17…
…8660) (#178978) # Backport This will backport the following commits from `main` to `8.13`: - [[kbn-ftr-common-functional-services] extend retry service (#178660)](#178660) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Dzmitry Lemechko","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-03-19T15:32:59Z","message":"[kbn-ftr-common-functional-services] extend retry service (#178660)\n\n## Summary\r\n\r\nI took the retry wrapper created by\r\n[jpdjere](https://github.com/jpdjere) in #173998 and extended\r\n`retryForSuccess<T>` with required capabilities to provide the same\r\nfunctionality.\r\n\r\nThis PR:\r\n1) extends retry service with new function `tryWithRetries<T> => :\r\nPromise<T>` to retry block `options.retryCount` times within\r\n`options.timeout` period and return block result\r\n\r\n```ts\r\n const response = await retry.tryWithRetries<SearchResponse>(\r\n 'search request',\r\n async () => {\r\n const response = await supertest\r\n .post(`/internal/search/es`)\r\n .set(ELASTIC_HTTP_VERSION_HEADER, '1')\r\n .send({\r\n params: {\r\n body: {\r\n query: {\r\n match_all: {},\r\n },\r\n },\r\n },\r\n })\r\n .expect(200);\r\n return response.body as SearchResponse;\r\n },\r\n {\r\n retryCount: 4,\r\n retryDelay: 100, // optional\r\n timeout: 30000, // optional\r\n }\r\n```\r\n\r\n2) removes `utils/retry.ts` wrapper and migrate tests to FTR Retry\r\nservice\r\n3) Adds descriptions to Retry service functions explaining the default\r\nuse case\r\n\r\nHow the failures look like:\r\n\r\n- when reached timeout before retry count limit \r\n```\r\n Error: retry.tryWithRetries reached timeout 11000 ms waiting for 'run console request'\r\n Error: expected '# Click the Variables button, above, to create your own variables.\\nGET ${exampleVariable1} // _search\\n{\\n \"query\": {\\n \"${exampleVariable2}\": {} // match_all\\n }\\n}' to sort of equal '5'\r\n at Assertion.assert (expect.js:100:11)\r\n at Assertion.eql (expect.js:244:8)\r\n at _console.ts:47:41\r\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\r\n at runAttempt (retry_with_retries.ts:29:15)\r\n at retryWithRetries (retry_with_retries.ts:97:21)\r\n at RetryService.tryForTime (retry.ts:38:12)\r\n at Context.<anonymous> (_console.ts:44:7)\r\n at Object.apply (wrap_function.js:73:16)\r\n```\r\n- when reached retry count limit before timeout\r\n```\r\n Error: retry.tryWithRetries reached the limit of attempts waiting for 'run console request': 2 out of 2\r\n Error: expected '# Click the Variables button, above, to create your own variables.\\nGET ${exampleVariable1} // _search\\n{\\n \"query\": {\\n \"${exampleVariable2}\": {} // match_all\\n }\\n}' to sort of equal '5'\r\n at Assertion.assert (expect.js:100:11)\r\n at Assertion.eql (expect.js:244:8)\r\n at _console.ts:47:41\r\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\r\n at runAttempt (retry_for_success.ts:29:15)\r\n at retryForSuccess (retry_for_success.ts:97:21)\r\n at RetryService.tryWithRetries (retry.ts:115:12)\r\n at Context.<anonymous> (_console.ts:44:7)\r\n at Object.apply (wrap_function.js:73:16)\r\n```","sha":"277b3fbc24889bedd512f23674e768d2f4c43294","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","FTR","v8.14.0","v8.13.1"],"title":"[kbn-ftr-common-functional-services] extend retry service","number":178660,"url":"https://github.com/elastic/kibana/pull/178660","mergeCommit":{"message":"[kbn-ftr-common-functional-services] extend retry service (#178660)\n\n## Summary\r\n\r\nI took the retry wrapper created by\r\n[jpdjere](https://github.com/jpdjere) in #173998 and extended\r\n`retryForSuccess<T>` with required capabilities to provide the same\r\nfunctionality.\r\n\r\nThis PR:\r\n1) extends retry service with new function `tryWithRetries<T> => :\r\nPromise<T>` to retry block `options.retryCount` times within\r\n`options.timeout` period and return block result\r\n\r\n```ts\r\n const response = await retry.tryWithRetries<SearchResponse>(\r\n 'search request',\r\n async () => {\r\n const response = await supertest\r\n .post(`/internal/search/es`)\r\n .set(ELASTIC_HTTP_VERSION_HEADER, '1')\r\n .send({\r\n params: {\r\n body: {\r\n query: {\r\n match_all: {},\r\n },\r\n },\r\n },\r\n })\r\n .expect(200);\r\n return response.body as SearchResponse;\r\n },\r\n {\r\n retryCount: 4,\r\n retryDelay: 100, // optional\r\n timeout: 30000, // optional\r\n }\r\n```\r\n\r\n2) removes `utils/retry.ts` wrapper and migrate tests to FTR Retry\r\nservice\r\n3) Adds descriptions to Retry service functions explaining the default\r\nuse case\r\n\r\nHow the failures look like:\r\n\r\n- when reached timeout before retry count limit \r\n```\r\n Error: retry.tryWithRetries reached timeout 11000 ms waiting for 'run console request'\r\n Error: expected '# Click the Variables button, above, to create your own variables.\\nGET ${exampleVariable1} // _search\\n{\\n \"query\": {\\n \"${exampleVariable2}\": {} // match_all\\n }\\n}' to sort of equal '5'\r\n at Assertion.assert (expect.js:100:11)\r\n at Assertion.eql (expect.js:244:8)\r\n at _console.ts:47:41\r\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\r\n at runAttempt (retry_with_retries.ts:29:15)\r\n at retryWithRetries (retry_with_retries.ts:97:21)\r\n at RetryService.tryForTime (retry.ts:38:12)\r\n at Context.<anonymous> (_console.ts:44:7)\r\n at Object.apply (wrap_function.js:73:16)\r\n```\r\n- when reached retry count limit before timeout\r\n```\r\n Error: retry.tryWithRetries reached the limit of attempts waiting for 'run console request': 2 out of 2\r\n Error: expected '# Click the Variables button, above, to create your own variables.\\nGET ${exampleVariable1} // _search\\n{\\n \"query\": {\\n \"${exampleVariable2}\": {} // match_all\\n }\\n}' to sort of equal '5'\r\n at Assertion.assert (expect.js:100:11)\r\n at Assertion.eql (expect.js:244:8)\r\n at _console.ts:47:41\r\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\r\n at runAttempt (retry_for_success.ts:29:15)\r\n at retryForSuccess (retry_for_success.ts:97:21)\r\n at RetryService.tryWithRetries (retry.ts:115:12)\r\n at Context.<anonymous> (_console.ts:44:7)\r\n at Object.apply (wrap_function.js:73:16)\r\n```","sha":"277b3fbc24889bedd512f23674e768d2f4c43294"}},"sourceBranch":"main","suggestedTargetBranches":["8.13"],"targetPullRequestStates":[{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/178660","number":178660,"mergeCommit":{"message":"[kbn-ftr-common-functional-services] extend retry service (#178660)\n\n## Summary\r\n\r\nI took the retry wrapper created by\r\n[jpdjere](https://github.com/jpdjere) in #173998 and extended\r\n`retryForSuccess<T>` with required capabilities to provide the same\r\nfunctionality.\r\n\r\nThis PR:\r\n1) extends retry service with new function `tryWithRetries<T> => :\r\nPromise<T>` to retry block `options.retryCount` times within\r\n`options.timeout` period and return block result\r\n\r\n```ts\r\n const response = await retry.tryWithRetries<SearchResponse>(\r\n 'search request',\r\n async () => {\r\n const response = await supertest\r\n .post(`/internal/search/es`)\r\n .set(ELASTIC_HTTP_VERSION_HEADER, '1')\r\n .send({\r\n params: {\r\n body: {\r\n query: {\r\n match_all: {},\r\n },\r\n },\r\n },\r\n })\r\n .expect(200);\r\n return response.body as SearchResponse;\r\n },\r\n {\r\n retryCount: 4,\r\n retryDelay: 100, // optional\r\n timeout: 30000, // optional\r\n }\r\n```\r\n\r\n2) removes `utils/retry.ts` wrapper and migrate tests to FTR Retry\r\nservice\r\n3) Adds descriptions to Retry service functions explaining the default\r\nuse case\r\n\r\nHow the failures look like:\r\n\r\n- when reached timeout before retry count limit \r\n```\r\n Error: retry.tryWithRetries reached timeout 11000 ms waiting for 'run console request'\r\n Error: expected '# Click the Variables button, above, to create your own variables.\\nGET ${exampleVariable1} // _search\\n{\\n \"query\": {\\n \"${exampleVariable2}\": {} // match_all\\n }\\n}' to sort of equal '5'\r\n at Assertion.assert (expect.js:100:11)\r\n at Assertion.eql (expect.js:244:8)\r\n at _console.ts:47:41\r\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\r\n at runAttempt (retry_with_retries.ts:29:15)\r\n at retryWithRetries (retry_with_retries.ts:97:21)\r\n at RetryService.tryForTime (retry.ts:38:12)\r\n at Context.<anonymous> (_console.ts:44:7)\r\n at Object.apply (wrap_function.js:73:16)\r\n```\r\n- when reached retry count limit before timeout\r\n```\r\n Error: retry.tryWithRetries reached the limit of attempts waiting for 'run console request': 2 out of 2\r\n Error: expected '# Click the Variables button, above, to create your own variables.\\nGET ${exampleVariable1} // _search\\n{\\n \"query\": {\\n \"${exampleVariable2}\": {} // match_all\\n }\\n}' to sort of equal '5'\r\n at Assertion.assert (expect.js:100:11)\r\n at Assertion.eql (expect.js:244:8)\r\n at _console.ts:47:41\r\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\r\n at runAttempt (retry_for_success.ts:29:15)\r\n at retryForSuccess (retry_for_success.ts:97:21)\r\n at RetryService.tryWithRetries (retry.ts:115:12)\r\n at Context.<anonymous> (_console.ts:44:7)\r\n at Object.apply (wrap_function.js:73:16)\r\n```","sha":"277b3fbc24889bedd512f23674e768d2f4c43294"}},{"branch":"8.13","label":"v8.13.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Dzmitry Lemechko <[email protected]>
- Loading branch information