Skip to content

Commit

Permalink
Support grpc gzip compression (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia authored Oct 9, 2023
1 parent f50f39e commit fb5f0a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/proxy/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/metadata"
)

Expand Down Expand Up @@ -64,6 +65,9 @@ func getDialOpts(p Config) ([]grpc.DialOption, error) {
} else {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
if p.GrpcCompression {
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name)))
}

if p.testGrpcDialer != nil {
dialOpts = append(dialOpts, grpc.WithContextDialer(p.testGrpcDialer))
Expand Down
2 changes: 2 additions & 0 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type Config struct {
GrpcCredentialsKey string `mapstructure:"grpc_credentials_key" json:"grpc_credentials_key,omitempty"`
// GrpcCredentialsValue is a custom value for GrpcCredentialsKey.
GrpcCredentialsValue string `mapstructure:"grpc_credentials_value" json:"grpc_credentials_value,omitempty"`
// GrpcCompression enables compression for outgoing calls (gzip).
GrpcCompression bool `mapstructure:"grpc_compression" json:"grpc_compression,omitempty"`

testGrpcDialer func(context.Context, string) (net.Conn, error)
}
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import (
"golang.org/x/crypto/acme/autocert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
_ "google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/reflection"
)
Expand Down Expand Up @@ -275,6 +276,7 @@ var defaults = map[string]any{
"proxy_binary_encoding": false,
"proxy_include_connection_meta": false,
"proxy_grpc_cert_file": "",
"proxy_grpc_compression": false,

"tarantool_mode": "standalone",
"tarantool_address": "tcp://127.0.0.1:3301",
Expand Down Expand Up @@ -1753,6 +1755,7 @@ func proxyMapConfig() (*client.ProxyMap, bool) {
GrpcCredentialsKey: v.GetString("proxy_grpc_credentials_key"),
GrpcCredentialsValue: v.GetString("proxy_grpc_credentials_value"),
GrpcMetadata: v.GetStringSlice("proxy_grpc_metadata"),
GrpcCompression: v.GetBool("proxy_grpc_compression"),
}

proxyConfig.HttpHeaders = v.GetStringSlice("proxy_http_headers")
Expand Down

0 comments on commit fb5f0a6

Please sign in to comment.