Skip to content

Commit

Permalink
fix(sharding): apply offset to both from and through in shard req…
Browse files Browse the repository at this point in the history
…uest (#14256)
  • Loading branch information
ashwanthgoli authored Sep 27, 2024
1 parent 6354ded commit 17c472d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pkg/querier/queryrange/shard_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ func (r *dynamicShardResolver) ShardingRanges(expr syntax.Expr, targetBytesPerSh
) {
log := spanlogger.FromContext(r.ctx)

adjustedFrom := r.from
var (
adjustedFrom = r.from
adjustedThrough model.Time
)

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

for _, grp := range grps {
diff := grp.Interval + grp.Offset
diff := grp.Interval

// For instant queries, when start == end,
// we have a default lookback which we add here
if grp.Interval == 0 {
diff = diff + r.defaultLookback
if diff == 0 {
diff = r.defaultLookback
}

diff += grp.Offset

// use the oldest adjustedFrom
if r.from.Add(-diff).Before(adjustedFrom) {
adjustedFrom = r.from.Add(-diff)
}

// use the latest adjustedThrough
if r.through.Add(-grp.Offset).After(adjustedThrough) {
adjustedThrough = r.through.Add(-grp.Offset)
}
}

// handle the case where there are no matchers
if adjustedThrough == 0 {
adjustedThrough = r.through
}

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

0 comments on commit 17c472d

Please sign in to comment.