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

Enable tracing of Cassandra queries #1038

Merged
merged 4 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 12 additions & 10 deletions cmd/query/app/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package app

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -153,7 +154,7 @@ func (aH *APIHandler) route(route string, args ...interface{}) string {
}

func (aH *APIHandler) getServices(w http.ResponseWriter, r *http.Request) {
services, err := aH.spanReader.GetServices()
services, err := aH.spanReader.GetServices(r.Context())
if aH.handleError(w, err, http.StatusInternalServerError) {
return
}
Expand All @@ -168,7 +169,7 @@ func (aH *APIHandler) getOperationsLegacy(w http.ResponseWriter, r *http.Request
vars := mux.Vars(r)
// given how getOperationsLegacy is bound to URL route, serviceParam cannot be empty
service, _ := url.QueryUnescape(vars[serviceParam])
operations, err := aH.spanReader.GetOperations(service)
operations, err := aH.spanReader.GetOperations(r.Context(), service)
if aH.handleError(w, err, http.StatusInternalServerError) {
return
}
Expand All @@ -186,7 +187,7 @@ func (aH *APIHandler) getOperations(w http.ResponseWriter, r *http.Request) {
return
}
}
operations, err := aH.spanReader.GetOperations(service)
operations, err := aH.spanReader.GetOperations(r.Context(), service)
if aH.handleError(w, err, http.StatusInternalServerError) {
return
}
Expand All @@ -206,12 +207,12 @@ func (aH *APIHandler) search(w http.ResponseWriter, r *http.Request) {
var uiErrors []structuredError
var tracesFromStorage []*model.Trace
if len(tQuery.traceIDs) > 0 {
tracesFromStorage, uiErrors, err = aH.tracesByIDs(tQuery.traceIDs)
tracesFromStorage, uiErrors, err = aH.tracesByIDs(r.Context(), tQuery.traceIDs)
if aH.handleError(w, err, http.StatusInternalServerError) {
return
}
} else {
tracesFromStorage, err = aH.spanReader.FindTraces(&tQuery.TraceQueryParameters)
tracesFromStorage, err = aH.spanReader.FindTraces(r.Context(), &tQuery.TraceQueryParameters)
if aH.handleError(w, err, http.StatusInternalServerError) {
return
}
Expand All @@ -233,11 +234,11 @@ func (aH *APIHandler) search(w http.ResponseWriter, r *http.Request) {
aH.writeJSON(w, r, &structuredRes)
}

func (aH *APIHandler) tracesByIDs(traceIDs []model.TraceID) ([]*model.Trace, []structuredError, error) {
func (aH *APIHandler) tracesByIDs(ctx context.Context, traceIDs []model.TraceID) ([]*model.Trace, []structuredError, error) {
var errors []structuredError
retMe := make([]*model.Trace, 0, len(traceIDs))
for _, traceID := range traceIDs {
if trace, err := trace(traceID, aH.spanReader, aH.archiveSpanReader); err != nil {
if trace, err := trace(ctx, traceID, aH.spanReader, aH.archiveSpanReader); err != nil {
if err != spanstore.ErrTraceNotFound {
return nil, nil, err
}
Expand Down Expand Up @@ -399,7 +400,7 @@ func (aH *APIHandler) withTraceFromReader(
if !ok {
return
}
trace, err := trace(traceID, reader, backupReader)
trace, err := trace(r.Context(), traceID, reader, backupReader)
if err == spanstore.ErrTraceNotFound {
aH.handleError(w, err, http.StatusNotFound)
return
Expand All @@ -411,16 +412,17 @@ func (aH *APIHandler) withTraceFromReader(
}

func trace(
ctx context.Context,
traceID model.TraceID,
reader spanstore.Reader,
backupReader spanstore.Reader,
) (*model.Trace, error) {
trace, err := reader.GetTrace(traceID)
trace, err := reader.GetTrace(ctx, traceID)
if err == spanstore.ErrTraceNotFound {
if backupReader == nil {
return nil, err
}
trace, err = backupReader.GetTrace(traceID)
trace, err = backupReader.GetTrace(ctx, traceID)
}
return trace, err
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
"syscall"

"github.com/gorilla/handlers"
"github.com/opentracing/opentracing-go"
"github.com/spf13/cobra"
"github.com/spf13/viper"
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
jaegerClientZapLog "github.com/uber/jaeger-client-go/log/zap"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/env"
Expand Down Expand Up @@ -86,11 +88,16 @@ func main() {
Param: 1.0,
},
RPCMetrics: true,
}.New("jaeger-query", jaegerClientConfig.Metrics(baseFactory.Namespace("client", nil)))
}.New(
"jaeger-query",
jaegerClientConfig.Metrics(baseFactory.Namespace("client", nil)),
jaegerClientConfig.Logger(jaegerClientZapLog.NewLogger(logger)),
)
if err != nil {
logger.Fatal("Failed to initialize tracer", zap.Error(err))
}
defer closer.Close()
opentracing.SetGlobalTracer(tracer)

storageFactory.InitFromViper(v)
if err := storageFactory.Initialize(baseFactory, logger); err != nil {
Expand Down
10 changes: 9 additions & 1 deletion cmd/standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import (
"syscall"

"github.com/gorilla/mux"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
jaegerClientZapLog "github.com/uber/jaeger-client-go/log/zap"
"github.com/uber/jaeger-lib/metrics"
"github.com/uber/tchannel-go"
"github.com/uber/tchannel-go/thrift"
Expand Down Expand Up @@ -277,10 +279,16 @@ func startQuery(
Param: 1.0,
},
RPCMetrics: true,
}.New("jaeger-query", jaegerClientConfig.Metrics(baseFactory.Namespace("client", nil)))
}.New(
"jaeger-query",
jaegerClientConfig.Metrics(baseFactory.Namespace("client", nil)),
jaegerClientConfig.Logger(jaegerClientZapLog.NewLogger(logger)),
)
if err != nil {
logger.Fatal("Failed to initialize tracer", zap.Error(err))
}
opentracing.SetGlobalTracer(tracer)

apiHandler := queryApp.NewAPIHandler(
spanReader,
depReader,
Expand Down
16 changes: 9 additions & 7 deletions plugin/storage/cassandra/savetracetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"context"
"time"

"github.com/uber/jaeger-lib/metrics"
Expand Down Expand Up @@ -50,7 +51,8 @@ func main() {
logger.Info("Saved span", zap.String("spanID", getSomeSpan().SpanID.String()))
}
s := getSomeSpan()
trace, err := spanReader.GetTrace(s.TraceID)
ctx := context.Background()
trace, err := spanReader.GetTrace(ctx, s.TraceID)
if err != nil {
logger.Fatal("Failed to read", zap.Error(err))
} else {
Expand All @@ -63,27 +65,27 @@ func main() {
StartTimeMax: time.Now().Add(time.Hour),
}
logger.Info("Check main query")
queryAndPrint(spanReader, tqp)
queryAndPrint(ctx, spanReader, tqp)

tqp.OperationName = "opName"
logger.Info("Check query with operation")
queryAndPrint(spanReader, tqp)
queryAndPrint(ctx, spanReader, tqp)

tqp.Tags = map[string]string{
"someKey": "someVal",
}
logger.Info("Check query with operation name and tags")
queryAndPrint(spanReader, tqp)
queryAndPrint(ctx, spanReader, tqp)

tqp.DurationMin = 0
tqp.DurationMax = time.Hour
tqp.Tags = map[string]string{}
logger.Info("check query with duration")
queryAndPrint(spanReader, tqp)
queryAndPrint(ctx, spanReader, tqp)
}

func queryAndPrint(spanReader *cSpanStore.SpanReader, tqp *spanstore.TraceQueryParameters) {
traces, err := spanReader.FindTraces(tqp)
func queryAndPrint(ctx context.Context, spanReader *cSpanStore.SpanReader, tqp *spanstore.TraceQueryParameters) {
traces, err := spanReader.FindTraces(ctx, tqp)
if err != nil {
logger.Fatal("Failed to query", zap.Error(err))
} else {
Expand Down
Loading