Skip to content

Commit

Permalink
[Fleet] Don't error on missing package_assets value (#91744) (#92003)
Browse files Browse the repository at this point in the history
## 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_

Co-authored-by: John Schulz <john.schulz@elastic.co>
  • Loading branch information
kibanamachine and John Schulz authored Feb 19, 2021
1 parent a23cab2 commit 90df80f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export type PackageInfo =
export interface Installation extends SavedObjectAttributes {
installed_kibana: KibanaAssetReference[];
installed_es: EsAssetReference[];
package_assets: PackageAssetReference[];
package_assets?: PackageAssetReference[];
es_index_patterns: Record<string, string>;
name: string;
version: string;
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/server/services/epm/archive/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ export async function archiveEntryToESDocument(opts: {

export async function removeArchiveEntries(opts: {
savedObjectsClient: SavedObjectsClientContract;
refs: PackageAssetReference[];
refs?: PackageAssetReference[];
}) {
const { savedObjectsClient, refs } = opts;
if (!refs) return;
const results = await Promise.all(
refs.map((ref) => savedObjectsClient.delete(ASSETS_SAVED_OBJECT_TYPE, ref.id))
);
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/fleet/server/services/epm/packages/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants';
import { ArchivePackage, RegistryPackage, EpmPackageAdditions } from '../../../../common/types';
import { Installation, PackageInfo, KibanaAssetType } from '../../../types';
import { IngestManagerError } from '../../../errors';
import * as Registry from '../registry';
import { createInstallableFrom, isRequiredPackage } from './index';
import { getEsPackage } from '../archive/storage';
Expand Down Expand Up @@ -185,7 +186,8 @@ export async function getPackageFromSource(options: {
name: pkgName,
version: pkgVersion,
});
if (!res) {

if (!res && installedPkg.package_assets) {
res = await getEsPackage(
pkgName,
pkgVersion,
Expand All @@ -207,7 +209,9 @@ export async function getPackageFromSource(options: {
// else package is not installed or installed and missing from cache and storage and installed from registry
res = await Registry.getRegistryPackage(pkgName, pkgVersion);
}
if (!res) throw new Error(`package info for ${pkgName}-${pkgVersion} does not exist`);
if (!res) {
throw new IngestManagerError(`package info for ${pkgName}-${pkgVersion} does not exist`);
}
return {
paths: res.paths,
packageInfo: res.packageInfo,
Expand Down

0 comments on commit 90df80f

Please sign in to comment.