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

[Reporting/Telemetry] Do not send telemetry if we are in screenshot mode #100388

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
14 changes: 3 additions & 11 deletions src/plugins/telemetry/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
"version": "kibana",
"server": true,
"ui": true,
"requiredPlugins": [
"telemetryCollectionManager",
"usageCollection"
],
"extraPublicDirs": [
"common/constants"
],
"requiredBundles": [
"kibanaUtils",
"kibanaReact"
]
"requiredPlugins": ["telemetryCollectionManager", "usageCollection", "screenshotMode"],
"extraPublicDirs": ["common/constants"],
"requiredBundles": ["kibanaUtils", "kibanaReact"]
}
3 changes: 3 additions & 0 deletions src/plugins/telemetry/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import { TelemetryPluginStart, TelemetryPluginSetup, TelemetryPluginConfig } fro
export interface TelemetryServiceMockOptions {
reportOptInStatusChange?: boolean;
currentKibanaVersion?: string;
isScreenshotMode?: boolean;
config?: Partial<TelemetryPluginConfig>;
}

export function mockTelemetryService({
reportOptInStatusChange,
currentKibanaVersion = 'mockKibanaVersion',
isScreenshotMode = false,
config: configOverride = {},
}: TelemetryServiceMockOptions = {}) {
const config = {
Expand All @@ -47,6 +49,7 @@ export function mockTelemetryService({
config,
http: httpServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
isScreenshotMode,
currentKibanaVersion,
reportOptInStatusChange,
});
Expand Down
12 changes: 11 additions & 1 deletion src/plugins/telemetry/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import type {
ApplicationStart,
} from 'src/core/public';

import { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/public';
Copy link
Member

Choose a reason for hiding this comment

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

NIT:

Suggested change
import { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/public';
import type { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/public';


import { TelemetrySender, TelemetryService, TelemetryNotifications } from './services';
import type {
TelemetrySavedObjectAttributes,
Expand Down Expand Up @@ -76,6 +78,10 @@ export interface TelemetryPluginStart {
};
}

interface TelemetryPluginSetupDependencies {
screenshotMode: ScreenshotModePluginSetup;
}

/**
* Public-exposed configuration
*/
Expand Down Expand Up @@ -113,11 +119,15 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
this.config = initializerContext.config.get();
}

public setup({ http, notifications }: CoreSetup): TelemetryPluginSetup {
public setup(
{ http, notifications }: CoreSetup,
{ screenshotMode }: TelemetryPluginSetupDependencies
): TelemetryPluginSetup {
const config = this.config;
const currentKibanaVersion = this.currentKibanaVersion;
this.telemetryService = new TelemetryService({
config,
isScreenshotMode: screenshotMode.isScreenshotMode(),
http,
notifications,
currentKibanaVersion,
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/telemetry/public/services/telemetry_sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class TelemetrySender {
};

private shouldSendReport = (): boolean => {
// check if opt-in for telemetry is enabled
if (this.telemetryService.getIsOptedIn()) {
if (this.telemetryService.canSendTelemetry()) {
if (!this.lastReported) {
return true;
}
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/telemetry/public/services/telemetry_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,15 @@ describe('TelemetryService', () => {
expect(mockFetch).toHaveBeenCalledTimes(1);
});
});

describe('shouldSendTelemetry', () => {
it('does not send telemetry if screenshotMode is true', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can we test the other scenario as well?

const telemetryService = mockTelemetryService({
isScreenshotMode: true,
config: { optIn: true },
});

expect(telemetryService.canSendTelemetry()).toBe(false);
});
});
});
9 changes: 9 additions & 0 deletions src/plugins/telemetry/public/services/telemetry_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import { i18n } from '@kbn/i18n';
import { CoreStart } from 'kibana/public';
import { TelemetryPluginConfig } from '../plugin';
import { ScreenshotModePluginSetup } from '../../../screenshot_mode/public';

interface TelemetryServiceConstructor {
config: TelemetryPluginConfig;
http: CoreStart['http'];
notifications: CoreStart['notifications'];
isScreenshotMode: boolean;
currentKibanaVersion: string;
reportOptInStatusChange?: boolean;
}
Expand All @@ -27,6 +29,7 @@ export class TelemetryService {
private readonly reportOptInStatusChange: boolean;
private readonly notifications: CoreStart['notifications'];
private readonly defaultConfig: TelemetryPluginConfig;
private readonly isScreenshotMode: boolean;
private updatedConfig?: TelemetryPluginConfig;

/** Current version of Kibana */
Expand All @@ -35,11 +38,13 @@ export class TelemetryService {
constructor({
config,
http,
isScreenshotMode,
notifications,
currentKibanaVersion,
reportOptInStatusChange = true,
}: TelemetryServiceConstructor) {
this.defaultConfig = config;
this.isScreenshotMode = isScreenshotMode;
this.reportOptInStatusChange = reportOptInStatusChange;
this.notifications = notifications;
this.currentKibanaVersion = currentKibanaVersion;
Expand Down Expand Up @@ -126,6 +131,10 @@ export class TelemetryService {
return this.isOptedIn;
};

public canSendTelemetry = (): boolean => {
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding the JSDocs to this public method?

return Boolean(this.getIsOptedIn() && !this.isScreenshotMode);
Copy link
Member

Choose a reason for hiding this comment

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

NITs:

  1. Why do we need to wrap it as Boolean?
  2. Can we check isScreenshotMode first to avoid running the additional checks of getIsOptedIn()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we need to wrap it as Boolean?

I wanted to be explicit about the return type and getIsOptedIn returns a boolean | null. Happy to update that function return value with a Boolean() instead?

Can we check isScreenshotMode first to avoid running the additional checks of getIsOptedIn()?

Can do!

};

/** Fetches an unencrypted telemetry payload so we can show it to the user **/
public fetchExample = async () => {
return await this.fetchTelemetry({ unencrypted: true });
Expand Down
14 changes: 5 additions & 9 deletions src/plugins/telemetry/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
"declarationMap": true,
"isolatedModules": true
},
"include": [
"public/**/**/*",
"server/**/**/*",
"common/**/*",
"../../../typings/**/*"
],
"include": ["public/**/**/*", "server/**/**/*", "common/**/*", "../../../typings/**/*"],
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../../plugins/usage_collection/tsconfig.json" },
{ "path": "../../plugins/telemetry_collection_manager/tsconfig.json" },
{ "path": "../../plugins/kibana_react/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" }
]
}