-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Telemetry] Set telemetry
SO as hidden
#147631
Conversation
bbc8ce7
to
a9ca182
Compare
this.internalRepository = new SavedObjectsClient( | ||
savedObjects.createInternalRepository([TELEMETRY_SAVED_OBJECT_TYPE]) | ||
); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
const body: FetchTelemetryConfigResponse = { | ||
allowChangingOptInStatus, | ||
optIn, | ||
sendUsageFrom, | ||
telemetryNotifyUserAboutOptInDefault, | ||
}; |
There was a problem hiding this comment.
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)
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(); | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
// it's not opted-in (in the YAML config) despite being opted-in via API/UI, and we still say false?? | ||
telemetryNotifyUserAboutOptInDefault: false, |
There was a problem hiding this comment.
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?? |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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.
a9ca182
to
4e07e7c
Compare
@@ -35,7 +35,7 @@ export async function sendTelemetryOptInStatus( | |||
channelName: 'optInStatus', | |||
}); | |||
|
|||
const optInStatusPayload: UnencryptedTelemetryPayload = | |||
const optInStatusPayload: UnencryptedTelemetryPayload | EncryptedTelemetryPayload = |
There was a problem hiding this comment.
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) 😇
25509ad
to
9e49452
Compare
9e49452
to
1acff4f
Compare
Pinging @elastic/kibana-core (Team:Core) |
buildkite test this |
There was a problem hiding this 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.
this.internalRepository = new SavedObjectsClient( | ||
savedObjects.createInternalRepository([TELEMETRY_SAVED_OBJECT_TYPE]) | ||
); |
There was a problem hiding this comment.
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)
There was a problem hiding this 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 😉
@elasticmachine merge upstream |
There was a problem hiding this 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 👍
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
.
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsasync chunk count
ESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Resolves #145399
Summary
Sets the
telemetry
SO ashidden
and makes the necessary changes to accommodate that:telemetry
plugin now instantiates the internal SO client and repositories to include the hidden typetelemetry
.GET /api/telemetry/v2/config
.common/telemetry_config
helpers have been moved to theserver
(except for one that is still relevant for the UI)..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 theopt-in
status 😇