This repository was archived by the owner on Aug 23, 2023. It is now read-only.
File tree 2 files changed +16
-7
lines changed
2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -407,6 +407,7 @@ func TestGetAggregated(t *testing.T) {
407
407
{Val : 21 + 22 , Ts : 25 },
408
408
{Val : 30 , Ts : 30 },
409
409
{Val : 31 + 32 , Ts : 35 },
410
+ {Val : 40 , Ts : 40 },
410
411
}
411
412
assertPointsEqual (t , got , expected )
412
413
}
@@ -454,6 +455,7 @@ func TestGetAggregatedIngestFrom(t *testing.T) {
454
455
expected := []schema.Point {
455
456
{Val : 26 + 30 , Ts : 30 },
456
457
{Val : 31 + 32 , Ts : 35 },
458
+ {Val : 40 , Ts : 40 },
457
459
}
458
460
assertPointsEqual (t , got , expected )
459
461
}
Original file line number Diff line number Diff line change @@ -100,19 +100,26 @@ func (agg *Aggregator) flush() {
100
100
func (agg * Aggregator ) Add (ts uint32 , val float64 ) {
101
101
boundary := AggBoundary (ts , agg .span )
102
102
103
- if boundary == agg .currentBoundary {
104
- agg .agg .Add (val )
105
- if ts == boundary {
106
- agg .flush ()
107
- }
103
+ if boundary < agg .currentBoundary {
104
+ // ignore the point it was for a previous bucket. we can't process it
105
+ return
108
106
} else if boundary > agg .currentBoundary {
109
- // store current totals as a new point in their series
107
+ // point is for a more recent bucket
108
+ // store current aggregates as a new point in their series and start the new bucket
110
109
// if the cnt is still 0, the numbers are invalid, not to be flushed and we can simply reuse the aggregation
111
110
if agg .agg .Cnt != 0 {
112
111
agg .flush ()
113
112
}
114
113
agg .currentBoundary = boundary
115
- agg .agg .Add (val )
114
+ }
115
+ agg .agg .Add (val )
116
+
117
+ // if the ts of the point is a boundary, it means no more point can possibly come in for the same aggregation.
118
+ // e.g. if aggspan is 10s and we're adding a point with timestamp 12:34:10, then any subsequent point will go
119
+ // in the bucket for 12:34:20 or later.
120
+ // so it is time to flush the result
121
+ if ts == boundary {
122
+ agg .flush ()
116
123
}
117
124
}
118
125
You can’t perform that action at this time.
0 commit comments