-
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] Application Usage implemented in @kbn/analytics #58401
Merged
afharo
merged 29 commits into
elastic:master
from
afharo:telemetry/application-usage-in-kbn-analytics
Feb 28, 2020
Merged
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0732a9d
[Telemetry] Report the Application Usage (time of usage + number of c…
afharo 0eaf763
Add Unit tests to the server side
afharo 8c2cc28
Do not use optional chaining in JS
afharo d952a92
Merge branch 'master' of github.com:elastic/kibana into telemetry/app…
afharo 799540f
Add tests on the public end
afharo debba6b
Merge branch 'master' of github.com:elastic/kibana into telemetry/app…
afharo 665dd4e
Fix jslint errors
afharo 91fca2e
jest.useFakeTimers() + jest.clearAllTimers()
afharo 5e81450
Merge branch 'master' of github.com:elastic/kibana into telemetry/app…
afharo 2e35ef5
Remove Jest timer handlers from my tests (only affecting to a minimum…
afharo 39c6730
Merge branch 'master' into telemetry/application-usage-plugin
elasticmachine 9226712
Catch ES actions in the setup/start steps because it broke core_servi…
afharo ec22dad
Fix boolean check
afharo 531267b
Use core's ES.adminCLient over .createClient
afharo 9fd1324
Fix tests after ES.adminClient
afharo 5721b08
Merge branch 'master' of github.com:elastic/kibana into telemetry/app…
afharo fbad163
[Telemetry] Application Usage implemented in kbn-analytics
afharo 6d1f137
Use bulkCreate in store_report
afharo be901eb
Merge branch 'master' into telemetry/application-usage-in-kbn-analytics
elasticmachine 771e3a2
ApplicationUsagePluginStart does not exist anymore
afharo a4d73cd
Fix usage_collection mock interface
afharo 528cb7f
Check there is something to store before calling the bulkCreate method
afharo ad91cfe
Add unit tests
afharo 061899b
Merge branch 'master' of github.com:elastic/kibana into telemetry/app…
afharo 56906b0
Fix types in tests
afharo 6db8986
Merge branch 'master' of github.com:elastic/kibana into telemetry/app…
afharo d7e8313
Unit tests for rollTotals and actual fix for the bug found
afharo fc272ba
Merge branch 'master' of github.com:elastic/kibana into telemetry/app…
afharo c53a740
Fix usage_collection mock after #57693 got merged
afharo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Aside and not for this PR: We might want to consider adding a generic type that devs can use for metrics not falling into any of the current metric types. For example: the recent File Upload migration to the NP includes a a request to add
File Upload
as a type. We should think about how to handle cases like these where we might not necessarily allow an overwrite of the generic type but rather have that if a generic type is used, there must be another descriptor (like adescription
) tag in the data we're capturing. e.g. metric type='generic', and description='File Upload`.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.
That's a fair comment. I think the main reason why we haven't used the
UIStatsMetrics
more is because of the way we report them (as arrays).I'm sure we'll be coming back to this at some point with the new Pulse approach where arrays won't be an issue anymore.