-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Adding MapperServiceProvider for plugins #16110
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16110 +/- ##
============================================
+ Coverage 71.86% 71.92% +0.05%
- Complexity 64447 64485 +38
============================================
Files 5288 5289 +1
Lines 301438 301455 +17
Branches 43552 43553 +1
============================================
+ Hits 216628 216818 +190
+ Misses 67034 66880 -154
+ Partials 17776 17757 -19 ☔ View full report in Codecov by Sentry. |
9a5dac6
to
3ce3c96
Compare
@dzane17 could you please provide more context behind this change: why do you need to expose the IndicesService to plugins? thank you |
Thanks @dzane17 , it still does not answer the question (but leads to more questions):
Could you please share the reference to the pull request or associated issue so it would be possible to understand the problem you are solving that asks for such solution. |
c87655b
to
de087da
Compare
❌ Gradle check result for de087da: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
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.
Can you update the PR title to reflect the latest changes?
be47a7c
to
7c9a8e2
Compare
I have linked the related RFC and PR above. |
server/src/main/java/org/opensearch/indices/IndicesService.java
Outdated
Show resolved
Hide resolved
if (indexService == null) { | ||
return null; | ||
} else { | ||
return indexService.mapperService(); |
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.
Do we need to include small test for this new method? Also, for the change from index as string to index as object
❕ Gradle check result for 7c9a8e2: UNSTABLE
Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Signed-off-by: David Zane <davizane@amazon.com>
7c9a8e2
to
51f28cd
Compare
❌ Gradle check result for 51f28cd: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
*/ | ||
@FunctionalInterface | ||
@PublicApi(since = "2.18.0") | ||
public interface MapperServiceProvider { |
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 am not sure if this is the best way to do it, that too exposing this inside a plugin package. It basically tells anyone to implement a MapperServiceProvider implementation, but underneath it returns a concrete MapperService
class
If the only intention is to expose this MapperService somehow, one way would be to pass it inside MapperAwarePlugin via param Function<Index, MapperService>
.
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.
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 @jainankitk I think we should not pursue this route, see please #16110 (comment)
Client client, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ResourceWatcherService resourceWatcherService, | ||
ScriptService scriptService, | ||
NamedXContentRegistry xContentRegistry, | ||
Environment environment, | ||
NodeEnvironment nodeEnvironment, | ||
NamedWriteableRegistry namedWriteableRegistry, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
Supplier<RepositoriesService> repositoriesServiceSupplier, |
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.
Not sure why we want to pass all these params. Any plugin already extends Plugin
class which already provides all these classes.
* @opensearch.internal | ||
*/ | ||
@PublicApi(since = "2.18.0") | ||
public interface MappingAwarePlugin { |
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 sounds more like MappingServiceAwarePlugin
?
NamedWriteableRegistry namedWriteableRegistry, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
Supplier<RepositoriesService> repositoriesServiceSupplier, | ||
MapperServiceProvider mapperServiceProvider |
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.
As mentioned this doesn't look right. One other way I think of doing this(ie exposing MappingService
) is by defining an interface sitting inside core(and not under plugins package), and one of the implementation being MapperService
. As then anyone trying to implement this plugin also have a ability to pass their own/other implementation of MapperService
and use that instead.
Thanks @dzane17 , MapperService is contextual component, I believe what you need is to use
In this case, you could inject
(same applies to |
Thanks @reta for this suggestion. Definitely something we should consider. Although, |
It has to, if not - that would be a good fix to have, thanks @dzane17 |
Okay, we will need to add
@reta - Given the amount of changes in core should be pretty small (limited to Node), is it possible for you to take a quick stab, in case we are missing something? |
@jainankitk why do you need that? The |
@dzane17 @jainankitk I haven't taken a deeper dive into this PR yet, but would this work for your use-case:
This is where indexModule becomes indexService: https://github.com/opensearch-project/security/blob/main/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java#L698-L709 |
@reta - How else will the
|
@jainankitk that is exactly the issue that @dzane17 brought up and we may need to fix: the instances of classes returned by |
@reta @jainankitk I originally intended to solve this by moving the creation of
However, We face a paradox where getGuiceServiceClasses() relies on dependency injection, but we are now attempting to return an object to be bound (QueryInsightsListener) from getGuiceServiceClasses(). |
Oh I see, thanks @dzane17 , that's unfortunate, let me think it through a bit |
@jainankitk @dzane17 Idk if this would be helpful as well, but Security creates a SearchOperationListener within onIndexModule: https://github.com/opensearch-project/security/blob/830b341453908332e4004d519ac2e0b099dca1f6/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java#L754-L837 The use-case for Security is Fls/Dls/FieldMasking feature which cluster administrators use to hide sensitive data stored in the clusters to users. Security must intercept search operations to apply the rules. See also my previous comment here |
Thanks @cwperks , I think |
@cwperks - Please correct me if I am wrong, but |
Correct, its shard-level. To my knowledge, the only request-level extension point is the handlerWrapper, but that is reserved for the security plugin to perform auth. My knowledge of how the internals of Search works is limited, but my understanding is that a SearchRequest lands on a coordinator node that then uses the routing table to figure out where to route the internal shard search requests to. It then sends out shard search requests to various nodes and collects the results before returning the results to the client. Is it possible to distinguish the request that lands on the coordinator node vs. the shard requests? iirc on the transport layer its the difference between Edit: All transport actions can be intercepted with |
Got it, thanks @jainankitk , so here is the way we could make it work, which is a bit cumbersome but solves the dependency problem, the
Since
|
Description
This PR introduces a new functional interface,
MapperServiceProvider
, to support the Query Insights plugin in accessing field types for search requests. TheIndicesService
holds the index mappings for each index, but rather than exposing the entire service to plugins, this interface allows them to retrieve theMapperService
for specific indices through thegetMapperService(Index index)
method.Related Issues
RFC opensearch-project/query-insights#69
PR opensearch-project/query-insights#130
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.