Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse dependency of home plugin and apm/ml/cloud #52883

Merged
merged 25 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
df78b66
Apply linting rule and start fixing errors
flash1293 Dec 10, 2019
1bf487c
extend code ownership
flash1293 Dec 10, 2019
22fab28
also validate exports of shimmed plugins
flash1293 Dec 10, 2019
a23d8b3
change import paths
flash1293 Dec 11, 2019
87ac45b
Merge remote-tracking branch 'upstream/master' into lint-import-paths
flash1293 Dec 11, 2019
5173e7a
fix imports
flash1293 Dec 11, 2019
5659695
fix tests
flash1293 Dec 11, 2019
527bef4
fix import paths
flash1293 Dec 11, 2019
5a59b5d
Merge remote-tracking branch 'upstream/master' into lint-import-paths
flash1293 Dec 12, 2019
2f3f5f5
resolve conflicts in ml and fix broken references
flash1293 Dec 12, 2019
625b1a8
fix src import
flash1293 Dec 12, 2019
95f9474
reverse dependency between home and xpack plugins
flash1293 Dec 12, 2019
2c9afe8
move back resources and fix dashboard listing bug
flash1293 Dec 12, 2019
dc8ed1e
Merge remote-tracking branch 'upstream/master' into lint-import-paths
flash1293 Dec 13, 2019
3237ab0
Merge branch 'lint-import-paths' into home-cloud-contract
flash1293 Dec 13, 2019
5db54c1
Merge remote-tracking branch 'upstream/master' into home-cloud-contract
flash1293 Dec 30, 2019
b4b6774
fix merge issues
flash1293 Dec 30, 2019
b75d59c
Merge remote-tracking branch 'upstream/master' into home-cloud-contract
flash1293 Dec 31, 2019
bb09ea9
fix tests and make registration in legacy platform possible
flash1293 Dec 31, 2019
889a06b
Merge remote-tracking branch 'upstream/master' into home-cloud-contract
flash1293 Jan 7, 2020
372ac82
fix duplicate feature registration and revert timelion change
flash1293 Jan 7, 2020
a6cdda2
Merge branch 'master' into home-cloud-contract
elasticmachine Jan 13, 2020
ed7a06a
Merge remote-tracking branch 'upstream/master' into home-cloud-contract
flash1293 Jan 13, 2020
9316f29
add explicit test condition
flash1293 Jan 13, 2020
a7cdd6d
remove home ui export dependency from visualize embeddable
flash1293 Jan 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ let copiedLegacyCatalogue = false;
},
});
instance.start(npStart.core, {
data: npStart.plugins.data,
...npStart.plugins,
});
})();
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
UiSettingsState,
} from 'kibana/public';
import { UiStatsMetricType } from '@kbn/analytics';
import { FeatureCatalogueEntry } from '../../../../../plugins/home/public';
import { Environment, FeatureCatalogueEntry } from '../../../../../plugins/home/public';

export interface HomeKibanaServices {
indexPatternService: any;
Expand Down Expand Up @@ -61,6 +61,7 @@ export interface HomeKibanaServices {
shouldShowTelemetryOptIn: boolean;
docLinks: DocLinksStart;
addBasePath: (url: string) => string;
environment: Environment;
}

let services: HomeKibanaServices | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@ import { HashRouter as Router, Switch, Route, Redirect } from 'react-router-dom'
import { getTutorial } from '../load_tutorials';
import { replaceTemplateStrings } from './tutorial/replace_template_strings';
import { getServices } from '../../kibana_services';
// TODO This is going to be refactored soon
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { npSetup } from 'ui/new_platform';
export function HomeApp({ directories }) {
const {
getInjected,
savedObjectsClient,
getBasePath,
addBasePath,
environment,
telemetryOptInProvider: { setOptInNoticeSeen, getOptIn },
} = getServices();
const { cloud } = npSetup.plugins;
const isCloudEnabled = !!(cloud && cloud.isCloudEnabled);
const isCloudEnabled = environment.cloud;
const mlEnabled = environment.ml;
const apmUiEnabled = environment.apmUi;

const apmUiEnabled = getInjected('apmUiEnabled', true);
const mlEnabled = getInjected('mlEnabled', false);
const defaultAppId = getInjected('kbnDefaultAppId', 'discover');

const renderTutorialDirectory = props => {
Expand Down
13 changes: 10 additions & 3 deletions src/legacy/core_plugins/kibana/public/home/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { UiStatsMetricType } from '@kbn/analytics';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { setServices } from './kibana_services';
import { KibanaLegacySetup } from '../../../../../plugins/kibana_legacy/public';
import { FeatureCatalogueEntry } from '../../../../../plugins/home/public';
import {
Environment,
FeatureCatalogueEntry,
HomePublicPluginStart,
} from '../../../../../plugins/home/public';

export interface LegacyAngularInjectedDependencies {
telemetryOptInProvider: any;
Expand All @@ -32,6 +36,7 @@ export interface LegacyAngularInjectedDependencies {

export interface HomePluginStartDependencies {
data: DataPublicPluginStart;
home: HomePublicPluginStart;
}

export interface HomePluginSetupDependencies {
Expand Down Expand Up @@ -60,6 +65,7 @@ export interface HomePluginSetupDependencies {
export class HomePlugin implements Plugin {
private dataStart: DataPublicPluginStart | null = null;
private savedObjectsClient: any = null;
private environment: Environment | null = null;

setup(
core: CoreSetup,
Expand All @@ -86,6 +92,7 @@ export class HomePlugin implements Plugin {
addBasePath: core.http.basePath.prepend,
getBasePath: core.http.basePath.get,
indexPatternService: this.dataStart!.indexPatterns,
environment: this.environment!,
...angularDependencies,
});
const { renderApp } = await import('./np_ready/application');
Expand All @@ -94,8 +101,8 @@ export class HomePlugin implements Plugin {
});
}

start(core: CoreStart, { data }: HomePluginStartDependencies) {
// TODO is this really the right way? I though the app context would give us those
start(core: CoreStart, { data, home }: HomePluginStartDependencies) {
this.environment = home.environment.get();
this.dataStart = data;
this.savedObjectsClient = core.savedObjects.client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'uiExports/docViews';
import 'uiExports/embeddableActions';
import 'uiExports/fieldFormatEditors';
import 'uiExports/fieldFormats';
import 'uiExports/home';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maryia-lapata this caused all home ui export entrypoints to be included in all bundles (because the visualize embeddable is loaded as a "hack" entrypoint). Could you confirm that it's not actually needed to render visualizations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that I'm a right person to confirm that. I just removed these exports during centralizing dependancies and then returned it back during Visualize shimming.

I also found that these exports were introduced in https://github.com/elastic/kibana/pull/39126/files#diff-53ca92fe2de1ead9193e8c05dc91d415R29. Maybe it helps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just looked one level deep in the git blame :) @stacey-gammon is there a dependency of the visualize embeddable code to the home exports you know of? I'm only seeing feature registrations but maybe I'm missing something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed, I was probably over-zealous in my copy/pasting that ended that line up here.

import 'uiExports/indexManagement';
import 'uiExports/inspectorViews';
import 'uiExports/savedObjectTypes';
Expand Down
3 changes: 3 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export const npSetup = {
featureCatalogue: {
register: sinon.fake(),
},
environment: {
update: sinon.fake(),
},
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/home/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export {
HomePublicPluginSetup,
HomePublicPluginStart,
} from './plugin';
export { FeatureCatalogueEntry, FeatureCatalogueCategory } from './services';
export { FeatureCatalogueEntry, FeatureCatalogueCategory, Environment } from './services';
import { HomePublicPlugin } from './plugin';

export const plugin = () => new HomePublicPlugin();
3 changes: 3 additions & 0 deletions src/plugins/home/public/plugin.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/

import { featureCatalogueRegistryMock } from './services/feature_catalogue/feature_catalogue_registry.mock';
import { environmentServiceMock } from './services/environment/environment.mock';

export const registryMock = featureCatalogueRegistryMock.create();
export const environmentMock = environmentServiceMock.create();
jest.doMock('./services', () => ({
FeatureCatalogueRegistry: jest.fn(() => registryMock),
EnvironmentService: jest.fn(() => environmentMock),
}));
20 changes: 19 additions & 1 deletion src/plugins/home/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
* under the License.
*/

import { registryMock } from './plugin.test.mocks';
import { registryMock, environmentMock } from './plugin.test.mocks';
import { HomePublicPlugin } from './plugin';

describe('HomePublicPlugin', () => {
beforeEach(() => {
registryMock.setup.mockClear();
registryMock.start.mockClear();
environmentMock.setup.mockClear();
environmentMock.start.mockClear();
});

describe('setup', () => {
Expand All @@ -32,6 +34,12 @@ describe('HomePublicPlugin', () => {
expect(setup).toHaveProperty('featureCatalogue');
expect(setup.featureCatalogue).toHaveProperty('register');
});

test('wires up and returns environment service', async () => {
const setup = await new HomePublicPlugin().setup();
expect(setup).toHaveProperty('environment');
expect(setup.environment).toHaveProperty('update');
});
});

describe('start', () => {
Expand All @@ -45,5 +53,15 @@ describe('HomePublicPlugin', () => {
});
expect(start.featureCatalogue.get).toBeDefined();
});

test('wires up and returns environment service', async () => {
const service = new HomePublicPlugin();
await service.setup();
const start = await service.start({
application: { capabilities: { catalogue: {} } },
} as any);
expect(environmentMock.start).toHaveBeenCalled();
expect(start.environment.get).toBeDefined();
});
});
});
19 changes: 19 additions & 0 deletions src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@

import { CoreStart, Plugin } from 'src/core/public';
import {
EnvironmentService,
EnvironmentServiceSetup,
EnvironmentServiceStart,
FeatureCatalogueRegistry,
FeatureCatalogueRegistrySetup,
FeatureCatalogueRegistryStart,
} from './services';

export class HomePublicPlugin implements Plugin<HomePublicPluginSetup, HomePublicPluginStart> {
private readonly featuresCatalogueRegistry = new FeatureCatalogueRegistry();
private readonly environmentService = new EnvironmentService();

public async setup() {
return {
featureCatalogue: { ...this.featuresCatalogueRegistry.setup() },
environment: { ...this.environmentService.setup() },
};
}

Expand All @@ -40,6 +45,7 @@ export class HomePublicPlugin implements Plugin<HomePublicPluginSetup, HomePubli
capabilities: core.application.capabilities,
}),
},
environment: { ...this.environmentService.start() },
};
}
}
Expand All @@ -50,12 +56,25 @@ export type FeatureCatalogueSetup = FeatureCatalogueRegistrySetup;
/** @public */
export type FeatureCatalogueStart = FeatureCatalogueRegistryStart;

/** @public */
export type EnvironmentSetup = EnvironmentServiceSetup;

/** @public */
export type EnvironmentStart = EnvironmentServiceStart;

/** @public */
export interface HomePublicPluginSetup {
featureCatalogue: FeatureCatalogueSetup;
/**
* The environment service is only available for a transition period and will
* be replaced by display specific extension points.
* @deprecated
*/
environment: EnvironmentSetup;
}

/** @public */
export interface HomePublicPluginStart {
featureCatalogue: FeatureCatalogueStart;
environment: EnvironmentStart;
}
54 changes: 54 additions & 0 deletions src/plugins/home/public/services/environment/environment.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {
EnvironmentService,
EnvironmentServiceSetup,
EnvironmentServiceStart,
} from './environment';

const createSetupMock = (): jest.Mocked<EnvironmentServiceSetup> => {
const setup = {
update: jest.fn(),
};
return setup;
};

const createStartMock = (): jest.Mocked<EnvironmentServiceStart> => {
const start = {
get: jest.fn(),
};
return start;
};

const createMock = (): jest.Mocked<PublicMethodsOf<EnvironmentService>> => {
const service = {
setup: jest.fn(),
start: jest.fn(),
};
service.setup.mockImplementation(createSetupMock);
service.start.mockImplementation(createStartMock);
return service;
};

export const environmentServiceMock = {
createSetup: createSetupMock,
createStart: createStartMock,
create: createMock,
};
47 changes: 47 additions & 0 deletions src/plugins/home/public/services/environment/environment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { EnvironmentService } from './environment';

describe('EnvironmentService', () => {
describe('setup', () => {
test('allows multiple update calls', () => {
const setup = new EnvironmentService().setup();
expect(() => {
setup.update({ ml: true });
setup.update({ apmUi: true });
}).not.toThrow();
});
});

describe('start', () => {
test('returns default values', () => {
const service = new EnvironmentService();
expect(service.start().get()).toEqual({ ml: false, cloud: false, apmUi: false });
});

test('returns last state of update calls', () => {
const service = new EnvironmentService();
const setup = service.setup();
setup.update({ ml: true, cloud: true });
setup.update({ ml: false, apmUi: true });
expect(service.start().get()).toEqual({ ml: false, cloud: true, apmUi: true });
});
});
});
Loading