chore(inputs.gnmi): Add more response information for easier debugging (#15297)

This commit is contained in:
Sven Rebhan 2024-05-07 12:03:47 -04:00 committed by GitHub
parent d4367b6be4
commit 079f6a901e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -27,10 +27,10 @@ import (
var sampleConfig string
// Define the warning to show if we cannot get a metric name.
const emptyNameWarning = `Got empty metric-name for response, usually indicating
configuration issues as the response cannot be related to any subscription.
Please open an issue on https://github.com/influxdata/telegraf including your
device model and the following response data:
const emptyNameWarning = `Got empty metric-name for response (field %q), usually
indicating configuration issues as the response cannot be related to any
subscription.Please open an issue on https://github.com/influxdata/telegraf
including your device model and the following response data:
%+v
This message is only printed once.`

View File

@ -3,6 +3,7 @@ package gnmi
import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
@ -237,7 +238,11 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
if name == "" {
h.log.Debugf("No measurement alias for gNMI path: %s", field.path)
if !h.emptyNameWarnShown {
h.log.Warnf(emptyNameWarning, response.Update)
if buf, err := json.Marshal(response); err == nil {
h.log.Warnf(emptyNameWarning, field.path, string(buf))
} else {
h.log.Warnf(emptyNameWarning, field.path, response.Update)
}
h.emptyNameWarnShown = true
}
}