-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Tagging of integration assets #137184
Merged
juliaElastic
merged 18 commits into
elastic:main
from
juliaElastic:feat/saved-object-tagging
Jul 29, 2022
+366
−18
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
90e46c9
WIP saved object tagging
juliaElastic cfe84a8
fixing plugin usage
juliaElastic 77ec521
added logic to create tags before assigning
juliaElastic d7cbcf4
moved constants out
juliaElastic c4373f9
fixed tests, added span
juliaElastic c7512b2
added unit test to tagKibanaAssets
juliaElastic 7706aab
fix test
juliaElastic d00478b
fix types
juliaElastic a5fa279
fixed tests
juliaElastic 3f92ebe
fixed tests
juliaElastic 4382894
fix types
juliaElastic 766ee1a
fix sot tests by loading empty kibana archive
juliaElastic f74e91d
added tag checking to api integration test
juliaElastic a430602
Merge branch 'main' into feat/saved-object-tagging
kibanamachine df7b186
Merge branch 'main' into feat/saved-object-tagging
kibanamachine 7660613
added refresh option to speed up tagging assets
juliaElastic d288690
fixed tests
juliaElastic 0c9f93e
workaround to prevent installing fleet packages in SOT functional tests
juliaElastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,10 @@ import type { SavedObjectsImportSuccess, SavedObjectsImportFailure } from '@kbn/ | |
import { createListStream } from '@kbn/utils'; | ||
import { partition } from 'lodash'; | ||
|
||
import type { IAssignmentService, ITagsClient } from '@kbn/saved-objects-tagging-plugin/server'; | ||
|
||
import { taggableTypes } from '@kbn/saved-objects-tagging-plugin/common/constants'; | ||
|
||
import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../../../common'; | ||
import { getAsset, getPathParts } from '../../archive'; | ||
import { KibanaAssetType, KibanaSavedObjectType } from '../../../../types'; | ||
|
@@ -128,15 +132,21 @@ export async function installKibanaAssets(options: { | |
export async function installKibanaAssetsAndReferences({ | ||
savedObjectsClient, | ||
savedObjectsImporter, | ||
savedObjectTagAssignmentService, | ||
savedObjectTagClient, | ||
logger, | ||
pkgName, | ||
pkgTitle, | ||
paths, | ||
installedPkg, | ||
}: { | ||
savedObjectsClient: SavedObjectsClientContract; | ||
savedObjectsImporter: Pick<SavedObjectsImporter, 'import' | 'resolveImportErrors'>; | ||
savedObjectTagAssignmentService: IAssignmentService; | ||
savedObjectTagClient: ITagsClient; | ||
logger: Logger; | ||
pkgName: string; | ||
pkgTitle: string; | ||
paths: string[]; | ||
installedPkg?: SavedObject<Installation>; | ||
}) { | ||
|
@@ -156,9 +166,67 @@ export async function installKibanaAssetsAndReferences({ | |
kibanaAssets, | ||
}); | ||
|
||
await tagKibanaAssets({ | ||
savedObjectTagAssignmentService, | ||
savedObjectTagClient, | ||
kibanaAssets, | ||
pkgTitle, | ||
}); | ||
|
||
return installedKibanaAssetsRefs; | ||
} | ||
|
||
export async function tagKibanaAssets({ | ||
savedObjectTagAssignmentService, | ||
savedObjectTagClient, | ||
kibanaAssets, | ||
pkgTitle, | ||
}: { | ||
savedObjectTagAssignmentService: IAssignmentService; | ||
savedObjectTagClient: ITagsClient; | ||
kibanaAssets: Record<KibanaAssetType, ArchiveAsset[]>; | ||
pkgTitle: string; | ||
}) { | ||
const taggableAssets = Object.entries(kibanaAssets).flatMap(([assetType, assets]) => { | ||
if (!taggableTypes.includes(assetType as KibanaAssetType)) { | ||
return []; | ||
} | ||
|
||
if (!assets.length) { | ||
return []; | ||
} | ||
|
||
return assets; | ||
}); | ||
|
||
const managedTagName = 'Managed'; | ||
const tagColor = '#FFFFFF'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it will be nice to move this to a constant |
||
const allTags = await savedObjectTagClient.getAll(); | ||
let managedTag = allTags.find((tag) => tag.name === managedTagName); | ||
if (!managedTag) { | ||
managedTag = await savedObjectTagClient.create({ | ||
juliaElastic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name: managedTagName, | ||
description: '', | ||
color: tagColor, | ||
}); | ||
} | ||
|
||
let packageTag = allTags.find((tag) => tag.name === pkgTitle); | ||
if (!packageTag) { | ||
packageTag = await savedObjectTagClient.create({ | ||
name: pkgTitle, | ||
description: '', | ||
color: tagColor, | ||
}); | ||
} | ||
|
||
savedObjectTagAssignmentService.updateTagAssignments({ | ||
tags: [managedTag.id, packageTag.id], | ||
assign: taggableAssets, | ||
unassign: [], | ||
}); | ||
} | ||
|
||
export const deleteKibanaInstalledRefs = async ( | ||
savedObjectsClient: SavedObjectsClientContract, | ||
pkgName: string, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you think it'd be possible to wrap this in an APM span and track how it impacts installation performance for packages?