-
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
[Telemetry] Application Usage implemented in @kbn/analytics #58401
Conversation
…lication-usage-plugin
…lication-usage-plugin
…lication-usage-plugin
…lication-usage-plugin
Pinging @elastic/pulse (Team:Pulse) |
I'm pending to write tests to this alternative implementation. @Bamieh the bit I like #57893 best is that the implementation is self-contained in one plugin, whereas in this one the logic is spread across 3 entities:
But I get it that this one reuses many of the capabilities already implemented and tested in those 3 components 👍 |
@elasticmachine merge upstream |
…lication-usage-in-kbn-analytics
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, lets get it merged!
Just a thought: I wish we had the event listeners in the application_usage/public
plugin instead of kbn-analytics/src/reporter.ts
and then these listeners would call the kbn analytics methods to update usage state.
Thanks for all the thorough tests!
I thought about it but then I thought it was maybe not a good idea to publicly expose the "add clicks" or like the common logic when it's supposed to send the report (similar to the But I don't have a strong opinion about it. Happy to revisit this at any point. Similarly, we should start adding tests to that side library at some point 😅(especially if it's going to grow over time). But we can do it on a separate PR if that's fine :) |
|
||
export type Metric = UiStatsMetric | UserAgentMetric; | ||
export type Metric = UiStatsMetric | UserAgentMetric | ApplicationUsageCurrent; |
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 a description
) 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.
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.
In an ideal world, we'd be adding the new collector directly in the NP and not extending anything in the Legacy world.
One nit to add yet more tests and I know I'm being greedy! Feel free to add later.
LGTM!
jest.runTimersToTime(ROLL_INDICES_INTERVAL); | ||
}); | ||
|
||
test('when savedObjectClient is initialised, return something', async () => { |
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: We should also be testing internal methods used when we are returning the 'something'. i.e: rollTotals
.
setTimeout(() => rollTotals(getSavedObjectsClient()), ROLL_INDICES_START); | ||
} | ||
|
||
async function rollTotals(savedObjectsClient?: ISavedObjectsRepository) { |
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're using this method to aggregate data and it should at least have a rudimentary test since it's also using findAll
.
You are right! I feel bad for having all these new additions to the Legacy folder. Good thing it's using the NP components internally, so migrating them should be a piece of cake once we solve all the other challenges (i.e.: the registered routes at the moment rely heavily on the Legacy code). The public side of the Since I have a fresh memory regarding this piece of code. I can volunteer to do the changes.
You are totally right! I was force-running it via
Thank you for your review :) |
…lication-usage-in-kbn-analytics
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
…58401) * [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 elastic#57693 got merged Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
…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 <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Pinging @elastic/kibana-core (Team:Core) |
Summary
Add a plugin that retrieves the time (in minutes) and the number of clicks on each application inside Kibana and report it via telemetry.
It uses its own index to store the grouped events in the form of
{ timestamp, appId, numberOfClicks, minutesOfScreenTime }
. Rolling up the information to saved objects for the entries older than 90 days (because the required reported data has 3 levels of aggregation: 30 days, 90 days and total).The finally reported information to our telemetry service looks like below:
Fixes #52737
Checklist
Delete any items that are not applicable to this PR.
For maintainers