Skip to content

Commit 21d44df

Browse files
ashwanthgolijeschkies
authored andcommitted
fix(sharding): apply offset to both from and through in shard request (grafana#14256)
1 parent 15fda7b commit 21d44df

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

pkg/querier/queryrange/shard_resolver.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ func (r *dynamicShardResolver) ShardingRanges(expr syntax.Expr, targetBytesPerSh
225225
) {
226226
log := spanlogger.FromContext(r.ctx)
227227

228-
adjustedFrom := r.from
228+
var (
229+
adjustedFrom = r.from
230+
adjustedThrough model.Time
231+
)
229232

230233
// NB(owen-d): there should only ever be 1 matcher group passed
231234
// to this call as we call it separately for different legs
@@ -236,18 +239,30 @@ func (r *dynamicShardResolver) ShardingRanges(expr syntax.Expr, targetBytesPerSh
236239
}
237240

238241
for _, grp := range grps {
239-
diff := grp.Interval + grp.Offset
242+
diff := grp.Interval
240243

241244
// For instant queries, when start == end,
242245
// we have a default lookback which we add here
243-
if grp.Interval == 0 {
244-
diff = diff + r.defaultLookback
246+
if diff == 0 {
247+
diff = r.defaultLookback
245248
}
246249

250+
diff += grp.Offset
251+
247252
// use the oldest adjustedFrom
248253
if r.from.Add(-diff).Before(adjustedFrom) {
249254
adjustedFrom = r.from.Add(-diff)
250255
}
256+
257+
// use the latest adjustedThrough
258+
if r.through.Add(-grp.Offset).After(adjustedThrough) {
259+
adjustedThrough = r.through.Add(-grp.Offset)
260+
}
261+
}
262+
263+
// handle the case where there are no matchers
264+
if adjustedThrough == 0 {
265+
adjustedThrough = r.through
251266
}
252267

253268
exprStr := expr.String()
@@ -256,7 +271,7 @@ func (r *dynamicShardResolver) ShardingRanges(expr syntax.Expr, targetBytesPerSh
256271
// use the retry handler here to retry transient errors
257272
resp, err := r.retryNextHandler.Do(r.ctx, &logproto.ShardsRequest{
258273
From: adjustedFrom,
259-
Through: r.through,
274+
Through: adjustedThrough,
260275
Query: expr.String(),
261276
TargetBytesPerShard: targetBytesPerShard,
262277
})

0 commit comments

Comments
 (0)