From 56ab29f6c8550a5930e228c5baff3eb42b07f986 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Wed, 15 Sep 2021 10:56:58 +0200 Subject: [PATCH] [Upgrade Assistant] Make infra plugin optional (#111960) * Make infra plugin optional * Fix CR requests --- .../helpers/app_context.mock.ts | 1 + .../fix_logs_step/fix_logs_step.test.tsx | 11 +++++++ x-pack/plugins/upgrade_assistant/kibana.json | 4 +-- .../overview/fix_logs_step/external_links.tsx | 32 +++++++++++-------- .../upgrade_assistant/public/plugin.ts | 6 +++- .../plugins/upgrade_assistant/public/types.ts | 1 + .../upgrade_assistant/server/plugin.ts | 2 +- 7 files changed, 39 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts index 42c05c2d80d37..46e3deda36fc9 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts @@ -74,6 +74,7 @@ export const getAppContextMock = () => ({ }, plugins: { share: shareMock, + infra: undefined, cloud: { ...cloudMock.createSetup(), isCloudEnabled: false, diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx index c81e0b2bd943e..96c0a874419a9 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx @@ -198,6 +198,9 @@ describe('Overview - Fix deprecation logs step', () => { prepend: (url: string) => url, }, }, + plugins: { + infra: {}, + }, }); }); @@ -211,6 +214,14 @@ describe('Overview - Fix deprecation logs step', () => { ); }); + test(`Doesn't show observability app link if infra app is not available`, async () => { + const { component, exists } = testBed; + + component.update(); + + expect(exists('viewObserveLogs')).toBe(false); + }); + test('Has a link to see logs in discover app', async () => { await act(async () => { testBed = await setupOverviewPage(); diff --git a/x-pack/plugins/upgrade_assistant/kibana.json b/x-pack/plugins/upgrade_assistant/kibana.json index c70d5e461d5bc..41789b393b68d 100644 --- a/x-pack/plugins/upgrade_assistant/kibana.json +++ b/x-pack/plugins/upgrade_assistant/kibana.json @@ -8,7 +8,7 @@ "githubTeam": "kibana-stack-management" }, "configPath": ["xpack", "upgrade_assistant"], - "requiredPlugins": ["management", "data", "licensing", "features", "infra", "share"], - "optionalPlugins": ["usageCollection", "cloud", "security"], + "requiredPlugins": ["management", "data", "licensing", "features", "share"], + "optionalPlugins": ["usageCollection", "cloud", "security", "infra"], "requiredBundles": ["esUiShared", "kibanaReact", "kibanaUtils"] } diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx index 7ced564fab204..d027b2f262e9e 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx @@ -105,22 +105,26 @@ const ObservabilityAppLink: FunctionComponent = ({ checkpoint }) => { }; export const ExternalLinks: FunctionComponent = ({ checkpoint }) => { + const { infra: hasInfraPlugin } = useAppContext().plugins; + return ( - - - -

- -

-
- - -
-
+ {hasInfraPlugin && ( + + + +

+ +

+
+ + +
+
+ )} diff --git a/x-pack/plugins/upgrade_assistant/public/plugin.ts b/x-pack/plugins/upgrade_assistant/public/plugin.ts index 24a9d75a7508b..bafcae79acc13 100644 --- a/x-pack/plugins/upgrade_assistant/public/plugin.ts +++ b/x-pack/plugins/upgrade_assistant/public/plugin.ts @@ -43,7 +43,7 @@ export class UpgradeAssistantUIPlugin title: pluginName, order: 1, async mount(params) { - const [coreStart, { data }] = await coreSetup.getStartServices(); + const [coreStart, { data, ...plugins }] = await coreSetup.getStartServices(); const { chrome: { docTitle }, @@ -57,6 +57,10 @@ export class UpgradeAssistantUIPlugin plugins: { cloud, share, + // Infra plugin doesnt export anything as a public interface. So the only + // way we have at this stage for checking if the plugin is available or not + // is by checking if the startServices has the `infra` key. + infra: plugins.hasOwnProperty('infra') ? {} : undefined, }, services: { core: coreStart, diff --git a/x-pack/plugins/upgrade_assistant/public/types.ts b/x-pack/plugins/upgrade_assistant/public/types.ts index 55c43e452a864..4d47c10fdeec2 100644 --- a/x-pack/plugins/upgrade_assistant/public/types.ts +++ b/x-pack/plugins/upgrade_assistant/public/types.ts @@ -45,6 +45,7 @@ export interface AppDependencies { plugins: { cloud?: CloudSetup; share: SharePluginSetup; + infra: object | undefined; }; services: { core: CoreStart; diff --git a/x-pack/plugins/upgrade_assistant/server/plugin.ts b/x-pack/plugins/upgrade_assistant/server/plugin.ts index 4c46b923f0650..800aeecc57d55 100644 --- a/x-pack/plugins/upgrade_assistant/server/plugin.ts +++ b/x-pack/plugins/upgrade_assistant/server/plugin.ts @@ -99,7 +99,7 @@ export class UpgradeAssistantServerPlugin implements Plugin { // We need to initialize the deprecation logs plugin so that we can // navigate from this app to the observability app using a source_id. - infra.defineInternalSourceConfiguration(DEPRECATION_LOGS_SOURCE_ID, { + infra?.defineInternalSourceConfiguration(DEPRECATION_LOGS_SOURCE_ID, { name: 'deprecationLogs', description: 'deprecation logs', logIndices: {