From 3a1e661660440852d5e0a4ca9d33974c78010b98 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Wed, 11 Jan 2023 12:38:03 -0700 Subject: [PATCH 1/2] feat(inputs.gnmi): set max gRPC message size Adds an option to let a user set the max gRPC message size. By default, this is set to 4MB and allows a user to receive larger messages if required by the end device. fixes: #12463 --- plugins/inputs/gnmi/README.md | 5 ++++- plugins/inputs/gnmi/gnmi.go | 13 +++++++++++-- plugins/inputs/gnmi/sample.conf | 7 +++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/gnmi/README.md b/plugins/inputs/gnmi/README.md index 51c37cc82eb39..1d712179a33f7 100644 --- a/plugins/inputs/gnmi/README.md +++ b/plugins/inputs/gnmi/README.md @@ -36,7 +36,10 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. # encoding = "proto" ## redial in case of failures after - redial = "10s" + # redial = "10s" + + ## gRPC Maximum Message Size in bytes, default is 4MB. + # max_msg_size = 4000000 ## enable client-side TLS and define CA to authenticate the device # enable_tls = false diff --git a/plugins/inputs/gnmi/gnmi.go b/plugins/inputs/gnmi/gnmi.go index b49cd5aeb807b..4f870cd87fb1a 100644 --- a/plugins/inputs/gnmi/gnmi.go +++ b/plugins/inputs/gnmi/gnmi.go @@ -52,6 +52,7 @@ type GNMI struct { Subscriptions []Subscription `toml:"subscription"` TagSubscriptions []TagSubscription `toml:"tag_subscription"` Aliases map[string]string `toml:"aliases"` + MaxMsgSize int `toml:"max_msg_size"` // Optional subscription configuration Encoding string @@ -298,9 +299,17 @@ func (c *GNMI) subscribeGNMI(ctx context.Context, worker *Worker, tlscfg *tls.Co } else { creds = insecure.NewCredentials() } - opt := grpc.WithTransportCredentials(creds) + opts := []grpc.DialOption{ + grpc.WithTransportCredentials(creds), + } + + if c.MaxMsgSize > 0 { + opts = append(opts, grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(c.MaxMsgSize), + )) + } - client, err := grpc.DialContext(ctx, worker.address, opt) + client, err := grpc.DialContext(ctx, worker.address, opts...) if err != nil { return fmt.Errorf("failed to dial: %v", err) } diff --git a/plugins/inputs/gnmi/sample.conf b/plugins/inputs/gnmi/sample.conf index a058647ee3209..bb005994487cc 100644 --- a/plugins/inputs/gnmi/sample.conf +++ b/plugins/inputs/gnmi/sample.conf @@ -11,7 +11,10 @@ # encoding = "proto" ## redial in case of failures after - redial = "10s" + # redial = "10s" + + ## gRPC Maximum Message Size in bytes, default is 4MB. + # max_msg_size = 4000000 ## enable client-side TLS and define CA to authenticate the device # enable_tls = false @@ -70,4 +73,4 @@ # ## At least one path element name must be supplied that contains at least # ## one key to match on. Multiple element names can be specified in any # ## order. In this case all element names must be present. - # elements = ["description", "interface"] \ No newline at end of file + # elements = ["description", "interface"] From 718560c57d79bf93f62f64f82c1c7549721f9cda Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Thu, 26 Jan 2023 07:12:05 -0700 Subject: [PATCH 2/2] use config.Size over int --- plugins/inputs/gnmi/README.md | 4 ++-- plugins/inputs/gnmi/gnmi.go | 4 ++-- plugins/inputs/gnmi/sample.conf | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/gnmi/README.md b/plugins/inputs/gnmi/README.md index 1d712179a33f7..78e0690bdbab9 100644 --- a/plugins/inputs/gnmi/README.md +++ b/plugins/inputs/gnmi/README.md @@ -38,8 +38,8 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details. ## redial in case of failures after # redial = "10s" - ## gRPC Maximum Message Size in bytes, default is 4MB. - # max_msg_size = 4000000 + ## gRPC Maximum Message Size + # max_msg_size = "4MB" ## enable client-side TLS and define CA to authenticate the device # enable_tls = false diff --git a/plugins/inputs/gnmi/gnmi.go b/plugins/inputs/gnmi/gnmi.go index 4f870cd87fb1a..a1401b5959c29 100644 --- a/plugins/inputs/gnmi/gnmi.go +++ b/plugins/inputs/gnmi/gnmi.go @@ -52,7 +52,7 @@ type GNMI struct { Subscriptions []Subscription `toml:"subscription"` TagSubscriptions []TagSubscription `toml:"tag_subscription"` Aliases map[string]string `toml:"aliases"` - MaxMsgSize int `toml:"max_msg_size"` + MaxMsgSize config.Size `toml:"max_msg_size"` // Optional subscription configuration Encoding string @@ -305,7 +305,7 @@ func (c *GNMI) subscribeGNMI(ctx context.Context, worker *Worker, tlscfg *tls.Co if c.MaxMsgSize > 0 { opts = append(opts, grpc.WithDefaultCallOptions( - grpc.MaxCallRecvMsgSize(c.MaxMsgSize), + grpc.MaxCallRecvMsgSize(int(c.MaxMsgSize)), )) } diff --git a/plugins/inputs/gnmi/sample.conf b/plugins/inputs/gnmi/sample.conf index bb005994487cc..8d043b00089a4 100644 --- a/plugins/inputs/gnmi/sample.conf +++ b/plugins/inputs/gnmi/sample.conf @@ -13,8 +13,8 @@ ## redial in case of failures after # redial = "10s" - ## gRPC Maximum Message Size in bytes, default is 4MB. - # max_msg_size = 4000000 + ## gRPC Maximum Message Size + # max_msg_size = "4MB" ## enable client-side TLS and define CA to authenticate the device # enable_tls = false