fix(processors.parser): handle empty metric names correctly (#12357)

This commit is contained in:
Sven Rebhan 2022-12-08 15:23:54 +01:00 committed by GitHub
parent 920a07fb5d
commit f2729298ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -30,7 +30,6 @@ func (p *Parser) SetParser(parser telegraf.Parser) {
func (p *Parser) Apply(metrics ...telegraf.Metric) []telegraf.Metric {
results := []telegraf.Metric{}
for _, metric := range metrics {
newMetrics := []telegraf.Metric{}
if !p.DropOriginal {
@ -80,7 +79,13 @@ func (p *Parser) Apply(metrics ...telegraf.Metric) []telegraf.Metric {
}
for _, m := range fromTagMetric {
if m.Name() == "" {
// The parser get the parent plugin's name as
// default measurement name. Thus, in case the
// parsed metric does not provide a name itself,
// the parser will return 'parser' as we are in
// processors.parser. In those cases we want to
// keep the original metric name.
if m.Name() == "" || m.Name() == "parser" {
m.SetName(metric.Name())
}
}