Skip to content

fix: [pkg/proxy/engines] fix data race in time range query normalization #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/proxy/engines/deltaproxycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func DeltaProxyCacheRequest(w http.ResponseWriter, r *http.Request, modeler *tim

pr := newProxyRequest(r, w)
rlo.FastForwardDisable = o.FastForwardDisable || rlo.FastForwardDisable
trq.NormalizeExtent()
trq = trq.NormalizeExtent()
now := time.Now()
bt := trq.GetBackfillTolerance(o.BackfillTolerance, o.BackfillTolerancePoints)
bfs := now.Add(-bt).Truncate(trq.Step) // start of the backfill tolerance window
Expand All @@ -118,7 +118,7 @@ func DeltaProxyCacheRequest(w http.ResponseWriter, r *http.Request, modeler *tim
Extent: timeseries.Extent{Start: time.Unix(0, 0), End: now},
Step: trq.Step,
}
normalizedNow.NormalizeExtent()
normalizedNow = normalizedNow.NormalizeExtent()

var cts timeseries.Timeseries
var doc *HTTPDocument
Expand Down
2 changes: 1 addition & 1 deletion pkg/timeseries/extent_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ func TestCalculateDeltas(t *testing.T) {

trq := TimeRangeQuery{Statement: "up", Extent: Extent{Start: time.Unix(test.start, 0),
End: time.Unix(test.end, 0)}, Step: time.Duration(test.stepSecs) * time.Second}
trq.NormalizeExtent()
trq = *trq.NormalizeExtent()
d := ExtentList(test.have).CalculateDeltas(trq.Extent, trq.Step)

if len(d) != len(test.expected) {
Expand Down
10 changes: 6 additions & 4 deletions pkg/timeseries/timerangequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ func (trq *TimeRangeQuery) Clone() *TimeRangeQuery {
}

// NormalizeExtent adjusts the Start and End of a TimeRangeQuery's Extent to align against normalized boundaries.
func (trq *TimeRangeQuery) NormalizeExtent() {
func (trq *TimeRangeQuery) NormalizeExtent() *TimeRangeQuery {
t := trq.Clone()
if trq.Step > 0 {
if !trq.IsOffset && trq.Extent.End.After(time.Now()) {
trq.Extent.End = time.Now()
t.Extent.End = time.Now()
}
trq.Extent.Start = trq.Extent.Start.Truncate(trq.Step)
trq.Extent.End = trq.Extent.End.Truncate(trq.Step)
t.Extent.Start = trq.Extent.Start.Truncate(trq.Step)
t.Extent.End = trq.Extent.End.Truncate(trq.Step)
}
return t
}

func (trq *TimeRangeQuery) String() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/timeseries/timerangequery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestNormalizeExtent(t *testing.T) {
trq := TimeRangeQuery{Statement: "up", Extent: Extent{Start: time.Unix(test.start, 0),
End: time.Unix(test.end, 0)}, Step: time.Duration(test.stepSecs) * time.Second}

trq.NormalizeExtent()
trq = *trq.NormalizeExtent()

if trq.Extent.Start.Unix() != test.rangeStart {
t.Errorf("Mismatch in rangeStart: expected=%d actual=%d", test.rangeStart, trq.Extent.Start.Unix())
Expand Down
Loading