-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Usage collection] Usage counters #96696
Conversation
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.
Wow! What an effort! Great job @Bamieh! I've added a few comments and NITs. Will review more in detail on Tuesday or when the PR is released from draft. Have a great weekend.
...gins/kibana_usage_collection/server/collectors/ui_counters/register_ui_counters_collector.ts
Outdated
Show resolved
Hide resolved
...kibana_usage_collection/server/collectors/ui_counters/register_ui_counters_collector.test.ts
Outdated
Show resolved
Hide resolved
...gins/kibana_usage_collection/server/collectors/ui_counters/register_ui_counters_collector.ts
Outdated
Show resolved
Hide resolved
...gins/kibana_usage_collection/server/collectors/ui_counters/register_ui_counters_collector.ts
Outdated
Show resolved
Hide resolved
src/plugins/kibana_usage_collection/server/collectors/ui_counters/rollups/rollups.ts
Outdated
Show resolved
Hide resolved
...plugins/kibana_usage_collection/server/collectors/usage_counters/rollups/register_rollups.ts
Show resolved
Hide resolved
src/plugins/usage_collection/server/usage_counters/usage_counters_service.ts
Outdated
Show resolved
Hide resolved
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.
Kibana app changes LGTM, code review only. Only mock import changes in tests.
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.
I've noticed a potential bug, holding the SOs from being stored.
...gins/kibana_usage_collection/server/collectors/ui_counters/register_ui_counters_collector.ts
Outdated
Show resolved
Hide resolved
src/plugins/usage_collection/server/usage_counters/usage_counters_service.ts
Show resolved
Hide resolved
src/plugins/usage_collection/server/usage_counters/usage_counters_service.ts
Outdated
Show resolved
Hide resolved
src/plugins/usage_collection/server/usage_counters/saved_objects.ts
Outdated
Show resolved
Hide resolved
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.
Only a few NITs and questions
src/plugins/kibana_usage_collection/server/collectors/ui_counters/rollups/register_rollups.ts
Outdated
Show resolved
Hide resolved
...ibana_usage_collection/server/collectors/usage_counters/register_usage_counters_collector.ts
Outdated
Show resolved
Hide resolved
src/plugins/kibana_usage_collection/server/collectors/usage_counters/rollups/rollups.ts
Outdated
Show resolved
Hide resolved
src/plugins/usage_collection/server/usage_counters/saved_objects.ts
Outdated
Show resolved
Hide resolved
src/plugins/usage_collection/server/usage_counters/usage_counter.ts
Outdated
Show resolved
Hide resolved
test/plugin_functional/plugins/usage_collection/server/config.ts
Outdated
Show resolved
Hide resolved
test/plugin_functional/plugins/usage_collection/server/plugin.ts
Outdated
Show resolved
Hide resolved
test/plugin_functional/plugins/usage_collection/server/routes.ts
Outdated
Show resolved
Hide resolved
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.
app services changes look good to me
Co-authored-by: Alejandro Fernández Haro <[email protected]>
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.
Tested locally (and played with the APIs). LGTM!
Great PR @Bamieh! 🎉
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 once the config renaming is done
…nto telemetry/usage_counters
💚 Build SucceededMetrics [docs]Saved Objects .kibana field count
History
To update your PR or re-run it, just comment with: |
Co-authored-by: Alejandro Fernández Haro <[email protected]>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…to-metrics-tab * 'master' of github.com:elastic/kibana: (61 commits) [Usage collection] Usage counters (elastic#96696) UI actions readme (elastic#96925) [TSVB] Enable brush for visualizations created with no index patterns (elastic#96727) [Data telemetry] Add Async Search to the tests (elastic#96693) added missing optional chain for bracket notation (elastic#96939) [Discover][DocViewer] Fix toggle columns from doc viewer table tab (elastic#95748) [TSVB] Fix per-request caching of index patterns (elastic#97043) [Datatable] Fix filter cell flakiness (elastic#96934) Unskip heatmap suite and fixes flakiness (elastic#96941) [Fleet] Improve performance of data stream API (elastic#97058) [ML] Data Frame Analytics: remove beta badge (elastic#96977) [App Search] Migrate expanded rows for meta engines table in Engines Overview (elastic#96251) Instances latency distribution chart tooltips and axis fixes (elastic#95577) [Monitoring] Using primary average shard size (elastic#96177) [Workplace Search] Hide Kibana chrome on 3rd party connector redirects (elastic#97028) ## [Security Solution] Fixes `Exit full screen` and `Copy to cliboard` styling issues (elastic#96676) Index pattern field editor - Add warning on name or type change (elastic#95528) [App Search] Add small engine breadcrumb utility helper (elastic#96917) Copy esArchiver commands from ./reassign.ts to fix tests (elastic#97012) [Security Solution][Detections] Updates MITRE Tactics, Techniques, and Subtechniques for 7.13 (elastic#97011) ...
Co-authored-by: Alejandro Fernández Haro <[email protected]> Co-authored-by: Ahmad Bamieh <[email protected]> Co-authored-by: Alejandro Fernández Haro <[email protected]>
Usage Counters
Usage counters allows plugins to report user triggered events from the server. This api has feature parity with UI Counters on the
public
plugin side of usage_collection.Usage counters provide instrumentation on the server to count triggered events such as "api called", "threshold reached", and miscellaneous events count.
It is useful for gathering semi-aggregated events with a per day granularity.
This allows tracking trends in usage and provides enough granularity for this type of telemetry to provide insights such as
How to use it
To create a usage counter for your plugin, use the API
usageCollection.createUsageCounter
as follows:Pass the created
usageCounter
around in your service to instrument usage.That's all you need to do! The Usage counters service will handle piping these counters all the way to the telemetry service.
Telemetry reported usage
Usage counters are reported inside the telemetry usage payload under
stack_stats.kibana.plugins.usage_counters
.Code reviewer?
Closes #81645
I've updated the
usage_collection.mocks
file which might have affected a few files outside the core team owned files. If you are requested a review please filter byCODEOWNERS
and look for changes ❤️ .Implementation Notes
RxJS is used to handle buffering the events every 5s to avoid redundant SO calls from the same counter.
The service uses a single
source$
which keeps the implementation light and allows batching multiple counters as a future enhancement (currently not supported bysavedObjects.incrementCounter
).Daily-aggregated events are deleted by a rollup function once they become older than 5 days. Until then telemetry will keep reporting these events in the daily payload.
We've chosen 5 days to make sure all triggered events are reported while accomodating to "The weekend effect".
If
usageCollection.usageCounters.enabled
is set tofalse
the service will notsubscribe
to the events source effectively it stops collecitng the data avoiding redundant function calls and if statements. Currently the service will keep on collecting data usage even if telemetry is disabled to stay consistent with other collection services. This can be easily changed via rxjs by changing thesubject.connect
logic from automtic on subscribe to manually callingconnect
in the telemetry plugin onstart
.Usage counters will be flushed to savedobjects on
start
once SO is ready. Duringsetup
the service will cache any counter increments in an in memory buffer (Rx.RelaySubject
).UI Counters is now using usage counters api to store the counters data. The collector is also fetching the data from the Usage Counters service and filtering on
uiCounter
domain ID.UI Counters will trigger roll ups against the deprecated
ui-counter
saved objects registry until all the previous data is drained. Migration from one SO registry to another is not yet supported hence this draining logic is needed to make sure we dont lose any data from the no longer usedui-counter
SO registry. In a future release we can remove the UI Counters roll up code.The service was implemented closely to how we've implemented other service inside
core
to allow easier transfer of usage_collection tocore
in the future.The service is fully tested:
api_integration/usage_counters
,api_integration/telemetry
,plugin_functional
(demo plugin), and unit tests!