gRPC support for opensearch-java#2062
Open
dayana-j wants to merge 1 commit into
Open
Conversation
5e44f37 to
cc3185c
Compare
Adds a transparent gRPC transport layer that routes bulk operations over gRPC for improved performance while falling back to REST for all other operations. Isolated in a separate java-client-grpc module to prevent classpath conflicts. Includes: - GrpcTransport + HybridTransport (automatic routing and fallback) - Translation layer (BulkRequest/Response <-> protobuf conversion) - TLS support (trust cert, trust store, mTLS, insecure, hostname override) - Basic auth, AWS SigV4, and JWT authentication interceptors - Channel health monitoring via gRPC connectivity state machine - Integration tests (framework-compliant, version-gated to 3.5.0+) - Sample code and CI configuration Signed-off-by: Dayana Jean <jeadayao@amazon.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR adds a transparent gRPC support to the opensearch-java as a separate
java-client-grpcmodule with a translation layer, transport layers, connection management, and security implementation for gRPC such as TLS/basic auth, SigV4, and JWT. Bulk operations are automatically routed over gRPC for improved performance; lower latency, higher throughput, and smaller payloads via HTTP/2 and Protocol Buffers, while all other operations fall back to REST seamlessly. Users configure the transport once and use the standardOpenSearchClientAPI without any protobuf imports, channel management, or code changes.OpenSearch 3.5+ exposes a gRPC endpoint (default port 9400) alongside REST for Bulk and k-NN operations. This implementation bridges the gap so that existing client code benefits from gRPC performance without migration effort.
The gRPC transport lives in its own module to isolate gRPC dependencies (
grpc-netty-shaded,protobuf-java) from the core client, preventing classpath conflicts with the OpenSearch test framework.Users add the gRPC module as an optional dependency:
How It Works
The
HybridTransportwraps both aGrpcTransport(for bulk) and a standard REST transport (for everything else). Whenclient.bulk()is called, the request is converted from the client's Java types to protobuf, sent over gRPC, and the response is converted back — all transparently. If gRPC is unavailable or the conversion fails, the request automatically retries via REST.Authentication
All three authentication methods supported by OpenSearch are implemented as gRPC
ClientInterceptors that attach credentials to every outgoing call's metadata.TLS + Basic Auth:
AWS SigV4 signs each gRPC call using AWS SDK v2 credential providers. The interceptor constructs a synthetic URL from the gRPC method path, signs it with
AwsV4HttpSigner, and attaches the Authorization headers as gRPC metadata. Body-aware payload signing is supported for full SigV4 compliance.JWT uses a token supplier called on every request for automatic token rotation:
.jwtAuth(() -> myOidcProvider.getAccessToken())Connection Management
The gRPC
ManagedChannelprovides built-in connection health management that's more capable than REST's passive dead-node tracking. The channel automatically reconnects on failure with exponential backoff, and theGrpcChannelHealthMonitorexposes the connectivity state machine (IDLE → CONNECTING → READY → TRANSIENT_FAILURE) so callers can check readiness or register state change callbacks.Retry logic is configurable via
GrpcTransportOptions— max retries, backoff interval, keepalive pings, idle timeout, and max inbound message size all have sensible defaults that match the OpenSearch server's gRPC settings.Translation Layer
BulkRequestConverterwalks the typedBulkOperationlist, serializes document bodies to JSON bytes viaJsonpMapper, and builds the protobufBulkRequest.BulkResponseConverterconverts each protobufResponseItemback to the client'sBulkResponseItemwith all fields. Status code mapping follows the OpenSearch server'sRestToGrpcStatusConverter.Tests
The implementation includes 112 unit tests across 6 test files covering all conversion logic, transport routing, authentication interceptors, channel management, and TLS configuration. Three condensed integration tests validate end-to-end behavior against a real OpenSearch 3.5+ cluster using the project's existing test framework (
OpenSearchJavaClientTestCase+ Testcontainers). Tests are version-gated viaassumeTrueand skip automatically on older clusters.CI Configuration
The Docker configuration in
.ci/opensearch/enables gRPC transport (port 9400) in the test container. A standalonevalidate-grpc-integration.shscript is included for local validation. gRPC integration tests run via./gradlew :java-client-grpc:test.Dependencies
gRPC support is configured as an optional feature (
grpcSupport) with zero impact on users who don't enable it. Dependencies areio.grpc(1.68.0),com.google.protobuf(3.25.5), andorg.opensearch:protobufs(1.2.0).Related
This is the Java counterpart to the opensearch-py gRPC implementation that I created, following the same design pattern:
OpenSearch gRPC API documentation: https://docs.opensearch.org/latest/api-reference/grpc-apis/index/
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.