diff --git a/internal/models/running_aggregator.go b/internal/models/running_aggregator.go index 0315aa671..4fb7bcbe1 100644 --- a/internal/models/running_aggregator.go +++ b/internal/models/running_aggregator.go @@ -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) diff --git a/internal/models/running_aggregator_test.go b/internal/models/running_aggregator_test.go index 2212829f9..6bacbf8ed 100644 --- a/internal/models/running_aggregator_test.go +++ b/internal/models/running_aggregator_test.go @@ -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) {