From 8a838634c7f78cd793c2cf804b1ce17e34246dca Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:01:52 +0100 Subject: [PATCH] fix(inputs.gnmi): Normalize path for inline origin handling (#14838) --- plugins/inputs/gnmi/path.go | 2 + .../gnmi/testcases/issue_14833/expected.out | 2 + .../gnmi/testcases/issue_14833/responses.json | 51 +++++++++++++++++++ .../gnmi/testcases/issue_14833/telegraf.conf | 9 ++++ 4 files changed, 64 insertions(+) create mode 100644 plugins/inputs/gnmi/testcases/issue_14833/expected.out create mode 100644 plugins/inputs/gnmi/testcases/issue_14833/responses.json create mode 100644 plugins/inputs/gnmi/testcases/issue_14833/telegraf.conf diff --git a/plugins/inputs/gnmi/path.go b/plugins/inputs/gnmi/path.go index f48ff5a3d..cc63814cd 100644 --- a/plugins/inputs/gnmi/path.go +++ b/plugins/inputs/gnmi/path.go @@ -141,6 +141,7 @@ func (pi *pathInfo) append(paths ...*gnmiLib.Path) *pathInfo { path.keyValues = append(path.keyValues, keyInfo) } } + path.normalize() return path } @@ -172,6 +173,7 @@ func (pi *pathInfo) appendSegments(segments ...string) *pathInfo { } path.segments = append(path.segments, s) } + path.normalize() return path } diff --git a/plugins/inputs/gnmi/testcases/issue_14833/expected.out b/plugins/inputs/gnmi/testcases/issue_14833/expected.out new file mode 100644 index 000000000..d04628a2c --- /dev/null +++ b/plugins/inputs/gnmi/testcases/issue_14833/expected.out @@ -0,0 +1,2 @@ +interfaces-counter,name=AppGigabitEthernet1/0/1,source=127.0.0.1 discontinuity_time="2023-11-15T05:50:40+00:00" 1708069483623763000 +interfaces-counter,name=FortyGigabitEthernet1/1/1,source=127.0.0.1 discontinuity_time="2023-11-15T05:50:40+00:00" 1708069483623763000 diff --git a/plugins/inputs/gnmi/testcases/issue_14833/responses.json b/plugins/inputs/gnmi/testcases/issue_14833/responses.json new file mode 100644 index 000000000..fd84cf21a --- /dev/null +++ b/plugins/inputs/gnmi/testcases/issue_14833/responses.json @@ -0,0 +1,51 @@ +[ + { + "update": { + "timestamp": "1708069483623763000", + "update": [ + { + "path": { + "elem": [ + { + "name": "Cisco-IOS-XE-interfaces-oper:interfaces" + }, + { + "name": "interface", + "key": { + "name": "AppGigabitEthernet1/0/1" + } + }, + { + "name": "statistics" + } + ] + }, + "val": { + "jsonIetfVal": "eyJkaXNjb250aW51aXR5LXRpbWUiOiIyMDIzLTExLTE1VDA1OjUwOjQwKzAwOjAwIn0K" + } + }, + { + "path": { + "elem": [ + { + "name": "Cisco-IOS-XE-interfaces-oper:interfaces" + }, + { + "name": "interface", + "key": { + "name": "FortyGigabitEthernet1/1/1" + } + }, + { + "name": "statistics" + } + ] + }, + "val": { + "jsonIetfVal": "eyJkaXNjb250aW51aXR5LXRpbWUiOiIyMDIzLTExLTE1VDA1OjUwOjQwKzAwOjAwIn0K" + } + } + ] + } + } +] \ No newline at end of file diff --git a/plugins/inputs/gnmi/testcases/issue_14833/telegraf.conf b/plugins/inputs/gnmi/testcases/issue_14833/telegraf.conf new file mode 100644 index 000000000..2d881f729 --- /dev/null +++ b/plugins/inputs/gnmi/testcases/issue_14833/telegraf.conf @@ -0,0 +1,9 @@ +[[inputs.gnmi]] + addresses = ["dummy"] + + [[inputs.gnmi.subscription]] + name = "interfaces-counter" + origin = "rfc7951" + path = "/Cisco-IOS-XE-interfaces-oper:interfaces/interface/statistics" + subscription_mode = "sample" + sample_interval = "5s"