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

View File

@ -3,6 +3,7 @@ package gnmi
import ( import (
"context" "context"
"crypto/tls" "crypto/tls"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -237,7 +238,11 @@ func (h *handler) handleSubscribeResponseUpdate(acc telegraf.Accumulator, respon
if name == "" { if name == "" {
h.log.Debugf("No measurement alias for gNMI path: %s", field.path) h.log.Debugf("No measurement alias for gNMI path: %s", field.path)
if !h.emptyNameWarnShown { 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 h.emptyNameWarnShown = true
} }
} }