Skip to content

Commit

Permalink
Move Cloud Integrations out of the cloud plugin (#141103)
Browse files Browse the repository at this point in the history
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
afharo and kibanamachine authored Oct 4, 2022
1 parent 10884e6 commit 74f30dc
Show file tree
Hide file tree
Showing 118 changed files with 1,907 additions and 1,263 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/storybooks/build_and_upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const STORYBOOKS = [
'apm',
'canvas',
'ci_composite',
'cloud',
'cloud_chat',
'coloring',
'chart_icons',
'controls',
Expand Down
12 changes: 12 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,22 @@ The plugin exposes the static DefaultEditorController class to consume.
|The cloud plugin adds Cloud-specific features to Kibana.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_chat/README.md[cloudChat]
|Integrates with DriftChat in order to provide live support to our Elastic Cloud users. This plugin should only run on Elastic Cloud.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_experiments/README.mdx[cloudExperiments]
|The Cloud Experiments Service provides the necessary APIs to implement A/B testing scenarios, fetching the variations in configuration and reporting back metrics to track conversion rates of the experiments.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_full_story/README.md[cloudFullStory]
|Integrates with FullStory in order to provide better product analytics, so we can understand how our users make use of Kibana. This plugin should only run on Elastic Cloud.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_links/README.md[cloudLinks]
|Adds all the links to the Elastic Cloud console.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_security_posture/README.md[cloudSecurityPosture]
|Cloud Posture automates the identification and remediation of risks across cloud infrastructures
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pageLoadAssetSize:
cases: 144442
charts: 55000
cloud: 21076
cloudChat: 19894
cloudExperiments: 59358
cloudFullStory: 18493
cloudLinks: 17629
cloudSecurityPosture: 19109
console: 46091
controls: 40000
Expand Down
2 changes: 1 addition & 1 deletion src/dev/storybook/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const storybookAliases = {
apm: 'x-pack/plugins/apm/.storybook',
canvas: 'x-pack/plugins/canvas/storybook',
ci_composite: '.ci/.storybook',
cloud: 'x-pack/plugins/cloud/.storybook',
cloud_chat: 'x-pack/plugins/cloud_integrations/cloud_chat/.storybook',
coloring: 'packages/kbn-coloring/.storybook',
chart_icons: 'packages/kbn-chart-icons/.storybook',
content_management: 'packages/content-management/.storybook',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/home/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"server": true,
"ui": true,
"requiredPlugins": ["dataViews", "share", "urlForwarding"],
"optionalPlugins": ["usageCollection", "customIntegrations"],
"optionalPlugins": ["usageCollection", "customIntegrations", "cloud"],
"requiredBundles": ["kibanaReact"]
}
98 changes: 58 additions & 40 deletions src/plugins/home/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { HomePublicPlugin } from './plugin';
import { coreMock } from '@kbn/core/public/mocks';
import { urlForwardingPluginMock } from '@kbn/url-forwarding-plugin/public/mocks';
import { SharePluginSetup } from '@kbn/share-plugin/public';
import { cloudMock } from '@kbn/cloud-plugin/public/mocks';

const mockInitializerContext = coreMock.createPluginInitializerContext();
const mockShare = {} as SharePluginSetup;
Expand All @@ -24,14 +25,11 @@ describe('HomePublicPlugin', () => {
});

describe('setup', () => {
test('registers tutorial directory to feature catalogue', async () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
test('registers tutorial directory to feature catalogue', () => {
const setup = new HomePublicPlugin(mockInitializerContext).setup(coreMock.createSetup(), {
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
});
expect(setup).toHaveProperty('featureCatalogue');
expect(setup.featureCatalogue.register).toHaveBeenCalledTimes(1);
expect(setup.featureCatalogue.register).toHaveBeenCalledWith(
Expand All @@ -44,53 +42,73 @@ describe('HomePublicPlugin', () => {
);
});

test('wires up and returns registry', async () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
test('wires up and returns registry', () => {
const setup = new HomePublicPlugin(mockInitializerContext).setup(coreMock.createSetup(), {
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
});
expect(setup).toHaveProperty('featureCatalogue');
expect(setup.featureCatalogue).toHaveProperty('register');
});

test('wires up and returns environment service', async () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: {} as SharePluginSetup,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
test('wires up and returns environment service', () => {
const setup = new HomePublicPlugin(mockInitializerContext).setup(coreMock.createSetup(), {
share: {} as SharePluginSetup,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
});
expect(setup).toHaveProperty('environment');
expect(setup.environment).toHaveProperty('update');
});

test('wires up and returns tutorial service', async () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
test('wires up and returns tutorial service', () => {
const setup = new HomePublicPlugin(mockInitializerContext).setup(coreMock.createSetup(), {
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
});
expect(setup).toHaveProperty('tutorials');
expect(setup.tutorials).toHaveProperty('setVariable');
});

test('wires up and returns welcome service', async () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
test('wires up and returns welcome service', () => {
const setup = new HomePublicPlugin(mockInitializerContext).setup(coreMock.createSetup(), {
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
});
expect(setup).toHaveProperty('welcomeScreen');
expect(setup.welcomeScreen).toHaveProperty('registerOnRendered');
expect(setup.welcomeScreen).toHaveProperty('registerTelemetryNoticeRenderer');
});

test('sets the cloud environment variable when the cloud plugin is present but isCloudEnabled: false', () => {
const cloud = { ...cloudMock.createSetup(), isCloudEnabled: false };
const plugin = new HomePublicPlugin(mockInitializerContext);
const setup = plugin.setup(coreMock.createSetup(), {
cloud,
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
});
expect(setup.environment.update).toHaveBeenCalledTimes(1);
expect(setup.environment.update).toHaveBeenCalledWith({ cloud: false });
expect(setup.tutorials.setVariable).toHaveBeenCalledTimes(0);
});

test('when cloud is enabled, it sets the cloud environment and the tutorials variable "cloud"', () => {
const cloud = { ...cloudMock.createSetup(), isCloudEnabled: true };
const plugin = new HomePublicPlugin(mockInitializerContext);
const setup = plugin.setup(coreMock.createSetup(), {
cloud,
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
});
expect(setup.environment.update).toHaveBeenCalledTimes(1);
expect(setup.environment.update).toHaveBeenCalledWith({ cloud: true });
expect(setup.tutorials.setVariable).toHaveBeenCalledTimes(1);
expect(setup.tutorials.setVariable).toHaveBeenCalledWith('cloud', {
id: 'mock-cloud-id',
baseUrl: 'base-url',
deploymentUrl: 'deployment-url',
profileUrl: 'profile-url',
});
});
});
});
23 changes: 20 additions & 3 deletions src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import { UrlForwardingSetup, UrlForwardingStart } from '@kbn/url-forwarding-plugin/public';
import { AppNavLinkStatus } from '@kbn/core/public';
import { SharePluginSetup } from '@kbn/share-plugin/public';
import type { CloudSetup } from '@kbn/cloud-plugin/public';
import { PLUGIN_ID, HOME_APP_BASE_PATH } from '../common/constants';
import { setServices } from './application/kibana_services';
import { ConfigSchema } from '../config';
Expand All @@ -42,6 +43,7 @@ export interface HomePluginStartDependencies {
}

export interface HomePluginSetupDependencies {
cloud?: CloudSetup;
share: SharePluginSetup;
usageCollection?: UsageCollectionSetup;
urlForwarding: UrlForwardingSetup;
Expand All @@ -66,7 +68,7 @@ export class HomePublicPlugin

public setup(
core: CoreSetup<HomePluginStartDependencies>,
{ share, urlForwarding, usageCollection }: HomePluginSetupDependencies
{ cloud, share, urlForwarding, usageCollection }: HomePluginSetupDependencies
): HomePublicPluginSetup {
core.application.register({
id: PLUGIN_ID,
Expand Down Expand Up @@ -127,10 +129,25 @@ export class HomePublicPlugin
order: 500,
});

const environment = { ...this.environmentService.setup() };
const tutorials = { ...this.tutorialService.setup() };
if (cloud) {
environment.update({ cloud: cloud.isCloudEnabled });
if (cloud.isCloudEnabled) {
tutorials.setVariable('cloud', {
id: cloud.cloudId,
baseUrl: cloud.baseUrl,
// Cloud's API already provides the full URLs
profileUrl: cloud.profileUrl?.replace(cloud.baseUrl ?? '', ''),
deploymentUrl: cloud.deploymentUrl?.replace(cloud.baseUrl ?? '', ''),
});
}
}

return {
featureCatalogue,
environment: { ...this.environmentService.setup() },
tutorials: { ...this.tutorialService.setup() },
environment,
tutorials,
addData: { ...this.addDataService.setup() },
welcomeScreen: { ...this.welcomeService.setup() },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ const createSetupMock = (): jest.Mocked<EnvironmentServiceSetup> => {

const createMock = (): jest.Mocked<PublicMethodsOf<EnvironmentService>> => {
const service = {
setup: jest.fn(),
setup: jest.fn(createSetupMock),
getEnvironment: jest.fn(() => ({
cloud: false,
apmUi: false,
ml: false,
})),
};
service.setup.mockImplementation(createSetupMock);
return service;
};

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/home/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{ "path": "../kibana_react/tsconfig.json" },
{ "path": "../share/tsconfig.json" },
{ "path": "../url_forwarding/tsconfig.json" },
{ "path": "../usage_collection/tsconfig.json" }
{ "path": "../usage_collection/tsconfig.json" },
{ "path": "../../../x-pack/plugins/cloud/tsconfig.json" }
]
}
8 changes: 8 additions & 0 deletions test/plugin_functional/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
'--corePluginDeprecations.noLongerUsed=still_using',
// for testing set buffer duration to 0 to immediately flush counters into saved objects.
'--usageCollection.usageCounters.bufferDuration=0',
// explicitly enable the cloud integration plugins to validate the rendered config keys
'--xpack.cloud_integrations.chat.enabled=true',
'--xpack.cloud_integrations.chat.chatURL=a_string',
'--xpack.cloud_integrations.experiments.enabled=true',
'--xpack.cloud_integrations.experiments.launch_darkly.sdk_key=a_string',
'--xpack.cloud_integrations.experiments.launch_darkly.client_id=a_string',
'--xpack.cloud_integrations.full_story.enabled=true',
'--xpack.cloud_integrations.full_story.org_id=a_string',
...plugins.map(
(pluginDir) => `--plugin-path=${path.resolve(__dirname, 'plugins', pluginDir)}`
),
Expand Down
13 changes: 8 additions & 5 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,17 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.cases.markdownPlugins.lens (boolean)',
'xpack.ccr.ui.enabled (boolean)',
'xpack.cloud.base_url (string)',
'xpack.cloud.chat.chatURL (string)',
'xpack.cloud.chat.enabled (boolean)',
'xpack.cloud.cname (string)',
'xpack.cloud.deployment_url (string)',
'xpack.cloud.full_story.enabled (boolean)',
'xpack.cloud.full_story.org_id (any)',
'xpack.cloud_integrations.chat.chatURL (string)',
// No PII. This is an escape patch to override LaunchDarkly's flag resolution mechanism for testing or quick fix.
'xpack.cloud_integrations.experiments.flag_overrides (record)',
// Commented because it's inside a schema conditional, and the test is not able to resolve it. But it's shared.
// Added here for documentation purposes.
// 'xpack.cloud_integrations.experiments.launch_darkly.client_id (string)',
'xpack.cloud_integrations.full_story.org_id (any)',
// No PII. Just the list of event types we want to forward to FullStory.
'xpack.cloud.full_story.eventTypesAllowlist (array)',
'xpack.cloud_integrations.full_story.eventTypesAllowlist (array)',
'xpack.cloud.id (string)',
'xpack.cloud.organization_url (string)',
'xpack.cloud.profile_url (string)',
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,14 @@
"@kbn/canvas-plugin/*": ["x-pack/plugins/canvas/*"],
"@kbn/cases-plugin": ["x-pack/plugins/cases"],
"@kbn/cases-plugin/*": ["x-pack/plugins/cases/*"],
"@kbn/cloud-chat-plugin": ["x-pack/plugins/cloud_integrations/cloud_chat"],
"@kbn/cloud-chat-plugin/*": ["x-pack/plugins/cloud_integrations/cloud_chat/*"],
"@kbn/cloud-experiments-plugin": ["x-pack/plugins/cloud_integrations/cloud_experiments"],
"@kbn/cloud-experiments-plugin/*": ["x-pack/plugins/cloud_integrations/cloud_experiments/*"],
"@kbn/cloud-full-story-plugin": ["x-pack/plugins/cloud_integrations/cloud_full_story"],
"@kbn/cloud-full-story-plugin/*": ["x-pack/plugins/cloud_integrations/cloud_full_story/*"],
"@kbn/cloud-links-plugin": ["x-pack/plugins/cloud_integrations/cloud_links"],
"@kbn/cloud-links-plugin/*": ["x-pack/plugins/cloud_integrations/cloud_links/*"],
"@kbn/cloud-security-posture-plugin": ["x-pack/plugins/cloud_security_posture"],
"@kbn/cloud-security-posture-plugin/*": ["x-pack/plugins/cloud_security_posture/*"],
"@kbn/cloud-plugin": ["x-pack/plugins/cloud"],
Expand Down
2 changes: 2 additions & 0 deletions x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"xpack.canvas": "plugins/canvas",
"xpack.cases": "plugins/cases",
"xpack.cloud": "plugins/cloud",
"xpack.cloudChat": "plugins/cloud_integrations/cloud_chat",
"xpack.cloudLinks": "plugins/cloud_integrations/cloud_links",
"xpack.csp": "plugins/cloud_security_posture",
"xpack.dashboard": "plugins/dashboard_enhanced",
"xpack.discover": "plugins/discover_enhanced",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/cloud/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

export const ELASTIC_SUPPORT_LINK = 'https://cloud.elastic.co/support';
export const GET_CHAT_USER_DATA_ROUTE_PATH = '/internal/cloud/chat_user';

/**
* This is the page for managing your snapshots on Cloud.
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cloud/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": ["xpack", "cloud"],
"optionalPlugins": ["cloudExperiments", "usageCollection", "home", "security"],
"optionalPlugins": ["usageCollection"],
"server": true,
"ui": true
}
2 changes: 0 additions & 2 deletions x-pack/plugins/cloud/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ export type { CloudSetup, CloudConfigType, CloudStart } from './plugin';
export function plugin(initializerContext: PluginInitializerContext) {
return new CloudPlugin(initializerContext);
}

export { Chat } from './components';
Loading

0 comments on commit 74f30dc

Please sign in to comment.