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

This commit is contained in:
Lauri Huotari 2025-02-14 00:46:26 +02:00 committed by GitHub
parent 9a43d7c35e
commit 601467fd51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 0 deletions

View File

@ -75,12 +75,19 @@ details on how to use them.
## gRPC Maximum Message Size
# max_msg_size = "4MB"
## Subtree depth for depth extension (disables if < 1)
## see https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-depth.md
# 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
## Only receive updates for the state, also suppresses receiving the initial state
# 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

View File

@ -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"
@ -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"`
@ -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{
@ -386,6 +401,7 @@ func (c *GNMI) newSubscribeRequest() (*gnmi.SubscribeRequest, error) {
UpdatesOnly: c.UpdatesOnly,
},
},
Extension: extensions,
}, nil
}

View File

@ -28,12 +28,19 @@
## gRPC Maximum Message Size
# max_msg_size = "4MB"
## Subtree depth for depth extension (disables if < 1)
## see https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-depth.md
# 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
## Only receive updates for the state, also suppresses receiving the initial state
# 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

View File

@ -28,12 +28,19 @@
## gRPC Maximum Message Size
# max_msg_size = "4MB"
## Subtree depth for depth extension (disables if < 1)
## see https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-depth.md
# 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
## Only receive updates for the state, also suppresses receiving the initial state
# 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