Skip to content

Commit

Permalink
make max message size configurable
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Jul 19, 2023
1 parent 0af2a07 commit f6d4393
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog/unreleased/configurable_max_message_size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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_MESSAGE_SIZE` . It is recommended to use this envvar only temporarily.
20 changes: 18 additions & 2 deletions pkg/rgrpc/todo/pool/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ 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
Expand Down Expand Up @@ -69,11 +72,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 {
return nil, errors.Wrap(err, "grpc max message size is not an 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

0 comments on commit f6d4393

Please sign in to comment.