-
Notifications
You must be signed in to change notification settings - Fork 225
refactor: use pure gRPC instead of grpc-web wrapper on the provider side #2194
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
Open
nimrod-teich
wants to merge
5
commits into
main
Choose a base branch
from
refactor/provider-listener-pure-grpc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,417
−314
Conversation
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
603a3fc to
cadf97a
Compare
Test Results 7 files ± 0 85 suites ±0 30m 53s ⏱️ -53s Results for commit 88bb60e. ± Comparison against base commit e4f7444. This pull request removes 7 and adds 19 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
BREAKING CHANGE: gRPC-web protocol is no longer supported. Browser-based clients that relied on grpc-web to communicate directly with providers will no longer work. Only native gRPC clients are supported. The previous implementation used grpc-web and h2c HTTP wrappers to support the Lava SDK (lava-sdk/lavajs) which allowed browser-based JavaScript clients to communicate with providers. Since SDK support has been removed (see #2186), this infrastructure is no longer needed. Replace the grpc-web/h2c/HTTP hybrid server with a cleaner architecture: - Use cmux to multiplex HTTP health checks and native gRPC on same port - Remove grpcweb.WrapServer and h2c.NewHandler complexity - Add gRPC health checking protocol support (grpc_health_v1) - Keep HTTP health endpoint for Kubernetes probes compatibility - Optimize cmux matching: HTTP1Fast() first, then Any() for gRPC (avoids expensive HTTP/2 header parsing at high scale) Benefits: - Native gRPC connection management (keepalives, stream limits) - Proper graceful shutdown via grpcServer.GracefulStop() - Simpler, more maintainable code - Better performance at scale (no protocol translation overhead) Also adds comprehensive test suite for provider_listener.go with 14 tests and 2 benchmarks covering HTTP health, gRPC health, relay/probe RPCs, concurrent requests, and error handling.
gRPC handles compression automatically when the gzip compressor is registered (via import) and the client uses grpc.UseCompressor(gzip.Name). Removed: - Manual compression in provider (common.CompressData) - Manual decompression in consumer/smartrouter (common.DecompressData) - Custom LavaCompressionSupportHeader and LavaCompressionHeader headers - Obsolete rpcsmartrouter_compression_test.go The --enable-application-level-compression flag still works, but now uses native gRPC compression instead of manual application-level compression. This is simpler, more efficient, and follows gRPC best practices. Note: common.CompressData/DecompressData utilities are kept as they're still used for cache storage compression.
- Renamed from --enable-application-level-compression to --enable-grpc-compression (more accurate now that we use native gRPC compression) - Updated flag description to explain the trade-off (bandwidth vs CPU) - Improved log message when compression is enabled
Add comprehensive tests verifying native gRPC compression works correctly between consumer and provider: - TestGRPCCompressionEnabled: verifies data is compressed (99%+ reduction) - TestGRPCCompressionDisabled: verifies no compression without flag - TestGRPCCompressionBidirectional: verifies both request and response compression - TestGRPCCompressionWithConnectGRPCClient: tests via actual ConnectGRPCClient function - TestGRPCCompressionSmallPayload: verifies small payload handling - BenchmarkGRPCWithCompression/WithoutCompression: performance comparison Uses gRPC stats handler to measure actual wire vs logical payload sizes.
df807cf to
88bb60e
Compare
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.
Summary
Replace the grpc-web/h2c/HTTP hybrid server with a cleaner architecture using pure gRPC and native compression.
Background
The previous implementation used grpc-web and h2c HTTP wrappers to support the Lava SDK (lava-sdk/lavajs), which allowed browser-based JavaScript clients to communicate with providers. Since SDK support has been removed (see #2186), this infrastructure is no longer needed.
Changes
1. Pure gRPC Provider Listener
Replace the hybrid server with a cleaner architecture:
cmuxto multiplex HTTP health checks and native gRPC on the same portgrpcweb.WrapServerandh2c.NewHandlercomplexitygrpc_health_v1)HTTP1Fast()first, thenAny()for gRPC (avoids expensive HTTP/2 header parsing at high scale)Benefits:
grpcServer.GracefulStop()2. Native gRPC Compression
Replace manual application-level compression with native gRPC gzip:
common.CompressData()/common.DecompressData()from relay pathLavaCompressionHeader,LavaCompressionSupportHeader)import _ "google.golang.org/grpc/encoding/gzip"grpc.UseCompressor(gzip.Name)when flag is enabled3. Flag Rename
--enable-application-level-compression→--enable-grpc-compressionBREAKING CHANGES
gRPC-web Protocol Removed
gRPC-web protocol is no longer supported. Browser-based clients that relied on grpc-web to communicate directly with providers will no longer work. Only native gRPC clients are supported.
Who is affected: Only the deprecated lava-sdk (browser clients) which has already been removed.
Compression Flag Renamed
The
--enable-application-level-compressionflag has been renamed to--enable-grpc-compression.Migration: Update any scripts, configurations, or Kubernetes manifests using the old flag name.
Description
Closes: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!in the type prefix if API or client breaking changemainbranchReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...