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

Enforce query response size limit after decompression in query-frontend #6607

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix lint tenantID issue
Signed-off-by: Ahmed Hassan <[email protected]>
afhassan committed Feb 27, 2025
commit 967ef4f2b19c255df9bee5761d2e2296ade03c1d
12 changes: 9 additions & 3 deletions pkg/querier/tripperware/instantquery/instant_query.go
Original file line number Diff line number Diff line change
@@ -105,14 +105,20 @@ func (c instantQueryCodec) DecodeResponse(ctx context.Context, r *http.Response,
return nil, err
}

userID, err := tenant.TenantID(ctx)
tenantIDs, err := tenant.TenantIDs(ctx)
if err != nil {
return nil, err
}

queryLimiter := limiter.NewQueryLimiter(c.limits.MaxFetchedSeriesPerQuery(userID), c.limits.MaxFetchedChunkBytesPerQuery(userID), c.limits.MaxChunksPerQuery(userID), c.limits.MaxFetchedDataBytesPerQuery(userID))
queryLimiter := limiter.NewQueryLimiter(
validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxFetchedSeriesPerQuery),
validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxFetchedChunkBytesPerQuery),
validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxChunksPerQuery),
validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxFetchedDataBytesPerQuery),
)

buf, err := tripperware.BodyBuffer(r, c.limits.MaxFetchedDataBytesPerQuery(userID), log)
maxByteSize := validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxFetchedDataBytesPerQuery)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we use the same data bytes limit here instead of introducing a new limit?

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 limit config is under the limits section, so I thought it is more appropriate to use instead of creating a QFE specific limit config. We can update the description to mention that it is applied in query-frontend as well.

# The maximum combined size of all data that a query can fetch from each
# ingester and storage. This limit is enforced in the querier, ruler, **and query-frontend** for
# `query`, `query_range` and `series` APIs. 0 to disable.
# CLI flag: -querier.max-fetched-data-bytes-per-query
[max_fetched_data_bytes_per_query: <int> | default = 0]

I am okay with introducing another limit instead, but should it go under query-frontend section or limits section?

buf, err := tripperware.BodyBuffer(r, maxByteSize, log)
if err != nil {
log.Error(err)
return nil, err
12 changes: 9 additions & 3 deletions pkg/querier/tripperware/queryrange/query_range.go
Original file line number Diff line number Diff line change
@@ -204,14 +204,20 @@ func (c prometheusCodec) DecodeResponse(ctx context.Context, r *http.Response, _
return nil, err
}

userID, err := tenant.TenantID(ctx)
tenantIDs, err := tenant.TenantIDs(ctx)
if err != nil {
return nil, err
}

queryLimiter := limiter.NewQueryLimiter(c.limits.MaxFetchedSeriesPerQuery(userID), c.limits.MaxFetchedChunkBytesPerQuery(userID), c.limits.MaxChunksPerQuery(userID), c.limits.MaxFetchedDataBytesPerQuery(userID))
queryLimiter := limiter.NewQueryLimiter(
validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxFetchedSeriesPerQuery),
validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxFetchedChunkBytesPerQuery),
validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxChunksPerQuery),
validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxFetchedDataBytesPerQuery),
)

buf, err := tripperware.BodyBuffer(r, c.limits.MaxFetchedDataBytesPerQuery(userID), log)
maxByteSize := validation.SmallestPositiveIntPerTenant(tenantIDs, c.limits.MaxFetchedDataBytesPerQuery)
buf, err := tripperware.BodyBuffer(r, maxByteSize, log)
if err != nil {
log.Error(err)
return nil, err
Loading