Skip to content

Use new format in calls to policy API#3307

Merged
jsoriano merged 51 commits intoelastic:mainfrom
jsoriano:refactor-policy-api
Mar 6, 2026
Merged

Use new format in calls to policy API#3307
jsoriano merged 51 commits intoelastic:mainfrom
jsoriano:refactor-policy-api

Conversation

@jsoriano
Copy link
Copy Markdown
Member

@jsoriano jsoriano commented Feb 25, 2026

Fixes #3038.

Use the recommended "simplified" format of the Fleet API to create policies. This format is based on objects instead of lists for variables, and automatically manages defaults.

To keep supporting old versions of the stack that don't support this API, a conversion layer is added. This conversion layer will need to be maintained while we support 8.5.0.

A new setting is added to system tests to allow forcing the use of an specific format, policy_api_format. This is added as a escape hatch for cases that cannot be solved with the simplified API, as seen for example in elastic/kibana#255976. Definition to package spec to be added in elastic/package-spec#1103.

The new "simplified" API enables all data streams for the configured inputs by default, so some new code is needed to disable the data streams that are not relevant for each test case.

Refactor the code related to policy creation so it is reused in the different places where the functionality is needed. Two main methods are created for that, BuildIntegrationPackagePolicy for integration packages, and BuildInputPackagePolicy for input packages.

A couple of additional enhancements:

New tests are added for the methods used to create package policies.

Change assisted by Copilot/Claude

@jsoriano jsoriano self-assigned this Feb 25, 2026
@jsoriano
Copy link
Copy Markdown
Member Author

test integrations

@jsoriano
Copy link
Copy Markdown
Member Author

test integrations

@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

Created or updated PR in integrations repository to test this version. Check elastic/integrations#17571

@jsoriano jsoriano mentioned this pull request Feb 26, 2026
@jsoriano
Copy link
Copy Markdown
Member Author

test integrations

@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

Created or updated PR in integrations repository to test this version. Check elastic/integrations#17571

@jsoriano
Copy link
Copy Markdown
Member Author

test integrations

@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

Created or updated PR in integrations repository to test this version. Check elastic/integrations#17571

@jsoriano
Copy link
Copy Markdown
Member Author

test integrations

@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

Created or updated PR in integrations repository to test this version. Check elastic/integrations#17571

@jsoriano jsoriano force-pushed the refactor-policy-api branch from a528d7e to 9082f51 Compare February 27, 2026 14:11
@jsoriano
Copy link
Copy Markdown
Member Author

test integrations

@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@mrodm mrodm 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 adding those tests! This will help for sure to ensure that everything works as expected

Just added a few questions

common.MapStr(packagePolicy.Vars),
!packagePolicy.Disabled,
)
pp.OutputID = policy.DataOutputID
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was wondering if it would be helpful to add this assignment into the BuildInputPackagePolicy and BuildIntegrationPackagePolicy methods.

In system tests, this variable is filled for the policy:
https://github.com/elastic/elastic-package/pull/3307/changes#diff-0bdd696fb9abd5e4aa12a3bab634cbac31ec1a1349b3a61e8a784a6bdeb6e7d8R1375-R1380

But it was not set in the package policies , so would this addition be missing too there? If it was required, it was not done in the current logic in main.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I would prefer to keep this separated, and let the callers of BuildInputPackagePolicy and BuildIntegrationPackagePolicy methods decide the output to use.

@jsoriano jsoriano requested a review from mrodm March 5, 2026 13:19
@jsoriano
Copy link
Copy Markdown
Member Author

jsoriano commented Mar 5, 2026

test integrations

@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

Created or updated PR in integrations repository to test this version. Check elastic/integrations#17571

@jsoriano jsoriano force-pushed the refactor-policy-api branch from d68cd7c to 2f6bc37 Compare March 5, 2026 13:32
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am going to remove the policy tests from this PR, as they are stricter than system tests and I cannot use policy_api_format till elastic/package-spec#1103 is released.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed in fdf61a9

I will set a reminder to myself to add them back when package-spec is released :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Recovering these tests in #3389.

@jsoriano
Copy link
Copy Markdown
Member Author

jsoriano commented Mar 5, 2026

test integrations

@elastic-vault-github-plugin-prod
Copy link
Copy Markdown

Created or updated PR in integrations repository to test this version. Check elastic/integrations#17571

@elasticmachine
Copy link
Copy Markdown
Collaborator

elasticmachine commented Mar 5, 2026

💛 Build succeeded, but was flaky

Failed CI Steps

History

cc @jsoriano

Copy link
Copy Markdown
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

Tested locally these changes and they worked successfully in different packages. Great coverage added to ensure correctness too!

Thanks!

@jsoriano jsoriano merged commit dc85784 into elastic:main Mar 6, 2026
3 checks passed
@jsoriano jsoriano deleted the refactor-policy-api branch March 6, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support to define use_apm variable in policy and system tests in input packages Use inputs as objects when creating package policies

3 participants