diff --git a/x-pack/plugins/apm/server/deprecations/deprecations.test.ts b/x-pack/plugins/apm/server/deprecations/deprecations.test.ts index 6b00c5cdd9a2b..8761e46df9aaa 100644 --- a/x-pack/plugins/apm/server/deprecations/deprecations.test.ts +++ b/x-pack/plugins/apm/server/deprecations/deprecations.test.ts @@ -27,8 +27,8 @@ describe('getDeprecations', () => { }); }); - describe('when running on cloud with legacy apm-server', () => { - it('returns deprecations', async () => { + describe('when running on cloud without cloud agent policy', () => { + it('returns no deprecations', async () => { const deprecationsCallback = getDeprecations({ branch: 'main', cloudSetup: { isCloudEnabled: true } as unknown as CloudSetup, @@ -39,6 +39,28 @@ describe('getDeprecations', () => { } as unknown as APMRouteHandlerResources['plugins']['fleet'], }); const deprecations = await deprecationsCallback(deprecationContext); + expect(deprecations).toEqual([]); + }); + }); + + describe('when running on cloud with cloud agent policy and without apm integration', () => { + it('returns deprecations', async () => { + const deprecationsCallback = getDeprecations({ + branch: 'main', + cloudSetup: { isCloudEnabled: true } as unknown as CloudSetup, + fleet: { + start: () => ({ + agentPolicyService: { + get: () => + ({ + id: 'foo', + package_policies: [''], + } as AgentPolicy), + }, + }), + } as unknown as APMRouteHandlerResources['plugins']['fleet'], + }); + const deprecations = await deprecationsCallback(deprecationContext); expect(deprecations).not.toEqual([]); // TODO: remove when docs support "main" if (kibanaPackageJson.branch === 'main') { @@ -50,7 +72,7 @@ describe('getDeprecations', () => { }); }); - describe('when running on cloud with fleet', () => { + describe('when running on cloud with cloud agent policy and apm integration', () => { it('returns no deprecations', async () => { const deprecationsCallback = getDeprecations({ branch: 'main', diff --git a/x-pack/plugins/apm/server/deprecations/index.ts b/x-pack/plugins/apm/server/deprecations/index.ts index 6c6567440f267..76637842e9503 100644 --- a/x-pack/plugins/apm/server/deprecations/index.ts +++ b/x-pack/plugins/apm/server/deprecations/index.ts @@ -31,6 +31,8 @@ export function getDeprecations({ if (!fleet) { return deprecations; } + // TODO: remove when docs support "main" + const docBranch = branch === 'main' ? 'master' : branch; const fleetPluginStart = await fleet.start(); const cloudAgentPolicy = await getCloudAgentPolicy({ @@ -39,12 +41,10 @@ export function getDeprecations({ }); const isCloudEnabled = !!cloudSetup?.isCloudEnabled; + const hasCloudAgentPolicy = !isEmpty(cloudAgentPolicy); const hasAPMPackagePolicy = !isEmpty(getApmPackagePolicy(cloudAgentPolicy)); - // TODO: remove when docs support "main" - const docBranch = branch === 'main' ? 'master' : branch; - - if (isCloudEnabled && !hasAPMPackagePolicy) { + if (isCloudEnabled && hasCloudAgentPolicy && !hasAPMPackagePolicy) { deprecations.push({ title: i18n.translate('xpack.apm.deprecations.legacyModeTitle', { defaultMessage: 'APM Server running in legacy mode',