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] Report the Application Usage (time of usage + number of clicks) #57893

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 31 additions & 0 deletions src/legacy/core_plugins/application_usage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Legacy } from '../../../../kibana';
import { mappings } from './mappings';

// eslint-disable-next-line import/no-default-export
export default function ApplicationUsagePlugin(kibana: any) {
const config: Legacy.PluginSpecOptions = {
id: 'application_usage',
uiExports: { mappings }, // Needed to define the mappings for the SavedObjects
};

return new kibana.Plugin(config);
}
28 changes: 28 additions & 0 deletions src/legacy/core_plugins/application_usage/mappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const mappings = {
application_usage: {
properties: {
appId: { type: 'keyword' },
numberOfClicks: { type: 'long' },
minutesOnScreen: { type: 'float' },
},
},
};
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/application_usage/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "application_usage",
"version": "kibana"
}
9 changes: 9 additions & 0 deletions src/legacy/ui/public/chrome/api/sub_url_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import url from 'url';

import { unhashUrl } from '../../../../../plugins/kibana_utils/public';
import { toastNotifications } from '../../notify/toasts';
import { npStart } from '../../new_platform';

export function registerSubUrlHooks(angularModule, internals) {
angularModule.run(($rootScope, Private, $location) => {
Expand All @@ -40,6 +41,7 @@ export function registerSubUrlHooks(angularModule, internals) {

function onRouteChange($event) {
if (subUrlRouteFilter($event)) {
updateUsage($event);
updateSubUrls();
}
}
Expand Down Expand Up @@ -67,6 +69,13 @@ export function registerSubUrlHooks(angularModule, internals) {
});
}

function updateUsage($event) {
const scope = $event.targetScope;
const app = scope.chrome.getApp();
const appId = app.id === 'kibana' ? scope.getFirstPathSegment() : app.id;
if (npStart.plugins.applicationUsage) npStart.plugins.applicationUsage.__LEGACY.appChanged(appId);
}

/**
* Creates a function that will be called on each route change
* to determine if the event should be used to update the last
Expand Down
2 changes: 2 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { IScope } from 'angular';

import { UiActionsStart, UiActionsSetup } from 'src/plugins/ui_actions/public';
import { IEmbeddableStart, IEmbeddableSetup } from 'src/plugins/embeddable/public';
import { ApplicationUsagePluginStart } from 'src/plugins/application_usage/public';
import { LegacyCoreSetup, LegacyCoreStart, App, AppMountDeprecated } from '../../../../core/public';
import { Plugin as DataPlugin } from '../../../../plugins/data/public';
import { Plugin as ExpressionsPlugin } from '../../../../plugins/expressions/public';
Expand Down Expand Up @@ -82,6 +83,7 @@ export interface PluginsStart {
management: ManagementStart;
advancedSettings: AdvancedSettingsStart;
telemetry?: TelemetryPluginStart;
applicationUsage?: ApplicationUsagePluginStart;
}

export const npSetup = {
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/application_usage/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "applicationUsage",
"version": "kibana",
"server": true,
"ui": true,
"optionalPlugins": [
"usageCollection"
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/plugins/application_usage/public/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Key for the localStorage service
*/
export const LOCALSTORAGE_KEY = 'application_usage.aggregated';
export const LOCALSTORAGE_KEY_LAST_REPORTED = 'application_usage.lastReported';

/**
* List of appIds not to report usage from (due to legacy hacks)
*/
export const DO_NOT_REPORT = ['kibana'];

/**
* Report to server every 10 minutes
*/
export const REPORT_INTERVAL = 10 * 60 * 1000;
Loading