Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit tracing span for remote queries #7332

Merged
merged 2 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions pkg/query/remote_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql"
Expand Down Expand Up @@ -187,10 +188,11 @@ func (r *remoteEngine) NewRangeQuery(_ context.Context, _ promql.QueryOpts, plan
client: r.client,
opts: r.opts,

plan: plan,
start: start,
end: end,
interval: interval,
plan: plan,
start: start,
end: end,
interval: interval,
remoteAddr: r.client.GetAddress(),
}, nil
}

Expand All @@ -200,10 +202,11 @@ func (r *remoteEngine) NewInstantQuery(_ context.Context, _ promql.QueryOpts, pl
client: r.client,
opts: r.opts,

plan: plan,
start: ts,
end: ts,
interval: 0,
plan: plan,
start: ts,
end: ts,
interval: 0,
remoteAddr: r.client.GetAddress(),
}, nil
}

Expand All @@ -212,21 +215,34 @@ type remoteQuery struct {
client Client
opts Opts

plan api.RemoteQuery
start time.Time
end time.Time
interval time.Duration
plan api.RemoteQuery
start time.Time
end time.Time
interval time.Duration
remoteAddr string

cancel context.CancelFunc
}

func (r *remoteQuery) Exec(ctx context.Context) *promql.Result {
start := time.Now()

qctx, cancel := context.WithCancel(ctx)
r.cancel = cancel
defer cancel()

queryRange := r.end.Sub(r.start)
span, qctx := opentracing.StartSpanFromContext(qctx, "remote_query_exec", opentracing.Tags{
"query": r.plan.String(),
"remote_address": r.remoteAddr,
"start": r.start.UTC().String(),
"end": r.end.UTC().String(),
"interval_seconds": r.interval.Seconds(),
"range_seconds": queryRange.Seconds(),
"range_human": queryRange,
})
defer span.Finish()

var maxResolution int64
if r.opts.AutoDownsample {
maxResolution = int64(r.interval.Seconds() / 5)
Expand Down
Loading