Remove outputs blocking inputs when output is slow (#4938)
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/filter"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
"github.com/influxdata/telegraf/metric"
|
||||
"github.com/influxdata/telegraf/plugins/processors"
|
||||
)
|
||||
|
||||
@@ -76,12 +77,12 @@ var sampleConfig = `
|
||||
## tags. If this setting is different than "" the plugin will add a
|
||||
## tag (which name will be the value of this setting) to each metric with
|
||||
## the value of the calculated GroupBy tag. Useful for debugging
|
||||
# add_groupby_tag = ""
|
||||
# add_groupby_tag = ""
|
||||
|
||||
## These settings provide a way to know the position of each metric in
|
||||
## the top k. The 'add_rank_field' setting allows to specify for which
|
||||
## fields the position is required. If the list is non empty, then a field
|
||||
## will be added to each and every metric for each string present in this
|
||||
## will be added to each and every metric for each string present in this
|
||||
## setting. This field will contain the ranking of the group that
|
||||
## the metric belonged to when aggregated over that field.
|
||||
## The name of the field will be set to the name of the aggregation field,
|
||||
@@ -208,6 +209,11 @@ func (t *TopK) Apply(in ...telegraf.Metric) []telegraf.Metric {
|
||||
|
||||
// Add the metrics received to our internal cache
|
||||
for _, m := range in {
|
||||
// When tracking metrics this plugin could deadlock the input by
|
||||
// holding undelivered metrics while the input waits for metrics to be
|
||||
// delivered. Instead, treat all handled metrics as delivered and
|
||||
// produced metrics as untracked in a similar way to aggregators.
|
||||
m.Drop()
|
||||
|
||||
// Check if the metric has any of the fields over which we are aggregating
|
||||
hasField := false
|
||||
@@ -281,7 +287,6 @@ func (t *TopK) push() []telegraf.Metric {
|
||||
|
||||
// Create a one dimensional list with the top K metrics of each key
|
||||
for i, ag := range aggregations[0:min(t.K, len(aggregations))] {
|
||||
|
||||
// Check whether of not we need to add fields of tags to the selected metrics
|
||||
if len(t.aggFieldSet) != 0 || len(t.rankFieldSet) != 0 || groupTag != "" {
|
||||
for _, m := range t.cache[ag.groupbykey] {
|
||||
@@ -311,7 +316,16 @@ func (t *TopK) push() []telegraf.Metric {
|
||||
|
||||
t.Reset()
|
||||
|
||||
return ret
|
||||
result := make([]telegraf.Metric, 0, len(ret))
|
||||
for _, m := range ret {
|
||||
copy, err := metric.New(m.Name(), m.Tags(), m.Fields(), m.Time(), m.Type())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, copy)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Function that generates the aggregation functions
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package topk
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
// Key, value pair that represents a telegraf.Metric Field
|
||||
@@ -95,7 +95,7 @@ func deepCopy(a []telegraf.Metric) []telegraf.Metric {
|
||||
|
||||
func belongs(m telegraf.Metric, ms []telegraf.Metric) bool {
|
||||
for _, i := range ms {
|
||||
if reflect.DeepEqual(i, m) {
|
||||
if testutil.MetricEqual(i, m) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user