Skip to content

Commit

Permalink
allow configuring grpc max receive message size
Browse files Browse the repository at this point in the history
  • Loading branch information
theoribeiro authored and jasonwbarnett committed Mar 15, 2024
1 parent 58ead82 commit 6a4661f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ OPTIONS:
server listener. Set to 0 to disable. (default: 9092)
[$BAZEL_REMOTE_GRPC_PORT]
--grpc_max_recv_msg_size value The maximum message size in bytes the gRPC
server can receive. (default: 4194304)
[$BAZEL_REMOTE_GRPC_MAX_RECV_MSG_SIZE]
--profile_address value Address specification for a http server to listen
on for profiling, formatted either as [host]:port for TCP or
unix://path.sock for Unix domain sockets. Off by default, but can also be
Expand Down Expand Up @@ -444,6 +448,9 @@ http_address: 0.0.0.0:8080
# as described above):
#grpc_address: 0.0.0.0:9092

# Increase the gRPC server maximum receive message size
#grpc_max_recv_msg_size: 26214400

# If profile_address (or the deprecated profile_port and/or profile_host)
# is specified, then serve /debug/pprof/* URLs here (unix sockets are also
# supported as described above):
Expand Down Expand Up @@ -575,7 +582,7 @@ http_address: 0.0.0.0:8080
# auth_method: environment_credential
#
# auth_method: default

# If set to a valid port number, then serve /debug/pprof/* URLs here:
#profile_port: 7070
# IP address to use, if profiling is enabled:
Expand Down Expand Up @@ -635,7 +642,7 @@ See [examples/docker-compose.yml](examples/docker-compose.yml) for an example co
configuration.

* Don't name your deployment `bazel-remote`!

Kubernetes sets some environment variables based on this name, which conflict
with the `BAZEL_REMOTE_*` environment variables that bazel-remote tries to
parse.
Expand Down
8 changes: 7 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type Config struct {
LogTimezone string `yaml:"log_timezone"`
MaxBlobSize int64 `yaml:"max_blob_size"`
MaxProxyBlobSize int64 `yaml:"max_proxy_blob_size"`
GrpcMaxRecvMsgSize int `yaml:"grpc_max_recv_msg_size"`

// Fields that are created by combinations of the flags above.
ProxyBackend cache.Proxy
Expand Down Expand Up @@ -169,7 +170,9 @@ func newFromArgs(dir string, maxSize int, storageMode string, zstdImplementation
accessLogLevel string,
logTimezone string,
maxBlobSize int64,
maxProxyBlobSize int64) (*Config, error) {
maxProxyBlobSize int64,
grpcMaxRecvMsgSize int,
) (*Config, error) {

c := Config{
HTTPAddress: httpAddress,
Expand Down Expand Up @@ -205,6 +208,7 @@ func newFromArgs(dir string, maxSize int, storageMode string, zstdImplementation
LogTimezone: logTimezone,
MaxBlobSize: maxBlobSize,
MaxProxyBlobSize: maxProxyBlobSize,
GrpcMaxRecvMsgSize: grpcMaxRecvMsgSize,
}

err := validateConfig(&c)
Expand Down Expand Up @@ -245,6 +249,7 @@ func newFromYaml(data []byte) (*Config, error) {
MetricsDurationBuckets: defaultDurationBuckets,
AccessLogLevel: "all",
LogTimezone: "UTC",
GrpcMaxRecvMsgSize: 1024 * 1024 * 4,
},
}

Expand Down Expand Up @@ -623,5 +628,6 @@ func get(ctx *cli.Context) (*Config, error) {
ctx.String("log_timezone"),
ctx.Int64("max_blob_size"),
ctx.Int64("max_proxy_blob_size"),
ctx.Int("grpc_max_recv_msg_size"),
)
}
10 changes: 6 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ http_read_timeout: 5s
http_write_timeout: 10s
access_log_level: none
log_timezone: local
grpc_max_recv_msg_size: 26214400
`

config, err := newFromYaml([]byte(yaml))
Expand Down Expand Up @@ -60,6 +61,7 @@ log_timezone: local
MetricsDurationBuckets: []float64{.5, 1, 2.5, 5, 10, 20, 40, 80, 160, 320},
AccessLogLevel: "none",
LogTimezone: "local",
GrpcMaxRecvMsgSize: 26214400,
}

if !reflect.DeepEqual(config, expectedConfig) {
Expand Down Expand Up @@ -341,15 +343,15 @@ func TestStorageModes(t *testing.T) {
}{{
yaml: `host: localhost
port: 1234
dir: /foo/bar
dir: /foo/bar
max_size: 20
`,
expected: "zstd",
},
{
yaml: `host: localhost
port: 1234
dir: /foo/bar
dir: /foo/bar
max_size: 20
storage_mode: zstd
`,
Expand All @@ -358,7 +360,7 @@ storage_mode: zstd
{
yaml: `host: localhost
port: 1234
dir: /foo/bar
dir: /foo/bar
max_size: 20
storage_mode: uncompressed
`,
Expand All @@ -367,7 +369,7 @@ storage_mode: uncompressed
{
yaml: `host: localhost
port: 1234
dir: /foo/bar
dir: /foo/bar
max_size: 20
storage_mode: gzip
`,
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ func startGrpcServer(c *config.Config, grpcServer **grpc.Server,

opts = append(opts, grpc.ChainStreamInterceptor(streamInterceptors...))
opts = append(opts, grpc.ChainUnaryInterceptor(unaryInterceptors...))
log.Println("Setting gRPC Max Receive Message Size to:", c.GrpcMaxRecvMsgSize)
opts = append(opts, grpc.MaxRecvMsgSize(c.GrpcMaxRecvMsgSize))

validateAC := !c.DisableGRPCACDepsCheck
validateStatus := "disabled"
Expand Down
7 changes: 7 additions & 0 deletions utils/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ func GetCliFlags() []cli.Flag {
DefaultText: strconv.FormatInt(math.MaxInt64, 10),
EnvVars: []string{"BAZEL_REMOTE_MAX_BLOB_SIZE"},
},
&cli.IntFlag{
Name: "grpc_max_recv_msg_size",
Value: 1024 * 1024 * 4,
Usage: "The maximum message size in bytes the gRPC server can receive.",
DefaultText: strconv.FormatInt(1024*1024*4, 10),
EnvVars: []string{"BAZEL_REMOTE_GRPC_MAX_RECV_MSG_SIZE"},
},
&cli.Int64Flag{
Name: "max_proxy_blob_size",
Value: math.MaxInt64,
Expand Down

0 comments on commit 6a4661f

Please sign in to comment.