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

[data.search] Add Kibana request to search strategy dependencies #98566

Merged
merged 7 commits into from
May 20, 2021

Conversation

lukasolson
Copy link
Member

@lukasolson lukasolson commented Apr 28, 2021

Summary

Resolves #96912.

This PR adds the raw KibanaRequest object to the list of dependencies for the search strategy, and provides another argument for the ES search strategy provider so that other strategies can opt into using the internal ES client.

Thoughts:

  • We eventually want to create some sort of registry that allows search strategies to register which dependencies they actually need, or even have them provide a function that takes in the raw request and returns the list of dependencies. But exposing the raw KibanaRequest might be a good short-term fix to unblock [Search Strategy] Include kibana request as a dependency #96912.

@lukasolson lukasolson changed the title [data.search] [discuss] Add Kibana request to search strategy dependencies [data.search] [discuss] [skip-ci] Add Kibana request to search strategy dependencies Apr 28, 2021
@yctercero
Copy link
Contributor

This would definitely work for our use case. The solution we had come up with made use of similar flags and it seems like this would be very easy to integrate on our end.

Just to add some context for anyone else reading this discussion, as part of the RAC effort we are adding RBAC for alerts. Our auth client works in conjunction with the security plugin and requires that we pass through the entire Kibana request in order for it to determine which features the user has access to.

I had been a bit nervous about exposing the internal user flag to end users, so I like what's proposed here of limiting it's scope to other search strategies.

I definitely see the use in allowing configuration of dependencies (as opposed to sending everything through by default), but we appreciate this effort of providing a temporary workaround to unblock the RAC efforts here.

@lukasolson lukasolson self-assigned this May 11, 2021
@lukasolson lukasolson added auto-backport Deprecated - use backport:version if exact versions are needed Feature:Search Querying infrastructure in Kibana release_note:skip Skip the PR/issue when compiling release notes review Team:AppServices v7.14.0 v8.0.0 labels May 11, 2021
@lukasolson lukasolson marked this pull request as ready for review May 11, 2021 18:15
@lukasolson lukasolson requested review from a team as code owners May 11, 2021 18:15
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

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

Thank you! that's exactly what we need for moving forward. 🏃‍♂️ 🏃‍♂️ ⭐ ⭐ ⭐

Copy link
Contributor

@yctercero yctercero left a comment

Choose a reason for hiding this comment

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

LGTM! It allows our team to move forward with RBAC and make the necessary calls using internal Kib user. Thanks for these changes to unblock us!

Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

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

LGTM

but 5¢:

We eventually want to create some sort of registry that allows search strategies to register which dependencies they actually need, or even have them provide a function that takes in the raw request and returns the list of dependencies. But exposing the raw KibanaRequest might be a good short-term fix to unblock #96912.

I'd probably consider now adding something like getRequestContext on ISearchStrategy so that when creating a search strategy consumers specified what exactly they need from raw request.

export const esSearchStrategyProvider = (
  config$: Observable<SharedGlobalConfig>,
  logger: Logger,
  usage?: SearchUsage,
): ISearchStrategy<.... , MyContext> => ({
  search: (req, options, context: MyContext) => {...},
  getRequestContext: (req: RawKibanaRequest): MyContext => {...}
})

What I think is nice here, is that it will be easier from a high-level view to see that search strategy relies on some specifics from raw request. There will be a single place where raw requests can be used. MyContext will be typed specific to a search strategy. Search strategies will be a bit easier to refactor. It also will be easier to unit test strategies methods because we will need to mock just MyContext instead of the whole kibana Request.

@lukasolson
Copy link
Member Author

I'd probably consider now adding something like getRequestContext on ISearchStrategy so that when creating a search strategy consumers specified what exactly they need from raw request.

This is exactly along the lines of what I was thinking. I'll open an issue for this.

@lukasolson
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

merge conflict between base and head

@lukasolson
Copy link
Member Author

@elasticmachine merge upstream

@lukasolson lukasolson changed the title [data.search] [discuss] [skip-ci] Add Kibana request to search strategy dependencies [data.search] [discuss] Add Kibana request to search strategy dependencies May 18, 2021
@simianhacker simianhacker self-requested a review May 18, 2021 19:55
Copy link
Member

@simianhacker simianhacker left a comment

Choose a reason for hiding this comment

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

LGTM

@lukasolson lukasolson force-pushed the searchStrategyKibanaRequest branch from c2c3dcb to 19aef72 Compare May 19, 2021 21:49
@lukasolson lukasolson changed the title [data.search] [discuss] Add Kibana request to search strategy dependencies [data.search] Add Kibana request to search strategy dependencies May 19, 2021
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
data 2959 2960 +1
Unknown metric groups

API count

id before after diff
data 3452 3453 +1

History

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

cc @lukasolson

@lukasolson lukasolson merged commit f728b22 into elastic:master May 20, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request May 20, 2021
…stic#98566)

* [data.search] Add Kibana request to search strategy dependencies

* Don't register internal strategy

* Update docs
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request May 20, 2021
) (#100425)

* [data.search] Add Kibana request to search strategy dependencies

* Don't register internal strategy

* Update docs

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>
yctercero pushed a commit to yctercero/kibana that referenced this pull request May 25, 2021
…stic#98566)

* [data.search] Add Kibana request to search strategy dependencies

* Don't register internal strategy

* Update docs
ecezalp pushed a commit to ecezalp/kibana that referenced this pull request May 26, 2021
…stic#98566)

* [data.search] Add Kibana request to search strategy dependencies

* Don't register internal strategy

* Update docs
ecezalp pushed a commit to ecezalp/kibana that referenced this pull request May 26, 2021
…stic#98566)

* [data.search] Add Kibana request to search strategy dependencies

* Don't register internal strategy

* Update docs
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:Search Querying infrastructure in Kibana release_note:skip Skip the PR/issue when compiling release notes review v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Search Strategy] Include kibana request as a dependency
7 participants