-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[GRPC] Publish transport-grpc-spi for QueryBuilderProtoConverter and QueryBuilderProtoConverterRegistry #18949
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4b79fc
Make QueryBuilderProtoConverter and QueryBuilderProtoConverterRegistr…
karenyrx 969470c
Merge branch 'main' into tgspi
karenyrx b7386ae
update readme
karenyrx e42b790
expose query registry to external plugins
karenyrx 44e4b3c
Merge branch 'main' into tgspi
karenyrx 3c79981
add packageinfo
karenyrx 42762d1
remove registry from SPI
karenyrx 5082498
Merge branch 'main' into tgspi
karenyrx d371c98
Merge branch 'main' into tgspi
karenyrx 2c59866
Merge branch 'main' into tgspi
msfroh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # transport-grpc-spi | ||
|
|
||
| Service Provider Interface (SPI) for the OpenSearch gRPC transport module. This module provides interfaces and utilities that allow external plugins to extend the gRPC transport functionality. | ||
|
|
||
| ## Overview | ||
|
|
||
| The `transport-grpc-spi` module enables plugin developers to: | ||
| - Implement custom query converters for gRPC transport | ||
| - Extend gRPC protocol buffer handling | ||
| - Register custom query types that can be processed via gRPC | ||
|
|
||
| ## Key Components | ||
|
|
||
| ### QueryBuilderProtoConverter | ||
|
|
||
| Interface for converting protobuf query messages to OpenSearch QueryBuilder objects. | ||
|
|
||
| ```java | ||
| public interface QueryBuilderProtoConverter { | ||
| QueryContainer.QueryContainerCase getHandledQueryCase(); | ||
| QueryBuilder fromProto(QueryContainer queryContainer); | ||
| } | ||
| ``` | ||
|
|
||
| ### QueryBuilderProtoConverterSpiRegistry | ||
|
|
||
| Registry that manages and discovers all available query converters. External plugins can register their custom converters through this registry. | ||
|
|
||
| ## Usage for Plugin Developers | ||
|
|
||
| ### 1. Add Dependency | ||
|
|
||
| Add the SPI dependency to your plugin's `build.gradle`: | ||
|
|
||
| ```gradle | ||
| dependencies { | ||
| compileOnly 'org.opensearch.plugin:transport-grpc-spi:${opensearch.version}' | ||
| compileOnly 'org.opensearch:protobufs:${protobufs.version}' | ||
| } | ||
| ``` | ||
|
|
||
| ### 2. Implement Custom Query Converter | ||
|
|
||
| ```java | ||
| public class MyCustomQueryConverter implements QueryBuilderProtoConverter { | ||
|
|
||
| @Override | ||
| public QueryContainer.QueryContainerCase getHandledQueryCase() { | ||
| return QueryContainer.QueryContainerCase.MY_CUSTOM_QUERY; | ||
| } | ||
|
|
||
| @Override | ||
| public QueryBuilder fromProto(QueryContainer queryContainer) { | ||
| // Convert your custom protobuf query to QueryBuilder | ||
| MyCustomQuery customQuery = queryContainer.getMyCustomQuery(); | ||
| return new MyCustomQueryBuilder(customQuery.getField(), customQuery.getValue()); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### 3. Register Your Converter | ||
|
|
||
| In your plugin's main class, register the converter: | ||
|
|
||
| ```java | ||
| public class MyPlugin extends Plugin implements ExtensiblePlugin { | ||
|
|
||
| @Override | ||
| public Collection<Object> createComponents(Client client, ClusterService clusterService, | ||
| ThreadPool threadPool, ResourceWatcherService resourceWatcherService, | ||
| ScriptService scriptService, NamedXContentRegistry xContentRegistry, | ||
| Environment environment, NodeEnvironment nodeEnvironment, | ||
| NamedWriteableRegistry namedWriteableRegistry, | ||
| IndexNameExpressionResolver indexNameExpressionResolver, | ||
| Supplier<RepositoriesService> repositoriesServiceSupplier) { | ||
|
|
||
| // Get the registry and register your converter | ||
| QueryBuilderProtoConverterSpiRegistry registry = | ||
| // Obtain registry from OpenSearch's dependency injection | ||
| registry.registerConverter(new MyCustomQueryConverter()); | ||
|
|
||
| return Collections.emptyList(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| ### Unit Tests | ||
|
|
||
| ```bash | ||
| ./gradlew :modules:transport-grpc:spi:test | ||
| ``` | ||
|
|
||
| ### Testing Your Custom Converter | ||
|
|
||
| ```java | ||
| @Test | ||
| public void testCustomQueryConverter() { | ||
| MyCustomQueryConverter converter = new MyCustomQueryConverter(); | ||
|
|
||
| // Create test protobuf query | ||
| QueryContainer queryContainer = QueryContainer.newBuilder() | ||
| .setMyCustomQuery(MyCustomQuery.newBuilder() | ||
| .setField("test_field") | ||
| .setValue("test_value") | ||
| .build()) | ||
| .build(); | ||
|
|
||
| // Convert and verify | ||
| QueryBuilder result = converter.fromProto(queryContainer); | ||
| assertThat(result, instanceOf(MyCustomQueryBuilder.class)); | ||
|
|
||
| MyCustomQueryBuilder customQuery = (MyCustomQueryBuilder) result; | ||
| assertEquals("test_field", customQuery.fieldName()); | ||
| assertEquals("test_value", customQuery.value()); | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| apply plugin: 'opensearch.build' | ||
| apply plugin: 'opensearch.publish' | ||
|
|
||
| base { | ||
| group = 'org.opensearch.plugin' | ||
| archivesName = 'transport-grpc-spi' | ||
| } | ||
|
|
||
| dependencies { | ||
| api project(":server") | ||
| api "org.opensearch:protobufs:0.6.0" | ||
|
|
||
| testImplementation project(":test:framework") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1675c5085e1376fd1a107b87f7e325944ab5b4dc |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.