chore(inputs.gnmi): Degrade empty-name error to a warning and add instructions. (#12305)

This commit is contained in:
Sven Rebhan 2022-11-30 12:09:31 +01:00 committed by GitHub
parent 176a416f64
commit d10ab3a417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 8 deletions

View File

@ -38,6 +38,14 @@ var sampleConfig string
// Regular expression to see if a path element contains an origin // Regular expression to see if a path element contains an origin
var originPattern = regexp.MustCompile(`^([\w-_]+):`) var originPattern = regexp.MustCompile(`^([\w-_]+):`)
// 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:
%+v
This message is only printed once.`
// gNMI plugin instance // gNMI plugin instance
type GNMI struct { type GNMI struct {
Addresses []string `toml:"addresses"` Addresses []string `toml:"addresses"`
@ -64,11 +72,12 @@ type GNMI struct {
internaltls.ClientConfig internaltls.ClientConfig
// Internal state // Internal state
internalAliases map[string]string internalAliases map[string]string
acc telegraf.Accumulator acc telegraf.Accumulator
cancel context.CancelFunc cancel context.CancelFunc
wg sync.WaitGroup wg sync.WaitGroup
legacyTags bool legacyTags bool
emptyNameWarnShown bool
Log telegraf.Logger Log telegraf.Logger
} }
@ -396,9 +405,9 @@ func (c *GNMI) handleSubscribeResponseUpdate(worker *Worker, response *gnmiLib.S
} }
// Check for empty names // Check for empty names
if name == "" { if name == "" && !c.emptyNameWarnShown {
c.acc.AddError(fmt.Errorf("got empty name for update %+v", update)) c.Log.Warnf(emptyNameWarning, response.Update)
continue c.emptyNameWarnShown = true
} }
// Group metrics // Group metrics