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] Set telemetry SO as hidden #147631

Merged
merged 3 commits into from
Dec 20, 2022

Conversation

afharo
Copy link
Member

@afharo afharo commented Dec 15, 2022

Resolves #145399

Summary

Sets the telemetry SO as hidden and makes the necessary changes to accommodate that:

  1. The telemetry plugin now instantiates the internal SO client and repositories to include the hidden type telemetry.
  2. The browser now fetches the configuration via the new endpoint GET /api/telemetry/v2/config.
  3. All the common/telemetry_config helpers have been moved to the server (except for one that is still relevant for the UI).
  4. FTR tests can no-longer use the SO Global HTTP APIs to set the scenarios => They now write the document to .kibana.

Checklist

For maintainers

Adding @elastic/enterprise-search-frontend as reviewers so they can fill in if they are happy with using GET /api/telemetry/v2/config to fetch the opt-in status 😇

@afharo afharo added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:Telemetry Feature:Saved Objects release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting labels Dec 15, 2022
@afharo afharo force-pushed the telemetry/hide-telemetry-saved-objects branch 2 times, most recently from bbc8ce7 to a9ca182 Compare December 15, 2022 17:13
Comment on lines +85 to +87
this.internalRepository = new SavedObjectsClient(
savedObjects.createInternalRepository([TELEMETRY_SAVED_OBJECT_TYPE])
);
Copy link
Member Author

Choose a reason for hiding this comment

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

nit: Potential improvement: Probably using the repository is good enough (no need to instantiate the client).

Copy link
Contributor

@TinaHeiligers TinaHeiligers Dec 18, 2022

Choose a reason for hiding this comment

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

ATM, hidden types aren't exposed to the SO client unless we instantiate a new client exposing the hidden types with includedHiddenTypes (ref: #147150). So yes, we don't need to create a new client (unless I'm missing something)

@@ -111,9 +115,9 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
*
* Using the internal client in all cases ensures the permissions to interact the document.
*/
private savedObjectsInternalClient$ = new ReplaySubject<SavedObjectsClient>(1);
private readonly savedObjectsInternalClient$ = new ReplaySubject<SavedObjectsClient>(1);
Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to my previous comment: probably the repository is enough for our usage here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, we can follow up in a new PR to make all the changes needed for methods to accept SavedObjectsClientContract rather than SavedObjectsClient.

Comment on lines +67 to +72
const body: FetchTelemetryConfigResponse = {
allowChangingOptInStatus,
optIn,
sendUsageFrom,
telemetryNotifyUserAboutOptInDefault,
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly porting the dynamic values of the deleted function updateConfigsBasedOnSavedObjects on the public side.

We may require follow-up PRs to validate the output of flags like telemetryNotifyUserAboutOptInDefault (refer to my comments in the FTRs)

Comment on lines +60 to +69
let telemetrySavedObject: TelemetrySavedObject | undefined;
try {
telemetrySavedObject = await getTelemetrySavedObject(soClient);
} catch (err) {
if (SavedObjectsErrorHelpers.isForbiddenError(err)) {
// If we couldn't get the saved object due to lack of permissions,
// we can assume the user won't be able to update it either
return res.forbidden();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the getTelemetrySavedObject method to return the value or throw. The forbidden only applies to this API and was causing unexpected behavior in the other usages of the method.

return attributes;
} catch (error) {
if (SavedObjectsErrorHelpers.isNotFoundError(error)) {
return null;
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing this because we relied on null when there was not a SO (for Opt-In handling). But we store so many things now in the SO, that we may return something and still not have a clear opt-in property stored in the SO, so it's better to check the property itself.

I plan to take #135107 to fix this existing bug.

@@ -42,6 +38,8 @@ export const getTelemetryOptIn: GetTelemetryOptIn = ({
// if enabled is true, return it
if (savedOptIn === true) return savedOptIn;

// TODO: Should we split the logic below into another OptIn getter?
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought I already did enough refactoring to also tackle this... IMO, it could be handled as part of #135107

}

expect(threw).toBe(true);
await expect(callGetTelemetrySavedObject(params)).rejects.toThrow(SavedObjectOtherErrorMessage);
Copy link
Member Author

Choose a reason for hiding this comment

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

Same test but using the expect().rejects.toThrow APIs.

Comment on lines +47 to +48
// it's not opted-in (in the YAML config) despite being opted-in via API/UI, and we still say false??
telemetryNotifyUserAboutOptInDefault: false,
Copy link
Member Author

Choose a reason for hiding this comment

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

This should be fixed on #135107

allowChangingOptInStatus: true,
optIn: false, // the config.js for this FTR sets it to `false`
sendUsageFrom: 'server',
telemetryNotifyUserAboutOptInDefault: false, // it's not opted-in, so we don't notify about opt-in??
Copy link
Member Author

Choose a reason for hiding this comment

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

This should be fixed on #135107

await supertest
.get('/api/telemetry/v2/last_reported')
.set('kbn-xsrf', 'xxx')
.expect(200, { lastReported: undefined });
Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason, now, when reporting lastReported: undefined the serializer removed the field entirely... Functionally, it's the same for JS, so no biggie.

@afharo afharo force-pushed the telemetry/hide-telemetry-saved-objects branch from a9ca182 to 4e07e7c Compare December 15, 2022 17:19
@@ -35,7 +35,7 @@ export async function sendTelemetryOptInStatus(
channelName: 'optInStatus',
});

const optInStatusPayload: UnencryptedTelemetryPayload =
const optInStatusPayload: UnencryptedTelemetryPayload | EncryptedTelemetryPayload =
Copy link
Member Author

Choose a reason for hiding this comment

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

It could also return EncryptedTelemetryPayload (actually, attending to the usage, it's the most likely output) 😇

@afharo afharo force-pushed the telemetry/hide-telemetry-saved-objects branch 2 times, most recently from 25509ad to 9e49452 Compare December 15, 2022 21:19
@afharo afharo force-pushed the telemetry/hide-telemetry-saved-objects branch from 9e49452 to 1acff4f Compare December 15, 2022 23:55
@afharo afharo marked this pull request as ready for review December 16, 2022 06:19
@afharo afharo requested a review from a team as a code owner December 16, 2022 06:19
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@afharo afharo requested a review from a team December 16, 2022 09:51
@afharo afharo added the ci:cloud-deploy Create or update a Cloud deployment label Dec 16, 2022
@afharo
Copy link
Member Author

afharo commented Dec 16, 2022

buildkite test this

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

Seems like there's a bit of follow-up work needed to polish off the change over to an API layer
This PR does what is required for Enterprise Search. I'm still considering edge cases and haven't come across anything immediate yet.

Comment on lines +85 to +87
this.internalRepository = new SavedObjectsClient(
savedObjects.createInternalRepository([TELEMETRY_SAVED_OBJECT_TYPE])
);
Copy link
Contributor

@TinaHeiligers TinaHeiligers Dec 18, 2022

Choose a reason for hiding this comment

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

ATM, hidden types aren't exposed to the SO client unless we instantiate a new client exposing the hidden types with includedHiddenTypes (ref: #147150). So yes, we don't need to create a new client (unless I'm missing something)

@TinaHeiligers TinaHeiligers requested review from a team and TinaHeiligers December 19, 2022 00:00
Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

We'll need to give detailed instructions for testing. Telemetry's always been a little hard to test fully 😉

@carlosdelest carlosdelest added ci:cloud-deploy Create or update a Cloud deployment ci:cloud-redeploy Always create a new Cloud deployment and removed ci:cloud-deploy Create or update a Cloud deployment labels Dec 19, 2022
@afharo afharo removed the ci:cloud-redeploy Always create a new Cloud deployment label Dec 19, 2022
@afharo
Copy link
Member Author

afharo commented Dec 19, 2022

@elasticmachine merge upstream

@afharo afharo requested review from carlosdelest and removed request for a team December 19, 2022 12:18
Copy link
Member

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

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

LGTM from Enterprise Search side. I have not validated the technical implementation though 👍

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

LGTM, based on the follow up PR's needed to wrap the conversion up.

@@ -111,9 +115,9 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
*
* Using the internal client in all cases ensures the permissions to interact the document.
*/
private savedObjectsInternalClient$ = new ReplaySubject<SavedObjectsClient>(1);
private readonly savedObjectsInternalClient$ = new ReplaySubject<SavedObjectsClient>(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, we can follow up in a new PR to make all the changes needed for methods to accept SavedObjectsClientContract rather than SavedObjectsClient.

@afharo
Copy link
Member Author

afharo commented Dec 20, 2022

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

kibana-ci commented Dec 20, 2022

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
telemetry 44 32 -12

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
telemetry 13.8KB 4.9KB -8.9KB

Page load bundle

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

id before after diff
telemetry 22.8KB 21.7KB -1.2KB
Unknown metric groups

async chunk count

id before after diff
telemetry 4 3 -1

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 61 67 +6
osquery 109 115 +6
securitySolution 439 445 +6
total +20

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 70 76 +6
osquery 110 117 +7
securitySolution 515 521 +6
total +21

History

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

@afharo afharo merged commit 30469a4 into elastic:main Dec 20, 2022
@afharo afharo deleted the telemetry/hide-telemetry-saved-objects branch December 20, 2022 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting ci:cloud-deploy Create or update a Cloud deployment Feature:Saved Objects Feature:Telemetry release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Layer for telemetry plugin
6 participants