Skip to content

Commit

Permalink
[8.x] [Fleet] Fix Install with streaming to save readme and icons (#1…
Browse files Browse the repository at this point in the history
…99727) (#199823)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Fleet] Fix Install with streaming to save readme and icons
(#199727)](#199727)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nicolas
Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-12T16:21:22Z","message":"[Fleet]
Fix Install with streaming to save readme and icons
(#199727)","sha":"839a9759ea56ded48477c8d31100c7f265add553","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Fleet","v9.0.0","backport:version","v8.17.0"],"title":"[Fleet]
Fix Install with streaming to save readme and
icons","number":199727,"url":"https://github.com/elastic/kibana/pull/199727","mergeCommit":{"message":"[Fleet]
Fix Install with streaming to save readme and icons
(#199727)","sha":"839a9759ea56ded48477c8d31100c7f265add553"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199727","number":199727,"mergeCommit":{"message":"[Fleet]
Fix Install with streaming to save readme and icons
(#199727)","sha":"839a9759ea56ded48477c8d31100c7f265add553"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nicolas Chaulet <[email protected]>
  • Loading branch information
kibanamachine and nchaulet authored Nov 12, 2024
1 parent 26dfbab commit 780a9f2
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ const mockedRemoveArchiveEntries = removeArchiveEntries as jest.MockedFunction<
let soClient: jest.Mocked<SavedObjectsClientContract>;
let esClient: jest.Mocked<ElasticsearchClient>;

const assetsMap = new Map([
[
'endpoint-0.16.0-dev.0/elasticsearch/transform/metadata_current/default.json',
Buffer.from('{"content": "data"}'),
],
['security_detection_engine-8.16.1/LICENSE.txt', Buffer.from('{"content": "data"}')],
['security_detection_engine-8.16.1/NOTICE.txt', Buffer.from('{"content": "data"}')],
['security_detection_engine-8.16.1/changelog.yml', Buffer.from('{"content": "data"}')],
['security_detection_engine-8.16.1/manifest.yml', Buffer.from('{"content": "data"}')],
['security_detection_engine-8.16.1/docs/README.md', Buffer.from('{"content": "data"}')],
[
'security_detection_engine-8.16.1/img/security-logo-color-64px.svg',
Buffer.from('{"content": "data"}'),
],
[
'security_detection_engine-8.16.1/kibana/security_rule/000047bb-b27a-47ec-8b62-ef1a5d2c9e19_208.json',
Buffer.from('{"content": "data"}'),
],
[
'security_detection_engine-8.16.1/kibana/security_rule/000047bb-b27a-47ec-8b62-ef1a5d2c9e19_209.json',
Buffer.from('{"content": "data"}'),
],
]);

const packageInstallContext = {
packageInfo: {
title: 'title',
Expand All @@ -56,13 +80,8 @@ const packageInstallContext = {
owner: { github: 'elastic/fleet' },
} as any,
paths: ['some/path/1', 'some/path/2'],
assetsMap: new Map([
[
'endpoint-0.16.0-dev.0/elasticsearch/transform/metadata_current/default.json',
Buffer.from('{"content": "data"}'),
],
]),
archiveIterator: createArchiveIteratorFromMap(new Map()),
assetsMap,
archiveIterator: createArchiveIteratorFromMap(assetsMap),
};
const getMockInstalledPackageSo = (
installedEs: EsAssetReference[] = []
Expand Down Expand Up @@ -196,6 +215,63 @@ describe('stepSaveArchiveEntries', () => {
],
});
});

it('should save package icons, readme, and changelog but not Kibana assets with useStreaming:true ', async () => {
jest.mocked(mockedSaveArchiveEntriesFromAssetsMap).mockResolvedValue({
saved_objects: [
{
id: 'test',
attributes: {
package_name: 'test-package',
package_version: '1.0.0',
install_source: 'registry',
asset_path: 'some/path',
media_type: '',
data_utf8: '',
data_base64: '',
},
type: '',
references: [],
},
],
});
await stepSaveArchiveEntries({
savedObjectsClient: soClient,
// @ts-ignore
savedObjectsImporter: jest.fn(),
esClient,
logger: loggerMock.create(),
packageInstallContext,
installedPkg,
installType: 'update',
installSource: 'registry',
spaceId: DEFAULT_SPACE_ID,
useStreaming: true,
esReferences: [
{
id: 'something',
type: ElasticsearchAssetType.ilmPolicy,
},
],
});
expect(
[
...(jest
.mocked(mockedSaveArchiveEntriesFromAssetsMap)
.mock.lastCall?.[0].assetsMap?.keys() ?? []),
].sort()
).toMatchInlineSnapshot(`
Array [
"endpoint-0.16.0-dev.0/elasticsearch/transform/metadata_current/default.json",
"security_detection_engine-8.16.1/LICENSE.txt",
"security_detection_engine-8.16.1/NOTICE.txt",
"security_detection_engine-8.16.1/changelog.yml",
"security_detection_engine-8.16.1/docs/README.md",
"security_detection_engine-8.16.1/img/security-logo-color-64px.svg",
"security_detection_engine-8.16.1/manifest.yml",
]
`);
});
});

describe('cleanupArchiveEntriesStep', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { withPackageSpan } from '../../utils';

import type { InstallContext } from '../_state_machine_package_install';
import { INSTALL_STATES } from '../../../../../../common/types';
import { MANIFEST_NAME } from '../../../archive/parse';
import { isKibanaAssetType } from '../../../kibana/assets/install';

export async function stepSaveArchiveEntries(context: InstallContext) {
const { packageInstallContext, savedObjectsClient, installSource, useStreaming } = context;
Expand All @@ -28,7 +28,8 @@ export async function stepSaveArchiveEntries(context: InstallContext) {
if (useStreaming) {
assetsMap = new Map();
await archiveIterator.traverseEntries(async (entry) => {
if (entry.path.endsWith(MANIFEST_NAME)) {
// Skip only kibana assets type
if (!isKibanaAssetType(entry.path)) {
assetsMap.set(entry.path, entry.buffer);
}
});
Expand Down

0 comments on commit 780a9f2

Please sign in to comment.