Skip to content

Commit

Permalink
forces a re-prompt of telemetry opt-in when Kibana version changes
Browse files Browse the repository at this point in the history
resolves elastic#49519

If a user has previously opted out of telemetry, we are making a
change to re-prompt them when the version of Kibana they are
running changes.  Previously, once opted out, they would never
get prompted again.
  • Loading branch information
pmuellr committed Oct 29, 2019
1 parent b6591eb commit 9586b4f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/legacy/core_plugins/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const telemetry = (kibana: any) => {
// `config` is used internally and not intended to be set
config: Joi.string().default(Joi.ref('$defaultConfigPath')),
banner: Joi.boolean().default(true),
lastVersionChecked: Joi.string()
.allow('')
.default(''),
url: Joi.when('$dev', {
is: true,
then: Joi.string().default(
Expand Down
3 changes: 3 additions & 0 deletions src/legacy/core_plugins/telemetry/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"properties": {
"enabled": {
"type": "boolean"
},
"lastVersionChecked": {
"type": "keyword"
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions src/legacy/core_plugins/telemetry/server/get_telemetry_opt_in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

export async function getTelemetryOptIn(request: any) {
export async function getTelemetryOptIn(request: any): Promise<boolean | null> {
const isRequestingApplication = request.path.startsWith('/app');

// Prevent interstitial screens (such as the space selector) from prompting for telemetry
Expand All @@ -27,9 +27,9 @@ export async function getTelemetryOptIn(request: any) {

const savedObjectsClient = request.getSavedObjectsClient();

let savedObject;
try {
const { attributes } = await savedObjectsClient.get('telemetry', 'telemetry');
return attributes.enabled;
savedObject = await savedObjectsClient.get('telemetry', 'telemetry');
} catch (error) {
if (savedObjectsClient.errors.isNotFoundError(error)) {
return null;
Expand All @@ -43,4 +43,16 @@ export async function getTelemetryOptIn(request: any) {

throw error;
}

const { attributes } = savedObject;
if (attributes.enabled !== false) return attributes.enabled;

// Additional check if they've already opted out (enabled: false) - if the
// Kibana version has changed since they opted out, set them back to the null
// state to get prompted again.
const config = request.server.config();
const kibanaVersion = config.get('pkg.version');
if (kibanaVersion !== attributes.lastVersionChecked) return null;

return attributes.enabled;
}
2 changes: 2 additions & 0 deletions src/legacy/core_plugins/telemetry/server/routes/opt_in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ export function registerOptInRoutes(core: CoreSetup) {
},
handler: async (req: any, h: any) => {
const savedObjectsClient = req.getSavedObjectsClient();
const lastVersionChecked = server.config().get('pkg.version');
try {
await savedObjectsClient.create(
'telemetry',
{
enabled: req.payload.enabled,
lastVersionChecked,
},
{
id: 'telemetry',
Expand Down

0 comments on commit 9586b4f

Please sign in to comment.