mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
# Backport This will backport the following commits from `main` to `8.6`: - [[Fleet] fix for apm not found in epr + prerelease flag (#147257)](https://github.com/elastic/kibana/pull/147257) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Julia Bardi","email":"90178898+juliaElastic@users.noreply.github.com"},"sourceCommit":{"committedDate":"2022-12-12T10:06:50Z","message":"[Fleet] fix for apm not found in epr + prerelease flag (#147257)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/146312\r\n\r\nFall back to bundled packages when loading package archive.\r\n\r\nAlso fixed an issue with prerelease flag caused by\r\nhttps://github.com/elastic/kibana/pull/144431\r\n\r\nLoading prerelease setting on Add/Edit integration page, so that it\r\nworks well for cases where the url doesn't contain a concrete version\r\nlike APM\r\n\r\nSteps to verify:\r\n- Start kibana locally, make sure that APM bundled package is there in\r\n`x-pack/plugins/fleet/target/bundled_packages`\r\n- Load http://localhost:5601/julia/app/integrations/detail/apm/overview\r\n(with default \"beta integrations\" off flag)\r\n- Expect that 8.6.0 version is showing up (or 8.7.0 depending on the\r\nbuild)\r\n- When clicking on Add Elastic APM, expect 8.6.0 to be loaded\r\nsuccessfully\r\n\r\n<img width=\"1773\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206482128-634ca823-bb21-46a9-a8b9-fc81d5dc126d.png\">\r\n\r\nNote: there is still a UI issue with loading assets on Overview page if\r\nthe package is not in EPR.\r\n\r\n<img width=\"1747\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206478275-ee8e9494-234f-44c8-88d9-a91c791b0196.png\">\r\n\r\n- switch \"beta integrations\" on on Integrations page\r\n- Open APM overview page again\r\n- expect `8.7.0-preview` version with the selector to change to last GA\r\n\r\n<img width=\"1100\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206480986-2ed05b12-49e4-4c88-97c6-6cdf12f819da.png\">\r\n\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"24e2fcf47014d937a5019d83b95565a010ae4e22","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v8.6.0","v8.7.0"],"number":147257,"url":"https://github.com/elastic/kibana/pull/147257","mergeCommit":{"message":"[Fleet] fix for apm not found in epr + prerelease flag (#147257)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/146312\r\n\r\nFall back to bundled packages when loading package archive.\r\n\r\nAlso fixed an issue with prerelease flag caused by\r\nhttps://github.com/elastic/kibana/pull/144431\r\n\r\nLoading prerelease setting on Add/Edit integration page, so that it\r\nworks well for cases where the url doesn't contain a concrete version\r\nlike APM\r\n\r\nSteps to verify:\r\n- Start kibana locally, make sure that APM bundled package is there in\r\n`x-pack/plugins/fleet/target/bundled_packages`\r\n- Load http://localhost:5601/julia/app/integrations/detail/apm/overview\r\n(with default \"beta integrations\" off flag)\r\n- Expect that 8.6.0 version is showing up (or 8.7.0 depending on the\r\nbuild)\r\n- When clicking on Add Elastic APM, expect 8.6.0 to be loaded\r\nsuccessfully\r\n\r\n<img width=\"1773\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206482128-634ca823-bb21-46a9-a8b9-fc81d5dc126d.png\">\r\n\r\nNote: there is still a UI issue with loading assets on Overview page if\r\nthe package is not in EPR.\r\n\r\n<img width=\"1747\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206478275-ee8e9494-234f-44c8-88d9-a91c791b0196.png\">\r\n\r\n- switch \"beta integrations\" on on Integrations page\r\n- Open APM overview page again\r\n- expect `8.7.0-preview` version with the selector to change to last GA\r\n\r\n<img width=\"1100\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206480986-2ed05b12-49e4-4c88-97c6-6cdf12f819da.png\">\r\n\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"24e2fcf47014d937a5019d83b95565a010ae4e22"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/147257","number":147257,"mergeCommit":{"message":"[Fleet] fix for apm not found in epr + prerelease flag (#147257)\n\n## Summary\r\n\r\nFixes https://github.com/elastic/kibana/issues/146312\r\n\r\nFall back to bundled packages when loading package archive.\r\n\r\nAlso fixed an issue with prerelease flag caused by\r\nhttps://github.com/elastic/kibana/pull/144431\r\n\r\nLoading prerelease setting on Add/Edit integration page, so that it\r\nworks well for cases where the url doesn't contain a concrete version\r\nlike APM\r\n\r\nSteps to verify:\r\n- Start kibana locally, make sure that APM bundled package is there in\r\n`x-pack/plugins/fleet/target/bundled_packages`\r\n- Load http://localhost:5601/julia/app/integrations/detail/apm/overview\r\n(with default \"beta integrations\" off flag)\r\n- Expect that 8.6.0 version is showing up (or 8.7.0 depending on the\r\nbuild)\r\n- When clicking on Add Elastic APM, expect 8.6.0 to be loaded\r\nsuccessfully\r\n\r\n<img width=\"1773\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206482128-634ca823-bb21-46a9-a8b9-fc81d5dc126d.png\">\r\n\r\nNote: there is still a UI issue with loading assets on Overview page if\r\nthe package is not in EPR.\r\n\r\n<img width=\"1747\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206478275-ee8e9494-234f-44c8-88d9-a91c791b0196.png\">\r\n\r\n- switch \"beta integrations\" on on Integrations page\r\n- Open APM overview page again\r\n- expect `8.7.0-preview` version with the selector to change to last GA\r\n\r\n<img width=\"1100\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/90178898/206480986-2ed05b12-49e4-4c88-97c6-6cdf12f819da.png\">\r\n\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"24e2fcf47014d937a5019d83b95565a010ae4e22"}}]}] BACKPORT--> Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
This commit is contained in:
parent
a24e1283e0
commit
34e5a4642d
9 changed files with 85 additions and 19 deletions
|
@ -4,10 +4,12 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import { useLocation, useRouteMatch } from 'react-router-dom';
|
||||
|
||||
import { useGetSettings } from '../../../hooks';
|
||||
|
||||
import type { AddToPolicyParams, EditPackagePolicyFrom } from './types';
|
||||
|
||||
import { CreatePackagePolicySinglePage } from './single_page_layout';
|
||||
|
@ -22,6 +24,17 @@ export const CreatePackagePolicyPage: React.FC<{}> = () => {
|
|||
() => queryParams.get('policyId') ?? undefined,
|
||||
[queryParams]
|
||||
);
|
||||
const [prerelease, setPrerelease] = React.useState<boolean>(false);
|
||||
|
||||
const { data: settings } = useGetSettings();
|
||||
|
||||
useEffect(() => {
|
||||
const isEnabled = Boolean(settings?.item.prerelease_integrations_enabled);
|
||||
if (settings?.item) {
|
||||
setPrerelease(isEnabled);
|
||||
}
|
||||
}, [settings?.item]);
|
||||
|
||||
/**
|
||||
* Please note: policyId can come from one of two sources. The URL param (in the URL path) or
|
||||
* in the query params (?policyId=foo).
|
||||
|
@ -39,6 +52,7 @@ export const CreatePackagePolicyPage: React.FC<{}> = () => {
|
|||
const pageParams = {
|
||||
from,
|
||||
queryParamsPolicyId,
|
||||
prerelease,
|
||||
};
|
||||
|
||||
if (useMultiPageLayout) {
|
||||
|
|
|
@ -52,6 +52,7 @@ const standaloneSteps = [addIntegrationStep, installAgentStep, confirmDataStep];
|
|||
export const CreatePackagePolicyMultiPage: CreatePackagePolicyParams = ({
|
||||
from,
|
||||
queryParamsPolicyId,
|
||||
prerelease,
|
||||
}) => {
|
||||
const { params } = useRouteMatch<AddToPolicyParams>();
|
||||
const { pkgkey, policyId, integration } = params;
|
||||
|
@ -70,7 +71,7 @@ export const CreatePackagePolicyMultiPage: CreatePackagePolicyParams = ({
|
|||
data: packageInfoData,
|
||||
error: packageInfoError,
|
||||
isLoading: isPackageInfoLoading,
|
||||
} = useGetPackageInfoByKey(pkgName, pkgVersion, { prerelease: true, full: true });
|
||||
} = useGetPackageInfoByKey(pkgName, pkgVersion, { prerelease, full: true });
|
||||
|
||||
const {
|
||||
agentPolicy,
|
||||
|
|
|
@ -109,7 +109,11 @@ describe('when on the package policy create page', () => {
|
|||
const render = (queryParamsPolicyId?: string) =>
|
||||
(renderResult = testRenderer.render(
|
||||
<Route path={FLEET_ROUTING_PATHS.add_integration_to_policy}>
|
||||
<CreatePackagePolicySinglePage from="package" queryParamsPolicyId={queryParamsPolicyId} />
|
||||
<CreatePackagePolicySinglePage
|
||||
from="package"
|
||||
queryParamsPolicyId={queryParamsPolicyId}
|
||||
prerelease={false}
|
||||
/>
|
||||
</Route>
|
||||
));
|
||||
let mockPackageInfo: any;
|
||||
|
|
|
@ -73,6 +73,7 @@ const CustomEuiBottomBar = styled(EuiBottomBar)`
|
|||
export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({
|
||||
from,
|
||||
queryParamsPolicyId,
|
||||
prerelease,
|
||||
}) => {
|
||||
const {
|
||||
agents: { enabled: isFleetEnabled },
|
||||
|
@ -99,7 +100,7 @@ export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({
|
|||
data: packageInfoData,
|
||||
error: packageInfoError,
|
||||
isLoading: isPackageInfoLoading,
|
||||
} = useGetPackageInfoByKey(pkgName, pkgVersion, { full: true, prerelease: true });
|
||||
} = useGetPackageInfoByKey(pkgName, pkgVersion, { full: true, prerelease });
|
||||
const packageInfo = useMemo(() => {
|
||||
if (packageInfoData && packageInfoData.item) {
|
||||
return packageInfoData.item;
|
||||
|
|
|
@ -32,4 +32,5 @@ export interface AddToPolicyParams {
|
|||
export type CreatePackagePolicyParams = React.FunctionComponent<{
|
||||
from: EditPackagePolicyFrom;
|
||||
queryParamsPolicyId?: string;
|
||||
prerelease: boolean;
|
||||
}>;
|
||||
|
|
|
@ -35,6 +35,7 @@ import {
|
|||
sendGetPackageInfoByKey,
|
||||
sendUpgradePackagePolicyDryRun,
|
||||
useAuthz,
|
||||
useGetSettings,
|
||||
} from '../../../hooks';
|
||||
import {
|
||||
useBreadcrumbs as useIntegrationsBreadcrumbs,
|
||||
|
@ -129,6 +130,17 @@ export const EditPackagePolicyForm = memo<{
|
|||
|
||||
const canWriteIntegrationPolicies = useAuthz().integrations.writeIntegrationPolicies;
|
||||
|
||||
const [prerelease, setPrerelease] = React.useState<boolean>(false);
|
||||
|
||||
const { data: settings } = useGetSettings();
|
||||
|
||||
useEffect(() => {
|
||||
const isEnabled = Boolean(settings?.item.prerelease_integrations_enabled);
|
||||
if (settings?.item) {
|
||||
setPrerelease(isEnabled);
|
||||
}
|
||||
}, [settings?.item]);
|
||||
|
||||
useEffect(() => {
|
||||
if (forceUpgrade) {
|
||||
setIsUpgrade(true);
|
||||
|
@ -266,7 +278,7 @@ export const EditPackagePolicyForm = memo<{
|
|||
const { data: packageData } = await sendGetPackageInfoByKey(
|
||||
_packageInfo!.name,
|
||||
_packageInfo!.version,
|
||||
{ prerelease: true, full: true }
|
||||
{ prerelease, full: true }
|
||||
);
|
||||
|
||||
if (packageData?.item) {
|
||||
|
@ -293,7 +305,7 @@ export const EditPackagePolicyForm = memo<{
|
|||
setIsLoadingData(false);
|
||||
};
|
||||
getData();
|
||||
}, [policyId, packagePolicyId, isUpgrade]);
|
||||
}, [policyId, packagePolicyId, isUpgrade, prerelease]);
|
||||
|
||||
// Retrieve agent count
|
||||
const [agentCount, setAgentCount] = useState<number>(0);
|
||||
|
|
|
@ -23,7 +23,12 @@ import type {
|
|||
GetCategoriesRequest,
|
||||
} from '../../../../common/types';
|
||||
import type { Installation, PackageInfo } from '../../../types';
|
||||
import { FleetError, PackageFailedVerificationError, PackageNotFoundError } from '../../../errors';
|
||||
import {
|
||||
FleetError,
|
||||
PackageFailedVerificationError,
|
||||
PackageNotFoundError,
|
||||
RegistryResponseError,
|
||||
} from '../../../errors';
|
||||
import { appContextService } from '../..';
|
||||
import * as Registry from '../registry';
|
||||
import { getEsPackage } from '../archive/storage';
|
||||
|
@ -305,8 +310,16 @@ export async function getPackageFromSource(options: {
|
|||
if (res) {
|
||||
logger.debug(`retrieved package ${pkgName}-${pkgVersion} from cache`);
|
||||
} else {
|
||||
res = await Registry.getPackage(pkgName, pkgVersion, { ignoreUnverified });
|
||||
logger.debug(`retrieved package ${pkgName}-${pkgVersion} from registry`);
|
||||
try {
|
||||
res = await Registry.getPackage(pkgName, pkgVersion, { ignoreUnverified });
|
||||
logger.debug(`retrieved package ${pkgName}-${pkgVersion} from registry`);
|
||||
} catch (err) {
|
||||
if (err instanceof RegistryResponseError && err.status === 404) {
|
||||
res = await Registry.getBundledArchive(pkgName, pkgVersion);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!res) {
|
||||
|
|
|
@ -184,24 +184,33 @@ export async function fetchInfo(
|
|||
return res;
|
||||
} catch (err) {
|
||||
if (err instanceof RegistryResponseError && err.status === 404) {
|
||||
// Check bundled packages in case the exact package being requested is available on disk
|
||||
const bundledPackage = await getBundledPackageByName(pkgName);
|
||||
|
||||
if (bundledPackage && bundledPackage.version === pkgVersion) {
|
||||
const archivePackage = await generatePackageInfoFromArchiveBuffer(
|
||||
bundledPackage.buffer,
|
||||
'application/zip'
|
||||
);
|
||||
|
||||
const archivePackage = await getBundledArchive(pkgName, pkgVersion);
|
||||
if (archivePackage) {
|
||||
return archivePackage.packageInfo;
|
||||
}
|
||||
|
||||
throw new PackageNotFoundError(`${pkgName}@${pkgVersion} not found`);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getBundledArchive(
|
||||
pkgName: string,
|
||||
pkgVersion: string
|
||||
): Promise<{ paths: string[]; packageInfo: ArchivePackage } | undefined> {
|
||||
// Check bundled packages in case the exact package being requested is available on disk
|
||||
const bundledPackage = await getBundledPackageByName(pkgName);
|
||||
|
||||
if (bundledPackage && bundledPackage.version === pkgVersion) {
|
||||
const archivePackage = await generatePackageInfoFromArchiveBuffer(
|
||||
bundledPackage.buffer,
|
||||
'application/zip'
|
||||
);
|
||||
|
||||
return archivePackage;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getFile(
|
||||
pkgName: string,
|
||||
pkgVersion: string,
|
||||
|
|
|
@ -100,6 +100,17 @@ export default function (providerContext: FtrProviderContext) {
|
|||
|
||||
expect(updateResponse.body._meta.install_source).to.be('bundled');
|
||||
});
|
||||
|
||||
it('should load package archive from bundled package', async () => {
|
||||
await bundlePackage('nginx-1.2.1');
|
||||
|
||||
const response = await supertest
|
||||
.get(`/api/fleet/epm/packages/nginx/1.2.1?full=true`)
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.item.name).to.eql('nginx');
|
||||
expect(response.body.item.version).to.eql('1.2.1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with registry', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue