Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inputs.gnmi): support for gnmi depth extension #16480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugins/inputs/gnmi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,20 @@ details on how to use them.
## gRPC Maximum Message Size
# max_msg_size = "4MB"

## gRPC Depth Extension
## See https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-depth.md
## If specified, adds gNMI depth extension, which controls depth of the subtree to be returned in the response.
# depth = 0

## Enable to get the canonical path as field-name
# canonical_field_names = false

## Remove leading slashes and dots in field-name
# trim_field_names = false

## An optional field to specify that only updates to current state should be sent to a client.
# updates_only = false

## Guess the path-tag if an update does not contain a prefix-path
## Supported values are
## none -- do not add a 'path' tag
Expand Down
16 changes: 16 additions & 0 deletions plugins/inputs/gnmi/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/google/gnxi/utils/xpath"
"github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/gnmi/proto/gnmi_ext"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"

Expand Down Expand Up @@ -54,6 +55,7 @@ type GNMI struct {
Password config.Secret `toml:"password"`
Redial config.Duration `toml:"redial"`
MaxMsgSize config.Size `toml:"max_msg_size"`
Depth int32 `toml:"depth"`
Trace bool `toml:"dump_responses"`
CanonicalFieldNames bool `toml:"canonical_field_names"`
TrimFieldNames bool `toml:"trim_field_names"`
Expand Down Expand Up @@ -376,6 +378,19 @@ func (c *GNMI) newSubscribeRequest() (*gnmi.SubscribeRequest, error) {
return nil, fmt.Errorf("unsupported encoding %s", c.Encoding)
}

var extensions []*gnmi_ext.Extension
if c.Depth > 0 {
extensions = []*gnmi_ext.Extension{
{
Ext: &gnmi_ext.Extension_Depth{
Depth: &gnmi_ext.Depth{
Level: uint32(c.Depth),
},
},
},
}
}

return &gnmi.SubscribeRequest{
Request: &gnmi.SubscribeRequest_Subscribe{
Subscribe: &gnmi.SubscriptionList{
Expand All @@ -386,6 +401,7 @@ func (c *GNMI) newSubscribeRequest() (*gnmi.SubscribeRequest, error) {
UpdatesOnly: c.UpdatesOnly,
},
},
Extension: extensions,
}, nil
}

Expand Down
8 changes: 8 additions & 0 deletions plugins/inputs/gnmi/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@
## gRPC Maximum Message Size
# max_msg_size = "4MB"

## gRPC Depth Extension
## See https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-depth.md
## If specified, adds gNMI depth extension, which controls depth of the subtree to be returned in the response.
# depth = 0

## Enable to get the canonical path as field-name
# canonical_field_names = false

## Remove leading slashes and dots in field-name
# trim_field_names = false

## An optional field to specify that only updates to current state should be sent to a client.
# updates_only = false

## Guess the path-tag if an update does not contain a prefix-path
## Supported values are
## none -- do not add a 'path' tag
Expand Down
8 changes: 8 additions & 0 deletions plugins/inputs/gnmi/sample.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@
## gRPC Maximum Message Size
# max_msg_size = "4MB"

## gRPC Depth Extension
## See https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-depth.md
## If specified, adds gNMI depth extension, which controls depth of the subtree to be returned in the response.
# depth = 0

## Enable to get the canonical path as field-name
# canonical_field_names = false

## Remove leading slashes and dots in field-name
# trim_field_names = false

## An optional field to specify that only updates to current state should be sent to a client.
# updates_only = false

## Guess the path-tag if an update does not contain a prefix-path
## Supported values are
## none -- do not add a 'path' tag
Expand Down
Loading