Skip to content

Commit

Permalink
Aggregate early metrics, rather than ignore (influxdata#5085)
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton authored and otherpirate committed Mar 15, 2019
1 parent 2382cad commit 55b35a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/models/running_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/models/running_aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 55b35a2

Please sign in to comment.