From 0c9570ada806d7ab5b99f3fa3ebc5a0c159e1bbb Mon Sep 17 00:00:00 2001 From: DylanGuedes <djmgguedes@gmail.com> Date: Fri, 21 Jun 2024 09:45:36 -0300 Subject: [PATCH] refactor to keep old signature/method name --- pkg/logcli/print/print.go | 2 +- pkg/logql/engine.go | 2 +- pkg/logqlmodel/stats/context.go | 17 +++++------------ pkg/logqlmodel/stats/context_test.go | 2 +- pkg/querier/http.go | 10 +++++----- pkg/querier/queryrange/stats.go | 4 +++- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/pkg/logcli/print/print.go b/pkg/logcli/print/print.go index 88058578243bb..0f7d5d131151e 100644 --- a/pkg/logcli/print/print.go +++ b/pkg/logcli/print/print.go @@ -209,7 +209,7 @@ func (k kvLogger) Log(keyvals ...interface{}) error { func (r *QueryResultPrinter) PrintStats(stats stats.Result) { writer := tabwriter.NewWriter(os.Stderr, 0, 8, 0, '\t', 0) - stats.LogWithLogger(kvLogger{Writer: writer}) + stats.Log(kvLogger{Writer: writer}) } func matchLabels(on bool, l loghttp.LabelSet, names []string) loghttp.LabelSet { diff --git a/pkg/logql/engine.go b/pkg/logql/engine.go index 7fb5c38070106..8b46ed4d833fb 100644 --- a/pkg/logql/engine.go +++ b/pkg/logql/engine.go @@ -263,7 +263,7 @@ func (q *query) Exec(ctx context.Context) (logqlmodel.Result, error) { queueTime, _ := ctx.Value(httpreq.QueryQueueTimeHTTPHeader).(time.Duration) statResult := statsCtx.Result(time.Since(start), queueTime, q.resultLength(data)) - statResult.LogWithSpan(sp) + sp.LogKV(statResult.KVList()...) status, _ := server.ClientHTTPStatusAndError(err) diff --git a/pkg/logqlmodel/stats/context.go b/pkg/logqlmodel/stats/context.go index d556751199905..082e78b2b69b4 100644 --- a/pkg/logqlmodel/stats/context.go +++ b/pkg/logqlmodel/stats/context.go @@ -520,18 +520,11 @@ func (c *Context) getCacheStatsByType(t CacheType) *Cache { return stats } -func (r Result) LogWithSpan(sp opentracing.Span) { - sp.LogKV(r.KVList()...) - - r.Caches.LogWithSpan(sp) - r.Summary.LogWithSpan(sp) -} - -func (r Result) LogWithLogger(logger log.Logger) { +func (r Result) Log(logger log.Logger) { logger.Log(r.KVList()...) - r.Caches.LogWithLogger(logger) - r.Summary.LogWithLogger(logger) + r.Caches.Log(logger) + r.Summary.Log(logger) } func (r Result) KVList() []any { @@ -567,7 +560,7 @@ func (r Result) KVList() []any { } } -func (s Summary) LogWithLogger(logger log.Logger) { +func (s Summary) Log(logger log.Logger) { logger.Log(s.KVList()...) } @@ -587,7 +580,7 @@ func (s Summary) LogWithSpan(sp opentracing.Span) { sp.LogKV(s.KVList()...) } -func (c Caches) LogWithLogger(logger log.Logger) { +func (c Caches) Log(logger log.Logger) { logger.Log(c.KVList()...) } diff --git a/pkg/logqlmodel/stats/context_test.go b/pkg/logqlmodel/stats/context_test.go index bc5c06a5bea37..55f5b93c70b05 100644 --- a/pkg/logqlmodel/stats/context_test.go +++ b/pkg/logqlmodel/stats/context_test.go @@ -32,7 +32,7 @@ func TestResult(t *testing.T) { fakeIngesterQuery(ctx) res := stats.Result(2*time.Second, 2*time.Nanosecond, 10) - res.LogWithLogger(util_log.Logger) + res.Log(util_log.Logger) expected := Result{ Ingester: Ingester{ TotalChunksMatched: 200, diff --git a/pkg/querier/http.go b/pkg/querier/http.go index 14ef51f6542c5..302c1c42814b3 100644 --- a/pkg/querier/http.go +++ b/pkg/querier/http.go @@ -113,7 +113,7 @@ func (q *QuerierAPI) LabelHandler(ctx context.Context, req *logproto.LabelReques } statResult := statsCtx.Result(time.Since(start), queueTime, resLength) if sp := opentracing.SpanFromContext(ctx); sp != nil { - statResult.LogWithSpan(sp) + sp.LogKV(statResult.KVList()...) } status := 200 @@ -268,7 +268,7 @@ func (q *QuerierAPI) SeriesHandler(ctx context.Context, req *logproto.SeriesRequ statResult := statsCtx.Result(time.Since(start), queueTime, resLength) if sp := opentracing.SpanFromContext(ctx); sp != nil { - statResult.LogWithSpan(sp) + sp.LogKV(statResult.KVList()...) } status := 200 @@ -299,7 +299,7 @@ func (q *QuerierAPI) IndexStatsHandler(ctx context.Context, req *loghttp.RangeQu queueTime, _ := ctx.Value(httpreq.QueryQueueTimeHTTPHeader).(time.Duration) statResult := statsCtx.Result(time.Since(start), queueTime, 1) if sp := opentracing.SpanFromContext(ctx); sp != nil { - statResult.LogWithSpan(sp) + sp.LogKV(statResult.KVList()...) } status := 200 @@ -331,7 +331,7 @@ func (q *QuerierAPI) IndexShardsHandler(ctx context.Context, req *loghttp.RangeQ statResult := statsCtx.Result(time.Since(start), queueTime, resLength) if sp := opentracing.SpanFromContext(ctx); sp != nil { - statResult.LogWithSpan(sp) + sp.LogKV(statResult.KVList()...) } status := 200 @@ -368,7 +368,7 @@ func (q *QuerierAPI) VolumeHandler(ctx context.Context, req *logproto.VolumeRequ queueTime, _ := ctx.Value(httpreq.QueryQueueTimeHTTPHeader).(time.Duration) statResult := statsCtx.Result(time.Since(start), queueTime, 1) if sp := opentracing.SpanFromContext(ctx); sp != nil { - statResult.LogWithSpan(sp) + sp.LogKV(statResult.KVList()...) } status := 200 diff --git a/pkg/querier/queryrange/stats.go b/pkg/querier/queryrange/stats.go index 0873cbc491b82..f890242d15d15 100644 --- a/pkg/querier/queryrange/stats.go +++ b/pkg/querier/queryrange/stats.go @@ -195,7 +195,9 @@ func StatsCollectorMiddleware() queryrangebase.Middleware { // Re-calculate the summary: the queueTime result is already merged so should not be updated // Log and record metrics for the current query responseStats.ComputeSummary(time.Since(start), 0, totalEntries) - responseStats.LogWithSpan(logger.Span) + if logger.Span != nil { + logger.Span.LogKV(responseStats.KVList()...) + } } ctxValue := ctx.Value(ctxKey) if data, ok := ctxValue.(*queryData); ok {