Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Don't throw concurrent installation error when encountering c…
…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]>
- Loading branch information