fix(outputs.bigquery): Ignore fields containing NaN or infinity (#14458)

This commit is contained in:
Thomas Casteleyn 2023-12-18 14:46:15 +01:00 committed by GitHub
parent e48b72f965
commit d6f509e869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"reflect"
"strings"
"sync"
@ -187,7 +188,18 @@ func (s *BigQuery) newCompactValuesSaver(m telegraf.Metric) (*bigquery.ValuesSav
return nil, fmt.Errorf("serializing tags: %w", err)
}
fields, err := json.Marshal(m.Fields())
rawFields := make(map[string]interface{}, len(m.FieldList()))
for _, field := range m.FieldList() {
if fv, ok := field.Value.(float64); ok {
// JSON does not support these special values
if math.IsNaN(fv) || math.IsInf(fv, 0) {
s.Log.Debugf("Ignoring unsupported field %s with value %q for metric %s", field.Key, field.Value, m.Name())
continue
}
}
rawFields[field.Key] = field.Value
}
fields, err := json.Marshal(rawFields)
if err != nil {
return nil, fmt.Errorf("serializing fields: %w", err)
}