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
|
// Add a metric to the aggregator and return true if the original metric
|
||||||
// should be dropped.
|
// should be dropped.
|
||||||
func (r *RunningAggregator) Add(metric telegraf.Metric) bool {
|
func (r *RunningAggregator) Add(metric telegraf.Metric) bool {
|
||||||
|
|
||||||
if ok := r.Config.Filter.Select(metric); !ok {
|
if ok := r.Config.Filter.Select(metric); !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -121,9 +122,9 @@ func (r *RunningAggregator) Add(metric telegraf.Metric) bool {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
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)
|
r.metricDropped(metric)
|
||||||
return false
|
return r.Config.DropOriginal
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Aggregator.Add(metric)
|
r.Aggregator.Add(metric)
|
||||||
|
|
|
@ -87,7 +87,7 @@ func TestAddMetricsOutsideCurrentPeriod(t *testing.T) {
|
||||||
|
|
||||||
ra.Push(&acc)
|
ra.Push(&acc)
|
||||||
require.Equal(t, 1, len(acc.Metrics))
|
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) {
|
func TestAddAndPushOnePeriod(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue