Use last path element as field key if path fully specified (#6848)

This commit is contained in:
Daniel Nelson
2020-01-08 10:52:36 -08:00
committed by GitHub
parent 69d9c10572
commit 73488eb61c
2 changed files with 353 additions and 130 deletions

View File

@@ -280,11 +280,26 @@ func (c *CiscoTelemetryGNMI) handleSubscribeResponse(address string, reply *gnmi
}
// Group metrics
for key, val := range fields {
if len(aliasPath) > 0 {
for k, v := range fields {
key := k
if len(aliasPath) < len(key) {
// This may not be an exact prefix, due to naming style
// conversion on the key.
key = key[len(aliasPath)+1:]
} else {
// 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 == "" {
c.Log.Errorf("invalid empty path: %q", k)
continue
}
}
grouper.Add(name, tags, timestamp, key, val)
grouper.Add(name, tags, timestamp, key, v)
}
lastAliasPath = aliasPath