From 72a2a19b3d1282f45c2b5816b9041d043e38a112 Mon Sep 17 00:00:00 2001 From: Callum Styan Date: Mon, 30 Sep 2024 10:39:57 -0700 Subject: [PATCH] add query user and query source to "executing query" log lines Signed-off-by: Callum Styan --- pkg/logql/engine.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/logql/engine.go b/pkg/logql/engine.go index c44ee06c16948..17e90520e7de5 100644 --- a/pkg/logql/engine.go +++ b/pkg/logql/engine.go @@ -241,11 +241,21 @@ func (q *query) Exec(ctx context.Context) (logqlmodel.Result, error) { if q.logExecQuery { queryHash := util.HashedQuery(q.params.QueryString()) + + logValues := []interface{}{ + "msg", "executing query", + "query", q.params.QueryString(), + "query_hash", queryHash, + } + tags := httpreq.ExtractQueryTagsFromContext(ctx) + tagValues := tagsToKeyValues(tags) if GetRangeType(q.params) == InstantType { - level.Info(logutil.WithContext(ctx, q.logger)).Log("msg", "executing query", "type", "instant", "query", q.params.QueryString(), "query_hash", queryHash) + logValues = append(logValues, "type", "instant") } else { - level.Info(logutil.WithContext(ctx, q.logger)).Log("msg", "executing query", "type", "range", "query", q.params.QueryString(), "length", q.params.End().Sub(q.params.Start()), "step", q.params.Step(), "query_hash", queryHash) + logValues = append(logValues, "type", "range", "length", q.params.End().Sub(q.params.Start()), "step", q.params.Step()) } + logValues = append(logValues, tagValues...) + level.Info(logutil.WithContext(ctx, q.logger)).Log(logValues...) } rangeType := GetRangeType(q.params) @@ -265,6 +275,7 @@ func (q *query) Exec(ctx context.Context) (logqlmodel.Result, error) { sp.LogKV(statResult.KVList()...) status, _ := server.ClientHTTPStatusAndError(err) + if q.record { RecordRangeAndInstantQueryMetrics(ctx, q.logger, q.params, strconv.Itoa(status), statResult, data) }