Skip to content
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

Add max-chunks-bytes-per-query limiter #4216

Merged
merged 10 commits into from
May 27, 2021

Conversation

treid314
Copy link
Contributor

@treid314 treid314 commented May 24, 2021

Signed-off-by: Tyler Reid [email protected]

What this PR does:
This PR adds a new -querier.max-chunk-bytes-per-query limit to limit the amount of bytes a query can use for storing chunks for a single query.

Which issue(s) this PR fixes:
Fixes #3669

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Tyler Reid added 2 commits May 24, 2021 17:40
chunkBytesCount *atomic.Int32

maxSeriesPerQuery int
maxChunkBytesPerQuery int
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This limits us to 2GB (2^31 -1 bytes) per query, is it worth making this an unsigned int which is about 4GB (2^32 bytes) per query or a 64 bit number?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int64 please. 4GB is not that much. We may have use cases setting higher limits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 64-bit systems, int is 64-bit, so this is fine. Note that Cortex officially doesn't support 32-bit systems.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be explicit like we do everywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also pass in an int64 at the config/limit.go level? Or is leaving NewQueryLimiter(int, int) and casting the maxChunkBytes value to an int64 ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be explicit like we do everywhere else.

I don't think we're explicit "everywhere else". I think it would make sense to use int here simply because we cannot fit more than max of int into memory anyway (applies for both 32-bit and 64-bit platforms).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To your question Tyler, if you go with int64 route, you will need to "extend" that everywhere to avoid losing precision somewhere (ie. in NewQueryLimiter too)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let's not block on this and keep int.

pkg/distributor/query.go Outdated Show resolved Hide resolved
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! I left few comments but overall logic LGTM 👏

pkg/util/validation/limits.go Outdated Show resolved Hide resolved
pkg/distributor/query.go Outdated Show resolved Hide resolved
pkg/distributor/query.go Outdated Show resolved Hide resolved
pkg/querier/blocks_store_queryable.go Outdated Show resolved Hide resolved
pkg/querier/blocks_store_queryable.go Outdated Show resolved Hide resolved
pkg/util/limiter/query_limiter.go Outdated Show resolved Hide resolved
pkg/util/limiter/query_limiter.go Outdated Show resolved Hide resolved
pkg/distributor/query.go Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/L and removed size/M labels May 25, 2021
@treid314 treid314 marked this pull request as ready for review May 25, 2021 23:17
CHANGELOG.md Outdated Show resolved Hide resolved
pkg/util/limiter/query_limiter.go Outdated Show resolved Hide resolved
pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
Tyler Reid added 2 commits May 26, 2021 12:35
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot Tyler to address my feedback! I think the PR logic is good to go. I just have few last comments on tests that I would be glad to see addressed before merging. Thanks! 🚀

pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I've left few nit comments (mention ruler in the changelog/help, remove duplicite mentions of blocks storage).

pkg/util/limiter/query_limiter.go Outdated Show resolved Hide resolved
pkg/util/validation/limits.go Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
return nil
}
if ql.chunkBytesCount.Add(int64(chunkSizeInBytes)) > int64(ql.maxChunkBytesPerQuery) {
return validation.LimitError(fmt.Sprintf(ErrMaxChunkBytesHit, ql.maxChunkBytesPerQuery))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Same comment as in AddSeries -- no need to return validation.LimitError from here. Simple return fmt.Sprintf(ErrMaxChunkBytesHit, ql.maxChunkBytesPerQuery) would remove dependency on validation package. Calling code (querier package) can add this wrapping when needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I jump in on this. It's in the TODO list, but I suggested to do it in a follow up PR to keep changes easier to review.

Tyler Reid added 2 commits May 27, 2021 09:30
…ther code review comments.

Signed-off-by: Tyler Reid <[email protected]>
Signed-off-by: Tyler Reid <[email protected]>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my feedback! One final nit and we go! 🚀 🌔

@@ -660,7 +661,8 @@ func TestHATracker_MetricsCleanup(t *testing.T) {
func TestCheckReplicaCleanup(t *testing.T) {
replica := "r1"
cluster := "c1"
user := "user"
userName := "user"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] userID.

Signed-off-by: Tyler Reid <[email protected]>
Signed-off-by: Tyler Reid <[email protected]>
@pracucci pracucci enabled auto-merge (squash) May 27, 2021 15:45
@pracucci pracucci merged commit 2ba3fdd into cortexproject:master May 27, 2021
pstibrany pushed a commit that referenced this pull request Jul 20, 2021
* Add per-user query metrics for series and bytes returned

Add stats included in query responses from the querier and distributor
for measuring the number of series and bytes included in successful
queries. These stats are emitted per-user as summaries from the query
frontends.

These stats are picked to add visibility into the same resources limited
as part of #4179 and #4216.

Fixes #4259

Signed-off-by: Nick Pillitteri <[email protected]>

* Formatting fix

Signed-off-by: Nick Pillitteri <[email protected]>

* Fix changelog to match actual changes

Signed-off-by: Nick Pillitteri <[email protected]>

* Typo

Signed-off-by: Nick Pillitteri <[email protected]>

* Code review changes, rename things for clarity

Signed-off-by: Nick Pillitteri <[email protected]>

* Apply suggestions from code review

Co-authored-by: Marco Pracucci <[email protected]>
Signed-off-by: Nick Pillitteri <[email protected]>

* Code review changes, remove superfluous summaries

Signed-off-by: Nick Pillitteri <[email protected]>

Co-authored-by: Marco Pracucci <[email protected]>
alvinlin123 pushed a commit to ac1214/cortex that referenced this pull request Jan 14, 2022
…ct#4343)

* Add per-user query metrics for series and bytes returned

Add stats included in query responses from the querier and distributor
for measuring the number of series and bytes included in successful
queries. These stats are emitted per-user as summaries from the query
frontends.

These stats are picked to add visibility into the same resources limited
as part of cortexproject#4179 and cortexproject#4216.

Fixes cortexproject#4259

Signed-off-by: Nick Pillitteri <[email protected]>

* Formatting fix

Signed-off-by: Nick Pillitteri <[email protected]>

* Fix changelog to match actual changes

Signed-off-by: Nick Pillitteri <[email protected]>

* Typo

Signed-off-by: Nick Pillitteri <[email protected]>

* Code review changes, rename things for clarity

Signed-off-by: Nick Pillitteri <[email protected]>

* Apply suggestions from code review

Co-authored-by: Marco Pracucci <[email protected]>
Signed-off-by: Nick Pillitteri <[email protected]>

* Code review changes, remove superfluous summaries

Signed-off-by: Nick Pillitteri <[email protected]>

Co-authored-by: Marco Pracucci <[email protected]>
Signed-off-by: Alvin Lin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Limit series per query in the blocks storage
3 participants