Skip to content

Commit

Permalink
[APM] APM support for bundled fleet packages (#149342)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogupte committed Apr 18, 2023
1 parent 9a09560 commit cecca8e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions x-pack/plugins/apm/server/routes/fleet/get_latest_apm_package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ export async function getLatestApmPackage({
request: KibanaRequest;
}) {
const packageClient = fleetPluginStart.packageService.asScoped(request);
const { name, version } = await packageClient.fetchFindLatestPackage(
const latestPackage = await packageClient.fetchFindLatestPackage(
APM_PACKAGE_NAME
);
const registryPackage = await packageClient.getPackage(name, version);
const { title, policy_templates: policyTemplates } =
registryPackage.packageInfo;
const packageInfo =
'buffer' in latestPackage
? (await packageClient.readBundledPackage(latestPackage)).packageInfo
: latestPackage;
const {
name,
version,
title,
policy_templates: policyTemplates,
} = packageInfo;
const firstTemplate = policyTemplates?.[0];
const policyTemplateInputVars =
firstTemplate && 'inputs' in firstTemplate
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/fleet/server/services/epm/package_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { installTransforms, isTransform } from './elasticsearch/transform/instal
import type { FetchFindLatestPackageOptions } from './registry';
import { fetchFindLatestPackageOrThrow, getPackage } from './registry';
import { ensureInstalledPackage, getInstallation, getPackages } from './packages';
import { generatePackageInfoFromArchiveBuffer } from './archive';

export type InstalledAssetType = EsAssetReference;

Expand All @@ -54,6 +55,10 @@ export interface PackageClient {
options?: FetchFindLatestPackageOptions
): Promise<RegistryPackage | BundledPackage>;

readBundledPackage(
bundledPackage: BundledPackage
): Promise<{ packageInfo: ArchivePackage; paths: string[] }>;

getPackage(
packageName: string,
packageVersion: string
Expand Down Expand Up @@ -137,6 +142,10 @@ class PackageClientImpl implements PackageClient {
return fetchFindLatestPackageOrThrow(packageName, options);
}

public async readBundledPackage(bundledPackage: BundledPackage) {
return generatePackageInfoFromArchiveBuffer(bundledPackage.buffer, 'application/zip');
}

public async getPackage(
packageName: string,
packageVersion: string,
Expand Down

0 comments on commit cecca8e

Please sign in to comment.