Aggregate early metrics, rather than ignore (#5085)
This commit is contained in:
parent
d0a6051fd7
commit
74d8523db6
|
@ -109,6 +109,7 @@ func (r *RunningAggregator) metricDropped(metric telegraf.Metric) {
|
|||
// Add a metric to the aggregator and return true if the original metric
|
||||
// should be dropped.
|
||||
func (r *RunningAggregator) Add(metric telegraf.Metric) bool {
|
||||
|
||||
if ok := r.Config.Filter.Select(metric); !ok {
|
||||
return false
|
||||
}
|
||||
|
@ -121,9 +122,9 @@ func (r *RunningAggregator) Add(metric telegraf.Metric) bool {
|
|||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
||||
if r.periodStart.IsZero() || metric.Time().Before(r.periodStart) || metric.Time().After(r.periodEnd) {
|
||||
if r.periodStart.IsZero() || metric.Time().After(r.periodEnd) {
|
||||
r.metricDropped(metric)
|
||||
return false
|
||||
return r.Config.DropOriginal
|
||||
}
|
||||
|
||||
r.Aggregator.Add(metric)
|
||||
|
|
|
@ -87,7 +87,7 @@ func TestAddMetricsOutsideCurrentPeriod(t *testing.T) {
|
|||
|
||||
ra.Push(&acc)
|
||||
require.Equal(t, 1, len(acc.Metrics))
|
||||
require.Equal(t, int64(101), acc.Metrics[0].Fields["sum"])
|
||||
require.Equal(t, int64(202), acc.Metrics[0].Fields["sum"])
|
||||
}
|
||||
|
||||
func TestAddAndPushOnePeriod(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue