Skip to content

Commit

Permalink
fix(inputs.gnmi): Handle canonical field-name correctly (#14953)
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored Mar 8, 2024
1 parent 66bd72b commit 8218651
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/inputs/gnmi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
var key string
if h.canonicalFieldNames {
// Strip the origin is any for the field names
if parts := strings.SplitN(strings.ReplaceAll(field.path.String(), "-", "_"), ":", 2); len(parts) == 2 {
key = parts[1]
}
field.path.origin = ""
key = field.path.String()
key = strings.ReplaceAll(key, "-", "_")
} else {
// If the alias is a subpath of the field path and the alias is
// shorter than the full path to avoid an empty key, then strip the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gnmi_sys_memory,path=/system/memory/state,source=127.0.0.1 /system/memory/state/reserved=6359478272u,/system/memory/state/used=3479629824u 1709737743568119333
gnmi_sys_memory,source=127.0.0.1 /system/memory/state/used=3479527424u 1709737753565697718
gnmi_sys_cpu,index=ALL,source=127.0.0.1 /system/cpus/cpu/state/hardware_interrupt/min_time=1709805333568034887u 1709805333566280930
gnmi_sys_cpu,index=ALL,path=/system/cpus/cpu/state,source=127.0.0.1 /system/cpus/cpu/state/hardware_interrupt/min_time=1709805343567684412u,/system/cpus/cpu/state/idle/avg=89u,/system/cpus/cpu/state/idle/instant=90u 1709805343565718902
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
[
{
"update": {
"timestamp": "1709737743568119333",
"prefix": {
"elem": [
{
"name": "system"
},
{
"name": "memory"
},
{
"name": "state"
}
]
},
"update": [
{
"path": {
"elem": [
{
"name": "reserved"
}
]
},
"val": {
"uintVal": "6359478272"
}
},
{
"path": {
"elem": [
{
"name": "used"
}
]
},
"val": {
"uintVal": "3479629824"
}
}
]
}
},
{
"update": {
"timestamp": "1709737753565697718",
"update": [
{
"path": {
"elem": [
{
"name": "system"
},
{
"name": "memory"
},
{
"name": "state"
},
{
"name": "used"
}
]
},
"val": {
"uintVal": "3479527424"
}
}
]
}
},
{
"update": {
"timestamp": "1709805333566280930",
"update": [
{
"path": {
"elem": [
{
"name": "system"
},
{
"name": "cpus"
},
{
"name": "cpu",
"key": {
"index": "ALL"
}
},
{
"name": "state"
},
{
"name": "hardware-interrupt"
},
{
"name": "min-time"
}
]
},
"val": {
"uintVal": "1709805333568034887"
}
}
]
}
},
{
"update": {
"timestamp": "1709805343565718902",
"prefix": {
"elem": [
{
"name": "system"
},
{
"name": "cpus"
},
{
"name": "cpu",
"key": {
"index": "ALL"
}
},
{
"name": "state"
}
]
},
"update": [
{
"path": {
"elem": [
{
"name": "hardware-interrupt"
},
{
"name": "min-time"
}
]
},
"val": {
"uintVal": "1709805343567684412"
}
},
{
"path": {
"elem": [
{
"name": "idle"
},
{
"name": "avg"
}
]
},
"val": {
"uintVal": "89"
}
},
{
"path": {
"elem": [
{
"name": "idle"
},
{
"name": "instant"
}
]
},
"val": {
"uintVal": "90"
}
}
]
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[inputs.gnmi]]
addresses = ["dummy"]
canonical_field_names = true

[[inputs.gnmi.subscription]]
name = "gnmi_sys_cpu"
path = "/system/cpus/cpu/state"
subscription_mode = "sample"
sample_interval = "10s"

[[inputs.gnmi.subscription]]
name = "gnmi_sys_memory"
path = "/system/memory/state"
subscription_mode = "sample"
sample_interval = "10s"

0 comments on commit 8218651

Please sign in to comment.