Commit f160ad3b by bergquist

add trace parameters for outgoing requests

parent 2e350bbb
......@@ -17,6 +17,8 @@ import (
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb"
opentracing "github.com/opentracing/opentracing-go"
tlog "github.com/opentracing/opentracing-go/log"
)
type GraphiteExecutor struct {
......@@ -49,21 +51,27 @@ func init() {
func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, context *tsdb.QueryContext) *tsdb.BatchResult {
result := &tsdb.BatchResult{}
from := "-" + formatTimeRange(context.TimeRange.From)
until := formatTimeRange(context.TimeRange.To)
var target string
formData := url.Values{
"from": []string{"-" + formatTimeRange(context.TimeRange.From)},
"until": []string{formatTimeRange(context.TimeRange.To)},
"from": []string{from},
"until": []string{until},
"format": []string{"json"},
"maxDataPoints": []string{"500"},
}
for _, query := range queries {
if fullTarget, err := query.Model.Get("targetFull").String(); err == nil {
formData["target"] = []string{fixIntervalFormat(fullTarget)}
target = fixIntervalFormat(fullTarget)
} else {
formData["target"] = []string{fixIntervalFormat(query.Model.Get("target").MustString())}
target = fixIntervalFormat(query.Model.Get("target").MustString())
}
}
formData["target"] = []string{target}
if setting.Env == setting.DEV {
glog.Debug("Graphite request", "params", formData)
}
......@@ -74,6 +82,19 @@ func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
return result
}
span, ctx := opentracing.StartSpanFromContext(ctx, "alerting.graphite")
span.LogFields(
tlog.String("target", target),
tlog.String("from", from),
tlog.String("until", until),
)
defer span.Finish()
opentracing.GlobalTracer().Inject(
span.Context(),
opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(req.Header))
res, err := ctxhttp.Do(ctx, e.HttpClient, req)
if err != nil {
result.Error = err
......
......@@ -7,6 +7,8 @@ import (
"strings"
"time"
"github.com/opentracing/opentracing-go"
"net/http"
"github.com/grafana/grafana/pkg/components/null"
......@@ -18,6 +20,7 @@ import (
"github.com/prometheus/common/model"
//api "github.com/prometheus/client_golang/api"
//apiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
tlog "github.com/opentracing/opentracing-go/log"
)
type PrometheusExecutor struct {
......@@ -101,6 +104,14 @@ func (e *PrometheusExecutor) Execute(ctx context.Context, queries tsdb.QuerySlic
Step: query.Step,
}
span, ctx := opentracing.StartSpanFromContext(ctx, "alerting.prometheus")
span.LogFields(
tlog.String("expr", query.Expr),
tlog.Int64("start_unixnano", int64(query.Start.UnixNano())),
tlog.Int64("stop_unixnano", int64(query.End.UnixNano())),
)
defer span.Finish()
value, err := client.QueryRange(ctx, query.Expr, timeRange)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment