Skip to content

Commit

Permalink
astmapper spanlogger
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d committed Feb 2, 2022
1 parent c28484d commit 23f6b55
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/querier/queryrange/querysharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/opentracing/opentracing-go"
otlog "github.com/opentracing/opentracing-go/log"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/promql/parser"
"github.com/weaveworks/common/httpgrpc"
Expand Down Expand Up @@ -90,29 +92,37 @@ type astMapperware struct {
func (ast *astMapperware) Do(ctx context.Context, r queryrangebase.Request) (queryrangebase.Response, error) {
conf, err := ast.confs.GetConf(r)
logger := util_log.WithContext(ctx, ast.logger)
sp, _ := opentracing.StartSpanFromContext(ctx, "astmapper")
defer sp.Finish()
sp.LogFields(otlog.String("msg", "setup"))
// cannot shard with this timerange
if err != nil {
sp.LogKV("msg", "error finding shardable configs", "err", err.Error())
level.Warn(logger).Log("err", err.Error(), "msg", "skipped AST mapper for request")
return ast.next.Do(ctx, r)
}

mapper, err := logql.NewShardMapper(int(conf.RowShards), ast.metrics)
if err != nil {
sp.LogKV("msg", "error building shardmapper", "err", err.Error())
return nil, err
}

noop, parsed, err := mapper.Parse(r.GetQuery())
if err != nil {
sp.LogKV("msg", "error parsing", "err", err.Error())
level.Warn(logger).Log("msg", "failed mapping AST", "err", err.Error(), "query", r.GetQuery())
return nil, err
}
level.Debug(logger).Log("no-op", noop, "mapped", parsed.String())

if noop {
sp.LogKV("msg", "noop")
// the ast can't be mapped to a sharded equivalent
// so we can bypass the sharding engine.
return ast.next.Do(ctx, r)
}
sp.LogKV("msg", "running query", "query", parsed.String())

params, err := paramsFromRequest(r)
if err != nil {
Expand Down

0 comments on commit 23f6b55

Please sign in to comment.