Skip to content
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] Default to namespaces:['*'] in soClient.find requests #93289

Merged

Conversation

afharo
Copy link
Member

@afharo afharo commented Mar 2, 2021

Summary

This PR creates a SavedObjectsClient wrapper that is provided in the fetch context's soClient. This wrapper sets namespaces:['*'] to the .find operations so collectors can retrieve all the related SOs, no matter the space.

Resolves #92001.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

Copy link
Member Author

@afharo afharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review

@@ -14,6 +14,7 @@ import {
createCollectorFetchContextMock,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Changes to this file are not actually needed, but I had to go through these because I was having weird bootstrap errors. It turned out it was due to the local bootstrap cache. Happy to revert the changes if anyone thinks they should.

const soClient = config.unencrypted
? this.savedObjectsService?.getScopedClient(config.request)
const soRepository = config.unencrypted
? this.savedObjectsService?.createScopedRepository(config.request)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're now getting the scoped repository instead of the client straight away. This way we can extend both clients: the scoped and internal with the same class TelemetrySavedObjectsClient.

@afharo afharo marked this pull request as ready for review March 3, 2021 09:47
@afharo afharo requested a review from a team as a code owner March 3, 2021 09:47
@afharo afharo added the release_note:skip Skip the PR/issue when compiling release notes label Mar 3, 2021
@afharo
Copy link
Member Author

afharo commented Mar 3, 2021

Q: Should we backport it to 7.12 as well?

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Can you add a test to assert that using the saved objects client from the telemetry collection context passes namespaces: [*] to the repository?

@afharo afharo requested a review from rudolf March 3, 2021 14:08
Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some nits, but otherwise 👍

const soClient = config.unencrypted
? this.savedObjectsService?.getScopedClient(config.request)
: this.savedObjectsService?.createInternalRepository();
const soClient =
Copy link
Contributor

@rudolf rudolf Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this ternary / conditional is quite long, I think the code would be easier to read if we had an if(config.unencrypted) and then configured the es client and soClient for each of the cases.

Thanks for the comment! Can you add that we scope it because this is a returned for a user request.

I think it's also worth adding a comment here to explain why we're returning a TelemetrySavedObjectsClient if it isn't a user request (to make it clear that we're using it to collect telemetry across all spaces)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I've refactored that part and added a few tests to make sure we are correctly picking the right client based on the unencrypted flag.

@afharo afharo requested a review from rudolf March 4, 2021 14:42
@afharo
Copy link
Member Author

afharo commented Mar 4, 2021

@elasticmachine merge upstream

* Find the SavedObjects matching the search query in all the Spaces by default
* @param options
*/
async find<T = unknown>(options: SavedObjectsFindOptions): Promise<SavedObjectsFindResponse<T>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the need to create a new find method for telemetry needs but am worried that if every service/plugin creates their own override, we'll end up with a mess.

Would it not be better to enhance the SavedObjectsClient itself rather than implement our own home-rolled version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fully understand this comment: are you suggesting we default to namespaces:['*'] in the base SavedObjectsClient instead of creating a Telemetry-specific wrapper?

Copy link
Contributor

@TinaHeiligers TinaHeiligers Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly. I'm suggesting we have an enhanced SavedObjectsClient find method (maybe findFromAllSpaces(name TBD)), that everyone can use without home-rolling their own. My comment isn't a direct reflection on the implementation here though, it's more of a 'food for thought' comment.

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about the benefits to everyone if the SavedObjectsClient were enhanced rather than home-rolling our own override for the find method.
There are likely other services/plugins that need to ensure their SavedObjectClient's are properly scoped.

* @param options
*/
async find<T = unknown>(options: SavedObjectsFindOptions): Promise<SavedObjectsFindResponse<T>> {
return super.find({ namespaces: ['*'], ...options });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to super makes me nervous.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @afharo

@TinaHeiligers TinaHeiligers self-requested a review March 5, 2021 01:09
Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional comments!

@rudolf
Copy link
Contributor

rudolf commented Mar 5, 2021

Like Tina I'm also a bit nervous about creating and exposing many different flavours of SavedObjectsClient which have slightly different underlying behaviour.

In this case we want collectors to work across all spaces when the request is encrypted, and only on the user's current space if the request isn't encrypted. So I don't really see a more elegant way to achieve that.

@afharo afharo added the auto-backport Deprecated - use backport:version if exact versions are needed label Mar 5, 2021
@afharo afharo merged commit 00d448b into elastic:master Mar 5, 2021
@afharo afharo deleted the telemetry/savedObjectsClient-find-all-namespaces branch March 5, 2021 11:11
@kibanamachine
Copy link
Contributor

💔 Backport failed

❌ 7.x: Commit could not be cherrypicked due to conflicts

To backport manually, check out the target branch and run:
node scripts/backport --pr 93289

afharo added a commit to afharo/kibana that referenced this pull request Mar 5, 2021
…lastic#93289)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	api_docs/telemetry_collection_manager.json
#	api_docs/usage_collection.json
afharo added a commit that referenced this pull request Mar 5, 2021
…93289) (#93759)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	api_docs/telemetry_collection_manager.json
#	api_docs/usage_collection.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Telemetry release_note:skip Skip the PR/issue when compiling release notes v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Usage Collection] Saved Objects APIs scopes might return incomplete data
4 participants