From 8805e74f5d957ac5751227c5463032cc82794852 Mon Sep 17 00:00:00 2001 From: Kevin Logan <56395104+kevinlog@users.noreply.github.com> Date: Mon, 23 Oct 2023 08:34:34 -0400 Subject: [PATCH] [EDR Workflows] Catch docker container deletion error (#168982) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This PR will have our `after:run` task catch potential errors when cleaning up the docker container used. There were instances where our tests were failing to complete properly because we were failing at this step: https://buildkite.com/elastic/kibana-pull-request/builds/168052#018b37fc-b2b1-4986-8c11-0701f447d972/6-2209 ``` An error was thrown in your plugins file while executing the handler for the after:run event. --   |     | The error we received was:   |     | Error: Command failed with exit code 1: docker kill 4080ac06a71871298f2a3163c915f0170e8f3dd9f6814e022d727e9958401361   | Error response from daemon: Cannot kill container: 4080ac06a71871298f2a3163c915f0170e8f3dd9f6814e022d727e9958401361: No such container: 4080ac06a71871298f2a3163c915f0170e8f3dd9f6814e022d727e9958401361   | at makeError (/opt/local-ssd/buildkite/builds/kb-n2-4-virt-debbcb53f059032d/elastic/kibana-pull-request/kibana/node_modules/execa/lib/error.js:60:11)   | at Function.module.exports.sync (/opt/local-ssd/buildkite/builds/kb-n2-4-virt-debbcb53f059032d/elastic/kibana-pull-request/kibana/node_modules/execa/index.js:194:17)   | at Object.handler (/opt/local-ssd/buildkite/builds/kb-n2-4-virt-debbcb53f059032d/elastic/kibana-pull-request/kibana/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts:321:13)   | at invoke (/var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:183:18)   | at /var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:59:14   | at tryCatcher (/var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/bluebird/js/release/util.js:16:23)   | at Function.Promise.attempt.Promise.try (/var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/bluebird/js/release/method.js:39:29)   | at Object.wrapChildPromise (/var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:58:23)   | at RunPlugins.execute (/var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:164:21)   | at EventEmitter. (/var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_plugins.js:56:12)   | at EventEmitter.emit (node:events:514:28)   | at EventEmitter.emit (node:domain:489:12)   | at process. (/var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/util.js:33:22)   | at process.emit (node:events:514:28)   | at process.emit (node:domain:489:12)   | at process.emit.sharedData.processEmitHook.installedValue [as emit] (/var/lib/buildkite-agent/.cache/Cypress/13.3.0/Cypress/resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)   | at emit (node:internal/child_process:937:14)   | at processTicksAndRejections (node:internal/process/task_queues:83:21) ``` In addition, I have a flaky test runner to ensure that we don't fail due to this error again: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3527 2nd flaky run: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3535 3rd flaky run ✅ : https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3592#_ - Note this run has a couple failures but they are on unrelated flaky tests that are being addressed in other PRs. ### Checklist - [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 --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Patryk Kopyciński --- .../public/management/cypress/support/data_loaders.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts b/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts index 93614b6dbb86d..82f9af7e114d2 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts +++ b/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts @@ -316,9 +316,14 @@ export const dataLoadersForRealEndpoints = ( fleetServerContainerId = data?.fleetServerContainerId; }); - on('after:run', () => { + on('after:run', async () => { + const { log } = await stackServicesPromise; if (fleetServerContainerId) { - execa.sync('docker', ['kill', fleetServerContainerId]); + try { + execa.sync('docker', ['kill', fleetServerContainerId]); + } catch (error) { + log.error(error); + } } });