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] Create and update package policy API return 409 conflict when names are not unique #153533

Merged
merged 2 commits into from
Mar 23, 2023

Conversation

criamico
Copy link
Contributor

@criamico criamico commented Mar 23, 2023

Closes #153026

Summary

The agent policy API returns a 409 in the case the policy already exists. The package policy API will now follow the same behavior.

Checklist

Delete any items that are not applicable to this PR.

@criamico criamico added release_note:enhancement Team:Fleet Team label for Observability Data Collection Fleet team v8.8.0 labels Mar 23, 2023
@criamico criamico self-assigned this Mar 23, 2023
@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.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@criamico criamico marked this pull request as ready for review March 23, 2023 11:58
@criamico criamico requested a review from a team as a code owner March 23, 2023 11:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

Copy link
Member

@kpollich kpollich left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for the refactor along the way 🚀

) {
const existingPoliciesWithName = await packagePolicyService.list(soClient, {
perPage: SO_SEARCH_LIMIT,
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name:"${packagePolicy.name}"`,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This logic could be simplified to use ES kuery to filter out the same id, and could use the total count without any hits.
Probably not a huge gain as there will be at least 1 matches, just some code simplification.

Something like:

  const existingPoliciesWithName = await packagePolicyService.list(soClient, {
    perPage: 0,
    kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name:"${packagePolicy.name}" AND NOT (${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.id:"${packagePolicy.id}")`,
  });
if (existingPoliciesWithName?.total > 0) {
  throw ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Julia! Since the gain it's not very big I'm going to merge as it is, but we can do this change the next time we touch this area :)

Copy link
Contributor

@juliaElastic juliaElastic left a comment

Choose a reason for hiding this comment

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

LGTM

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 433 436 +3

Total ESLint disabled count

id before after diff
securitySolution 513 516 +3

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

cc @criamico

@criamico criamico merged commit d75df24 into elastic:main Mar 23, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:enhancement Team:Fleet Team label for Observability Data Collection Fleet team v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Create package policy API should return a 409 Conflict when package policy of same name already exists
7 participants