Skip to content

Commit

Permalink
separate query limits for store gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 committed Sep 26, 2023
1 parent 189e6c5 commit d24b4c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/storegateway/bucket_stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ func newChunksLimiterFactory(limits *validation.Overrides, userID string) store.
// Since limit overrides could be live reloaded, we have to get the current user's limit
// each time a new limiter is instantiated.
return &limiter{
limiter: store.NewLimiter(uint64(limits.MaxChunksPerQueryFromStore(userID)), failedCounter),
limiter: store.NewLimiter(uint64(limits.MaxChunksPerRequest(userID)), failedCounter),
}
}
}
Expand All @@ -740,7 +740,7 @@ func newSeriesLimiterFactory(limits *validation.Overrides, userID string) store.
// Since limit overrides could be live reloaded, we have to get the current user's limit
// each time a new limiter is instantiated.
return &limiter{
limiter: store.NewLimiter(uint64(limits.MaxFetchedSeriesPerQuery(userID)), failedCounter),
limiter: store.NewLimiter(uint64(limits.MaxSeriesPerRequest(userID)), failedCounter),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storegateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ func TestStoreGateway_SeriesQueryingShouldEnforceMaxChunksPerQueryLimit(t *testi
//parallel testing causes data race
// Customise the limits.
limits := defaultLimitsConfig()
limits.MaxChunksPerQuery = testData.limit
limits.MaxChunksPerRequest = testData.limit
overrides, err := validation.NewOverrides(limits, nil)
require.NoError(t, err)

Expand Down Expand Up @@ -1130,7 +1130,7 @@ func TestStoreGateway_SeriesQueryingShouldEnforceMaxSeriesPerQueryLimit(t *testi
//parallel testing causes data race
// Customise the limits.
limits := defaultLimitsConfig()
limits.MaxFetchedSeriesPerQuery = testData.limit
limits.MaxSeriesPerRequest = testData.limit
overrides, err := validation.NewOverrides(limits, nil)
require.NoError(t, err)

Expand Down
16 changes: 16 additions & 0 deletions pkg/util/validation/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ type Limits struct {
// Store-gateway.
StoreGatewayTenantShardSize float64 `yaml:"store_gateway_tenant_shard_size" json:"store_gateway_tenant_shard_size"`
MaxDownloadedBytesPerRequest int `yaml:"max_downloaded_bytes_per_request" json:"max_downloaded_bytes_per_request"`
MaxSeriesPerRequest int `yaml:"max_series_per_request" json:"max_series_per_request"`
MaxChunksPerRequest int `yaml:"max_chunks_per_request" json:"max_chunks_per_request"`

// Compactor.
CompactorBlocksRetentionPeriod model.Duration `yaml:"compactor_blocks_retention_period" json:"compactor_blocks_retention_period"`
Expand Down Expand Up @@ -200,6 +202,8 @@ func (l *Limits) RegisterFlags(f *flag.FlagSet) {
// Store-gateway.
f.Float64Var(&l.StoreGatewayTenantShardSize, "store-gateway.tenant-shard-size", 0, "The default tenant's shard size when the shuffle-sharding strategy is used. Must be set when the store-gateway sharding is enabled with the shuffle-sharding strategy. When this setting is specified in the per-tenant overrides, a value of 0 disables shuffle sharding for the tenant. If the value is < 1 the shard size will be a percentage of the total store-gateways.")
f.IntVar(&l.MaxDownloadedBytesPerRequest, "store-gateway.max-downloaded-bytes-per-request", 0, "The maximum number of data bytes to download per gRPC request in Store Gateway, including Series/LabelNames/LabelValues requests. 0 to disable.")
f.IntVar(&l.MaxSeriesPerRequest, "store-gateway.max-series-per-request", 0, "The maximum number of series to fetch per gRPC request in Store Gateway, including Series/LabelNames/LabelValues requests. 0 to disable.")
f.IntVar(&l.MaxChunksPerRequest, "store-gateway.max-chunks-per-request", 0, "The maximum number of chunks to fetch per gRPC request in Store Gateway for Series requests. 0 to disable.")

// Alertmanager.
f.Var(&l.AlertmanagerReceiversBlockCIDRNetworks, "alertmanager.receivers-firewall-block-cidr-networks", "Comma-separated list of network CIDRs to block in Alertmanager receiver integrations.")
Expand Down Expand Up @@ -454,6 +458,18 @@ func (o *Overrides) MaxDownloadedBytesPerRequest(userID string) int {
return o.GetOverridesForUser(userID).MaxDownloadedBytesPerRequest
}

// MaxSeriesPerRequest returns the maximum number of series to download for each gRPC request in Store Gateway,
// including any series fetched from cache or object storage.
func (o *Overrides) MaxSeriesPerRequest(userID string) int {
return o.GetOverridesForUser(userID).MaxSeriesPerRequest
}

// MaxChunksPerRequest returns the maximum number of chunks to download for each gRPC request in Store Gateway,
// including any chunks fetched from cache or object storage.
func (o *Overrides) MaxChunksPerRequest(userID string) int {
return o.GetOverridesForUser(userID).MaxChunksPerRequest
}

// MaxQueryLookback returns the max lookback period of queries.
func (o *Overrides) MaxQueryLookback(userID string) time.Duration {
return time.Duration(o.GetOverridesForUser(userID).MaxQueryLookback)
Expand Down

0 comments on commit d24b4c5

Please sign in to comment.