Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.13] [Fleet] Fix issue of agent sometimes not getting inputs using …
…a new agent policy with system integration (elastic#177594) (elastic#177725) # Backport This will backport the following commits from `main` to `8.13`: - [[Fleet] Fix issue of agent sometimes not getting inputs using a new agent policy with system integration (elastic#177594)](elastic#177594) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Julia Bardi","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-02-23T14:46:48Z","message":"[Fleet] Fix issue of agent sometimes not getting inputs using a new agent policy with system integration (elastic#177594)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/177372\r\n\r\nWhen creating an agent policy with a package policy immediately (e.g.\r\nsystem integration), the `deployPolicy` logic was called once, creating\r\na doc in `.fleet-policies` with `revision:1` without `inputs`, and then\r\nupdating the doc with `inputs`, still on `revision:1`.\r\nThis is causing an intermittent issue on the agents, if Fleet-server\r\npicks up the first document, and delivers to agent without `inputs`.\r\nAs a fix, added an option to skip `deploPolicy` when called from the\r\n`createAgentPolicyWithPackages` function, as the policy will be deployed\r\nafter creating the package policies.\r\n\r\nTo verify:\r\n- create an agent policy with system monitoring (default option)\r\n- check that the created documents in `.fleet-policies` are correct:\r\nthere should be one doc with `revision_idx:1` and `coordinator_idx:0`\r\n(created by Fleet API), and one doc with `revision_idx:1` and\r\n`coordinator_idx:1` (created by fleet-server)\r\n- verify that both documents have `data.inputs` field populated\r\n\r\nUsed this query to verify:\r\n```\r\nPOST .fleet-policies/_search\r\n{\r\n \"query\": {\r\n \"bool\": {\r\n \"must\": [\r\n {\r\n \"term\": {\"coordinator_idx\": 0}\r\n }\r\n ],\r\n \"filter\": {\r\n \"term\": {\r\n \"policy_id\": \"<agent policy id>\"\r\n }\r\n }\r\n }\r\n }, \r\n \"_source\": [\r\n \"revision_idx\",\"coordinator_idx\", \"policy_id\", \"@timestamp\", \"data.inputs\"\r\n ],\r\n \"sort\": [\r\n {\r\n \"revision_idx\": {\r\n \"order\": \"desc\"\r\n }\r\n }\r\n ]\r\n}\r\n```\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"5f17b39a1d4aa326f8b75bc0d2375f620433e9be","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.14.0"],"title":"[Fleet] Fix issue of agent sometimes not getting inputs using a new agent policy with system integration","number":177594,"url":"https://github.com/elastic/kibana/pull/177594","mergeCommit":{"message":"[Fleet] Fix issue of agent sometimes not getting inputs using a new agent policy with system integration (elastic#177594)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/177372\r\n\r\nWhen creating an agent policy with a package policy immediately (e.g.\r\nsystem integration), the `deployPolicy` logic was called once, creating\r\na doc in `.fleet-policies` with `revision:1` without `inputs`, and then\r\nupdating the doc with `inputs`, still on `revision:1`.\r\nThis is causing an intermittent issue on the agents, if Fleet-server\r\npicks up the first document, and delivers to agent without `inputs`.\r\nAs a fix, added an option to skip `deploPolicy` when called from the\r\n`createAgentPolicyWithPackages` function, as the policy will be deployed\r\nafter creating the package policies.\r\n\r\nTo verify:\r\n- create an agent policy with system monitoring (default option)\r\n- check that the created documents in `.fleet-policies` are correct:\r\nthere should be one doc with `revision_idx:1` and `coordinator_idx:0`\r\n(created by Fleet API), and one doc with `revision_idx:1` and\r\n`coordinator_idx:1` (created by fleet-server)\r\n- verify that both documents have `data.inputs` field populated\r\n\r\nUsed this query to verify:\r\n```\r\nPOST .fleet-policies/_search\r\n{\r\n \"query\": {\r\n \"bool\": {\r\n \"must\": [\r\n {\r\n \"term\": {\"coordinator_idx\": 0}\r\n }\r\n ],\r\n \"filter\": {\r\n \"term\": {\r\n \"policy_id\": \"<agent policy id>\"\r\n }\r\n }\r\n }\r\n }, \r\n \"_source\": [\r\n \"revision_idx\",\"coordinator_idx\", \"policy_id\", \"@timestamp\", \"data.inputs\"\r\n ],\r\n \"sort\": [\r\n {\r\n \"revision_idx\": {\r\n \"order\": \"desc\"\r\n }\r\n }\r\n ]\r\n}\r\n```\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"5f17b39a1d4aa326f8b75bc0d2375f620433e9be"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/177594","number":177594,"mergeCommit":{"message":"[Fleet] Fix issue of agent sometimes not getting inputs using a new agent policy with system integration (elastic#177594)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/177372\r\n\r\nWhen creating an agent policy with a package policy immediately (e.g.\r\nsystem integration), the `deployPolicy` logic was called once, creating\r\na doc in `.fleet-policies` with `revision:1` without `inputs`, and then\r\nupdating the doc with `inputs`, still on `revision:1`.\r\nThis is causing an intermittent issue on the agents, if Fleet-server\r\npicks up the first document, and delivers to agent without `inputs`.\r\nAs a fix, added an option to skip `deploPolicy` when called from the\r\n`createAgentPolicyWithPackages` function, as the policy will be deployed\r\nafter creating the package policies.\r\n\r\nTo verify:\r\n- create an agent policy with system monitoring (default option)\r\n- check that the created documents in `.fleet-policies` are correct:\r\nthere should be one doc with `revision_idx:1` and `coordinator_idx:0`\r\n(created by Fleet API), and one doc with `revision_idx:1` and\r\n`coordinator_idx:1` (created by fleet-server)\r\n- verify that both documents have `data.inputs` field populated\r\n\r\nUsed this query to verify:\r\n```\r\nPOST .fleet-policies/_search\r\n{\r\n \"query\": {\r\n \"bool\": {\r\n \"must\": [\r\n {\r\n \"term\": {\"coordinator_idx\": 0}\r\n }\r\n ],\r\n \"filter\": {\r\n \"term\": {\r\n \"policy_id\": \"<agent policy id>\"\r\n }\r\n }\r\n }\r\n }, \r\n \"_source\": [\r\n \"revision_idx\",\"coordinator_idx\", \"policy_id\", \"@timestamp\", \"data.inputs\"\r\n ],\r\n \"sort\": [\r\n {\r\n \"revision_idx\": {\r\n \"order\": \"desc\"\r\n }\r\n }\r\n ]\r\n}\r\n```\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"5f17b39a1d4aa326f8b75bc0d2375f620433e9be"}}]}] BACKPORT--> Co-authored-by: Julia Bardi <[email protected]>
- Loading branch information