Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Fix issue of agent sometimes not getting inputs using a new agent policy with system integration #177594

Merged
merged 7 commits into from
Feb 23, 2024

Conversation

juliaElastic
Copy link
Contributor

@juliaElastic juliaElastic commented Feb 22, 2024

Summary

Closes #177372

When creating an agent policy with a package policy immediately (e.g. system integration), the deployPolicy logic was called once, creating a doc in .fleet-policies with revision:1 without inputs, and then updating the doc with inputs, still on revision:1.
This is causing an intermittent issue on the agents, if Fleet-server picks up the first document, and delivers to agent without inputs.
As a fix, added an option to skip deploPolicy when called from the createAgentPolicyWithPackages function, as the policy will be deployed after creating the package policies.

To verify:

  • create an agent policy with system monitoring (default option)
  • check that the created documents in .fleet-policies are correct: there should be one doc with revision_idx:1 and coordinator_idx:0 (created by Fleet API), and one doc with revision_idx:1 and coordinator_idx:1 (created by fleet-server)
  • verify that both documents have data.inputs field populated

Used this query to verify:

POST .fleet-policies/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {"coordinator_idx": 0}
        }
      ],
    "filter": {
      "term": {
      "policy_id": "<agent policy id>"
      }
    }
    }
  }, 
  "_source": [
    "revision_idx","coordinator_idx", "policy_id",  "@timestamp", "data.inputs"
  ],
  "sort": [
    {
      "revision_idx": {
        "order": "desc"
      }
    }
  ]
}

Checklist

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@@ -1034,7 +1038,7 @@ class AgentPolicyService {

const bulkResponse = await esClient.bulk({
index: AGENT_POLICY_INDEX,
body: fleetServerPoliciesBulkBody,
operations: fleetServerPoliciesBulkBody,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced deprecated field

@juliaElastic
Copy link
Contributor Author

/ci

@juliaElastic juliaElastic marked this pull request as ready for review February 22, 2024 15:52
@juliaElastic juliaElastic requested a review from a team as a code owner February 22, 2024 15:52
@juliaElastic
Copy link
Contributor Author

I'm working on an integration test as well to check the correct .fleet-policies doc.

@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Feb 23, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@juliaElastic juliaElastic added the backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) label Feb 23, 2024
Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.
Curious why this was never caught before

@juliaElastic
Copy link
Contributor Author

LGTM 🚀. Curious why this was never caught before

Yeah it's interesting, this logic was there for a few years.

@juliaElastic juliaElastic enabled auto-merge (squash) February 23, 2024 14:08
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @juliaElastic

@juliaElastic juliaElastic merged commit 5f17b39 into elastic:main Feb 23, 2024
18 checks passed
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 23, 2024
…gent policy with system integration (elastic#177594)

## Summary

Closes elastic#177372

When creating an agent policy with a package policy immediately (e.g.
system integration), the `deployPolicy` logic was called once, creating
a doc in `.fleet-policies` with `revision:1` without `inputs`, and then
updating the doc with `inputs`, still on `revision:1`.
This is causing an intermittent issue on the agents, if Fleet-server
picks up the first document, and delivers to agent without `inputs`.
As a fix, added an option to skip `deploPolicy` when called from the
`createAgentPolicyWithPackages` function, as the policy will be deployed
after creating the package policies.

To verify:
- create an agent policy with system monitoring (default option)
- check that the created documents in `.fleet-policies` are correct:
there should be one doc with `revision_idx:1` and `coordinator_idx:0`
(created by Fleet API), and one doc with `revision_idx:1` and
`coordinator_idx:1` (created by fleet-server)
- verify that both documents have `data.inputs` field populated

Used this query to verify:
```
POST .fleet-policies/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {"coordinator_idx": 0}
        }
      ],
    "filter": {
      "term": {
      "policy_id": "<agent policy id>"
      }
    }
    }
  },
  "_source": [
    "revision_idx","coordinator_idx", "policy_id",  "@timestamp", "data.inputs"
  ],
  "sort": [
    {
      "revision_idx": {
        "order": "desc"
      }
    }
  ]
}
```

### 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

(cherry picked from commit 5f17b39)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.13

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Feb 23, 2024
…a new agent policy with system integration (#177594) (#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
(#177594)](#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 (#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 (#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 (#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]>
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
…gent policy with system integration (elastic#177594)

## Summary

Closes elastic#177372

When creating an agent policy with a package policy immediately (e.g.
system integration), the `deployPolicy` logic was called once, creating
a doc in `.fleet-policies` with `revision:1` without `inputs`, and then
updating the doc with `inputs`, still on `revision:1`.
This is causing an intermittent issue on the agents, if Fleet-server
picks up the first document, and delivers to agent without `inputs`.
As a fix, added an option to skip `deploPolicy` when called from the
`createAgentPolicyWithPackages` function, as the policy will be deployed
after creating the package policies.

To verify:
- create an agent policy with system monitoring (default option)
- check that the created documents in `.fleet-policies` are correct:
there should be one doc with `revision_idx:1` and `coordinator_idx:0`
(created by Fleet API), and one doc with `revision_idx:1` and
`coordinator_idx:1` (created by fleet-server)
- verify that both documents have `data.inputs` field populated

Used this query to verify:
```
POST .fleet-policies/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {"coordinator_idx": 0}
        }
      ],
    "filter": {
      "term": {
      "policy_id": "<agent policy id>"
      }
    }
    }
  }, 
  "_source": [
    "revision_idx","coordinator_idx", "policy_id",  "@timestamp", "data.inputs"
  ],
  "sort": [
    {
      "revision_idx": {
        "order": "desc"
      }
    }
  ]
}
```


### 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:fix Team:Fleet Team label for Observability Data Collection Fleet team v8.13.0 v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] System integration inputs never configured for agent installed on self-managed 8.13.0.
6 participants