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 agent policy mappings for space awareness #201689

Merged

Conversation

nchaulet
Copy link
Member

@nchaulet nchaulet commented Nov 25, 2024

Summary

In #193361 we introduced new mappings for the agent policy.

We now have two saved object for agent policies, one space aware, one not, and mappings should be added to both, that PR fix that.

I also added a unit test so we make sure that both mappings stay the same

How to reproduce

Enable space awareness (feature flag + API call) than try to enable http monitoring

Screenshot 2024-11-25 at 2 40 44 PM

@nchaulet nchaulet added release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) v8.17.0 labels Nov 25, 2024
@nchaulet nchaulet self-assigned this Nov 25, 2024
@nchaulet nchaulet requested review from a team as code owners November 25, 2024 20:39
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@nchaulet nchaulet requested a review from jen-huang November 25, 2024 21:07
Copy link
Contributor

@jen-huang jen-huang left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this

Object.keys(soTypes['fleet-agent-policies'].mappings).sort()
);
});
it('should have the same mappings for space and non-space aware package policies', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

… src/core/server/integration_tests/ci_checks'
@nchaulet nchaulet enabled auto-merge (squash) November 25, 2024 23:41
…nchaulet/kibana into fix-agent-policies-space-aware-mappings
Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Please avoid using index: false or enabled: false.

There's more context in this internal RFC https://docs.google.com/document/d/1wCAaIQ68J1EAPH4eOdWe8LPQvwr3AXPQZx0ryHC7bK0/edit?tab=t.0#bookmark=id.trb1dli8hz4n

But we recently learned that not all teams were aware of this. So we've added some docs https://github.com/elastic/kibana/pull/201969/files and will also remove it from the mappings type so that it causes a type failure (fleet uses this quite extensively so we'll need to add ts-expect-error to ignore these).

@nchaulet
Copy link
Member Author

@rudolf can we update dynamic: false on existing mappings? I tried to make the change but I got the following error when trying to write my saved object?

Unexpected bulk response [400] strict_dynamic_mapping_exception: [1:196] mapping set to strict, dynamic introduction of [monitoring_http] within [fleet-agent-policies] is not allowed

@rudolf
Copy link
Contributor

rudolf commented Nov 27, 2024

Yeah it should be possible. That error indicates that somehow you don't have dynamic: false inside fleet-agent-policies. Did you introduce the new mappings by adding a new model version?

@nchaulet
Copy link
Member Author

Yeah it should be possible. That error indicates that somehow you don't have dynamic: false inside fleet-agent-policies. Did you introduce the new mappings by adding a new model version?

@rudolf thank it seems to work when I add an empty modelVersion I will update my PR

  modelVersions: {
        '1': {
          changes: [
            {
              type: 'mappings_addition',
              addedMappings: {},
            },
          ],
        },
      },

@nchaulet nchaulet requested a review from rudolf November 27, 2024 15:21
@elasticmachine
Copy link
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

History

cc @nchaulet

@nchaulet
Copy link
Member Author

@elasticmachine merge upstream

changes: [
{
type: 'mappings_addition',
addedMappings: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
addedMappings: {},
addedMappings: {
dynamic: false,
},

You should also specify the change in mappings here. It's unfortunate that we have this duplication of the mappings definitions, but we didn't see a good way around it.

https://github.com/elastic/kibana/blob/skip-transform-on-mappings-change/docs/developer/architecture/core/saved-objects-service.asciidoc?plain=1#L324-L325

Copy link
Member Author

@nchaulet nchaulet Nov 28, 2024

Choose a reason for hiding this comment

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

@rudolf I tried this but I got a type error Type 'boolean' is not assignable to type 'SavedObjectsFieldMapping' Should we ignore that error?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah I see, you're right, looks like a limitation in the modelVersions API in that you can't actually specify a change that sets the top-level dynamic option.

changes: [
{
type: 'mappings_addition',
addedMappings: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
addedMappings: {},
addedMappings: {
dynamic: false,
},

@rudolf
Copy link
Contributor

rudolf commented Nov 28, 2024

We have sent previous guidance around strict API validation. But with making the mappings dynamic: false it's worth double checking that HTTP APIs that write AGENT_POLICY_SAVED_OBJECT_TYPE saved objects have validation that would prevent adding an introduce a new invalid field to these saved objects.

@nchaulet
Copy link
Member Author

We have sent previous guidance around strict API validation. But with making the mappings dynamic: false it's worth double checking that HTTP APIs that write AGENT_POLICY_SAVED_OBJECT_TYPE saved objects have validation that would prevent adding an introduce a new invalid field to these saved objects.

Yes the policy API seems safe on that side, we valid every field added to that saved object.

changes: [
{
type: 'mappings_addition',
addedMappings: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

ah I see, you're right, looks like a limitation in the modelVersions API in that you can't actually specify a change that sets the top-level dynamic option.

@nchaulet nchaulet merged commit 721b4be into elastic:main Nov 28, 2024
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/12075965885

@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.16
8.17
8.x

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 Nov 28, 2024
#202240)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Fleet] Fix agent policy mappings for space awareness
(#201689)](#201689)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-28T22:11:10Z","message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor","v8.17.0","v8.16.2"],"title":"[Fleet]
Fix agent policy mappings for space
awareness","number":201689,"url":"https://github.com/elastic/kibana/pull/201689","mergeCommit":{"message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201689","number":201689,"mergeCommit":{"message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nicolas Chaulet <[email protected]>
kibanamachine added a commit that referenced this pull request Nov 28, 2024
#202239)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Fleet] Fix agent policy mappings for space awareness
(#201689)](#201689)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-28T22:11:10Z","message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor","v8.17.0","v8.16.2"],"title":"[Fleet]
Fix agent policy mappings for space
awareness","number":201689,"url":"https://github.com/elastic/kibana/pull/201689","mergeCommit":{"message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201689","number":201689,"mergeCommit":{"message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nicolas Chaulet <[email protected]>
kibanamachine added a commit that referenced this pull request Nov 28, 2024
…#202241)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Fix agent policy mappings for space awareness
(#201689)](#201689)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-28T22:11:10Z","message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor","v8.17.0","v8.16.2"],"title":"[Fleet]
Fix agent policy mappings for space
awareness","number":201689,"url":"https://github.com/elastic/kibana/pull/201689","mergeCommit":{"message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201689","number":201689,"mergeCommit":{"message":"[Fleet]
Fix agent policy mappings for space awareness
(#201689)","sha":"721b4beb1ae7f12171a34d50ba6068b8c2d7288e"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nicolas Chaulet <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
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:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.16.2 v8.17.0 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants