Ignore errors serializing single metrics (#5943)
This commit is contained in:
@@ -113,6 +113,9 @@ func (s *Serializer) SerializeBatch(metrics []telegraf.Metric) ([]byte, error) {
|
||||
for _, m := range metrics {
|
||||
_, err := s.Write(&s.buf, m)
|
||||
if err != nil {
|
||||
if _, ok := err.(*MetricError); ok {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,12 +53,13 @@ func (r *reader) Read(p []byte) (int, error) {
|
||||
r.offset += 1
|
||||
if err != nil {
|
||||
r.buf.Reset()
|
||||
if err != nil {
|
||||
// Since we are serializing multiple metrics, don't fail the
|
||||
// the entire batch just because of one unserializable metric.
|
||||
log.Printf("E! [serializers.influx] could not serialize metric: %v; discarding metric", err)
|
||||
if _, ok := err.(*MetricError); ok {
|
||||
continue
|
||||
}
|
||||
// Since we are serializing multiple metrics, don't fail the
|
||||
// the entire batch just because of one unserializable metric.
|
||||
log.Printf("E! [serializers.influx] could not serialize metric: %v; discarding metric", err)
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ type Serializer interface {
|
||||
// Serialize takes a single telegraf metric and turns it into a byte buffer.
|
||||
// separate metrics should be separated by a newline, and there should be
|
||||
// a newline at the end of the buffer.
|
||||
//
|
||||
// New plugins should use SerializeBatch instead to allow for non-line
|
||||
// delimited metrics.
|
||||
Serialize(metric telegraf.Metric) ([]byte, error)
|
||||
|
||||
// SerializeBatch takes an array of telegraf metric and serializes it into
|
||||
@@ -41,7 +44,7 @@ type Serializer interface {
|
||||
// Config is a struct that covers the data types needed for all serializer types,
|
||||
// and can be used to instantiate _any_ of the serializers.
|
||||
type Config struct {
|
||||
// Dataformat can be one of: influx, graphite, or json
|
||||
// Dataformat can be one of the serializer types listed in NewSerializer.
|
||||
DataFormat string
|
||||
|
||||
// Support tags in graphite protocol
|
||||
|
||||
Reference in New Issue
Block a user