-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Don't throw concurrent installation error when encountering conflicts #173190
[Fleet] Don't throw concurrent installation error when encountering conflicts #173190
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
I think you can reproduce the conflict error by manually creating a tag with the same id in a different space, before installing a package |
@elasticmachine merge upstream |
I have added testing instructions + a basic unit test that ensures we throw the right error type in this instance, but it's not the most valuable test imo. I would have liked to try and add some logic to https://github.com/elastic/kibana/blob/main/x-pack/test/fleet_api_integration/apis/epm/install_integration_in_multiple_spaces.ts for a better integration test but
|
Pinging @elastic/fleet (Team:Fleet) |
@elasticmachine merge upstream |
I would have liked to add an integration test for this, but there's not a great way to create tags in other spaces to force this conflict case from FTR tests that I've found. Rather than hit my head on that for any longer, I think it's okay to consider this ready to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚢
💚 Build Succeeded
Metrics [docs]
To update your PR or re-run it, just comment with: cc @kpollich |
…onflicts (elastic#173190) ## Summary Closes elastic#171986 ## How to test You'll need to get into a state where a tag with a conflicting ID exists in a second Kibana space outside of the default space. It seems like the tags API doesn't support providing an ID at least from the REST API, so that makes creating duplicate tags in other spaces a bit challenging. e.g. ``` POST kbn:api/saved_objects_tagging/tags/create { "id": "my-tag", "name": "My tag", "description": "", "color": "#FFFFFF" } ``` results in ``` { "statusCode": 400, "error": "Bad Request", "message": "[request body.id]: definition for this key is missing" } ``` So, in order to enable creating tags with ID's easily, I made some quick code changes to the tags service ```diff diff --git a/x-pack/plugins/saved_objects_tagging/server/routes/tags/create_tag.ts b/x-pack/plugins/saved_objects_tagging/server/routes/tags/create_tag.ts index 0c48168eed2..fa0e7fbe7b9 100644 --- a/x-pack/plugins/saved_objects_tagging/server/routes/tags/create_tag.ts +++ b/x-pack/plugins/saved_objects_tagging/server/routes/tags/create_tag.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import { omit } from 'lodash'; import type { TagsPluginRouter } from '../../types'; import { TagValidationError } from '../../services/tags'; @@ -15,6 +16,7 @@ export const registerCreateTagRoute = (router: TagsPluginRouter) => { path: '/api/saved_objects_tagging/tags/create', validate: { body: schema.object({ + id: schema.maybe(schema.string()), name: schema.string(), description: schema.string(), color: schema.string(), @@ -32,7 +34,7 @@ export const registerCreateTagRoute = (router: TagsPluginRouter) => { }); } - const tag = await tagsClient.create(req.body); + const tag = await tagsClient.create(omit(req.body, 'id'), { id: req.body.id }); return res.ok({ body: { tag, ``` With those changes in place (I don't think committing them is necessary), I was able to create a tag in my second space e.g. ``` POST kbn:api/saved_objects_tagging/tags/create { "id": "fleet-pkg-nginx-default", "name": "Nginx duplicate tag", "description": "", "color": "#DADADA" } ``` Then, from my default space I installed the nginx package ``` POST kbn:/api/fleet/epm/packages/nginx ``` This throws the concurrent install error as expected on `main` ``` { "statusCode": 409, "error": "Conflict", "message": "Concurrent installation or upgrade of nginx-1.17.0 detected, aborting. Original error: Saved object [tag/fleet-pkg-nginx-default] conflict" } ``` With this PR, we get this error instead ``` { "statusCode": 400, "error": "Bad Request", "message": "Saved Object conflict encountered while installing nginx-1.17.0. There may be a conflicting Saved Object saved to another Space. Original error: Saved object [tag/fleet-pkg-nginx-default] conflict" } ``` --------- Co-authored-by: Kibana Machine <[email protected]>
Summary
Closes #171986
How to test
You'll need to get into a state where a tag with a conflicting ID exists in a second Kibana space outside of the default space.
It seems like the tags API doesn't support providing an ID at least from the REST API, so that makes creating duplicate tags in other spaces a bit challenging.
e.g.
results in
So, in order to enable creating tags with ID's easily, I made some quick code changes to the tags service
With those changes in place (I don't think committing them is necessary), I was able to create a tag in my second space e.g.
Then, from my default space I installed the nginx package
This throws the concurrent install error as expected on
main
With this PR, we get this error instead