Skip to content

Commit e10ccda

Browse files
authored
Handle the case of large step causing single pt extents (cortexproject#3818)
* Handle the case of large step causing single pt extents We noticed that we were ignoring samples if the step is 24h and this fixes it. Signed-off-by: Goutham Veeramachaneni <[email protected]> * Handle the case of start == end better Signed-off-by: Goutham Veeramachaneni <[email protected]> * Address feedback Signed-off-by: Goutham Veeramachaneni <[email protected]>
1 parent 16265a0 commit e10ccda

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

pkg/querier/queryrange/results_cache.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,13 @@ func (s resultsCache) partition(req Request, extents []Extent) ([]Request, []Res
484484
if extent.GetEnd() < start || extent.Start > req.GetEnd() {
485485
continue
486486
}
487-
// If this extent is tiny, discard it: more efficient to do a few larger queries
488-
if extent.End-extent.Start < s.minCacheExtent {
487+
488+
// If this extent is tiny, discard it: more efficient to do a few larger queries.
489+
490+
// However if the step is large enough, the split_query_by_interval middleware would generate a query with same start and end.
491+
// For example, if the step size is more than 12h and the interval is 24h.
492+
// This means the extent's start and end time would be same, even if the timerange covers several hours.
493+
if (req.GetStart() != req.GetEnd()) && (extent.End-extent.Start < s.minCacheExtent) {
489494
continue
490495
}
491496

@@ -509,6 +514,12 @@ func (s resultsCache) partition(req Request, extents []Extent) ([]Request, []Res
509514
requests = append(requests, r)
510515
}
511516

517+
// If start and end are the same (valid in promql), start == req.GetEnd() and we won't do the query.
518+
// But we should only do the request if we don't have a valid cached response for it.
519+
if req.GetStart() == req.GetEnd() && len(cachedResponses) == 0 {
520+
requests = append(requests, req)
521+
}
522+
512523
return requests, cachedResponses, nil
513524
}
514525

pkg/querier/queryrange/results_cache_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,36 @@ func TestPartition(t *testing.T) {
486486
mkAPIResponse(100, 120, 10),
487487
},
488488
},
489+
// Extent is outside the range and the request has a single step (same start and end).
490+
{
491+
input: &PrometheusRequest{
492+
Start: 100,
493+
End: 100,
494+
},
495+
prevCachedResponse: []Extent{
496+
mkExtent(50, 90),
497+
},
498+
expectedRequests: []Request{
499+
&PrometheusRequest{
500+
Start: 100,
501+
End: 100,
502+
},
503+
},
504+
},
505+
// Test when hit has a large step and only a single sample extent.
506+
{
507+
// If there is a only a single sample in the split interval, start and end will be the same.
508+
input: &PrometheusRequest{
509+
Start: 100,
510+
End: 100,
511+
},
512+
prevCachedResponse: []Extent{
513+
mkExtent(100, 100),
514+
},
515+
expectedCachedResponse: []Response{
516+
mkAPIResponse(100, 105, 10),
517+
},
518+
},
489519
} {
490520
t.Run(strconv.Itoa(i), func(t *testing.T) {
491521
s := resultsCache{

0 commit comments

Comments
 (0)