fix(inputs.gnmi): Ensure path contains elements to avoid panic (#15259)
This commit is contained in:
parent
d3f0ba9368
commit
d6671eb05e
|
|
@ -212,6 +212,10 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
|
||||||
|
|
||||||
// Parse individual update message and create measurements
|
// Parse individual update message and create measurements
|
||||||
for _, field := range valueFields {
|
for _, field := range valueFields {
|
||||||
|
if field.path.empty() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare tags from prefix
|
// Prepare tags from prefix
|
||||||
fieldTags := field.path.Tags()
|
fieldTags := field.path.Tags()
|
||||||
tags := make(map[string]string, len(headerTags)+len(fieldTags))
|
tags := make(map[string]string, len(headerTags)+len(fieldTags))
|
||||||
|
|
@ -258,8 +262,11 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
|
||||||
relative := field.path.segments[len(aliasInfo.segments):len(field.path.segments)]
|
relative := field.path.segments[len(aliasInfo.segments):len(field.path.segments)]
|
||||||
key = strings.Join(relative, "/")
|
key = strings.Join(relative, "/")
|
||||||
} else {
|
} else {
|
||||||
// Otherwise use the last path element as the field key.
|
// Otherwise use the last path element as the field key if it
|
||||||
key = field.path.segments[len(field.path.segments)-1]
|
// exists.
|
||||||
|
if len(field.path.segments) > 0 {
|
||||||
|
key = field.path.segments[len(field.path.segments)-1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
key = strings.ReplaceAll(key, "-", "_")
|
key = strings.ReplaceAll(key, "-", "_")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue