Skip to content

Commit 03c2aa5

Browse files
committed
Make QueryBuilderProtoConverter and QueryBuilderProtoConverterRegistry an SPI
Signed-off-by: Karen Xu <karenxyr@gmail.com>
1 parent 8f310f5 commit 03c2aa5

File tree

15 files changed

+1694
-140
lines changed

15 files changed

+1694
-140
lines changed

CHANGELOG.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,57 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
- Add temporal routing processors for time-based document routing ([#18920](https://github.com/opensearch-project/OpenSearch/issues/18920))
1010

1111

12+
- [Feature Request] Enhance Terms lookup query to support query clause instead of docId ([#18195](https://github.com/opensearch-project/OpenSearch/issues/18195))
13+
- Add hierarchical routing processors for ingest and search pipelines ([#18826](https://github.com/opensearch-project/OpenSearch/pull/18826))
14+
- Add ACL-aware routing processors for ingest and search pipelines ([#18834](https://github.com/opensearch-project/OpenSearch/pull/18834))
15+
- Add support for Warm Indices Write Block on Flood Watermark breach ([#18375](https://github.com/opensearch-project/OpenSearch/pull/18375))
16+
- FS stats for warm nodes based on addressable space ([#18767](https://github.com/opensearch-project/OpenSearch/pull/18767))
17+
- Add support for custom index name resolver from cluster plugin ([#18593](https://github.com/opensearch-project/OpenSearch/pull/18593))
18+
- Rename WorkloadGroupTestUtil to WorkloadManagementTestUtil ([#18709](https://github.com/opensearch-project/OpenSearch/pull/18709))
19+
- Disallow resize for Warm Index, add Parameterized ITs for close in remote store ([#18686](https://github.com/opensearch-project/OpenSearch/pull/18686))
20+
- Ability to run Code Coverage with Gradle and produce the jacoco reports locally ([#18509](https://github.com/opensearch-project/OpenSearch/issues/18509))
21+
- Extend BooleanQuery must_not rewrite to numeric must, term, and terms queries ([#18498](https://github.com/opensearch-project/OpenSearch/pull/18498))
22+
- [Workload Management] Update logging and Javadoc, rename QueryGroup to WorkloadGroup ([#18711](https://github.com/opensearch-project/OpenSearch/issues/18711))
23+
- Add NodeResourceUsageStats to ClusterInfo ([#18480](https://github.com/opensearch-project/OpenSearch/issues/18472))
24+
- Introduce SecureHttpTransportParameters experimental API (to complement SecureTransportParameters counterpart) ([#18572](https://github.com/opensearch-project/OpenSearch/issues/18572))
25+
- Create equivalents of JSM's AccessController in the java agent ([#18346](https://github.com/opensearch-project/OpenSearch/issues/18346))
26+
- [WLM] Add WLM mode validation for workload group CRUD requests ([#18652](https://github.com/opensearch-project/OpenSearch/issues/18652))
27+
- Introduced a new cluster-level API to fetch remote store metadata (segments and translogs) for each shard of an index. ([#18257](https://github.com/opensearch-project/OpenSearch/pull/18257))
28+
- Add last index request timestamp columns to the `_cat/indices` API. ([10766](https://github.com/opensearch-project/OpenSearch/issues/10766))
29+
- Introduce a new pull-based ingestion plugin for file-based indexing (for local testing) ([#18591](https://github.com/opensearch-project/OpenSearch/pull/18591))
30+
- Add support for search pipeline in search and msearch template ([#18564](https://github.com/opensearch-project/OpenSearch/pull/18564))
31+
- [Workload Management] Modify logging message in WorkloadGroupService ([#18712](https://github.com/opensearch-project/OpenSearch/pull/18712))
32+
- Add BooleanQuery rewrite moving constant-scoring must clauses to filter clauses ([#18510](https://github.com/opensearch-project/OpenSearch/issues/18510))
33+
- Add functionality for plugins to inject QueryCollectorContext during QueryPhase ([#18637](https://github.com/opensearch-project/OpenSearch/pull/18637))
34+
- Add support for non-timing info in profiler ([#18460](https://github.com/opensearch-project/OpenSearch/issues/18460))
35+
- [Rule-based auto tagging] Bug fix and improvements ([#18726](https://github.com/opensearch-project/OpenSearch/pull/18726))
36+
- Extend Approximation Framework to other numeric types ([#18530](https://github.com/opensearch-project/OpenSearch/issues/18530))
37+
- Add Semantic Version field type mapper and extensive unit tests([#18454](https://github.com/opensearch-project/OpenSearch/pull/18454))
38+
- Pass index settings to system ingest processor factories. ([#18708](https://github.com/opensearch-project/OpenSearch/pull/18708))
39+
- Add fetch phase profiling. ([#18664](https://github.com/opensearch-project/OpenSearch/pull/18664))
40+
- Include named queries from rescore contexts in matched_queries array ([#18697](https://github.com/opensearch-project/OpenSearch/pull/18697))
41+
- Add the configurable limit on rule cardinality ([#18663](https://github.com/opensearch-project/OpenSearch/pull/18663))
42+
- Disable approximation framework when dealing with multiple sorts ([#18763](https://github.com/opensearch-project/OpenSearch/pull/18763))
43+
- [Experimental] Start in "clusterless" mode if a clusterless ClusterPlugin is loaded ([#18479](https://github.com/opensearch-project/OpenSearch/pull/18479))
44+
- [Star-Tree] Add star-tree search related stats ([#18707](https://github.com/opensearch-project/OpenSearch/pull/18707))
45+
- Add support for plugins to profile information ([#18656](https://github.com/opensearch-project/OpenSearch/pull/18656))
46+
- Add support for Combined Fields query ([#18724](https://github.com/opensearch-project/OpenSearch/pull/18724))
47+
- Make GRPC transport extensible to allow plugins to register and expose their own GRPC services ([#18516](https://github.com/opensearch-project/OpenSearch/pull/18516))
48+
- Added approximation support for range queries with now in date field ([#18511](https://github.com/opensearch-project/OpenSearch/pull/18511))
49+
- Upgrade to protobufs 0.6.0 and clean up deprecated TermQueryProtoUtils code ([#18880](https://github.com/opensearch-project/OpenSearch/pull/18880))
50+
- Expand fetch phase profiling to multi-shard queries ([#18887](https://github.com/opensearch-project/OpenSearch/pull/18887))
51+
- Prevent shard initialization failure due to streaming consumer errors ([#18877](https://github.com/opensearch-project/OpenSearch/pull/18877))
52+
- APIs for stream transport and new stream-based search api action ([#18722](https://github.com/opensearch-project/OpenSearch/pull/18722))
53+
- Add support for custom remote store segment path prefix to support clusterless configurations ([#18750](https://github.com/opensearch-project/OpenSearch/issues/18750))
54+
- Added the core process for warming merged segments in remote-store enabled domains ([#18683](https://github.com/opensearch-project/OpenSearch/pull/18683))
55+
- Streaming aggregation ([#18874](https://github.com/opensearch-project/OpenSearch/pull/18874))
56+
- Optimize Composite Aggregations by removing unnecessary object allocations ([#18531](https://github.com/opensearch-project/OpenSearch/pull/18531))
57+
- [Star-Tree] Add search support for ip field type ([#18671](https://github.com/opensearch-project/OpenSearch/pull/18671))
58+
- [Derived Source] Add integration of derived source feature across various paths like get/search/recovery ([#18565](https://github.com/opensearch-project/OpenSearch/pull/18565))
59+
- Supporting Scripted Metric Aggregation when reducing aggregations in InternalValueCount and InternalAvg ([18411](https://github.com/opensearch-project/OpenSearch/pull18411)))
60+
- Support `search_after` numeric queries with Approximation Framework ([#18896](https://github.com/opensearch-project/OpenSearch/pull/18896))
61+
- Add skip_list parameter to Numeric Field Mappers (default false) ([#18889](https://github.com/opensearch-project/OpenSearch/pull/18889))
62+
- Publish transport-grpc-spi exposing QueryBuilderProtoConverter and QueryBuilderProtoConverterRegistry ([#18949](https://github.com/opensearch-project/OpenSearch/pull/18949))
1263
### Changed
1364
- Add CompletionStage variants to methods in the Client Interface and default to ActionListener impl ([#18998](https://github.com/opensearch-project/OpenSearch/pull/18998))
1465

modules/transport-grpc/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ testClusters {
2121
}
2222

2323
dependencies {
24+
api project('spi')
2425
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
2526
runtimeOnly "com.google.guava:guava:${versions.guava}"
2627
implementation "com.google.errorprone:error_prone_annotations:2.24.1"
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# transport-grpc-spi
2+
3+
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.
4+
5+
## Overview
6+
7+
The `transport-grpc-spi` module enables plugin developers to:
8+
- Implement custom query converters for gRPC transport
9+
- Extend gRPC protocol buffer handling
10+
- Register custom query types that can be processed via gRPC
11+
12+
## Key Components
13+
14+
### QueryBuilderProtoConverter
15+
16+
Interface for converting protobuf query messages to OpenSearch QueryBuilder objects.
17+
18+
```java
19+
public interface QueryBuilderProtoConverter {
20+
QueryContainer.QueryContainerCase getHandledQueryCase();
21+
QueryBuilder fromProto(QueryContainer queryContainer);
22+
}
23+
```
24+
25+
### QueryBuilderProtoConverterSpiRegistry
26+
27+
Registry that manages and discovers all available query converters. External plugins can register their custom converters through this registry.
28+
29+
## Usage for Plugin Developers
30+
31+
### 1. Add Dependency
32+
33+
Add the SPI dependency to your plugin's `build.gradle`:
34+
35+
```gradle
36+
dependencies {
37+
compileOnly 'org.opensearch.plugin:transport-grpc-spi:${opensearch.version}'
38+
compileOnly 'org.opensearch:protobufs:${protobufs.version}'
39+
}
40+
```
41+
42+
### 2. Implement Custom Query Converter
43+
44+
```java
45+
public class MyCustomQueryConverter implements QueryBuilderProtoConverter {
46+
47+
@Override
48+
public QueryContainer.QueryContainerCase getHandledQueryCase() {
49+
return QueryContainer.QueryContainerCase.MY_CUSTOM_QUERY;
50+
}
51+
52+
@Override
53+
public QueryBuilder fromProto(QueryContainer queryContainer) {
54+
// Convert your custom protobuf query to QueryBuilder
55+
MyCustomQuery customQuery = queryContainer.getMyCustomQuery();
56+
return new MyCustomQueryBuilder(customQuery.getField(), customQuery.getValue());
57+
}
58+
}
59+
```
60+
61+
### 3. Register Your Converter
62+
63+
In your plugin's main class, register the converter:
64+
65+
```java
66+
public class MyPlugin extends Plugin implements ExtensiblePlugin {
67+
68+
@Override
69+
public Collection<Object> createComponents(Client client, ClusterService clusterService,
70+
ThreadPool threadPool, ResourceWatcherService resourceWatcherService,
71+
ScriptService scriptService, NamedXContentRegistry xContentRegistry,
72+
Environment environment, NodeEnvironment nodeEnvironment,
73+
NamedWriteableRegistry namedWriteableRegistry,
74+
IndexNameExpressionResolver indexNameExpressionResolver,
75+
Supplier<RepositoriesService> repositoriesServiceSupplier) {
76+
77+
// Get the registry and register your converter
78+
QueryBuilderProtoConverterSpiRegistry registry =
79+
// Obtain registry from OpenSearch's dependency injection
80+
registry.registerConverter(new MyCustomQueryConverter());
81+
82+
return Collections.emptyList();
83+
}
84+
}
85+
```
86+
87+
## Testing
88+
89+
### Unit Tests
90+
91+
```bash
92+
./gradlew :modules:transport-grpc:spi:test
93+
```
94+
95+
### Testing Your Custom Converter
96+
97+
```java
98+
@Test
99+
public void testCustomQueryConverter() {
100+
MyCustomQueryConverter converter = new MyCustomQueryConverter();
101+
102+
// Create test protobuf query
103+
QueryContainer queryContainer = QueryContainer.newBuilder()
104+
.setMyCustomQuery(MyCustomQuery.newBuilder()
105+
.setField("test_field")
106+
.setValue("test_value")
107+
.build())
108+
.build();
109+
110+
// Convert and verify
111+
QueryBuilder result = converter.fromProto(queryContainer);
112+
assertThat(result, instanceOf(MyCustomQueryBuilder.class));
113+
114+
MyCustomQueryBuilder customQuery = (MyCustomQueryBuilder) result;
115+
assertEquals("test_field", customQuery.fieldName());
116+
assertEquals("test_value", customQuery.value());
117+
}
118+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
apply plugin: 'opensearch.build'
10+
apply plugin: 'opensearch.publish'
11+
12+
base {
13+
group = 'org.opensearch.plugin'
14+
archivesName = 'transport-grpc-spi'
15+
}
16+
17+
dependencies {
18+
api project(":server")
19+
api "org.opensearch:protobufs:0.6.0"
20+
21+
testImplementation project(":test:framework")
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1675c5085e1376fd1a107b87f7e325944ab5b4dc

0 commit comments

Comments
 (0)