Skip to content

Commit

Permalink
refactor to keep old signature/method name
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanGuedes committed Jun 21, 2024
1 parent 6f7aea4 commit 0c9570a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/logcli/print/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/logql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 5 additions & 12 deletions pkg/logqlmodel/stats/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()...)
}

Expand All @@ -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()...)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/logqlmodel/stats/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions pkg/querier/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/querier/queryrange/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0c9570a

Please sign in to comment.