From ecf4b7c2a6b1df8fb97d17e1c9790a9bd6abf9e6 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 13 Sep 2021 16:27:00 +0200 Subject: [PATCH 1/2] Make infra plugin optional --- .../helpers/app_context.mock.ts | 1 + .../fix_logs_step/fix_logs_step.test.tsx | 14 ++++++++ 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, 42 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..73a6e74a9e5ea 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 @@ -55,6 +55,7 @@ shareMock.url.locators.get = (id: IdKey) => ({ export const getAppContextMock = () => ({ isReadOnlyMode: false, + isInfraPluginAvailable: true, kibanaVersionInfo: { currentMajor: mockKibanaSemverVersion.major, prevMajor: mockKibanaSemverVersion.major - 1, 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..2dd88036c6fcb 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 @@ -211,6 +211,20 @@ describe('Overview - Fix deprecation logs step', () => { ); }); + test(`Doesn't show observability app link if infra app is not available`, async () => { + await act(async () => { + testBed = await setupOverviewPage({ + isInfraPluginAvailable: false, + }); + }); + + 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 4573be8fdc041..db53d7b1ae6f2 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"], + "requiredPlugins": ["management", "data", "licensing", "features", "share"], + "optionalPlugins": ["usageCollection", "cloud", "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..3a16b7ac78f7d 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 { isInfraPluginAvailable } = useAppContext(); + return ( - - - -

- -

-
- - -
-
+ {isInfraPluginAvailable && ( + + + +

+ +

+
+ + +
+
+ )} diff --git a/x-pack/plugins/upgrade_assistant/public/plugin.ts b/x-pack/plugins/upgrade_assistant/public/plugin.ts index 1b33ec676e1c0..47bcb442e8321 100644 --- a/x-pack/plugins/upgrade_assistant/public/plugin.ts +++ b/x-pack/plugins/upgrade_assistant/public/plugin.ts @@ -42,7 +42,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 }, @@ -53,6 +53,10 @@ export class UpgradeAssistantUIPlugin const appDependencies: AppDependencies = { kibanaVersionInfo, isReadOnlyMode: readonly, + // 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. + isInfraPluginAvailable: plugins.hasOwnProperty('infra'), plugins: { cloud, share, diff --git a/x-pack/plugins/upgrade_assistant/public/types.ts b/x-pack/plugins/upgrade_assistant/public/types.ts index d59e9b158b74e..dfdf0006a2bb3 100644 --- a/x-pack/plugins/upgrade_assistant/public/types.ts +++ b/x-pack/plugins/upgrade_assistant/public/types.ts @@ -34,6 +34,7 @@ export interface StartDependencies { export interface AppDependencies { isReadOnlyMode: boolean; + isInfraPluginAvailable: boolean; kibanaVersionInfo: KibanaVersionContext; plugins: { cloud?: CloudSetup; diff --git a/x-pack/plugins/upgrade_assistant/server/plugin.ts b/x-pack/plugins/upgrade_assistant/server/plugin.ts index b47400c065bdd..27f7111b499ce 100644 --- a/x-pack/plugins/upgrade_assistant/server/plugin.ts +++ b/x-pack/plugins/upgrade_assistant/server/plugin.ts @@ -94,7 +94,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: { From 9f5325da2d5b4130e51b8b9fbcb0343e33aa79ae Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 14 Sep 2021 14:30:39 +0200 Subject: [PATCH 2/2] Fix CR requests --- .../client_integration/helpers/app_context.mock.ts | 2 +- .../overview/fix_logs_step/fix_logs_step.test.tsx | 9 +++------ .../components/overview/fix_logs_step/external_links.tsx | 4 ++-- x-pack/plugins/upgrade_assistant/public/plugin.ts | 8 ++++---- x-pack/plugins/upgrade_assistant/public/types.ts | 2 +- 5 files changed, 11 insertions(+), 14 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 73a6e74a9e5ea..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 @@ -55,7 +55,6 @@ shareMock.url.locators.get = (id: IdKey) => ({ export const getAppContextMock = () => ({ isReadOnlyMode: false, - isInfraPluginAvailable: true, kibanaVersionInfo: { currentMajor: mockKibanaSemverVersion.major, prevMajor: mockKibanaSemverVersion.major - 1, @@ -75,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 2dd88036c6fcb..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: {}, + }, }); }); @@ -212,12 +215,6 @@ describe('Overview - Fix deprecation logs step', () => { }); test(`Doesn't show observability app link if infra app is not available`, async () => { - await act(async () => { - testBed = await setupOverviewPage({ - isInfraPluginAvailable: false, - }); - }); - const { component, exists } = testBed; component.update(); 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 3a16b7ac78f7d..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,11 +105,11 @@ const ObservabilityAppLink: FunctionComponent = ({ checkpoint }) => { }; export const ExternalLinks: FunctionComponent = ({ checkpoint }) => { - const { isInfraPluginAvailable } = useAppContext(); + const { infra: hasInfraPlugin } = useAppContext().plugins; return ( - {isInfraPluginAvailable && ( + {hasInfraPlugin && ( diff --git a/x-pack/plugins/upgrade_assistant/public/plugin.ts b/x-pack/plugins/upgrade_assistant/public/plugin.ts index 47bcb442e8321..366ea2f1e8c8b 100644 --- a/x-pack/plugins/upgrade_assistant/public/plugin.ts +++ b/x-pack/plugins/upgrade_assistant/public/plugin.ts @@ -53,13 +53,13 @@ export class UpgradeAssistantUIPlugin const appDependencies: AppDependencies = { kibanaVersionInfo, isReadOnlyMode: readonly, - // 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. - isInfraPluginAvailable: plugins.hasOwnProperty('infra'), 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 dfdf0006a2bb3..de5f29593b7c6 100644 --- a/x-pack/plugins/upgrade_assistant/public/types.ts +++ b/x-pack/plugins/upgrade_assistant/public/types.ts @@ -34,11 +34,11 @@ export interface StartDependencies { export interface AppDependencies { isReadOnlyMode: boolean; - isInfraPluginAvailable: boolean; kibanaVersionInfo: KibanaVersionContext; plugins: { cloud?: CloudSetup; share: SharePluginSetup; + infra: object | undefined; }; services: { core: CoreStart;