Aggregate early metrics, rather than ignore (#5085)

This commit is contained in:
Greg 2018-12-10 17:07:08 -07:00 committed by Daniel Nelson
parent d0a6051fd7
commit 74d8523db6
2 changed files with 4 additions and 3 deletions

View File

@ -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)

View File

@ -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) {