From 74d8523db62de1f8530ddd3699c9ac70f44a5d02 Mon Sep 17 00:00:00 2001 From: Greg <2653109+glinton@users.noreply.github.com> Date: Mon, 10 Dec 2018 17:07:08 -0700 Subject: [PATCH] Aggregate early metrics, rather than ignore (#5085) --- internal/models/running_aggregator.go | 5 +++-- internal/models/running_aggregator_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) 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) {