mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 10:23:14 -04:00
* do not send telemetry if isScreenshotMode * Implement PR feedback: * added another Jest test * move Boolean() to make the opt-in value always boolean * remove unused import and convert to import type * fix type issues * update jest snapshot * Expanded test coverage - added plugin functional test - added jest test to check TelemetrySender behaviour - exported the localStorage/window value that flags screenshot mode * fix test plugin name in package.json and make sure to opt out of telemetry when the test finishes * added missing type file to plugin_functional test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> # Conflicts: # src/plugins/telemetry/kibana.json
This commit is contained in:
parent
313a887d34
commit
09129c8e38
22 changed files with 247 additions and 24 deletions
|
@ -10,6 +10,7 @@ export {
|
||||||
getScreenshotMode,
|
getScreenshotMode,
|
||||||
setScreenshotModeEnabled,
|
setScreenshotModeEnabled,
|
||||||
setScreenshotModeDisabled,
|
setScreenshotModeDisabled,
|
||||||
|
KBN_SCREENSHOT_MODE_ENABLED_KEY,
|
||||||
} from './get_set_browser_screenshot_mode';
|
} from './get_set_browser_screenshot_mode';
|
||||||
|
|
||||||
export { KBN_SCREENSHOT_MODE_HEADER } from './constants';
|
export { KBN_SCREENSHOT_MODE_HEADER } from './constants';
|
||||||
|
|
|
@ -12,6 +12,10 @@ export function plugin() {
|
||||||
return new ScreenshotModePlugin();
|
return new ScreenshotModePlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
export { KBN_SCREENSHOT_MODE_HEADER, setScreenshotModeEnabled } from '../common';
|
export {
|
||||||
|
KBN_SCREENSHOT_MODE_HEADER,
|
||||||
|
setScreenshotModeEnabled,
|
||||||
|
KBN_SCREENSHOT_MODE_ENABLED_KEY,
|
||||||
|
} from '../common';
|
||||||
|
|
||||||
export { ScreenshotModePluginSetup } from './types';
|
export { ScreenshotModePluginSetup } from './types';
|
||||||
|
|
|
@ -8,7 +8,11 @@
|
||||||
|
|
||||||
import { ScreenshotModePlugin } from './plugin';
|
import { ScreenshotModePlugin } from './plugin';
|
||||||
|
|
||||||
export { setScreenshotModeEnabled, KBN_SCREENSHOT_MODE_HEADER } from '../common';
|
export {
|
||||||
|
setScreenshotModeEnabled,
|
||||||
|
KBN_SCREENSHOT_MODE_HEADER,
|
||||||
|
KBN_SCREENSHOT_MODE_ENABLED_KEY,
|
||||||
|
} from '../common';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ScreenshotModeRequestHandlerContext,
|
ScreenshotModeRequestHandlerContext,
|
||||||
|
|
|
@ -3,13 +3,7 @@
|
||||||
"version": "kibana",
|
"version": "kibana",
|
||||||
"server": true,
|
"server": true,
|
||||||
"ui": true,
|
"ui": true,
|
||||||
"requiredPlugins": [
|
"requiredPlugins": ["telemetryCollectionManager", "screenshotMode", "usageCollection"],
|
||||||
"telemetryCollectionManager",
|
|
||||||
"usageCollection"
|
|
||||||
],
|
|
||||||
"extraPublicDirs": ["common/constants"],
|
"extraPublicDirs": ["common/constants"],
|
||||||
"requiredBundles": [
|
"requiredBundles": ["kibanaUtils", "kibanaReact"]
|
||||||
"kibanaUtils",
|
|
||||||
"kibanaReact"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,14 @@ import { TelemetryPluginStart, TelemetryPluginSetup, TelemetryPluginConfig } fro
|
||||||
export interface TelemetryServiceMockOptions {
|
export interface TelemetryServiceMockOptions {
|
||||||
reportOptInStatusChange?: boolean;
|
reportOptInStatusChange?: boolean;
|
||||||
currentKibanaVersion?: string;
|
currentKibanaVersion?: string;
|
||||||
|
isScreenshotMode?: boolean;
|
||||||
config?: Partial<TelemetryPluginConfig>;
|
config?: Partial<TelemetryPluginConfig>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockTelemetryService({
|
export function mockTelemetryService({
|
||||||
reportOptInStatusChange,
|
reportOptInStatusChange,
|
||||||
currentKibanaVersion = 'mockKibanaVersion',
|
currentKibanaVersion = 'mockKibanaVersion',
|
||||||
|
isScreenshotMode = false,
|
||||||
config: configOverride = {},
|
config: configOverride = {},
|
||||||
}: TelemetryServiceMockOptions = {}) {
|
}: TelemetryServiceMockOptions = {}) {
|
||||||
const config = {
|
const config = {
|
||||||
|
@ -47,6 +49,7 @@ export function mockTelemetryService({
|
||||||
config,
|
config,
|
||||||
http: httpServiceMock.createStartContract(),
|
http: httpServiceMock.createStartContract(),
|
||||||
notifications: notificationServiceMock.createStartContract(),
|
notifications: notificationServiceMock.createStartContract(),
|
||||||
|
isScreenshotMode,
|
||||||
currentKibanaVersion,
|
currentKibanaVersion,
|
||||||
reportOptInStatusChange,
|
reportOptInStatusChange,
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,6 +17,8 @@ import type {
|
||||||
ApplicationStart,
|
ApplicationStart,
|
||||||
} from 'src/core/public';
|
} from 'src/core/public';
|
||||||
|
|
||||||
|
import type { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/public';
|
||||||
|
|
||||||
import { TelemetrySender, TelemetryService, TelemetryNotifications } from './services';
|
import { TelemetrySender, TelemetryService, TelemetryNotifications } from './services';
|
||||||
import type {
|
import type {
|
||||||
TelemetrySavedObjectAttributes,
|
TelemetrySavedObjectAttributes,
|
||||||
|
@ -38,6 +40,8 @@ export interface TelemetryServicePublicApis {
|
||||||
getIsOptedIn: () => boolean | null;
|
getIsOptedIn: () => boolean | null;
|
||||||
/** Is the user allowed to change the opt-in/out status? **/
|
/** Is the user allowed to change the opt-in/out status? **/
|
||||||
userCanChangeSettings: boolean;
|
userCanChangeSettings: boolean;
|
||||||
|
/** Can phone-home telemetry calls be made? This depends on whether we have opted-in or if we are rendering a report */
|
||||||
|
canSendTelemetry: () => boolean;
|
||||||
/** Is the cluster allowed to change the opt-in/out status? **/
|
/** Is the cluster allowed to change the opt-in/out status? **/
|
||||||
getCanChangeOptInStatus: () => boolean;
|
getCanChangeOptInStatus: () => boolean;
|
||||||
/** Fetches an unencrypted telemetry payload so we can show it to the user **/
|
/** Fetches an unencrypted telemetry payload so we can show it to the user **/
|
||||||
|
@ -76,6 +80,10 @@ export interface TelemetryPluginStart {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TelemetryPluginSetupDependencies {
|
||||||
|
screenshotMode: ScreenshotModePluginSetup;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public-exposed configuration
|
* Public-exposed configuration
|
||||||
*/
|
*/
|
||||||
|
@ -113,11 +121,15 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
|
||||||
this.config = initializerContext.config.get();
|
this.config = initializerContext.config.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public setup({ http, notifications }: CoreSetup): TelemetryPluginSetup {
|
public setup(
|
||||||
|
{ http, notifications }: CoreSetup,
|
||||||
|
{ screenshotMode }: TelemetryPluginSetupDependencies
|
||||||
|
): TelemetryPluginSetup {
|
||||||
const config = this.config;
|
const config = this.config;
|
||||||
const currentKibanaVersion = this.currentKibanaVersion;
|
const currentKibanaVersion = this.currentKibanaVersion;
|
||||||
this.telemetryService = new TelemetryService({
|
this.telemetryService = new TelemetryService({
|
||||||
config,
|
config,
|
||||||
|
isScreenshotMode: screenshotMode.isScreenshotMode(),
|
||||||
http,
|
http,
|
||||||
notifications,
|
notifications,
|
||||||
currentKibanaVersion,
|
currentKibanaVersion,
|
||||||
|
@ -181,6 +193,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
|
||||||
return {
|
return {
|
||||||
getIsOptedIn: () => telemetryService.getIsOptedIn(),
|
getIsOptedIn: () => telemetryService.getIsOptedIn(),
|
||||||
setOptIn: (optedIn) => telemetryService.setOptIn(optedIn),
|
setOptIn: (optedIn) => telemetryService.setOptIn(optedIn),
|
||||||
|
canSendTelemetry: () => telemetryService.canSendTelemetry(),
|
||||||
userCanChangeSettings: telemetryService.userCanChangeSettings,
|
userCanChangeSettings: telemetryService.userCanChangeSettings,
|
||||||
getCanChangeOptInStatus: () => telemetryService.getCanChangeOptInStatus(),
|
getCanChangeOptInStatus: () => telemetryService.getCanChangeOptInStatus(),
|
||||||
fetchExample: () => telemetryService.fetchExample(),
|
fetchExample: () => telemetryService.fetchExample(),
|
||||||
|
|
|
@ -118,6 +118,16 @@ describe('TelemetrySender', () => {
|
||||||
expect(shouldSendReport).toBe(true);
|
expect(shouldSendReport).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns false if we are in screenshot mode', () => {
|
||||||
|
const telemetryService = mockTelemetryService({ isScreenshotMode: true });
|
||||||
|
telemetryService.getIsOptedIn = jest.fn().mockReturnValue(false);
|
||||||
|
const telemetrySender = new TelemetrySender(telemetryService);
|
||||||
|
const shouldSendReport = telemetrySender['shouldSendReport']();
|
||||||
|
|
||||||
|
expect(telemetryService.getIsOptedIn).toBeCalledTimes(0);
|
||||||
|
expect(shouldSendReport).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
describe('sendIfDue', () => {
|
describe('sendIfDue', () => {
|
||||||
let originalFetch: typeof window['fetch'];
|
let originalFetch: typeof window['fetch'];
|
||||||
let mockFetch: jest.Mock<typeof window['fetch']>;
|
let mockFetch: jest.Mock<typeof window['fetch']>;
|
||||||
|
@ -151,6 +161,15 @@ describe('TelemetrySender', () => {
|
||||||
expect(mockFetch).toBeCalledTimes(0);
|
expect(mockFetch).toBeCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not send if we are in screenshot mode', async () => {
|
||||||
|
const telemetryService = mockTelemetryService({ isScreenshotMode: true });
|
||||||
|
const telemetrySender = new TelemetrySender(telemetryService);
|
||||||
|
telemetrySender['isSending'] = false;
|
||||||
|
await telemetrySender['sendIfDue']();
|
||||||
|
|
||||||
|
expect(mockFetch).toBeCalledTimes(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('sends report if due', async () => {
|
it('sends report if due', async () => {
|
||||||
const mockTelemetryUrl = 'telemetry_cluster_url';
|
const mockTelemetryUrl = 'telemetry_cluster_url';
|
||||||
const mockTelemetryPayload = ['hashed_cluster_usage_data1'];
|
const mockTelemetryPayload = ['hashed_cluster_usage_data1'];
|
||||||
|
|
|
@ -33,8 +33,7 @@ export class TelemetrySender {
|
||||||
};
|
};
|
||||||
|
|
||||||
private shouldSendReport = (): boolean => {
|
private shouldSendReport = (): boolean => {
|
||||||
// check if opt-in for telemetry is enabled
|
if (this.telemetryService.canSendTelemetry()) {
|
||||||
if (this.telemetryService.getIsOptedIn()) {
|
|
||||||
if (!this.lastReported) {
|
if (!this.lastReported) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,4 +256,24 @@ describe('TelemetryService', () => {
|
||||||
expect(mockFetch).toHaveBeenCalledTimes(1);
|
expect(mockFetch).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('canSendTelemetry', () => {
|
||||||
|
it('does not send telemetry if screenshotMode is true', () => {
|
||||||
|
const telemetryService = mockTelemetryService({
|
||||||
|
isScreenshotMode: true,
|
||||||
|
config: { optIn: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(telemetryService.canSendTelemetry()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does send telemetry if screenshotMode is false and we are opted in', () => {
|
||||||
|
const telemetryService = mockTelemetryService({
|
||||||
|
isScreenshotMode: false,
|
||||||
|
config: { optIn: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(telemetryService.canSendTelemetry()).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,7 @@ interface TelemetryServiceConstructor {
|
||||||
config: TelemetryPluginConfig;
|
config: TelemetryPluginConfig;
|
||||||
http: CoreStart['http'];
|
http: CoreStart['http'];
|
||||||
notifications: CoreStart['notifications'];
|
notifications: CoreStart['notifications'];
|
||||||
|
isScreenshotMode: boolean;
|
||||||
currentKibanaVersion: string;
|
currentKibanaVersion: string;
|
||||||
reportOptInStatusChange?: boolean;
|
reportOptInStatusChange?: boolean;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +28,7 @@ export class TelemetryService {
|
||||||
private readonly reportOptInStatusChange: boolean;
|
private readonly reportOptInStatusChange: boolean;
|
||||||
private readonly notifications: CoreStart['notifications'];
|
private readonly notifications: CoreStart['notifications'];
|
||||||
private readonly defaultConfig: TelemetryPluginConfig;
|
private readonly defaultConfig: TelemetryPluginConfig;
|
||||||
|
private readonly isScreenshotMode: boolean;
|
||||||
private updatedConfig?: TelemetryPluginConfig;
|
private updatedConfig?: TelemetryPluginConfig;
|
||||||
|
|
||||||
/** Current version of Kibana */
|
/** Current version of Kibana */
|
||||||
|
@ -35,11 +37,13 @@ export class TelemetryService {
|
||||||
constructor({
|
constructor({
|
||||||
config,
|
config,
|
||||||
http,
|
http,
|
||||||
|
isScreenshotMode,
|
||||||
notifications,
|
notifications,
|
||||||
currentKibanaVersion,
|
currentKibanaVersion,
|
||||||
reportOptInStatusChange = true,
|
reportOptInStatusChange = true,
|
||||||
}: TelemetryServiceConstructor) {
|
}: TelemetryServiceConstructor) {
|
||||||
this.defaultConfig = config;
|
this.defaultConfig = config;
|
||||||
|
this.isScreenshotMode = isScreenshotMode;
|
||||||
this.reportOptInStatusChange = reportOptInStatusChange;
|
this.reportOptInStatusChange = reportOptInStatusChange;
|
||||||
this.notifications = notifications;
|
this.notifications = notifications;
|
||||||
this.currentKibanaVersion = currentKibanaVersion;
|
this.currentKibanaVersion = currentKibanaVersion;
|
||||||
|
@ -63,7 +67,7 @@ export class TelemetryService {
|
||||||
|
|
||||||
/** Is the cluster opted-in to telemetry **/
|
/** Is the cluster opted-in to telemetry **/
|
||||||
public get isOptedIn() {
|
public get isOptedIn() {
|
||||||
return this.config.optIn;
|
return Boolean(this.config.optIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Changes the opt-in status **/
|
/** Changes the opt-in status **/
|
||||||
|
@ -122,10 +126,15 @@ export class TelemetryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Is the cluster opted-in to telemetry **/
|
/** Is the cluster opted-in to telemetry **/
|
||||||
public getIsOptedIn = () => {
|
public getIsOptedIn = (): boolean => {
|
||||||
return this.isOptedIn;
|
return this.isOptedIn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Are there any blockers for sending telemetry */
|
||||||
|
public canSendTelemetry = (): boolean => {
|
||||||
|
return !this.isScreenshotMode && this.getIsOptedIn();
|
||||||
|
};
|
||||||
|
|
||||||
/** Fetches an unencrypted telemetry payload so we can show it to the user **/
|
/** Fetches an unencrypted telemetry payload so we can show it to the user **/
|
||||||
public fetchExample = async () => {
|
public fetchExample = async () => {
|
||||||
return await this.fetchTelemetry({ unencrypted: true });
|
return await this.fetchTelemetry({ unencrypted: true });
|
||||||
|
|
|
@ -8,17 +8,13 @@
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"isolatedModules": true
|
"isolatedModules": true
|
||||||
},
|
},
|
||||||
"include": [
|
"include": ["public/**/**/*", "server/**/**/*", "common/**/*", "../../../typings/**/*"],
|
||||||
"public/**/**/*",
|
|
||||||
"server/**/**/*",
|
|
||||||
"common/**/*",
|
|
||||||
"../../../typings/**/*"
|
|
||||||
],
|
|
||||||
"references": [
|
"references": [
|
||||||
{ "path": "../../core/tsconfig.json" },
|
{ "path": "../../core/tsconfig.json" },
|
||||||
{ "path": "../../plugins/usage_collection/tsconfig.json" },
|
{ "path": "../../plugins/kibana_react/tsconfig.json" },
|
||||||
{ "path": "../../plugins/telemetry_collection_manager/tsconfig.json" },
|
|
||||||
{ "path": "../../plugins/kibana_utils/tsconfig.json" },
|
{ "path": "../../plugins/kibana_utils/tsconfig.json" },
|
||||||
{ "path": "../../plugins/kibana_react/tsconfig.json" }
|
{ "path": "../../plugins/screenshot_mode/tsconfig.json" },
|
||||||
|
{ "path": "../../plugins/telemetry_collection_manager/tsconfig.json" },
|
||||||
|
{ "path": "../../plugins/usage_collection/tsconfig.json" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,6 +306,7 @@ exports[`TelemetryManagementSectionComponent renders null because allowChangingO
|
||||||
showAppliesSettingMessage={true}
|
showAppliesSettingMessage={true}
|
||||||
telemetryService={
|
telemetryService={
|
||||||
TelemetryService {
|
TelemetryService {
|
||||||
|
"canSendTelemetry": [Function],
|
||||||
"currentKibanaVersion": "mock_kibana_version",
|
"currentKibanaVersion": "mock_kibana_version",
|
||||||
"defaultConfig": Object {
|
"defaultConfig": Object {
|
||||||
"allowChangingOptInStatus": false,
|
"allowChangingOptInStatus": false,
|
||||||
|
@ -350,6 +351,7 @@ exports[`TelemetryManagementSectionComponent renders null because allowChangingO
|
||||||
"post": [MockFunction],
|
"post": [MockFunction],
|
||||||
"put": [MockFunction],
|
"put": [MockFunction],
|
||||||
},
|
},
|
||||||
|
"isScreenshotMode": false,
|
||||||
"notifications": Object {
|
"notifications": Object {
|
||||||
"toasts": Object {
|
"toasts": Object {
|
||||||
"add": [MockFunction],
|
"add": [MockFunction],
|
||||||
|
|
|
@ -32,6 +32,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
|
@ -66,6 +67,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
|
@ -121,6 +123,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
|
@ -169,6 +172,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
|
@ -208,6 +212,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
|
@ -248,6 +253,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
|
@ -288,6 +294,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
|
@ -328,6 +335,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
|
@ -378,6 +386,7 @@ describe('TelemetryManagementSectionComponent', () => {
|
||||||
optInStatusUrl: '',
|
optInStatusUrl: '',
|
||||||
sendUsageFrom: 'browser',
|
sendUsageFrom: 'browser',
|
||||||
},
|
},
|
||||||
|
isScreenshotMode: false,
|
||||||
reportOptInStatusChange: false,
|
reportOptInStatusChange: false,
|
||||||
notifications: coreStart.notifications,
|
notifications: coreStart.notifications,
|
||||||
currentKibanaVersion: 'mock_kibana_version',
|
currentKibanaVersion: 'mock_kibana_version',
|
||||||
|
|
|
@ -22,6 +22,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
|
||||||
return {
|
return {
|
||||||
testFiles: [
|
testFiles: [
|
||||||
require.resolve('./test_suites/usage_collection'),
|
require.resolve('./test_suites/usage_collection'),
|
||||||
|
require.resolve('./test_suites/telemetry'),
|
||||||
require.resolve('./test_suites/core'),
|
require.resolve('./test_suites/core'),
|
||||||
require.resolve('./test_suites/custom_visualizations'),
|
require.resolve('./test_suites/custom_visualizations'),
|
||||||
require.resolve('./test_suites/panel_actions'),
|
require.resolve('./test_suites/panel_actions'),
|
||||||
|
|
9
test/plugin_functional/plugins/telemetry/kibana.json
Normal file
9
test/plugin_functional/plugins/telemetry/kibana.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"id": "telemetryTestPlugin",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"kibanaVersion": "kibana",
|
||||||
|
"configPath": ["telemetryTestPlugin"],
|
||||||
|
"requiredPlugins": ["telemetry"],
|
||||||
|
"server": false,
|
||||||
|
"ui": true
|
||||||
|
}
|
14
test/plugin_functional/plugins/telemetry/package.json
Normal file
14
test/plugin_functional/plugins/telemetry/package.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "telemetry_test_plugin",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "target/test/plugin_functional/plugins/telemetry",
|
||||||
|
"kibana": {
|
||||||
|
"version": "kibana",
|
||||||
|
"templateVersion": "1.0.0"
|
||||||
|
},
|
||||||
|
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||||
|
"scripts": {
|
||||||
|
"kbn": "node ../../../../scripts/kbn.js",
|
||||||
|
"build": "rm -rf './target' && ../../../../node_modules/.bin/tsc"
|
||||||
|
}
|
||||||
|
}
|
11
test/plugin_functional/plugins/telemetry/public/index.ts
Normal file
11
test/plugin_functional/plugins/telemetry/public/index.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { TelemetryTestPlugin } from './plugin';
|
||||||
|
|
||||||
|
export const plugin = () => new TelemetryTestPlugin();
|
28
test/plugin_functional/plugins/telemetry/public/plugin.ts
Normal file
28
test/plugin_functional/plugins/telemetry/public/plugin.ts
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CoreSetup, Plugin } from 'src/core/public';
|
||||||
|
import type { TelemetryPluginSetup } from '../../../../../src/plugins/telemetry/public';
|
||||||
|
|
||||||
|
interface TelemetryTestPluginSetupDependencies {
|
||||||
|
telemetry: TelemetryPluginSetup;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TelemetryTestPlugin implements Plugin {
|
||||||
|
setup(core: CoreSetup, { telemetry }: TelemetryTestPluginSetupDependencies) {
|
||||||
|
window._checkCanSendTelemetry = async () => {
|
||||||
|
await telemetry.telemetryService.setOptIn(true);
|
||||||
|
return telemetry.telemetryService.canSendTelemetry();
|
||||||
|
};
|
||||||
|
|
||||||
|
window._resetTelemetry = async () => {
|
||||||
|
await telemetry.telemetryService.setOptIn(false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
start() {}
|
||||||
|
}
|
10
test/plugin_functional/plugins/telemetry/tsconfig.json
Normal file
10
test/plugin_functional/plugins/telemetry/tsconfig.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./target",
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"include": ["public/**/*.ts", "types.ts", "../../../../typings/**/*"],
|
||||||
|
"exclude": [],
|
||||||
|
"references": [{ "path": "../../../../src/core/tsconfig.json" }]
|
||||||
|
}
|
17
test/plugin_functional/plugins/telemetry/types.ts
Normal file
17
test/plugin_functional/plugins/telemetry/types.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
_checkCanSendTelemetry: () => Promise<boolean>;
|
||||||
|
_resetTelemetry: () => Promise<void>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Turn this file into a module
|
||||||
|
export {};
|
15
test/plugin_functional/test_suites/telemetry/index.ts
Normal file
15
test/plugin_functional/test_suites/telemetry/index.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { PluginFunctionalProviderContext } from '../../services';
|
||||||
|
|
||||||
|
export default function ({ loadTestFile }: PluginFunctionalProviderContext) {
|
||||||
|
describe('telemetry', function () {
|
||||||
|
loadTestFile(require.resolve('./telemetry'));
|
||||||
|
});
|
||||||
|
}
|
45
test/plugin_functional/test_suites/telemetry/telemetry.ts
Normal file
45
test/plugin_functional/test_suites/telemetry/telemetry.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import expect from '@kbn/expect';
|
||||||
|
import { PluginFunctionalProviderContext } from '../../services';
|
||||||
|
import { KBN_SCREENSHOT_MODE_ENABLED_KEY } from '../../../../src/plugins/screenshot_mode/public';
|
||||||
|
|
||||||
|
export default function ({ getService, getPageObjects }: PluginFunctionalProviderContext) {
|
||||||
|
const browser = getService('browser');
|
||||||
|
const PageObjects = getPageObjects(['common']);
|
||||||
|
|
||||||
|
describe('Telemetry service', () => {
|
||||||
|
const checkCanSendTelemetry = (): Promise<boolean> => {
|
||||||
|
return browser.executeAsync<boolean>((cb) => {
|
||||||
|
((window as unknown) as Record<string, () => Promise<boolean>>)
|
||||||
|
._checkCanSendTelemetry()
|
||||||
|
.then(cb);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await browser.removeLocalStorageItem(KBN_SCREENSHOT_MODE_ENABLED_KEY);
|
||||||
|
await browser.executeAsync<void>((cb) => {
|
||||||
|
((window as unknown) as Record<string, () => Promise<boolean>>)
|
||||||
|
._resetTelemetry()
|
||||||
|
.then(() => cb());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('detects that telemetry cannot be sent in screenshot mode', async () => {
|
||||||
|
await PageObjects.common.navigateToApp('home');
|
||||||
|
expect(await checkCanSendTelemetry()).to.be(true);
|
||||||
|
|
||||||
|
await browser.setLocalStorageItem(KBN_SCREENSHOT_MODE_ENABLED_KEY, 'true');
|
||||||
|
await PageObjects.common.navigateToApp('home');
|
||||||
|
|
||||||
|
expect(await checkCanSendTelemetry()).to.be(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue