Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.7] [Fleet] Fix agent policy selection and creation when there are …
…a large number of agent policies ( > 1k) (#151119) (#151131) # Backport This will backport the following commits from `main` to `8.7`: - [[Fleet] Fix agent policy selection and creation when there are a large number of agent policies ( > 1k) (#151119)](#151119) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Mark Hopkin","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-02-14T13:36:17Z","message":"[Fleet] Fix agent policy selection and creation when there are a large number of agent policies ( > 1k) (#151119)\n\n## Summary\r\n\r\nCloses #150605\r\n\r\nWhen adding an integration, the agent policy selector (create or select\r\nexisting agent policy) does not work if there are too many agent\r\npolicies.\r\n\r\nIn an environment with a large number of agent policies (e.g 1000+) the\r\nfollowing API request times out or takes 30 - 60 seconds to respond:\r\n\r\n```\r\nhttp://localhost:5601/mark/api/fleet/agent_policies?page=1&perPage=10000&sortField=name&sortOrder=asc&full=true\r\n```\r\n\r\nThat is because for each agent policy we get the saved object twice, get\r\nALL package policies, and count the agents, so for 1000 agents we fun\r\n4000 queries using `pmap` in some places.\r\n\r\nthis PR changes it so that we do not get the agent count or `full` agent\r\npolicy for every agent policy when populating the agent policy select,\r\ninstead we only get the selected agent policy.\r\n\r\nThis has meant that I have to separately query package policies in order\r\nto do the limited packages and APM output checks, but the component now\r\nloads instantly on an environment with 3k agent policies.\r\n\r\nKey changes:\r\n\r\n- add `noAgentCount` query param to agent policies API, to not count the\r\nagents for all agent policies\r\n- populate `agents` in the get one agent policy API, this was an\r\ninconsistency in our agent policy API\r\n- when selecting an existing agent policy, only get the full agent\r\npolicy for the selected agent policy\r\n\r\n\r\n###Testing\r\n\r\nNo behaviour should have changed for the agent policy select, some niche\r\nbehaviour of the selector:\r\n\r\n- if adding the APM integration, any agent policy with a logstash output\r\nconfigured for integration data should be disabled\r\n- if adding a limited integration e.g apm or defend, any agent policy\r\nalready containing that integration should be disabled\r\n\r\n<img width=\"1052\" alt=\"Screenshot 2023-02-14 at 10 45 03\"\r\nsrc=\"https://user-images.githubusercontent.com/3315046/218745430-4a8f0ded-1e0b-4319-bc2c-cc5253b4cdd2.png\">","sha":"9a52ef4baf07baa8a877252e3a740cfde1624063","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","v8.7.0","v8.8.0"],"number":151119,"url":"https://github.com/elastic/kibana/pull/151119","mergeCommit":{"message":"[Fleet] Fix agent policy selection and creation when there are a large number of agent policies ( > 1k) (#151119)\n\n## Summary\r\n\r\nCloses #150605\r\n\r\nWhen adding an integration, the agent policy selector (create or select\r\nexisting agent policy) does not work if there are too many agent\r\npolicies.\r\n\r\nIn an environment with a large number of agent policies (e.g 1000+) the\r\nfollowing API request times out or takes 30 - 60 seconds to respond:\r\n\r\n```\r\nhttp://localhost:5601/mark/api/fleet/agent_policies?page=1&perPage=10000&sortField=name&sortOrder=asc&full=true\r\n```\r\n\r\nThat is because for each agent policy we get the saved object twice, get\r\nALL package policies, and count the agents, so for 1000 agents we fun\r\n4000 queries using `pmap` in some places.\r\n\r\nthis PR changes it so that we do not get the agent count or `full` agent\r\npolicy for every agent policy when populating the agent policy select,\r\ninstead we only get the selected agent policy.\r\n\r\nThis has meant that I have to separately query package policies in order\r\nto do the limited packages and APM output checks, but the component now\r\nloads instantly on an environment with 3k agent policies.\r\n\r\nKey changes:\r\n\r\n- add `noAgentCount` query param to agent policies API, to not count the\r\nagents for all agent policies\r\n- populate `agents` in the get one agent policy API, this was an\r\ninconsistency in our agent policy API\r\n- when selecting an existing agent policy, only get the full agent\r\npolicy for the selected agent policy\r\n\r\n\r\n###Testing\r\n\r\nNo behaviour should have changed for the agent policy select, some niche\r\nbehaviour of the selector:\r\n\r\n- if adding the APM integration, any agent policy with a logstash output\r\nconfigured for integration data should be disabled\r\n- if adding a limited integration e.g apm or defend, any agent policy\r\nalready containing that integration should be disabled\r\n\r\n<img width=\"1052\" alt=\"Screenshot 2023-02-14 at 10 45 03\"\r\nsrc=\"https://user-images.githubusercontent.com/3315046/218745430-4a8f0ded-1e0b-4319-bc2c-cc5253b4cdd2.png\">","sha":"9a52ef4baf07baa8a877252e3a740cfde1624063"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/151119","number":151119,"mergeCommit":{"message":"[Fleet] Fix agent policy selection and creation when there are a large number of agent policies ( > 1k) (#151119)\n\n## Summary\r\n\r\nCloses #150605\r\n\r\nWhen adding an integration, the agent policy selector (create or select\r\nexisting agent policy) does not work if there are too many agent\r\npolicies.\r\n\r\nIn an environment with a large number of agent policies (e.g 1000+) the\r\nfollowing API request times out or takes 30 - 60 seconds to respond:\r\n\r\n```\r\nhttp://localhost:5601/mark/api/fleet/agent_policies?page=1&perPage=10000&sortField=name&sortOrder=asc&full=true\r\n```\r\n\r\nThat is because for each agent policy we get the saved object twice, get\r\nALL package policies, and count the agents, so for 1000 agents we fun\r\n4000 queries using `pmap` in some places.\r\n\r\nthis PR changes it so that we do not get the agent count or `full` agent\r\npolicy for every agent policy when populating the agent policy select,\r\ninstead we only get the selected agent policy.\r\n\r\nThis has meant that I have to separately query package policies in order\r\nto do the limited packages and APM output checks, but the component now\r\nloads instantly on an environment with 3k agent policies.\r\n\r\nKey changes:\r\n\r\n- add `noAgentCount` query param to agent policies API, to not count the\r\nagents for all agent policies\r\n- populate `agents` in the get one agent policy API, this was an\r\ninconsistency in our agent policy API\r\n- when selecting an existing agent policy, only get the full agent\r\npolicy for the selected agent policy\r\n\r\n\r\n###Testing\r\n\r\nNo behaviour should have changed for the agent policy select, some niche\r\nbehaviour of the selector:\r\n\r\n- if adding the APM integration, any agent policy with a logstash output\r\nconfigured for integration data should be disabled\r\n- if adding a limited integration e.g apm or defend, any agent policy\r\nalready containing that integration should be disabled\r\n\r\n<img width=\"1052\" alt=\"Screenshot 2023-02-14 at 10 45 03\"\r\nsrc=\"https://user-images.githubusercontent.com/3315046/218745430-4a8f0ded-1e0b-4319-bc2c-cc5253b4cdd2.png\">","sha":"9a52ef4baf07baa8a877252e3a740cfde1624063"}}]}] BACKPORT--> Co-authored-by: Mark Hopkin <[email protected]>
- Loading branch information