Skip to content

Commit 84db4d4

Browse files
John Schulzkibanamachine
authored andcommitted
[Fleet] Don't error on missing package_assets value (#91744)
## Summary closes #89111 * Update TS type to make `package_assets` key in EPM packages saved object optional * Update two places in code to deal with optional vs required property ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios #### Manual testing 1. checkout `7.10` branch 1. **start ES:** `nvm use; yarn kbn bootstrap; yarn es snapshot --version 7.10.3 --license=trial -E xpack.security.authc.api_key.enabled=true -E path.data=../data` 1. **start Kibana**: `yarn start --no-base-path` 1. **run** `curl -X POST -H 'kbn-xsrf: 1234' --user elastic:changeme localhost:5601/api/fleet/setup` 2. **observe** `{"is_initialized: true}` 1. checkout `7.11` branch 1. **start ES:** `nvm use; yarn kbn bootstrap; yarn es snapshot --version 7.11.1 --license=trial -E xpack.security.authc.api_key.enabled=true -E path.data=../data` 1. **start Kibana**: `yarn start --no-base-path` 1. **run** `curl -X POST -H 'kbn-xsrf: 1234' --user elastic:changeme localhost:5601/api/fleet/setup` 1. **observe** `{"is_initialized: true}` 1. checkout `master` branch 1. **start ES:** `nvm use; yarn kbn bootstrap; yarn es snapshot --version 8.0.0 --license=trial -E xpack.security.authc.api_key.enabled=true -E path.data=../data` 1. **start Kibana**: `yarn start --no-base-path` 1. **run** `curl -X POST -H 'kbn-xsrf: 1234' --user elastic:changeme localhost:5601/api/fleet/setup` 1. **observe error** {"statusCode":500,"error":"Internal Server Error","message":"Cannot read property 'map' of undefined"} 1. checkout this PR `8911-fleet-startup-error` 1. **start ES:** `nvm use; yarn kbn bootstrap; yarn es snapshot --version 8.0.0 --license=trial -E xpack.security.authc.api_key.enabled=true -E path.data=../data` 1. **start Kibana**: `yarn start --no-base-path` 1. **run** `curl -X POST -H 'kbn-xsrf: 1234' --user elastic:changeme localhost:5601/api/fleet/setup` 1. **observe success** `{"is_initialized: true}` **_Notes_** * _you might need to do a `yarn kbn clean` when starting kibana if it fails. There have been some big changes in the tooling recently_
1 parent 038fd51 commit 84db4d4

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

x-pack/plugins/fleet/common/types/models/epm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export type PackageInfo =
273273
export interface Installation extends SavedObjectAttributes {
274274
installed_kibana: KibanaAssetReference[];
275275
installed_es: EsAssetReference[];
276-
package_assets: PackageAssetReference[];
276+
package_assets?: PackageAssetReference[];
277277
es_index_patterns: Record<string, string>;
278278
name: string;
279279
version: string;

x-pack/plugins/fleet/server/services/epm/archive/storage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ export async function archiveEntryToESDocument(opts: {
8383

8484
export async function removeArchiveEntries(opts: {
8585
savedObjectsClient: SavedObjectsClientContract;
86-
refs: PackageAssetReference[];
86+
refs?: PackageAssetReference[];
8787
}) {
8888
const { savedObjectsClient, refs } = opts;
89+
if (!refs) return;
8990
const results = await Promise.all(
9091
refs.map((ref) => savedObjectsClient.delete(ASSETS_SAVED_OBJECT_TYPE, ref.id))
9192
);

x-pack/plugins/fleet/server/services/epm/packages/get.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants';
1717
import { ArchivePackage, RegistryPackage, EpmPackageAdditions } from '../../../../common/types';
1818
import { Installation, PackageInfo, KibanaAssetType } from '../../../types';
19+
import { IngestManagerError } from '../../../errors';
1920
import * as Registry from '../registry';
2021
import { createInstallableFrom, isRequiredPackage } from './index';
2122
import { getEsPackage } from '../archive/storage';
@@ -185,7 +186,8 @@ export async function getPackageFromSource(options: {
185186
name: pkgName,
186187
version: pkgVersion,
187188
});
188-
if (!res) {
189+
190+
if (!res && installedPkg.package_assets) {
189191
res = await getEsPackage(
190192
pkgName,
191193
pkgVersion,
@@ -207,7 +209,9 @@ export async function getPackageFromSource(options: {
207209
// else package is not installed or installed and missing from cache and storage and installed from registry
208210
res = await Registry.getRegistryPackage(pkgName, pkgVersion);
209211
}
210-
if (!res) throw new Error(`package info for ${pkgName}-${pkgVersion} does not exist`);
212+
if (!res) {
213+
throw new IngestManagerError(`package info for ${pkgName}-${pkgVersion} does not exist`);
214+
}
211215
return {
212216
paths: res.paths,
213217
packageInfo: res.packageInfo,

0 commit comments

Comments
 (0)