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

Conversation

jloleysens
Copy link
Contributor

Summary

Fix #41402

To reviewers

  • Is this the correct place to intercept the process of sending telemetry? Are some calls happening that can still be avoided?

Checklist

Delete any items that are not applicable to this PR.

@jloleysens jloleysens added (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead v8.0.0 Team:AppServices release_note:skip Skip the PR/issue when compiling release notes v7.14.0 labels May 20, 2021
Copy link
Member

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

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

code changes LGTM! a very welcomed changed :elasticheart:

Can we add a functional test do make sure this is working in the browser as intended?

Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

Thank you for these changes! This will prove super useful!

I've added a couple of comments & NITs.

@@ -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';

@@ -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?

@@ -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?

@@ -126,6 +131,10 @@ export class TelemetryService {
return this.isOptedIn;
};

public canSendTelemetry = (): boolean => {
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!

* added another Jest test
* move Boolean() to make the opt-in value always boolean
- added plugin functional test
- added jest test to check TelemetrySender behaviour
- exported the localStorage/window value that flags screenshot
  mode
@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@jloleysens
Copy link
Contributor Author

@Bamieh @afharo I think I've addressed your feedback, would you mind taking another look?

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

LGTM

@jloleysens jloleysens marked this pull request as ready for review May 26, 2021 07:38
@jloleysens jloleysens requested a review from a team as a code owner May 26, 2021 07:38
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-reporting-services (Team:Reporting Services)

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

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

LGTM. @afharo's comments are addressed. He's on PTO so we can dismiss his review

@Bamieh Bamieh requested a review from afharo May 31, 2021 07:42
@Bamieh
Copy link
Member

Bamieh commented May 31, 2021

@elasticmachine merge upstream

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
screenshotMode 11 16 +5

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
screenshotMode 0 1 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
screenshotMode 3.0KB 3.2KB +191.0B
telemetry 36.4KB 36.8KB +397.0B
total +588.0B
Unknown metric groups

API count

id before after diff
screenshotMode 15 21 +6
telemetry 41 42 +1
total +7

References to deprecated APIs

id before after diff
canvas 29 25 -4
crossClusterReplication 8 6 -2
fleet 22 20 -2
globalSearch 4 2 -2
indexManagement 12 7 -5
infra 261 149 -112
lens 67 45 -22
licensing 18 15 -3
lists 239 236 -3
maps 286 208 -78
ml 121 115 -6
monitoring 109 56 -53
securitySolution 390 346 -44
stackAlerts 101 95 -6
total -342

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jloleysens jloleysens merged commit 0ecca23 into elastic:master Jun 1, 2021
@jloleysens jloleysens deleted the reporting/prevent-sending-telemetry branch June 1, 2021 17:03
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jun 1, 2021
…ode (elastic#100388)

* 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
jloleysens added a commit that referenced this pull request Jun 1, 2021
…ode (#100388) (#101076)

* 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
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jun 2, 2021
…sens/kibana into reporting/new-png-pdf-report-type

* 'reporting/new-png-pdf-report-type' of github.com:jloleysens/kibana: (46 commits)
  [Security Solution] Add Ransomware canary advanced policy option (elastic#101068)
  [Exploratory view] Core web vitals (elastic#100320)
  [Security solution][Endpoint] Add unit tests for fleet event filters/trusted apps cards (elastic#101034)
  [Lens] Use a setter function for the dimension panel (elastic#101123)
  [Index Patterns] Fix return saved index pattern object (elastic#101051)
  [CI] For PRs, build TS refs before public api docs check (elastic#100791)
  [Maps] fix line and polygon label regression (elastic#101085)
  Migrate CCR to new ES JS client. (elastic#100131)
  [Canvas] Switch Canvas to use React Router (elastic#100579)
  [Expressions] Use table column ID instead of name when set (elastic#99724)
  [DOCS] Updates docs landing page (elastic#100749)
  [DOCS] Corrects typo in step 3 (elastic#101079)
  [DOCS] Updates runtime example in Discover (elastic#100926)
  Migrate kibana.autocomplete config to data plugin (elastic#100586)
  [Uptime] New width/delay definition for waterfall sidebar item tooltip (elastic#100147)
  [FTR] Use importExport for saved_object/basic archive (elastic#100244)
  [Fleet] Better input for multi text input in agent policy builder (elastic#101020)
  [CI] Buildkite support with Baseline pipeline (elastic#100492)
  [Reporting/Telemetry] Do not send telemetry if we are in screenshot mode (elastic#100388)
  Create API keys with metadata (elastic#100682)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead release_note:skip Skip the PR/issue when compiling release notes v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Reporting] Chromium headless browser should not send telemetry
7 participants