feat(inputs.gnmi): Set max gRPC message size (#12495)

This commit is contained in:
Joshua Powers 2023-01-27 02:11:29 -07:00 committed by GitHub
parent eb03bb5599
commit d3e1f95b87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -36,7 +36,10 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
# encoding = "proto" # encoding = "proto"
## redial in case of failures after ## redial in case of failures after
redial = "10s" # redial = "10s"
## gRPC Maximum Message Size
# max_msg_size = "4MB"
## enable client-side TLS and define CA to authenticate the device ## enable client-side TLS and define CA to authenticate the device
# enable_tls = false # enable_tls = false

View File

@ -52,6 +52,7 @@ type GNMI struct {
Subscriptions []Subscription `toml:"subscription"` Subscriptions []Subscription `toml:"subscription"`
TagSubscriptions []TagSubscription `toml:"tag_subscription"` TagSubscriptions []TagSubscription `toml:"tag_subscription"`
Aliases map[string]string `toml:"aliases"` Aliases map[string]string `toml:"aliases"`
MaxMsgSize config.Size `toml:"max_msg_size"`
// Optional subscription configuration // Optional subscription configuration
Encoding string Encoding string
@ -298,9 +299,17 @@ func (c *GNMI) subscribeGNMI(ctx context.Context, worker *Worker, tlscfg *tls.Co
} else { } else {
creds = insecure.NewCredentials() creds = insecure.NewCredentials()
} }
opt := grpc.WithTransportCredentials(creds) opts := []grpc.DialOption{
grpc.WithTransportCredentials(creds),
}
client, err := grpc.DialContext(ctx, worker.address, opt) if c.MaxMsgSize > 0 {
opts = append(opts, grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(int(c.MaxMsgSize)),
))
}
client, err := grpc.DialContext(ctx, worker.address, opts...)
if err != nil { if err != nil {
return fmt.Errorf("failed to dial: %v", err) return fmt.Errorf("failed to dial: %v", err)
} }

View File

@ -11,7 +11,10 @@
# encoding = "proto" # encoding = "proto"
## redial in case of failures after ## redial in case of failures after
redial = "10s" # redial = "10s"
## gRPC Maximum Message Size
# max_msg_size = "4MB"
## enable client-side TLS and define CA to authenticate the device ## enable client-side TLS and define CA to authenticate the device
# enable_tls = false # enable_tls = false