fix(inputs.gnmi): Handle canonical field-name correctly for non-explicit subscriptions (#13332)

This commit is contained in:
Sven Rebhan 2023-06-01 19:32:51 +02:00 committed by GitHub
parent 1c60c057e9
commit 9147afbeca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 27 deletions

View File

@ -239,29 +239,26 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
// Group metrics
for k, v := range fields {
key := k
if len(aliasPath) < len(key) && len(aliasPath) != 0 {
// This may not be an exact prefix, due to naming style
// conversion on the key.
key = key[len(aliasPath)+1:]
} else if len(aliasPath) >= len(key) {
if h.canonicalFieldNames {
// Strip the origin is any for the field names
if parts := strings.SplitN(key, ":", 2); len(parts) == 2 {
key = parts[1]
}
} else {
if h.canonicalFieldNames {
// Strip the origin is any for the field names
if parts := strings.SplitN(key, ":", 2); len(parts) == 2 {
key = parts[1]
}
} else {
if len(aliasPath) < len(key) && len(aliasPath) != 0 {
// This may not be an exact prefix, due to naming style
// conversion on the key.
key = key[len(aliasPath)+1:]
} else if len(aliasPath) >= len(key) {
// Otherwise use the last path element as the field key.
key = path.Base(key)
// If there are no elements skip the item; this would be an
// invalid message.
key = strings.TrimLeft(key, "/.")
if key == "" {
h.log.Errorf("invalid empty path: %q", k)
continue
}
}
}
key = strings.TrimLeft(key, "/.")
if key == "" {
h.log.Errorf("invalid empty path: %q", k)
continue
}
grouper.Add(name, tags, timestamp, key, v)
}
}

View File

@ -1 +1 @@
interfaces,name=eth42,path=openconfig-interfaces:/interfaces/interface,source=127.0.0.1 /interfaces/interface/descr="eth42",/interfaces/interface/config/id=42425u,/interfaces/interface/state/in_pkts=5678u,/interfaces/interface/state/out_pkts=5125u 1673608605875353770
interfaces,name=eth42,path=openconfig-interfaces:/interfaces/interface,source=127.0.0.1 interfaces/interface/descr="eth42",interfaces/interface/config/id=42425u,interfaces/interface/state/in_pkts=5678u,interfaces/interface/state/out_pkts=5125u 1673608605875353770

View File

@ -18,12 +18,6 @@
[[inputs.gnmi.subscription]]
name = "interfaces"
origin = "openconfig-interfaces"
path = "/interfaces/interface/state/in-pkts"
subscription_mode = "sample"
sample_interval = "10s"
[[inputs.gnmi.subscription]]
name = "interfaces"
origin = "openconfig-interfaces"
path = "/interfaces/interface/state/out-pkts"
path = "/interfaces/interface/state"
subscription_mode = "sample"
sample_interval = "10s"