Skip to content

Commit 82acbd5

Browse files
authored
fix: fix integer overrun when calculating parallelism for very long time range queries (#17428)
1 parent f70d797 commit 82acbd5

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

pkg/querier/queryrange/limits.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ func WeightedParallelism(
679679
}
680680
}
681681

682-
totalDur := int(tsdbDur + otherDur)
682+
totalDur := int64(tsdbDur + otherDur)
683683
// If totalDur is 0, the query likely does not overlap any of the schema configs so just use parallelism of 1 and
684684
// let the downstream code handle it.
685685
if totalDur == 0 {
@@ -688,11 +688,11 @@ func WeightedParallelism(
688688
return 1
689689
}
690690

691-
tsdbPart := int(tsdbDur) * tsdbMaxQueryParallelism / totalDur
692-
regPart := int(otherDur) * regMaxQueryParallelism / totalDur
691+
tsdbPart := int64(tsdbDur) * int64(tsdbMaxQueryParallelism) / totalDur
692+
regPart := int64(otherDur) * int64(regMaxQueryParallelism) / totalDur
693693

694694
if combined := regPart + tsdbPart; combined > 0 {
695-
return combined
695+
return int(combined)
696696
}
697697

698698
// As long as the actual config is not zero,

pkg/querier/queryrange/limits_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,12 @@ func Test_WeightedParallelism(t *testing.T) {
741741
end: borderTime.Add(time.Hour),
742742
exp: 100,
743743
},
744+
{
745+
desc: "huge range which previously overflowed int",
746+
start: model.Now().Add(-24 * 60 * time.Hour),
747+
end: model.Now(),
748+
exp: 100,
749+
},
744750
} {
745751
t.Run(cfgs.desc+tc.desc, func(t *testing.T) {
746752
require.Equal(t, tc.exp, WeightedParallelism(context.Background(), confs, "fake", limits, tc.start, tc.end))

0 commit comments

Comments
 (0)