Skip to content

Handle the case of large step causing single pt extents #3818

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

Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 13 additions & 2 deletions pkg/querier/queryrange/results_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,13 @@ func (s resultsCache) partition(req Request, extents []Extent) ([]Request, []Res
if extent.GetEnd() < start || extent.Start > req.GetEnd() {
continue
}
// If this extent is tiny, discard it: more efficient to do a few larger queries
if extent.End-extent.Start < s.minCacheExtent {

// If this extent is tiny, discard it: more efficient to do a few larger queries.

// However if the step is large enough, the split_query_by_interval middlware would generate a query with same start and end.
// For example, if the step size is more than 12h and the interval is 24h.
// This means the extent's start and end time would be same, even if the timerange covers several hours.
if (req.GetStart() != req.GetEnd()) && (extent.End-extent.Start < s.minCacheExtent) {
continue
}

Expand All @@ -504,6 +509,12 @@ func (s resultsCache) partition(req Request, extents []Extent) ([]Request, []Res
requests = append(requests, r)
}

// If start and end are the same (valid in promql), start == req.GetEnd() and we won't do the query.
// But we should only do the request if we don't have a valid cached response for it.
if req.GetStart() == req.GetEnd() && len(cachedResponses) == 0 {
requests = append(requests, req)
}

return requests, cachedResponses, nil
}

Expand Down
30 changes: 30 additions & 0 deletions pkg/querier/queryrange/results_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,36 @@ func TestPartition(t *testing.T) {
mkAPIResponse(100, 120, 10),
},
},
// Extent is outside the range and the request has a single step (same start and end).
{
input: &PrometheusRequest{
Start: 100,
End: 100,
},
prevCachedResponse: []Extent{
mkExtent(50, 90),
},
expectedRequests: []Request{
&PrometheusRequest{
Start: 100,
End: 100,
},
},
},
// Test when hit has a large step and only a single sample extent.
{
// If there is a only a single sample in the split interval, start and end will be the same.
input: &PrometheusRequest{
Start: 100,
End: 100,
},
prevCachedResponse: []Extent{
mkExtent(100, 100),
},
expectedCachedResponse: []Response{
mkAPIResponse(100, 105, 10),
},
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
s := resultsCache{
Expand Down