-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…58904) * [Telemetry] Report the Application Usage (time of usage + number of clicks) * Add Unit tests to the server side * Do not use optional chaining in JS * Add tests on the public end * Fix jslint errors * jest.useFakeTimers() + jest.clearAllTimers() * Remove Jest timer handlers from my tests (only affecting to a minimum coverage bit) * Catch ES actions in the setup/start steps because it broke core_services tests * Fix boolean check * Use core's ES.adminCLient over .createClient * Fix tests after ES.adminClient * [Telemetry] Application Usage implemented in kbn-analytics * Use bulkCreate in store_report * ApplicationUsagePluginStart does not exist anymore * Fix usage_collection mock interface * Check there is something to store before calling the bulkCreate method * Add unit tests * Fix types in tests * Unit tests for rollTotals and actual fix for the bug found * Fix usage_collection mock after #57693 got merged Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
126665b
commit a0fb93b
Showing
32 changed files
with
966 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 moment, { Moment } from 'moment-timezone'; | ||
import { METRIC_TYPE } from './'; | ||
|
||
export interface ApplicationUsageCurrent { | ||
type: METRIC_TYPE.APPLICATION_USAGE; | ||
appId: string; | ||
startTime: Moment; | ||
numberOfClicks: number; | ||
} | ||
|
||
export class ApplicationUsage { | ||
private currentUsage?: ApplicationUsageCurrent; | ||
|
||
public start() { | ||
// Count any clicks and assign it to the current app | ||
if (window) | ||
window.addEventListener( | ||
'click', | ||
() => this.currentUsage && this.currentUsage.numberOfClicks++ | ||
); | ||
} | ||
|
||
public appChanged(appId?: string) { | ||
const currentUsage = this.currentUsage; | ||
|
||
if (appId) { | ||
this.currentUsage = { | ||
type: METRIC_TYPE.APPLICATION_USAGE, | ||
appId, | ||
startTime: moment(), | ||
numberOfClicks: 0, | ||
}; | ||
} else { | ||
this.currentUsage = void 0; | ||
} | ||
return currentUsage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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_totals: { | ||
properties: { | ||
appId: { type: 'keyword' }, | ||
numberOfClicks: { type: 'long' }, | ||
minutesOnScreen: { type: 'float' }, | ||
}, | ||
}, | ||
application_usage_transactional: { | ||
properties: { | ||
timestamp: { type: 'date' }, | ||
appId: { type: 'keyword' }, | ||
numberOfClicks: { type: 'long' }, | ||
minutesOnScreen: { type: 'float' }, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "application_usage", | ||
"version": "kibana" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.