From cafb5026c21cb0672c88dc4541d311a437a6f123 Mon Sep 17 00:00:00 2001 From: Josh Powers Date: Mon, 8 Jan 2024 14:21:51 -0700 Subject: [PATCH] fix(inputs.gnmi): Refactor alias handling 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 --- plugins/inputs/gnmi/handler.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/gnmi/handler.go b/plugins/inputs/gnmi/handler.go index c89f495475d6b..bab4b9a21a978 100644 --- a/plugins/inputs/gnmi/handler.go +++ b/plugins/inputs/gnmi/handler.go @@ -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) } }