Commit f160ad3b by bergquist

add trace parameters for outgoing requests

parent 2e350bbb
...@@ -17,6 +17,8 @@ import ( ...@@ -17,6 +17,8 @@ import (
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb" "github.com/grafana/grafana/pkg/tsdb"
opentracing "github.com/opentracing/opentracing-go"
tlog "github.com/opentracing/opentracing-go/log"
) )
type GraphiteExecutor struct { type GraphiteExecutor struct {
...@@ -49,21 +51,27 @@ func init() { ...@@ -49,21 +51,27 @@ func init() {
func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, context *tsdb.QueryContext) *tsdb.BatchResult { func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, context *tsdb.QueryContext) *tsdb.BatchResult {
result := &tsdb.BatchResult{} result := &tsdb.BatchResult{}
from := "-" + formatTimeRange(context.TimeRange.From)
until := formatTimeRange(context.TimeRange.To)
var target string
formData := url.Values{ formData := url.Values{
"from": []string{"-" + formatTimeRange(context.TimeRange.From)}, "from": []string{from},
"until": []string{formatTimeRange(context.TimeRange.To)}, "until": []string{until},
"format": []string{"json"}, "format": []string{"json"},
"maxDataPoints": []string{"500"}, "maxDataPoints": []string{"500"},
} }
for _, query := range queries { for _, query := range queries {
if fullTarget, err := query.Model.Get("targetFull").String(); err == nil { if fullTarget, err := query.Model.Get("targetFull").String(); err == nil {
formData["target"] = []string{fixIntervalFormat(fullTarget)} target = fixIntervalFormat(fullTarget)
} else { } 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 { if setting.Env == setting.DEV {
glog.Debug("Graphite request", "params", formData) glog.Debug("Graphite request", "params", formData)
} }
...@@ -74,6 +82,19 @@ func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, ...@@ -74,6 +82,19 @@ func (e *GraphiteExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
return result 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) res, err := ctxhttp.Do(ctx, e.HttpClient, req)
if err != nil { if err != nil {
result.Error = err result.Error = err
......
...@@ -7,6 +7,8 @@ import ( ...@@ -7,6 +7,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/opentracing/opentracing-go"
"net/http" "net/http"
"github.com/grafana/grafana/pkg/components/null" "github.com/grafana/grafana/pkg/components/null"
...@@ -18,6 +20,7 @@ import ( ...@@ -18,6 +20,7 @@ import (
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
//api "github.com/prometheus/client_golang/api" //api "github.com/prometheus/client_golang/api"
//apiv1 "github.com/prometheus/client_golang/api/prometheus/v1" //apiv1 "github.com/prometheus/client_golang/api/prometheus/v1"
tlog "github.com/opentracing/opentracing-go/log"
) )
type PrometheusExecutor struct { type PrometheusExecutor struct {
...@@ -101,6 +104,14 @@ func (e *PrometheusExecutor) Execute(ctx context.Context, queries tsdb.QuerySlic ...@@ -101,6 +104,14 @@ func (e *PrometheusExecutor) Execute(ctx context.Context, queries tsdb.QuerySlic
Step: query.Step, 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) value, err := client.QueryRange(ctx, query.Expr, timeRange)
if err != nil { 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