feat(daml): add flag to control the max request size for a grpc request

Signed-off-by: Kai Davenport <kaiyadavenport@gmail.com>
This commit is contained in:
Kai Davenport 2021-01-21 11:46:59 +00:00
parent 06a970022e
commit 0531be0049
No known key found for this signature in database
GPG Key ID: A51F04038D003AAF
1 changed files with 29 additions and 3 deletions

View File

@ -125,9 +125,15 @@ var (
The maximum total time the operation can take, in seconds. This is
useful for preventing batch jobs that use grpcurl from hanging due to
slow or bad network links or due to incorrect stream method usage.`))
maxMsgSz = flags.Int("max-msg-sz", 0, prettify(`
maxReqSz = flags.Int("max-req-sz", 0, prettify(`
The maximum encoded size of a request message, in bytes, that grpcurl
will accept. If not specified, defaults to 4,194,304 (4 megabytes).`))
maxResSz = flags.Int("max-res-sz", 0, prettify(`
The maximum encoded size of a response message, in bytes, that grpcurl
will accept. If not specified, defaults to 4,194,304 (4 megabytes).`))
maxMsgSz = flags.Int("max-msg-sz", 0, prettify(`
The maximum encoded size of a request and response message, in bytes, that grpcurl
will accept. If not specified, defaults to 4,194,304 (4 megabytes).`))
emitDefaults = flags.Bool("emit-defaults", false, prettify(`
Emit default values for JSON-encoded responses.`))
protosetOut = flags.String("protoset-out", "", prettify(`
@ -277,6 +283,12 @@ func main() {
if *maxTime < 0 {
fail(nil, "The -max-time argument must not be negative.")
}
if *maxReqSz < 0 {
fail(nil, "The -max-req-sz argument must not be negative.")
}
if *maxResSz < 0 {
fail(nil, "The -max-res-sz argument must not be negative.")
}
if *maxMsgSz < 0 {
fail(nil, "The -max-msg-sz argument must not be negative.")
}
@ -299,6 +311,17 @@ func main() {
warn("The -emit-defaults is only used when using json format.")
}
// apply max-msg-sz -> both max-req-sz & max-res-sz
// on the condition they do not have their own values
if *maxMsgSz != 0 {
if *maxReqSz == 0 {
maxReqSz = maxMsgSz
}
if *maxResSz == 0 {
maxResSz = maxMsgSz
}
}
args := flags.Args()
if len(args) == 0 {
@ -400,8 +423,11 @@ func main() {
Timeout: timeout,
}))
}
if *maxMsgSz > 0 {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxMsgSz)))
if *maxReqSz > 0 {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(*maxReqSz)))
}
if *maxResSz > 0 {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxResSz)))
}
var creds credentials.TransportCredentials
if !*plaintext {