Skip to content

Commit 292c423

Browse files
authored
Add flag to disable store gateway query stats (#5749)
* add flag to enable store gateway query stats Signed-off-by: Ben Ye <[email protected]> * docs update Signed-off-by: Ben Ye <[email protected]> * fix tests Signed-off-by: Ben Ye <[email protected]> --------- Signed-off-by: Ben Ye <[email protected]>
1 parent f2b7591 commit 292c423

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [ENHANCEMENT] Index Cache: Multi level cache adds config `max_backfill_items` to cap max items to backfill per async operation. #5686
1717
* [ENHANCEMENT] Query Frontend: Log number of split queries in `query stats` log. #5703
1818
* [ENHANCEMENT] Logging: Added new options for logging HTTP request headers: `-server.log-request-headers` enables logging HTTP request headers, `-server.log-request-headers-exclude-list` allows users to specify headers which should not be logged. #5744
19+
* [ENHANCEMENT] Querier: Added `querier.store-gateway-query-stats-enabled` to enable or disable store gateway query stats log. #5749
1920
* [BUGFIX] Distributor: Do not use label with empty values for sharding #5717
2021
* [BUGFIX] Query Frontend: queries with negative offset should check whether it is cacheable or not. #5719
2122
* [BUGFIX] Redis Cache: pass `cache_size` config correctly. #5734

docs/blocks-storage/querier.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ querier:
214214
# CLI flag: -querier.store-gateway-client.grpc-compression
215215
[grpc_compression: <string> | default = ""]
216216

217+
# If enabled, store gateway query stats will be logged using `info` log level.
218+
# CLI flag: -querier.store-gateway-query-stats-enabled
219+
[store_gateway_query_stats: <boolean> | default = true]
220+
217221
# When distributor's sharding strategy is shuffle-sharding and this setting is
218222
# > 0, queriers fetch in-memory series from the minimum set of required
219223
# ingesters, selecting only ingesters which may have received series since

docs/configuration/config-file-reference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3527,6 +3527,10 @@ store_gateway_client:
35273527
# CLI flag: -querier.store-gateway-client.grpc-compression
35283528
[grpc_compression: <string> | default = ""]
35293529
3530+
# If enabled, store gateway query stats will be logged using `info` log level.
3531+
# CLI flag: -querier.store-gateway-query-stats-enabled
3532+
[store_gateway_query_stats: <boolean> | default = true]
3533+
35303534
# When distributor's sharding strategy is shuffle-sharding and this setting is >
35313535
# 0, queriers fetch in-memory series from the minimum set of required ingesters,
35323536
# selecting only ingesters which may have received series since 'now - lookback

pkg/querier/blocks_store_queryable.go

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ type BlocksStoreQueryable struct {
138138
metrics *blocksStoreQueryableMetrics
139139
limits BlocksStoreLimits
140140

141+
storeGatewayQueryStatsEnabled bool
142+
141143
// Subservices manager.
142144
subservices *services.Manager
143145
subservicesWatcher *services.FailureWatcher
@@ -149,6 +151,7 @@ func NewBlocksStoreQueryable(
149151
consistency *BlocksConsistencyChecker,
150152
limits BlocksStoreLimits,
151153
queryStoreAfter time.Duration,
154+
storeGatewayQueryStatsEnabled bool,
152155
logger log.Logger,
153156
reg prometheus.Registerer,
154157
) (*BlocksStoreQueryable, error) {
@@ -158,15 +161,16 @@ func NewBlocksStoreQueryable(
158161
}
159162

160163
q := &BlocksStoreQueryable{
161-
stores: stores,
162-
finder: finder,
163-
consistency: consistency,
164-
queryStoreAfter: queryStoreAfter,
165-
logger: logger,
166-
subservices: manager,
167-
subservicesWatcher: services.NewFailureWatcher(),
168-
metrics: newBlocksStoreQueryableMetrics(reg),
169-
limits: limits,
164+
stores: stores,
165+
finder: finder,
166+
consistency: consistency,
167+
queryStoreAfter: queryStoreAfter,
168+
logger: logger,
169+
subservices: manager,
170+
subservicesWatcher: services.NewFailureWatcher(),
171+
metrics: newBlocksStoreQueryableMetrics(reg),
172+
limits: limits,
173+
storeGatewayQueryStatsEnabled: storeGatewayQueryStatsEnabled,
170174
}
171175

172176
q.Service = services.NewBasicService(q.starting, q.running, q.stopping)
@@ -256,7 +260,7 @@ func NewBlocksStoreQueryableFromConfig(querierCfg Config, gatewayCfg storegatewa
256260
reg,
257261
)
258262

259-
return NewBlocksStoreQueryable(stores, finder, consistency, limits, querierCfg.QueryStoreAfter, logger, reg)
263+
return NewBlocksStoreQueryable(stores, finder, consistency, limits, querierCfg.QueryStoreAfter, querierCfg.StoreGatewayQueryStatsEnabled, logger, reg)
260264
}
261265

262266
func (q *BlocksStoreQueryable) starting(ctx context.Context) error {
@@ -291,15 +295,16 @@ func (q *BlocksStoreQueryable) Querier(mint, maxt int64) (storage.Querier, error
291295
}
292296

293297
return &blocksStoreQuerier{
294-
minT: mint,
295-
maxT: maxt,
296-
finder: q.finder,
297-
stores: q.stores,
298-
metrics: q.metrics,
299-
limits: q.limits,
300-
consistency: q.consistency,
301-
logger: q.logger,
302-
queryStoreAfter: q.queryStoreAfter,
298+
minT: mint,
299+
maxT: maxt,
300+
finder: q.finder,
301+
stores: q.stores,
302+
metrics: q.metrics,
303+
limits: q.limits,
304+
consistency: q.consistency,
305+
logger: q.logger,
306+
queryStoreAfter: q.queryStoreAfter,
307+
storeGatewayQueryStatsEnabled: q.storeGatewayQueryStatsEnabled,
303308
}, nil
304309
}
305310

@@ -315,6 +320,10 @@ type blocksStoreQuerier struct {
315320
// If set, the querier manipulates the max time to not be greater than
316321
// "now - queryStoreAfter" so that most recent blocks are not queried.
317322
queryStoreAfter time.Duration
323+
324+
// If enabled, query stats of store gateway requests will be logged
325+
// using `info` level.
326+
storeGatewayQueryStatsEnabled bool
318327
}
319328

320329
// Select implements storage.Querier interface.
@@ -753,7 +762,7 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
753762
// Use number of blocks queried to check whether we should log the query
754763
// or not. It might be logging too much but good to understand per request
755764
// performance.
756-
if seriesQueryStats.BlocksQueried > 0 {
765+
if q.storeGatewayQueryStatsEnabled && seriesQueryStats.BlocksQueried > 0 {
757766
level.Info(spanLog).Log("msg", "store gateway series request stats",
758767
"instance", c.RemoteAddress(),
759768
"queryable_chunk_bytes_fetched", chunkBytes,

pkg/querier/blocks_store_queryable_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ func TestBlocksStoreQuerier_PromQLExecution(t *testing.T) {
15881588
}
15891589

15901590
// Instance the querier that will be executed to run the query.
1591-
queryable, err := NewBlocksStoreQueryable(stores, finder, NewBlocksConsistencyChecker(0, 0, logger, nil), &blocksStoreLimitsMock{}, 0, logger, nil)
1591+
queryable, err := NewBlocksStoreQueryable(stores, finder, NewBlocksConsistencyChecker(0, 0, logger, nil), &blocksStoreLimitsMock{}, 0, false, logger, nil)
15921592
require.NoError(t, err)
15931593
require.NoError(t, services.StartAndAwaitRunning(context.Background(), queryable))
15941594
defer services.StopAndAwaitTerminated(context.Background(), queryable) // nolint:errcheck

pkg/querier/querier.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ type Config struct {
7575
LookbackDelta time.Duration `yaml:"lookback_delta"`
7676

7777
// Blocks storage only.
78-
StoreGatewayAddresses string `yaml:"store_gateway_addresses"`
79-
StoreGatewayClient ClientConfig `yaml:"store_gateway_client"`
78+
StoreGatewayAddresses string `yaml:"store_gateway_addresses"`
79+
StoreGatewayClient ClientConfig `yaml:"store_gateway_client"`
80+
StoreGatewayQueryStatsEnabled bool `yaml:"store_gateway_query_stats"`
8081

8182
ShuffleShardingIngestersLookbackPeriod time.Duration `yaml:"shuffle_sharding_ingesters_lookback_period"`
8283

@@ -112,6 +113,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
112113
f.DurationVar(&cfg.QueryStoreAfter, "querier.query-store-after", 0, "The time after which a metric should be queried from storage and not just ingesters. 0 means all queries are sent to store. When running the blocks storage, if this option is enabled, the time range of the query sent to the store will be manipulated to ensure the query end is not more recent than 'now - query-store-after'.")
113114
f.StringVar(&cfg.ActiveQueryTrackerDir, "querier.active-query-tracker-dir", "./active-query-tracker", "Active query tracker monitors active queries, and writes them to the file in given directory. If Cortex discovers any queries in this log during startup, it will log them to the log file. Setting to empty value disables active query tracker, which also disables -querier.max-concurrent option.")
114115
f.StringVar(&cfg.StoreGatewayAddresses, "querier.store-gateway-addresses", "", "Comma separated list of store-gateway addresses in DNS Service Discovery format. This option should be set when using the blocks storage and the store-gateway sharding is disabled (when enabled, the store-gateway instances form a ring and addresses are picked from the ring).")
116+
f.BoolVar(&cfg.StoreGatewayQueryStatsEnabled, "querier.store-gateway-query-stats-enabled", true, "If enabled, store gateway query stats will be logged using `info` log level.")
115117
f.DurationVar(&cfg.LookbackDelta, "querier.lookback-delta", 5*time.Minute, "Time since the last sample after which a time series is considered stale and ignored by expression evaluations.")
116118
f.DurationVar(&cfg.ShuffleShardingIngestersLookbackPeriod, "querier.shuffle-sharding-ingesters-lookback-period", 0, "When distributor's sharding strategy is shuffle-sharding and this setting is > 0, queriers fetch in-memory series from the minimum set of required ingesters, selecting only ingesters which may have received series since 'now - lookback period'. The lookback period should be greater or equal than the configured 'query store after' and 'query ingesters within'. If this setting is 0, queriers always query all ingesters (ingesters shuffle sharding on read path is disabled).")
117119
f.BoolVar(&cfg.ThanosEngine, "querier.thanos-engine", false, "Experimental. Use Thanos promql engine https://github.com/thanos-io/promql-engine rather than the Prometheus promql engine.")

0 commit comments

Comments
 (0)