From e13f1c5fb20f0526d5f247f1e6fa250083097c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20C=C3=B4t=C3=A9?= Date: Wed, 29 Mar 2023 09:02:38 -0400 Subject: [PATCH] Fix flaky RBAC Legacy test due to archive containing tasks and rules together (#153803) Resolves https://github.com/elastic/kibana/issues/153800 Resolves https://github.com/elastic/kibana/issues/142704 Resolves https://github.com/elastic/kibana/issues/153801 Resolves https://github.com/elastic/kibana/issues/142947 Resolves https://github.com/elastic/kibana/issues/140867 Similar to https://github.com/elastic/kibana/pull/152841#discussion_r1147716618, the rule and tasks archives don't seem to play nicely when combined. The flakiness goes away when loading the rules then the tasks in sequence. Otherwise, the tasks sometimes run before it can find the rule, causing the task to delete itself. I took a look at why the task would run an not be able to find the rule. My best guess after looking at a failing flaky test is that the task manager migration completes before the .kibana. And while .kibana migrates, the task runs and fails to load the task because the .kibana index is in an interim state. Flaky test runner: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2045 --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../group2/tests/alerting/rbac_legacy.ts | 15 +- .../alerts_legacy/{ => rules}/data.json | 159 ------------------ .../alerts_legacy/{ => rules}/mappings.json | 121 ------------- .../es_archives/alerts_legacy/tasks/data.json | 158 +++++++++++++++++ .../alerts_legacy/tasks/mappings.json | 120 +++++++++++++ 5 files changed, 286 insertions(+), 287 deletions(-) rename x-pack/test/functional/es_archives/alerts_legacy/{ => rules}/data.json (70%) rename x-pack/test/functional/es_archives/alerts_legacy/{ => rules}/mappings.json (95%) create mode 100644 x-pack/test/functional/es_archives/alerts_legacy/tasks/data.json create mode 100644 x-pack/test/functional/es_archives/alerts_legacy/tasks/mappings.json diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/rbac_legacy.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/rbac_legacy.ts index 36bc3637d5185..65b0389392104 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/rbac_legacy.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/rbac_legacy.ts @@ -56,17 +56,17 @@ export default function alertTests({ getService }: FtrProviderContext) { ), }; - // Failing: See https://github.com/elastic/kibana/issues/140867 - // Failing: See https://github.com/elastic/kibana/issues/142704 - // Failing: See https://github.com/elastic/kibana/issues/153801 - // Failing: See https://github.com/elastic/kibana/issues/153800 - describe.skip('alerts', () => { + describe('alerts', () => { const authorizationIndex = '.kibana-test-authorization'; const objectRemover = new ObjectRemover(supertest); before(async () => { await esTestIndexTool.destroy(); - await esArchiver.load('x-pack/test/functional/es_archives/alerts_legacy'); + // Not 100% sure why, seems the rules need to be loaded separately to avoid the task + // failing to load the rule during execution and deleting itself. Otherwise + // we have flakiness + await esArchiver.load('x-pack/test/functional/es_archives/alerts_legacy/rules'); + await esArchiver.load('x-pack/test/functional/es_archives/alerts_legacy/tasks'); await esTestIndexTool.setup(); await es.indices.create({ index: authorizationIndex }); await setupSpacesAndUsers(getService); @@ -75,7 +75,8 @@ export default function alertTests({ getService }: FtrProviderContext) { after(async () => { await esTestIndexTool.destroy(); await es.indices.delete({ index: authorizationIndex }); - await esArchiver.unload('x-pack/test/functional/es_archives/alerts_legacy'); + await esArchiver.unload('x-pack/test/functional/es_archives/alerts_legacy/tasks'); + await esArchiver.unload('x-pack/test/functional/es_archives/alerts_legacy/rules'); }); for (const scenario of UserAtSpaceScenarios) { diff --git a/x-pack/test/functional/es_archives/alerts_legacy/data.json b/x-pack/test/functional/es_archives/alerts_legacy/rules/data.json similarity index 70% rename from x-pack/test/functional/es_archives/alerts_legacy/data.json rename to x-pack/test/functional/es_archives/alerts_legacy/rules/data.json index 770e8e7c15617..2c0552acb6054 100644 --- a/x-pack/test/functional/es_archives/alerts_legacy/data.json +++ b/x-pack/test/functional/es_archives/alerts_legacy/rules/data.json @@ -83,37 +83,6 @@ } } -{ - "type": "doc", - "value": { - "id": "task:e9c069d0-eea4-11ea-a285-352ee3aecffa", - "index": ".kibana_task_manager_1", - "source": { - "migrationVersion": { - "task": "7.6.0" - }, - "references": [ - ], - "task": { - "attempts": 0, - "params": "{\"alertId\":\"6ee9630a-a20e-44af-9465-217a3717d2ab\",\"spaceId\":\"space1\"}", - "retryAt": null, - "runAt": "2020-09-04T11:51:05.197Z", - "scheduledAt": "2020-09-04T11:51:05.197Z", - "scope": [ - "alerting" - ], - "startedAt": null, - "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", - "status": "idle", - "taskType": "alerting:test.always-firing" - }, - "type": "task", - "updated_at": "2020-09-04T11:51:05.197Z" - } - } -} - { "type": "doc", "value": { @@ -176,38 +145,6 @@ } } -{ - "type": "doc", - "value": { - "id": "task:e39a02f0-eea4-11ea-a285-352ee3aecffa", - "index": ".kibana_task_manager_1", - "source": { - "migrationVersion": { - "task": "7.6.0" - }, - "references": [ - ], - "task": { - "attempts": 0, - "ownerId": null, - "params": "{\"alertId\":\"b384be60-ec53-4b26-857e-0253ee55b277\",\"spaceId\":\"space1\"}", - "retryAt": null, - "runAt": "2020-09-04T11:51:04.804Z", - "scheduledAt": "2020-09-04T11:50:54.879Z", - "scope": [ - "alerting" - ], - "startedAt": null, - "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", - "status": "idle", - "taskType": "alerting:test.always-firing" - }, - "type": "task", - "updated_at": "2020-09-04T11:51:04.273Z" - } - } -} - { "type": "doc", "value": { @@ -270,38 +207,6 @@ } } -{ - "type": "doc", - "value": { - "id": "task:e8885f00-eea4-11ea-a285-352ee3aecffa", - "index": ".kibana_task_manager_1", - "source": { - "migrationVersion": { - "task": "7.6.0" - }, - "references": [ - ], - "task": { - "attempts": 1, - "ownerId": "kibana:5b2de169-2785-441b-ae8c-186a1936b17d", - "params": "{\"alertId\":\"5cc59319-74ee-4edc-8646-a79ea91067cd\",\"spaceId\":\"space1\"}", - "retryAt": "2020-09-04T12:01:05.793Z", - "runAt": "2020-09-04T11:51:03.152Z", - "scheduledAt": "2020-09-04T11:51:03.152Z", - "scope": [ - "alerting" - ], - "startedAt": "2020-09-04T11:51:05.793Z", - "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", - "status": "running", - "taskType": "alerting:test.always-firing" - }, - "type": "task", - "updated_at": "2020-09-04T11:51:05.794Z" - } - } -} - { "type": "doc", "value": { @@ -364,38 +269,6 @@ } } -{ - "type": "doc", - "value": { - "id": "task:e616c2c0-eea4-11ea-a285-352ee3aecffa", - "index": ".kibana_task_manager_1", - "source": { - "migrationVersion": { - "task": "7.6.0" - }, - "references": [ - ], - "task": { - "attempts": 1, - "ownerId": "kibana:5b2de169-2785-441b-ae8c-186a1936b17d", - "params": "{\"alertId\":\"d41a6abb-b93b-46df-a80a-926221ea847c\",\"spaceId\":\"space1\"}", - "retryAt": "2020-09-04T12:01:05.793Z", - "runAt": "2020-09-04T11:51:04.804Z", - "scheduledAt": "2020-09-04T11:50:59.052Z", - "scope": [ - "alerting" - ], - "startedAt": "2020-09-04T11:51:05.793Z", - "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", - "status": "idle", - "taskType": "alerting:test.always-firing" - }, - "type": "task", - "updated_at": "2020-09-04T11:51:05.794Z" - } - } -} - { "type": "doc", "value": { @@ -457,35 +330,3 @@ } } } - -{ - "type": "doc", - "value": { - "id": "task:e4df5430-eea4-11ea-a285-352ee3aecffa", - "index": ".kibana_task_manager_1", - "source": { - "migrationVersion": { - "task": "7.6.0" - }, - "references": [ - ], - "task": { - "attempts": 1, - "ownerId": "kibana:5b2de169-2785-441b-ae8c-186a1936b17d", - "params": "{\"alertId\":\"362e362b-a137-4aa2-9434-43e3d0d84a34\",\"spaceId\":\"space1\"}", - "retryAt": "2020-09-04T12:01:05.793Z", - "runAt": "2020-09-04T11:51:04.804Z", - "scheduledAt": "2020-09-04T11:50:57.011Z", - "scope": [ - "alerting" - ], - "startedAt": "2020-09-04T11:51:05.793Z", - "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", - "status": "running", - "taskType": "alerting:test.always-firing" - }, - "type": "task", - "updated_at": "2020-09-04T11:51:05.794Z" - } - } -} \ No newline at end of file diff --git a/x-pack/test/functional/es_archives/alerts_legacy/mappings.json b/x-pack/test/functional/es_archives/alerts_legacy/rules/mappings.json similarity index 95% rename from x-pack/test/functional/es_archives/alerts_legacy/mappings.json rename to x-pack/test/functional/es_archives/alerts_legacy/rules/mappings.json index 6e40f811e1af4..23f170737f498 100644 --- a/x-pack/test/functional/es_archives/alerts_legacy/mappings.json +++ b/x-pack/test/functional/es_archives/alerts_legacy/rules/mappings.json @@ -2520,124 +2520,3 @@ } } } - -{ - "type": "index", - "value": { - "aliases": { - ".kibana_task_manager": { - } - }, - "index": ".kibana_task_manager_1", - "mappings": { - "_meta": { - "migrationMappingPropertyHashes": { - "migrationVersion": "4a1746014a75ade3a714e1db5763276f", - "namespace": "2f4316de49999235636386fe51dc06c1", - "namespaces": "2f4316de49999235636386fe51dc06c1", - "references": "7997cf5a56cc02bdc9c93361bde732b0", - "task": "235412e52d09e7165fac8a67a43ad6b4", - "type": "2f4316de49999235636386fe51dc06c1", - "updated_at": "00da57df13e94e9d98437d13ace4bfe0" - } - }, - "dynamic": "strict", - "properties": { - "migrationVersion": { - "dynamic": "true", - "properties": { - "task": { - "fields": { - "keyword": { - "ignore_above": 256, - "type": "keyword" - } - }, - "type": "text" - } - } - }, - "namespace": { - "type": "keyword" - }, - "namespaces": { - "type": "keyword" - }, - "references": { - "properties": { - "id": { - "type": "keyword" - }, - "name": { - "type": "keyword" - }, - "type": { - "type": "keyword" - } - }, - "type": "nested" - }, - "task": { - "properties": { - "attempts": { - "type": "integer" - }, - "ownerId": { - "type": "keyword" - }, - "params": { - "type": "text" - }, - "retryAt": { - "type": "date" - }, - "runAt": { - "type": "date" - }, - "schedule": { - "properties": { - "interval": { - "type": "keyword" - } - } - }, - "scheduledAt": { - "type": "date" - }, - "scope": { - "type": "keyword" - }, - "startedAt": { - "type": "date" - }, - "state": { - "type": "text" - }, - "status": { - "type": "keyword" - }, - "taskType": { - "type": "keyword" - }, - "user": { - "type": "keyword" - } - } - }, - "type": { - "type": "keyword" - }, - "updated_at": { - "type": "date" - } - } - }, - "settings": { - "index": { - "auto_expand_replicas": "0-1", - "number_of_replicas": "0", - "number_of_shards": "1" - } - } - } -} diff --git a/x-pack/test/functional/es_archives/alerts_legacy/tasks/data.json b/x-pack/test/functional/es_archives/alerts_legacy/tasks/data.json new file mode 100644 index 0000000000000..e7c99521ff360 --- /dev/null +++ b/x-pack/test/functional/es_archives/alerts_legacy/tasks/data.json @@ -0,0 +1,158 @@ +{ + "type": "doc", + "value": { + "id": "task:e9c069d0-eea4-11ea-a285-352ee3aecffa", + "index": ".kibana_task_manager_1", + "source": { + "migrationVersion": { + "task": "7.6.0" + }, + "references": [ + ], + "task": { + "attempts": 0, + "params": "{\"alertId\":\"6ee9630a-a20e-44af-9465-217a3717d2ab\",\"spaceId\":\"space1\"}", + "retryAt": null, + "runAt": "2020-09-04T11:51:05.197Z", + "scheduledAt": "2020-09-04T11:51:05.197Z", + "scope": [ + "alerting" + ], + "startedAt": null, + "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", + "status": "idle", + "taskType": "alerting:test.always-firing" + }, + "type": "task", + "updated_at": "2020-09-04T11:51:05.197Z" + } + } +} + +{ + "type": "doc", + "value": { + "id": "task:e39a02f0-eea4-11ea-a285-352ee3aecffa", + "index": ".kibana_task_manager_1", + "source": { + "migrationVersion": { + "task": "7.6.0" + }, + "references": [ + ], + "task": { + "attempts": 0, + "ownerId": null, + "params": "{\"alertId\":\"b384be60-ec53-4b26-857e-0253ee55b277\",\"spaceId\":\"space1\"}", + "retryAt": null, + "runAt": "2020-09-04T11:51:04.804Z", + "scheduledAt": "2020-09-04T11:50:54.879Z", + "scope": [ + "alerting" + ], + "startedAt": null, + "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", + "status": "idle", + "taskType": "alerting:test.always-firing" + }, + "type": "task", + "updated_at": "2020-09-04T11:51:04.273Z" + } + } +} + +{ + "type": "doc", + "value": { + "id": "task:e8885f00-eea4-11ea-a285-352ee3aecffa", + "index": ".kibana_task_manager_1", + "source": { + "migrationVersion": { + "task": "7.6.0" + }, + "references": [ + ], + "task": { + "attempts": 1, + "ownerId": "kibana:5b2de169-2785-441b-ae8c-186a1936b17d", + "params": "{\"alertId\":\"5cc59319-74ee-4edc-8646-a79ea91067cd\",\"spaceId\":\"space1\"}", + "retryAt": "2020-09-04T12:01:05.793Z", + "runAt": "2020-09-04T11:51:03.152Z", + "scheduledAt": "2020-09-04T11:51:03.152Z", + "scope": [ + "alerting" + ], + "startedAt": "2020-09-04T11:51:05.793Z", + "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", + "status": "running", + "taskType": "alerting:test.always-firing" + }, + "type": "task", + "updated_at": "2020-09-04T11:51:05.794Z" + } + } +} + +{ + "type": "doc", + "value": { + "id": "task:e616c2c0-eea4-11ea-a285-352ee3aecffa", + "index": ".kibana_task_manager_1", + "source": { + "migrationVersion": { + "task": "7.6.0" + }, + "references": [ + ], + "task": { + "attempts": 1, + "ownerId": "kibana:5b2de169-2785-441b-ae8c-186a1936b17d", + "params": "{\"alertId\":\"d41a6abb-b93b-46df-a80a-926221ea847c\",\"spaceId\":\"space1\"}", + "retryAt": "2020-09-04T12:01:05.793Z", + "runAt": "2020-09-04T11:51:04.804Z", + "scheduledAt": "2020-09-04T11:50:59.052Z", + "scope": [ + "alerting" + ], + "startedAt": "2020-09-04T11:51:05.793Z", + "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", + "status": "idle", + "taskType": "alerting:test.always-firing" + }, + "type": "task", + "updated_at": "2020-09-04T11:51:05.794Z" + } + } +} + +{ + "type": "doc", + "value": { + "id": "task:e4df5430-eea4-11ea-a285-352ee3aecffa", + "index": ".kibana_task_manager_1", + "source": { + "migrationVersion": { + "task": "7.6.0" + }, + "references": [ + ], + "task": { + "attempts": 1, + "ownerId": "kibana:5b2de169-2785-441b-ae8c-186a1936b17d", + "params": "{\"alertId\":\"362e362b-a137-4aa2-9434-43e3d0d84a34\",\"spaceId\":\"space1\"}", + "retryAt": "2020-09-04T12:01:05.793Z", + "runAt": "2020-09-04T11:51:04.804Z", + "scheduledAt": "2020-09-04T11:50:57.011Z", + "scope": [ + "alerting" + ], + "startedAt": "2020-09-04T11:51:05.793Z", + "state": "{\"previousStartedAt\":null,\"alertTypeState\":{},\"alertInstances\":{}}", + "status": "running", + "taskType": "alerting:test.always-firing" + }, + "type": "task", + "updated_at": "2020-09-04T11:51:05.794Z" + } + } +} diff --git a/x-pack/test/functional/es_archives/alerts_legacy/tasks/mappings.json b/x-pack/test/functional/es_archives/alerts_legacy/tasks/mappings.json new file mode 100644 index 0000000000000..d139264b8de93 --- /dev/null +++ b/x-pack/test/functional/es_archives/alerts_legacy/tasks/mappings.json @@ -0,0 +1,120 @@ +{ + "type": "index", + "value": { + "aliases": { + ".kibana_task_manager": { + } + }, + "index": ".kibana_task_manager_1", + "mappings": { + "_meta": { + "migrationMappingPropertyHashes": { + "migrationVersion": "4a1746014a75ade3a714e1db5763276f", + "namespace": "2f4316de49999235636386fe51dc06c1", + "namespaces": "2f4316de49999235636386fe51dc06c1", + "references": "7997cf5a56cc02bdc9c93361bde732b0", + "task": "235412e52d09e7165fac8a67a43ad6b4", + "type": "2f4316de49999235636386fe51dc06c1", + "updated_at": "00da57df13e94e9d98437d13ace4bfe0" + } + }, + "dynamic": "strict", + "properties": { + "migrationVersion": { + "dynamic": "true", + "properties": { + "task": { + "fields": { + "keyword": { + "ignore_above": 256, + "type": "keyword" + } + }, + "type": "text" + } + } + }, + "namespace": { + "type": "keyword" + }, + "namespaces": { + "type": "keyword" + }, + "references": { + "properties": { + "id": { + "type": "keyword" + }, + "name": { + "type": "keyword" + }, + "type": { + "type": "keyword" + } + }, + "type": "nested" + }, + "task": { + "properties": { + "attempts": { + "type": "integer" + }, + "ownerId": { + "type": "keyword" + }, + "params": { + "type": "text" + }, + "retryAt": { + "type": "date" + }, + "runAt": { + "type": "date" + }, + "schedule": { + "properties": { + "interval": { + "type": "keyword" + } + } + }, + "scheduledAt": { + "type": "date" + }, + "scope": { + "type": "keyword" + }, + "startedAt": { + "type": "date" + }, + "state": { + "type": "text" + }, + "status": { + "type": "keyword" + }, + "taskType": { + "type": "keyword" + }, + "user": { + "type": "keyword" + } + } + }, + "type": { + "type": "keyword" + }, + "updated_at": { + "type": "date" + } + } + }, + "settings": { + "index": { + "auto_expand_replicas": "0-1", + "number_of_replicas": "0", + "number_of_shards": "1" + } + } + } +}