Skip to content

Commit 4c9a2af

Browse files
pracuccipstibrany
andauthored
Propagate whether query stats is enabled from query-frontend down the request path (#3595)
* Propagate whether query stats is enabled from query-frontend down the request path Signed-off-by: Marco Pracucci <[email protected]> * Update CHANGELOG.md Signed-off-by: Marco Pracucci <[email protected]> Co-authored-by: Peter Štibraný <[email protected]> Co-authored-by: Peter Štibraný <[email protected]>
1 parent d1da3c1 commit 4c9a2af

File tree

17 files changed

+275
-114
lines changed

17 files changed

+275
-114
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master / unreleased
44

5+
* [CHANGE] Querier: it's not required to set `-frontend.query-stats-enabled=true` in the querier anymore to enable query statistics logging in the query-frontend. The flag is now required to be configured only in the query-frontend and it will be propagated to the queriers. #3595
56
* [CHANGE] Blocks storage: compactor is now required when running a Cortex cluster with the blocks storage, because it also keeps the bucket index updated. #3583
67
* [CHANGE] Blocks storage: block deletion marks are now stored in a per-tenant global markers/ location too, other than within the block location. The compactor, at startup, will copy deletion marks from the block location to the global location. This migration is required only once, so you can safely disable it via `-compactor.block-deletion-marks-migration-enabled=false` once new compactor has successfully started once in your cluster. #3583
78
* [ENHANCEMENT] Blocks storage: introduced a per-tenant bucket index, periodically updated by the compactor, used to avoid full bucket scanning done by queriers and store-gateways. The bucket index is updated by the compactor during blocks cleanup, on every `-compactor.cleanup-interval`. #3553 #3555 #3561 #3583

docs/configuration/config-file-reference.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,7 @@ The `query_frontend_config` configures the Cortex query-frontend.
877877
[max_body_size: <int> | default = 10485760]
878878
879879
# True to enable query statistics tracking. When enabled, a message with some
880-
# statistics is logged for every query. This configuration option must be set
881-
# both on query-frontend and querier.
880+
# statistics is logged for every query.
882881
# CLI flag: -frontend.query-stats-enabled
883882
[query_stats_enabled: <boolean> | default = false]
884883

pkg/cortex/modules.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ func (t *Cortex) initQuerier() (serv services.Service, err error) {
306306
}
307307

308308
t.Cfg.Worker.MaxConcurrentRequests = t.Cfg.Querier.MaxConcurrent
309-
t.Cfg.Worker.QueryStatsEnabled = t.Cfg.Frontend.Handler.QueryStatsEnabled
310309
return querier_worker.NewQuerierWorker(t.Cfg.Worker, httpgrpc_server.NewServer(internalQuerierRouter), util.Logger, prometheus.DefaultRegisterer)
311310
}
312311

pkg/frontend/transport/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type HandlerConfig struct {
4545
func (cfg *HandlerConfig) RegisterFlags(f *flag.FlagSet) {
4646
f.DurationVar(&cfg.LogQueriesLongerThan, "frontend.log-queries-longer-than", 0, "Log queries that are slower than the specified duration. Set to 0 to disable. Set to < 0 to enable on all queries.")
4747
f.Int64Var(&cfg.MaxBodySize, "frontend.max-body-size", 10*1024*1024, "Max body size for downstream prometheus.")
48-
f.BoolVar(&cfg.QueryStatsEnabled, "frontend.query-stats-enabled", false, "True to enable query statistics tracking. When enabled, a message with some statistics is logged for every query. This configuration option must be set both on query-frontend and querier.")
48+
f.BoolVar(&cfg.QueryStatsEnabled, "frontend.query-stats-enabled", false, "True to enable query statistics tracking. When enabled, a message with some statistics is logged for every query.")
4949
}
5050

5151
// Handler accepts queries and forwards them to RoundTripper. It can log slow queries,

pkg/frontend/v1/frontend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ func (f *Frontend) Process(server frontendv1pb.Frontend_ProcessServer) error {
190190
errs := make(chan error, 1)
191191
go func() {
192192
err = server.Send(&frontendv1pb.FrontendToClient{
193-
Type: frontendv1pb.HTTP_REQUEST,
194-
HttpRequest: req.request,
193+
Type: frontendv1pb.HTTP_REQUEST,
194+
HttpRequest: req.request,
195+
StatsEnabled: stats.IsEnabled(req.originalCtx),
195196
})
196197
if err != nil {
197198
errs <- err

pkg/frontend/v1/frontendv1pb/frontend.pb.go

Lines changed: 78 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/frontend/v1/frontendv1pb/frontend.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ enum Type {
2727
message FrontendToClient {
2828
httpgrpc.HTTPRequest httpRequest = 1;
2929
Type type = 2;
30+
31+
// Whether query statistics tracking should be enabled. The response will include
32+
// statistics only when this option is enabled.
33+
bool statsEnabled = 3;
3034
}
3135

3236
message ClientToFrontend {

pkg/frontend/v2/frontend.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ type Frontend struct {
7373
}
7474

7575
type frontendRequest struct {
76-
queryID uint64
77-
request *httpgrpc.HTTPRequest
78-
userID string
76+
queryID uint64
77+
request *httpgrpc.HTTPRequest
78+
userID string
79+
statsEnabled bool
7980

8081
cancel context.CancelFunc
8182

@@ -170,9 +171,10 @@ func (f *Frontend) RoundTripGRPC(ctx context.Context, req *httpgrpc.HTTPRequest)
170171
defer cancel()
171172

172173
freq := &frontendRequest{
173-
queryID: f.lastQueryID.Inc(),
174-
request: req,
175-
userID: userID,
174+
queryID: f.lastQueryID.Inc(),
175+
request: req,
176+
userID: userID,
177+
statsEnabled: stats.IsEnabled(ctx),
176178

177179
cancel: cancel,
178180

pkg/frontend/v2/frontend_scheduler_worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func (w *frontendSchedulerWorker) schedulerLoop(loop schedulerpb.SchedulerForFro
261261
UserID: req.userID,
262262
HttpRequest: req.request,
263263
FrontendAddress: w.frontendAddr,
264+
StatsEnabled: req.statsEnabled,
264265
})
265266

266267
if err != nil {

pkg/querier/stats/stats.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ func FromContext(ctx context.Context) *Stats {
2929
return o.(*Stats)
3030
}
3131

32+
// IsEnabled returns whether stats tracking is enabled in the context.
33+
func IsEnabled(ctx context.Context) bool {
34+
// When query statistics are enabled, the stats object is already initialised
35+
// within the context, so we can just check it.
36+
return FromContext(ctx) != nil
37+
}
38+
3239
// AddWallTime adds some time to the counter.
3340
func (s *Stats) AddWallTime(t time.Duration) {
3441
if s == nil {

0 commit comments

Comments
 (0)