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

[Telemetry] Migrate public to NP #56285

Merged
merged 61 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4602235
NP telemetry plugin barebones
Bamieh Jan 27, 2020
45d39de
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Jan 28, 2020
cc39460
fully migrate telemetry sender
Bamieh Jan 29, 2020
9438a19
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Jan 29, 2020
4841c72
license plugin to use NP telemetry
Bamieh Jan 29, 2020
8cf5605
merge master
Bamieh Jan 29, 2020
04b496b
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Jan 30, 2020
980fae1
fully migrated public to NP
Bamieh Jan 30, 2020
2da7f87
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Jan 30, 2020
f16ef88
finish components testing
Bamieh Jan 30, 2020
7bdb667
fix all tests
Bamieh Jan 31, 2020
48b572c
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Jan 31, 2020
9f7e69b
self code review
Bamieh Jan 31, 2020
b7ef413
remove commented code
Bamieh Jan 31, 2020
ad2afa1
bracket notication for private methods
Bamieh Jan 31, 2020
569c404
bracket notication for private methods
Bamieh Jan 31, 2020
b393639
update license management tests
Bamieh Jan 31, 2020
e0f417f
afharo code review fixes
Bamieh Jan 31, 2020
75b4b29
type safe private method access in tests
Bamieh Jan 31, 2020
5bdb6a3
fix typecheck
Bamieh Jan 31, 2020
b62011c
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Jan 31, 2020
39584c1
more type check fixes
Bamieh Jan 31, 2020
ba34fde
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Jan 31, 2020
becd967
i18n check
Bamieh Jan 31, 2020
c8cd3d9
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Feb 3, 2020
93cbe84
fix welcome page tests
Bamieh Feb 3, 2020
91e1882
i18n optedInNoticeBanner title
Bamieh Feb 3, 2020
4ec632d
fix advanced settings field settings
Bamieh Feb 3, 2020
f0a1c47
field name
Bamieh Feb 3, 2020
d0f4da0
fix home snapshots
Bamieh Feb 3, 2020
336f0c5
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Feb 3, 2020
b4c95f9
merge master
Bamieh Feb 4, 2020
e9285a9
listen to app id change
Bamieh Feb 4, 2020
aac057e
NP code review fixes
Bamieh Feb 4, 2020
e1d95e0
NP code review fixes
Bamieh Feb 4, 2020
e968825
update telemetry configs with np deprecations
Bamieh Feb 4, 2020
5136e28
pass telemetry from setup instead of npStart
Bamieh Feb 4, 2020
02a5412
type check
Bamieh Feb 4, 2020
aa459f3
merge master
Bamieh Feb 5, 2020
c0c4ab1
update core snapshots with new api exposed
Bamieh Feb 5, 2020
bb3055f
remove debugging logs
Bamieh Feb 5, 2020
e296a9d
merge master and continue debugging
Bamieh Feb 10, 2020
6a2fd40
merge master
Bamieh Feb 10, 2020
7f544ff
update home contract
Bamieh Feb 10, 2020
8b7ebbe
update home contract
Bamieh Feb 10, 2020
9945f67
fix test eslint import
Bamieh Feb 10, 2020
d62567f
navigate back to dashboard before start of next case for reporting
Bamieh Feb 10, 2020
3e0cc95
gitignore reporting failure_debug generated dir
Bamieh Feb 10, 2020
cb24627
use gotoDashboardEditMode instead of switch
Bamieh Feb 10, 2020
1fcd139
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Feb 10, 2020
50f3cca
= instead of :
Bamieh Feb 10, 2020
3420be7
merge master
Bamieh Feb 11, 2020
6b021b0
merge master
Bamieh Feb 11, 2020
1f7593c
escape unused forced types in Field
Bamieh Feb 11, 2020
d872f94
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Feb 11, 2020
6ac8b4e
Merge branch 'master' of github.com:elastic/kibana into telemetry/mig…
Bamieh Feb 12, 2020
d1238c4
rename mock to mocks for eslint
Bamieh Feb 12, 2020
cd70972
Update src/plugins/telemetry/public/components/telemetry_management_s…
Bamieh Feb 12, 2020
aaae6c5
fix save/clear type
Bamieh Feb 12, 2020
55a797c
Merge branch 'master' into telemetry/migrate_public
elasticmachine Feb 12, 2020
d5847da
Merge branch 'master' into telemetry/migrate_public
elasticmachine Feb 13, 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
5 changes: 4 additions & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
"savedObjects": "src/plugins/saved_objects",
"server": "src/legacy/server",
"statusPage": "src/legacy/core_plugins/status_page",
"telemetry": "src/legacy/core_plugins/telemetry",
"telemetry": [
"src/legacy/core_plugins/telemetry",
"src/plugins/telemetry"
],
"tileMap": "src/legacy/core_plugins/tile_map",
"timelion": ["src/legacy/core_plugins/timelion", "src/legacy/core_plugins/vis_type_timelion", "src/plugins/timelion"],
"uiActions": "src/plugins/ui_actions",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ApplicationStart](./kibana-plugin-public.applicationstart.md) &gt; [currentAppId$](./kibana-plugin-public.applicationstart.currentappid_.md)

## ApplicationStart.currentAppId$ property

An observable that emits the current application id and each subsequent id update.

<b>Signature:</b>

```typescript
currentAppId$: Observable<string | undefined>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ApplicationStart
| Property | Type | Description |
| --- | --- | --- |
| [capabilities](./kibana-plugin-public.applicationstart.capabilities.md) | <code>RecursiveReadonly&lt;Capabilities&gt;</code> | Gets the read-only capabilities. |
| [currentAppId$](./kibana-plugin-public.applicationstart.currentappid_.md) | <code>Observable&lt;string &#124; undefined&gt;</code> | An observable that emits the current application id and each subsequent id update. |

## Methods

Expand Down
17 changes: 11 additions & 6 deletions src/core/public/application/application_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ const createInternalSetupContractMock = (): jest.Mocked<InternalApplicationSetup
registerMountContext: jest.fn(),
});

const createStartContractMock = (): jest.Mocked<ApplicationStart> => ({
capabilities: capabilitiesServiceMock.createStartContract().capabilities,
navigateToApp: jest.fn(),
getUrlForApp: jest.fn(),
registerMountContext: jest.fn(),
});
const createStartContractMock = (): jest.Mocked<ApplicationStart> => {
const currentAppId$ = new Subject<string | undefined>();

return {
currentAppId$: currentAppId$.asObservable(),
capabilities: capabilitiesServiceMock.createStartContract().capabilities,
navigateToApp: jest.fn(),
getUrlForApp: jest.fn(),
registerMountContext: jest.fn(),
};
};

const createInternalStartContractMock = (): jest.Mocked<InternalApplicationStart> => {
const currentAppId$ = new Subject<string | undefined>();
Expand Down
11 changes: 9 additions & 2 deletions src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,19 @@ export interface ApplicationStart {
contextName: T,
provider: IContextProvider<AppMountDeprecated, T>
): void;

/**
* An observable that emits the current application id and each subsequent id update.
*/
currentAppId$: Observable<string | undefined>;
Bamieh marked this conversation as resolved.
Show resolved Hide resolved
}

/** @internal */
export interface InternalApplicationStart
extends Pick<ApplicationStart, 'capabilities' | 'navigateToApp' | 'getUrlForApp'> {
extends Pick<
ApplicationStart,
'capabilities' | 'navigateToApp' | 'getUrlForApp' | 'currentAppId$'
> {
/**
* Apps available based on the current capabilities.
* Should be used to show navigation links and make routing decisions.
Expand All @@ -640,7 +648,6 @@ export interface InternalApplicationStart
): void;

// Internal APIs
currentAppId$: Observable<string | undefined>;
getComponent(): JSX.Element | null;
}

Expand Down
1 change: 1 addition & 0 deletions src/core/public/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class LegacyPlatformService {
const legacyCore: LegacyCoreStart = {
...core,
application: {
currentAppId$: core.application.currentAppId$,
capabilities: core.application.capabilities,
getUrlForApp: core.application.getUrlForApp,
navigateToApp: core.application.navigateToApp,
Expand Down
1 change: 1 addition & 0 deletions src/core/public/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function createPluginStartContext<
): CoreStart {
return {
application: {
currentAppId$: deps.application.currentAppId$,
capabilities: deps.application.capabilities,
navigateToApp: deps.application.navigateToApp,
getUrlForApp: deps.application.getUrlForApp,
Expand Down
1 change: 1 addition & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface ApplicationSetup {
// @public (undocumented)
export interface ApplicationStart {
capabilities: RecursiveReadonly<Capabilities>;
currentAppId$: Observable<string | undefined>;
getUrlForApp(appId: string, options?: {
path?: string;
}): string;
Expand Down
3 changes: 3 additions & 0 deletions src/core/server/config/deprecation/core_deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export const coreDeprecationProvider: ConfigDeprecationProvider = ({
renameFromRoot('optimize.lazyHost', 'optimize.watchHost'),
renameFromRoot('optimize.lazyPrebuild', 'optimize.watchPrebuild'),
renameFromRoot('optimize.lazyProxyTimeout', 'optimize.watchProxyTimeout'),
renameFromRoot('xpack.xpack_main.telemetry.config', 'telemetry.config'),
renameFromRoot('xpack.xpack_main.telemetry.url', 'telemetry.url'),
renameFromRoot('xpack.xpack_main.telemetry.enabled', 'telemetry.enabled'),
renameFromRoot('xpack.telemetry.enabled', 'telemetry.enabled'),
renameFromRoot('xpack.telemetry.config', 'telemetry.config'),
renameFromRoot('xpack.telemetry.banner', 'telemetry.banner'),
Expand Down
31 changes: 3 additions & 28 deletions src/legacy/core_plugins/kibana/public/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,16 @@
*/

import { npSetup, npStart } from 'ui/new_platform';
import chrome from 'ui/chrome';
import { HomePlugin, LegacyAngularInjectedDependencies } from './plugin';
import { TelemetryOptInProvider } from '../../../telemetry/public/services';
import { IPrivate } from '../../../../../plugins/kibana_legacy/public';

/**
* Get dependencies relying on the global angular context.
* They also have to get resolved together with the legacy imports above
*/
async function getAngularDependencies(): Promise<LegacyAngularInjectedDependencies> {
const injector = await chrome.dangerouslyGetActiveInjector();

const Private = injector.get<IPrivate>('Private');

const telemetryEnabled = npStart.core.injectedMetadata.getInjectedVar('telemetryEnabled');
const telemetryBanner = npStart.core.injectedMetadata.getInjectedVar('telemetryBanner');
const telemetryOptInProvider = Private(TelemetryOptInProvider);

return {
telemetryOptInProvider,
shouldShowTelemetryOptIn:
telemetryEnabled && telemetryBanner && !telemetryOptInProvider.getOptIn(),
};
}
import { HomePlugin } from './plugin';

(async () => {
const instance = new HomePlugin();
instance.setup(npSetup.core, {
...npSetup.plugins,
__LEGACY: {
metadata: npStart.core.injectedMetadata.getLegacyMetadata(),
getAngularDependencies,
},
});
instance.start(npStart.core, {
...npStart.plugins,
});

instance.start(npStart.core, npStart.plugins);
})();
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/kibana/public/home/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
UiSettingsState,
} from 'kibana/public';
import { UiStatsMetricType } from '@kbn/analytics';
import { TelemetryPluginStart } from '../../../../../plugins/telemetry/public';
import {
Environment,
HomePublicPluginSetup,
Expand All @@ -53,7 +54,6 @@ export interface HomeKibanaServices {
};
getInjected: (name: string, defaultValue?: any) => unknown;
chrome: ChromeStart;
telemetryOptInProvider: any;
uiSettings: IUiSettingsClient;
config: KibanaLegacySetup['config'];
homeConfig: HomePublicPluginSetup['config'];
Expand All @@ -64,10 +64,10 @@ export interface HomeKibanaServices {
banners: OverlayStart['banners'];
trackUiMetric: (type: UiStatsMetricType, eventNames: string | string[], count?: number) => void;
getBasePath: () => string;
shouldShowTelemetryOptIn: boolean;
docLinks: DocLinksStart;
addBasePath: (url: string) => string;
environment: Environment;
telemetry?: TelemetryPluginStart;
}

let services: HomeKibanaServices | null = null;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class Home extends Component {
getServices().homeConfig.disableWelcomeScreen ||
props.localStorage.getItem(KEY_ENABLE_WELCOME) === 'false'
);
const currentOptInStatus = this.props.getOptInStatus();
this.state = {
// If welcome is enabled, we wait for loading to complete
// before rendering. This prevents an annoying flickering
Expand All @@ -60,7 +59,6 @@ export class Home extends Component {
isLoading: isWelcomeEnabled,
isNewKibanaInstance: false,
isWelcomeEnabled,
currentOptInStatus,
};
}

Expand Down Expand Up @@ -224,8 +222,7 @@ export class Home extends Component {
<Welcome
onSkip={this.skipWelcome}
urlBasePath={this.props.urlBasePath}
onOptInSeen={this.props.onOptInSeen}
currentOptInStatus={this.state.currentOptInStatus}
telemetry={this.props.telemetry}
/>
);
}
Expand Down Expand Up @@ -264,6 +261,8 @@ Home.propTypes = {
localStorage: PropTypes.object.isRequired,
urlBasePath: PropTypes.string.isRequired,
mlEnabled: PropTypes.bool.isRequired,
onOptInSeen: PropTypes.func.isRequired,
getOptInStatus: PropTypes.func.isRequired,
telemetry: PropTypes.shape({
telemetryService: PropTypes.any,
telemetryNotifications: PropTypes.any,
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function HomeApp({ directories }) {
getBasePath,
addBasePath,
environment,
telemetryOptInProvider: { setOptInNoticeSeen, getOptIn },
telemetry,
} = getServices();
const isCloudEnabled = environment.cloud;
const mlEnabled = environment.ml;
Expand Down Expand Up @@ -84,8 +84,7 @@ export function HomeApp({ directories }) {
find={savedObjectsClient.find}
localStorage={localStorage}
urlBasePath={getBasePath()}
onOptInSeen={setOptInNoticeSeen}
getOptInStatus={getOptIn}
telemetry={telemetry}
/>
</Route>
<Route path="/home">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Welcome } from './welcome';

import { telemetryPluginMock } from '../../../../../../../plugins/telemetry/public/telemetry.mock';
Bamieh marked this conversation as resolved.
Show resolved Hide resolved
jest.mock('../../kibana_services', () => ({
getServices: () => ({
addBasePath: (path: string) => `root${path}`,
Expand All @@ -29,27 +29,32 @@ jest.mock('../../kibana_services', () => ({
}));

test('should render a Welcome screen with the telemetry disclaimer', () => {
const telemetry = telemetryPluginMock.createSetupContract();
const component = shallow(
// @ts-ignore
<Welcome urlBasePath="/" onSkip={() => {}} onOptInSeen={() => {}} />
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />
);

expect(component).toMatchSnapshot();
});

test('should render a Welcome screen with the telemetry disclaimer when optIn is true', () => {
const telemetry = telemetryPluginMock.createSetupContract();
telemetry.telemetryService.getIsOptedIn = jest.fn().mockReturnValue(true);
const component = shallow(
// @ts-ignore
<Welcome urlBasePath="/" onSkip={() => {}} onOptInSeen={() => {}} currentOptInStatus={true} />
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />
);

expect(component).toMatchSnapshot();
});

test('should render a Welcome screen with the telemetry disclaimer when optIn is false', () => {
const telemetry = telemetryPluginMock.createSetupContract();
telemetry.telemetryService.getIsOptedIn = jest.fn().mockReturnValue(false);
const component = shallow(
// @ts-ignore
<Welcome urlBasePath="/" onSkip={() => {}} onOptInSeen={() => {}} currentOptInStatus={false} />
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />
);

expect(component).toMatchSnapshot();
Expand All @@ -59,19 +64,21 @@ test('should render a Welcome screen with no telemetry disclaimer', () => {
// @ts-ignore
const component = shallow(
// @ts-ignore
<Welcome urlBasePath="/" onSkip={() => {}} onOptInSeen={() => {}} />
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={null} />
);

expect(component).toMatchSnapshot();
});

test('fires opt-in seen when mounted', () => {
const seen = jest.fn();

const telemetry = telemetryPluginMock.createSetupContract();
const mockSetOptedInNoticeSeen = jest.fn();
// @ts-ignore
telemetry.telemetryNotifications.setOptedInNoticeSeen = mockSetOptedInNoticeSeen;
shallow(
// @ts-ignore
<Welcome urlBasePath="/" onSkip={() => {}} onOptInSeen={seen} />
<Welcome urlBasePath="/" onSkip={() => {}} telemetry={telemetry} />
);

expect(seen).toHaveBeenCalled();
expect(mockSetOptedInNoticeSeen).toHaveBeenCalled();
});
Loading