Skip to content

Commit

Permalink
Handle bulkGet errors on package retrieval from ES storage (#111114)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover authored Sep 3, 2021
1 parent 21b4752 commit ed18699
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions x-pack/plugins/fleet/server/services/epm/archive/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import type {
} from '../../../../common';
import { pkgToPkgKey } from '../registry';

import { appContextService } from '../../app_context';

import { getArchiveEntry, setArchiveEntry, setArchiveFilelist, setPackageInfo } from './index';
import type { ArchiveEntry } from './index';
import { parseAndVerifyPolicyTemplates, parseAndVerifyStreams } from './validation';
Expand Down Expand Up @@ -165,15 +167,35 @@ export const getEsPackage = async (
references: PackageAssetReference[],
savedObjectsClient: SavedObjectsClientContract
) => {
const logger = appContextService.getLogger();
const pkgKey = pkgToPkgKey({ name: pkgName, version: pkgVersion });
const bulkRes = await savedObjectsClient.bulkGet<PackageAsset>(
references.map((reference) => ({
...reference,
fields: ['asset_path', 'data_utf8', 'data_base64'],
}))
);
const errors = bulkRes.saved_objects.filter((so) => so.error || !so.attributes);
const assets = bulkRes.saved_objects.map((so) => so.attributes);

if (errors.length) {
const resolvedErrors = errors.map((so) =>
so.error
? { type: so.type, id: so.id, error: so.error }
: !so.attributes
? { type: so.type, id: so.id, error: { error: `No attributes retrieved` } }
: { type: so.type, id: so.id, error: { error: `Unknown` } }
);

logger.warn(
`Failed to retrieve ${pkgName}-${pkgVersion} package from ES storage. bulkGet failed for assets: ${JSON.stringify(
resolvedErrors
)}`
);

return undefined;
}

const paths: string[] = [];
const entries: ArchiveEntry[] = assets.map(packageAssetToArchiveEntry);
entries.forEach(({ path, buffer }) => {
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/fleet/server/services/epm/packages/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ export async function getPackageFromSource(options: {
installedPkg.package_assets,
savedObjectsClient
);
logger.debug(`retrieved installed package ${pkgName}-${pkgVersion} from ES`);

if (res) {
logger.debug(`retrieved installed package ${pkgName}-${pkgVersion} from ES`);
}
}
// for packages not in cache or package storage and installed from registry, check registry
if (!res && pkgInstallSource === 'registry') {
Expand Down

0 comments on commit ed18699

Please sign in to comment.