-
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
[UsageCollection] Expose KibanaRequest
to explicitly opted-in collectors
#83413
[UsageCollection] Expose KibanaRequest
to explicitly opted-in collectors
#83413
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.
Self-review.
Sorry for the number of changes: if we had opted to skip the opt-in requirement, it would be 16 changes only (and simpler). But I understand the need to explicitly request the collector to opt-in.
|
||
const usageCollectionMock = createUsageCollectionSetupMock(); | ||
usageCollectionMock.makeUsageCollector.mockImplementation((config) => { | ||
collector = config; | ||
collector = new Collector(logger, config); |
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.
This change is required because TS would complain about fetch
not having the this
context
Pinging @elastic/kibana-telemetry (Team:KibanaTelemetry) |
KibanaRequest
to collectors explicitly opted-inKibanaRequest
to explicitly opted-in collectors
I'm trying to log |
@chrisronline yes, it's intended: Even after opting-in, it's optional: it's only provided when the request needs to be scoped. This usually happens in 3 situations:
It will be I tried to explain this behaviour in my update in the JSDocs and the README. Please, let me know if it's not clear enough and I need to explain it further. |
x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts
Outdated
Show resolved
Hide resolved
@@ -18,9 +18,9 @@ import { fetchClusters } from '../../lib/alerts/fetch_clusters'; | |||
export function getMonitoringUsageCollector( | |||
usageCollection: UsageCollectionSetup, | |||
config: MonitoringConfig, | |||
callCluster: LegacyAPICaller | |||
esClient: ILegacyClusterClient |
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: This feels inconsitent in terms of nomenclature. esClient
should indicate we're using the new elasticsearch client, whereas callCluster
traditionally refers to the legacy elasticsearch client. When I first dug into the issue of the esClient
being "missing" for the SO tags collector issue, I thought it was because the new elasticsearch client wasn't available yet. Even so, the legacy client should be available from the setup
contract, so how are we solving for the client not be available yet?
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 arch generated docs changes LGTM
import { KibanaRequest } from 'src/core/server'; | ||
import { KibanaRequest as KibanaRequest_2 } from 'kibana/server'; |
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 guess importing from kibana/server
vs src/core/server
will create a new/duplicate import in the generated docs. From what I can see this isn't a problem, but TIL.
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 added a few comments and suggestions but they're not blockers for pushing this work through.
The implementation does the job.
LGTM
x-pack/plugins/monitoring/server/kibana_monitoring/collectors/index.ts
Outdated
Show resolved
Hide resolved
src/plugins/telemetry/server/telemetry_collection/get_local_stats.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_usage_collector.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/monitoring/server/kibana_monitoring/collectors/index.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.
LGTM
@@ -157,7 +157,10 @@ export class TelemetryCollectionManagerPlugin | |||
const soClient = config.unencrypted | |||
? collectionSoService.getScopedClient(config.request) | |||
: collectionSoService.createInternalRepository(); | |||
return { callCluster, timestamp, usageCollection, esClient, soClient }; | |||
// Provide the kibanaRequest so opted-in plugins can scope their custom clients only if the request is not encrypted | |||
const kibanaRequest = config.unencrypted ? request : void 0; |
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.
why void 0
instead of undefined
?
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.
It's essentially the same. But JS allows you do do let undefined = 1
, while void 0
is univoquely undefined
:)
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-security changes LGTM 👍
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.
KibanaApp changes LGTM, only mock adjustments in tests
From #83413 (comment), I'm a bit confused and maybe this is something that will be changed in #82638. If a user has monitoring enabled (in addition to using legacy collection), the monitoring bulk_uploader will collect the telemetry data without any valid With this setup, can't a limited privilege user call the Also, for the monitoring usage collector, does this mean we have to handle two different ways of being called, one with a request and one without? I can understand how this makes sense in the context of security, but it also affects what kind of telemetry data we can return. For example, the ability to access the |
@chrisronline you are very correct! If the user has access to the Also, to be fair, that scenario already happens nowadays: if the user has read access to the
That is also correct: when a real user requests the telemetry payload, they should only get the data they have access to. However, when sending telemetry to the remote telemetry service, we shouldn't scope that data to the user requesting it (following your example, we'll likely want to report all the existing alerts, not a partial representation of that). This has always been automatically handled in the |
This definitely makes sense to me, but I worry about how this will work in practice. Now that I can opt-in and sometimes receive a It seems clear that this problem falls more on the Alerts side of things, rather than Telemetry so I don't think we need to dig more into it (outside of the comments above). |
@chrisronline that is an interesting way of putting it. The way I see it, the collector should prioritise the behaviour with the Internal client (no Re Metricbeat's collection via Also, I hope we can stop Metricbeat's extended collection soon enough as well (as agreed in the RFC, the end goal is to stop collecting in the |
I think my main point is that the telemetry data will differ and I hope it's clear to the consumer of this data why this may differ With that said, it does sound like #83521 may remove the following scenario and please let me know if it will or will not: Let's say the Lens team decides to use Now, let's say the developer or PM is looking to test this functionality in cloud staging (which currently only supports legacy monitoring collection). Because legacy monitoring collection handles collecting the Kibana usage data without access to a They will fail to see any of this enhanced SO data showing up in their telemetry data and wonder why. This would also be a problem if/when they pushed these changes to production and some users sent this enhanced SO data, but most would likely not (due to most users still using legacy monitoring collection). |
@chrisronline the only possible scenario where I think some reported telemetry might include it vs. some might not is comparing Metricbeat's-collected telemetry (assuming Metricbeat's user has access to the SOs you mentioned) vs. Legacy collection (to be removed in #83521) or even "local/local X-Pack" collections. The legacy and local collections will not provide That's also why we went for an explicitly opt-in approach (despite making types harder to follow and maintain). If the dev opts-in when developing the collector, they should fully understand the caveats and limitations. However, thanks to this conversation, I added another TODO to #83521 to make sure we also stop collecting the |
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.
Thanks for hoping on a call and clarifying this for me! This works LGTM! Great work!
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
…o-node-details * 'master' of github.com:elastic/kibana: (65 commits) update chromedriver dependency to 87 (elastic#83624) [TSVB] use new Search API for rollup search (elastic#83275) [TSVB] Y-axis has number formatting not considering all series formatters in the group (elastic#83438) [Logs UI] Update <LogStream /> internal state when its props change (elastic#83302) Add tag bulk action context menu (elastic#82816) [code coverage] adding plugin to flush coverage data (elastic#83447) [UsageCollection] Expose `KibanaRequest` to explicitly opted-in collectors (elastic#83413) Added eventBus to trigger and listen plotHandler event (elastic#83435) [Runtime fields] Editor phase 1 (elastic#81472) [Maps] Fix threshold alert issue resolving nested fields (elastic#83577) chore(NA): remove usage of unverified es snapshots (elastic#83589) [DOCS] Adds Elastic Contributor Program link (elastic#83561) Upgrade EUI to v30.2.0 (elastic#82730) Don't show loading screen during auto-reload (elastic#83376) Functional tests - fix esArchive mappings with runtime fields (elastic#83530) [deb/rpm] Create keystore after installation (elastic#76465) [rpm] Create default environment file at "/etc/sysconfig/kibana" (elastic#82144) [docker] removes workaround for missing crypto-policies-scripts subpackage (elastic#83455) [ML] Persisted URL state for the Data frame analytics jobs and models pages (elastic#83439) adds xpack.security.authc.selector.enabled setting (elastic#83551) ...
Pinging @elastic/kibana-core (Team:Core) |
Summary
Provide the
kibanaRequest
property when calling thefetch
method. It is only provided for those collectors that have explicitly opted-in viaextendFetchContext.kibanaRequest: true
.This PR is a blocker for completing #82638
Checklist
Delete any items that are not applicable to this PR.
For maintainers