fix(inputs.gnmi): Handle canonical field-name correctly for non-explicit subscriptions (#13332)
This commit is contained in:
parent
1c60c057e9
commit
9147afbeca
|
|
@ -239,29 +239,26 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
|
||||||
// Group metrics
|
// Group metrics
|
||||||
for k, v := range fields {
|
for k, v := range fields {
|
||||||
key := k
|
key := k
|
||||||
if len(aliasPath) < len(key) && len(aliasPath) != 0 {
|
if h.canonicalFieldNames {
|
||||||
// This may not be an exact prefix, due to naming style
|
// Strip the origin is any for the field names
|
||||||
// conversion on the key.
|
if parts := strings.SplitN(key, ":", 2); len(parts) == 2 {
|
||||||
key = key[len(aliasPath)+1:]
|
key = parts[1]
|
||||||
} else if len(aliasPath) >= len(key) {
|
}
|
||||||
if h.canonicalFieldNames {
|
} else {
|
||||||
// Strip the origin is any for the field names
|
if len(aliasPath) < len(key) && len(aliasPath) != 0 {
|
||||||
if parts := strings.SplitN(key, ":", 2); len(parts) == 2 {
|
// This may not be an exact prefix, due to naming style
|
||||||
key = parts[1]
|
// conversion on the key.
|
||||||
}
|
key = key[len(aliasPath)+1:]
|
||||||
} else {
|
} else if len(aliasPath) >= len(key) {
|
||||||
// Otherwise use the last path element as the field key.
|
// Otherwise use the last path element as the field key.
|
||||||
key = path.Base(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)
|
grouper.Add(name, tags, timestamp, key, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -18,12 +18,6 @@
|
||||||
[[inputs.gnmi.subscription]]
|
[[inputs.gnmi.subscription]]
|
||||||
name = "interfaces"
|
name = "interfaces"
|
||||||
origin = "openconfig-interfaces"
|
origin = "openconfig-interfaces"
|
||||||
path = "/interfaces/interface/state/in-pkts"
|
path = "/interfaces/interface/state"
|
||||||
subscription_mode = "sample"
|
|
||||||
sample_interval = "10s"
|
|
||||||
[[inputs.gnmi.subscription]]
|
|
||||||
name = "interfaces"
|
|
||||||
origin = "openconfig-interfaces"
|
|
||||||
path = "/interfaces/interface/state/out-pkts"
|
|
||||||
subscription_mode = "sample"
|
subscription_mode = "sample"
|
||||||
sample_interval = "10s"
|
sample_interval = "10s"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue