Skip to content

Commit

Permalink
fix(inputs.gnmi): Refactor alias handling
Browse files Browse the repository at this point in the history
Rather than abritrarily take the substring of key, ensure that the key
contains the alias in the first place, then do the removal. Otherwise,
always take the base path.

fixes: #14530
  • Loading branch information
powersj committed Jan 9, 2024
1 parent 5f5a56e commit cafb502
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions plugins/inputs/gnmi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,9 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
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.
if len(aliasPath) != 0 && strings.Contains(key, aliasPath) && len(aliasPath) < len(key) {
key = key[len(aliasPath)+1:]
} else if len(aliasPath) >= len(key) {
// Otherwise use the last path element as the field key.
} else {
key = path.Base(key)
}
}
Expand Down

0 comments on commit cafb502

Please sign in to comment.