Skip to content

Commit

Permalink
[Telemetry] Migrate public to NP (#56285)
Browse files Browse the repository at this point in the history
* NP telemetry plugin barebones

* fully migrate telemetry sender

* license plugin to use NP telemetry

* fully migrated public to NP

* finish components testing

* fix all tests

* self code review

* remove commented code

* bracket notication for private methods

* bracket notication for private methods

* update license management tests

* afharo code review fixes

* type safe private method access in tests

* fix typecheck

* more type check fixes

* i18n check

* fix welcome page tests

* i18n optedInNoticeBanner title

* fix advanced settings field settings

* field name

* fix home snapshots

* listen to app id change

* NP code review fixes

* NP code review fixes

* update telemetry configs with np deprecations

* pass telemetry from setup instead of npStart

* type check

* update core snapshots with new api exposed

* remove debugging logs

* update home contract

* update home contract

* fix test eslint import

* navigate back to dashboard before start of next case for reporting

* gitignore reporting failure_debug generated dir

* use gotoDashboardEditMode instead of switch

* = instead of :

* merge master

* escape unused forced types in Field

* rename mock to mocks for eslint

* Update src/plugins/telemetry/public/components/telemetry_management_section.tsx

Co-Authored-By: Alejandro Fernández Haro <[email protected]>

* fix save/clear type

Co-authored-by: Alejandro Fernández Haro <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Feb 13, 2020
1 parent c5a60b9 commit 06df2b0
Show file tree
Hide file tree
Showing 104 changed files with 1,815 additions and 3,095 deletions.
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>;
}

/** @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 @@ -98,6 +98,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,6 +20,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Welcome } from './welcome';
import { telemetryPluginMock } from '../../../../../../../plugins/telemetry/public/mocks';

jest.mock('../../kibana_services', () => ({
getServices: () => ({
Expand All @@ -29,27 +30,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 +65,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

0 comments on commit 06df2b0

Please sign in to comment.