Skip to content
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

MaxMessageSizeConfig for Dummies #4074

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/configurable_max_message_size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Allow configuring the max size of grpc messages

We added a possibility to make the max size of grpc messsages configurable.
It is only configurable via envvar `OCIS_GRPC_MAX_RECEIVED_MESSAGE_SIZE` . It is recommended to use this envvar only temporarily.

https://github.com/cs3org/reva/pull/4074
21 changes: 18 additions & 3 deletions pkg/rgrpc/todo/pool/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@ package pool

import (
"crypto/tls"
"os"
"strconv"

rtrace "github.com/cs3org/reva/v2/pkg/trace"
"github.com/pkg/errors"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

var (
maxCallRecvMsgSize = 10240000
_defaultMaxCallRecvMsgSize = 10240000
)

// NewConn creates a new connection to a grpc server
// with open census tracing support.
// TODO(labkode): make grpc tls configurable.
// TODO make maxCallRecvMsgSize configurable, raised from the default 4MB to be able to list 10k files
func NewConn(address string, opts ...Option) (*grpc.ClientConn, error) {

options := ClientOptions{}
Expand Down Expand Up @@ -69,11 +71,24 @@ func NewConn(address string, opts ...Option) (*grpc.ClientConn, error) {
}
}

// NOTE: We need to configure some grpc options in a central place.
// If many services configure the (e.g.) gateway client differently, one will be pick randomly. This leads to inconsistencies when using the single binary.
// To avoid inconsistencies and race conditions we get the configuration here.
// Please do NOT follow the pattern of calling `os.Getenv` in the wild without consulting docu team first.
maxRcvMsgSize := _defaultMaxCallRecvMsgSize
if e := os.Getenv("OCIS_GRPC_MAX_RECEIVED_MESSAGE_SIZE"); e != "" {
s, err := strconv.Atoi(e)
if err != nil || s <= 0 {
return nil, errors.Wrap(err, "grpc max message size is not a valid int")
}
maxRcvMsgSize = s
}

conn, err := grpc.Dial(
address,
grpc.WithTransportCredentials(cred),
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(maxCallRecvMsgSize),
grpc.MaxCallRecvMsgSize(maxRcvMsgSize),
),
grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(
otelgrpc.WithTracerProvider(
Expand Down