From 0790c2f4eb92a0fe8172917d99b100a3c7f7055d Mon Sep 17 00:00:00 2001 From: Mahad Zaryab <43658574+mahadzaryab1@users.noreply.github.com> Date: Thu, 2 Jan 2025 23:39:59 -0500 Subject: [PATCH] [api_v3][query] Change api_v3 http handler to use v2 query service (#6459) ## Which problem is this PR solving? - Part of #6460 ## Description of the changes - This PR migrates the v3_api HTTP handler to use the new v2 query service. ## How was this change tested? - Added unit tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Mahad Zaryab --- cmd/query/app/apiv3/gateway_test.go | 57 ++++----- cmd/query/app/apiv3/grpc_handler_test.go | 5 +- cmd/query/app/apiv3/http_gateway.go | 86 +++++++------ cmd/query/app/apiv3/http_gateway_test.go | 118 ++++++++++++------ cmd/query/app/apiv3/otlp_translator.go | 17 --- cmd/query/app/apiv3/snapshots/FindTraces.json | 6 +- cmd/query/app/apiv3/snapshots/GetTrace.json | 6 +- cmd/query/app/server.go | 14 ++- 8 files changed, 162 insertions(+), 147 deletions(-) delete mode 100644 cmd/query/app/apiv3/otlp_translator.go diff --git a/cmd/query/app/apiv3/gateway_test.go b/cmd/query/app/apiv3/gateway_test.go index c796701ee75..27e992a6b73 100644 --- a/cmd/query/app/apiv3/gateway_test.go +++ b/cmd/query/app/apiv3/gateway_test.go @@ -22,10 +22,10 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" "github.com/jaegertracing/jaeger/internal/proto/api_v3" - "github.com/jaegertracing/jaeger/model" _ "github.com/jaegertracing/jaeger/pkg/gogocodec" // force gogo codec registration - "github.com/jaegertracing/jaeger/storage/spanstore" - spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" + "github.com/jaegertracing/jaeger/pkg/iter" + "github.com/jaegertracing/jaeger/storage_v2/tracestore" + tracestoremocks "github.com/jaegertracing/jaeger/storage_v2/tracestore/mocks" ) // Utility functions used from http_gateway_test.go. @@ -43,7 +43,7 @@ var ( ) type testGateway struct { - reader *spanstoremocks.Reader + reader *tracestoremocks.Reader url string router *mux.Router // used to set a tenancy header when executing requests @@ -85,25 +85,6 @@ func parseResponse(t *testing.T, body []byte, obj gogoproto.Message) { require.NoError(t, gogojsonpb.Unmarshal(bytes.NewBuffer(body), obj)) } -func makeTestTrace() (*model.Trace, spanstore.GetTraceParameters) { - traceID := model.NewTraceID(150, 160) - query := spanstore.GetTraceParameters{TraceID: traceID} - return &model.Trace{ - Spans: []*model.Span{ - { - TraceID: traceID, - SpanID: model.NewSpanID(180), - OperationName: "foobar", - Tags: []model.KeyValue{ - model.SpanKindTag(model.SpanKindServer), - model.Bool("error", true), - }, - Process: &model.Process{}, - }, - }, - }, query -} - func makeTestTraceV2() ptrace.Traces { trace := ptrace.NewTraces() resources := trace.ResourceSpans().AppendEmpty() @@ -112,9 +93,9 @@ func makeTestTraceV2() ptrace.Traces { spanA := scopes.Spans().AppendEmpty() spanA.SetName("foobar") spanA.SetTraceID(traceID) - spanA.SetSpanID(pcommon.SpanID([8]byte{180})) + spanA.SetSpanID(pcommon.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 2})) spanA.SetKind(ptrace.SpanKindServer) - spanA.Attributes().PutBool("error", true) + spanA.Status().SetCode(ptrace.StatusCodeError) return trace } @@ -145,10 +126,10 @@ func (gw *testGateway) runGatewayGetServices(t *testing.T) { } func (gw *testGateway) runGatewayGetOperations(t *testing.T) { - qp := spanstore.OperationQueryParameters{ServiceName: "foo", SpanKind: "server"} + qp := tracestore.OperationQueryParams{ServiceName: "foo", SpanKind: "server"} gw.reader. On("GetOperations", matchContext, qp). - Return([]spanstore.Operation{{Name: "get_users", SpanKind: "server"}}, nil).Once() + Return([]tracestore.Operation{{Name: "get_users", SpanKind: "server"}}, nil).Once() body, statusCode := gw.execRequest(t, "/api/v3/operations?service=foo&span_kind=server") require.Equal(t, http.StatusOK, statusCode) @@ -162,21 +143,25 @@ func (gw *testGateway) runGatewayGetOperations(t *testing.T) { } func (gw *testGateway) runGatewayGetTrace(t *testing.T) { - trace, query := makeTestTrace() - gw.reader.On("GetTrace", matchContext, query).Return(trace, nil).Once() - gw.getTracesAndVerify(t, "/api/v3/traces/"+query.TraceID.String(), query.TraceID) + query := tracestore.GetTraceParams{TraceID: traceID} + gw.reader. + On("GetTraces", matchContext, query). + Return(iter.Seq2[[]ptrace.Traces, error](func(yield func([]ptrace.Traces, error) bool) { + yield([]ptrace.Traces{makeTestTraceV2()}, nil) + })).Once() + gw.getTracesAndVerify(t, "/api/v3/traces/1", traceID) } func (gw *testGateway) runGatewayFindTraces(t *testing.T) { - trace, query := makeTestTrace() q, qp := mockFindQueries() - gw.reader. - On("FindTraces", matchContext, qp). - Return([]*model.Trace{trace}, nil).Once() - gw.getTracesAndVerify(t, "/api/v3/traces?"+q.Encode(), query.TraceID) + gw.reader.On("FindTraces", matchContext, qp). + Return(iter.Seq2[[]ptrace.Traces, error](func(yield func([]ptrace.Traces, error) bool) { + yield([]ptrace.Traces{makeTestTraceV2()}, nil) + })).Once() + gw.getTracesAndVerify(t, "/api/v3/traces?"+q.Encode(), traceID) } -func (gw *testGateway) getTracesAndVerify(t *testing.T, url string, expectedTraceID model.TraceID) { +func (gw *testGateway) getTracesAndVerify(t *testing.T, url string, expectedTraceID pcommon.TraceID) { body, statusCode := gw.execRequest(t, url) require.Equal(t, http.StatusOK, statusCode, "response=%s", string(body)) body = gw.verifySnapshot(t, body) diff --git a/cmd/query/app/apiv3/grpc_handler_test.go b/cmd/query/app/apiv3/grpc_handler_test.go index df2b5952bc7..f37f0420fad 100644 --- a/cmd/query/app/apiv3/grpc_handler_test.go +++ b/cmd/query/app/apiv3/grpc_handler_test.go @@ -25,10 +25,7 @@ import ( tracestoremocks "github.com/jaegertracing/jaeger/storage_v2/tracestore/mocks" ) -var ( - matchContext = mock.AnythingOfType("*context.valueCtx") - matchGetTraceParameters = mock.AnythingOfType("spanstore.GetTraceParameters") -) +var matchContext = mock.AnythingOfType("*context.valueCtx") func newGrpcServer(t *testing.T, handler *Handler) (*grpc.Server, net.Addr) { server := grpc.NewServer() diff --git a/cmd/query/app/apiv3/http_gateway.go b/cmd/query/app/apiv3/http_gateway.go index ab257720730..0470cf8b60b 100644 --- a/cmd/query/app/apiv3/http_gateway.go +++ b/cmd/query/app/apiv3/http_gateway.go @@ -20,10 +20,12 @@ import ( "go.opentelemetry.io/otel/trace" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" + "github.com/jaegertracing/jaeger/cmd/query/app/querysvc/v2/querysvc" "github.com/jaegertracing/jaeger/internal/proto/api_v3" "github.com/jaegertracing/jaeger/model" + "github.com/jaegertracing/jaeger/pkg/iter" "github.com/jaegertracing/jaeger/storage/spanstore" + "github.com/jaegertracing/jaeger/storage_v2/tracestore" ) const ( @@ -108,17 +110,7 @@ func (h *HTTPGateway) tryParamError(w http.ResponseWriter, err error, paramName return h.tryHandleError(w, fmt.Errorf("malformed parameter %s: %w", paramName, err), http.StatusBadRequest) } -func (h *HTTPGateway) returnSpans(spans []*model.Span, w http.ResponseWriter) { - // modelToOTLP does not easily return an error, so allow mocking it - h.returnSpansTestable(spans, w, modelToOTLP) -} - -func (h *HTTPGateway) returnSpansTestable( - spans []*model.Span, - w http.ResponseWriter, - modelToOTLP func(_ []*model.Span) ptrace.Traces, -) { - td := modelToOTLP(spans) +func (h *HTTPGateway) returnTrace(td ptrace.Traces, w http.ResponseWriter) { tracesData := api_v3.TracesData(td) response := &api_v3.GRPCGatewayWrapper{ Result: &tracesData, @@ -126,6 +118,35 @@ func (h *HTTPGateway) returnSpansTestable( h.marshalResponse(response, w) } +func (h *HTTPGateway) returnTraces(traces []ptrace.Traces, err error, w http.ResponseWriter) { + // TODO how do we distinguish internal error from bad parameters? + if h.tryHandleError(w, err, http.StatusInternalServerError) { + return + } + if len(traces) == 0 { + errorResponse := api_v3.GRPCGatewayError{ + Error: &api_v3.GRPCGatewayError_GRPCGatewayErrorDetails{ + HttpCode: http.StatusNotFound, + Message: "No traces found", + }, + } + resp, _ := json.Marshal(&errorResponse) + http.Error(w, string(resp), http.StatusNotFound) + return + } + // TODO: the response should be streamed back to the client + // https://github.com/jaegertracing/jaeger/issues/6467 + combinedTrace := ptrace.NewTraces() + for _, t := range traces { + resources := t.ResourceSpans() + for i := 0; i < resources.Len(); i++ { + resource := resources.At(i) + resource.CopyTo(combinedTrace.ResourceSpans().AppendEmpty()) + } + } + h.returnTrace(combinedTrace, w) +} + func (*HTTPGateway) marshalResponse(response proto.Message, w http.ResponseWriter) { _ = new(jsonpb.Marshaler).Marshal(w, response) } @@ -137,9 +158,11 @@ func (h *HTTPGateway) getTrace(w http.ResponseWriter, r *http.Request) { if h.tryParamError(w, err, paramTraceID) { return } - request := querysvc.GetTraceParameters{ - GetTraceParameters: spanstore.GetTraceParameters{ - TraceID: traceID, + request := querysvc.GetTraceParams{ + TraceIDs: []tracestore.GetTraceParams{ + { + TraceID: traceID.ToOTELTraceID(), + }, }, } http_query := r.URL.Query() @@ -149,7 +172,7 @@ func (h *HTTPGateway) getTrace(w http.ResponseWriter, r *http.Request) { if h.tryParamError(w, err, paramStartTime) { return } - request.StartTime = timeParsed.UTC() + request.TraceIDs[0].Start = timeParsed.UTC() } endTime := http_query.Get(paramEndTime) if endTime != "" { @@ -157,7 +180,7 @@ func (h *HTTPGateway) getTrace(w http.ResponseWriter, r *http.Request) { if h.tryParamError(w, err, paramEndTime) { return } - request.EndTime = timeParsed.UTC() + request.TraceIDs[0].End = timeParsed.UTC() } if r := http_query.Get(paramRawTraces); r != "" { rawTraces, err := strconv.ParseBool(r) @@ -166,11 +189,9 @@ func (h *HTTPGateway) getTrace(w http.ResponseWriter, r *http.Request) { } request.RawTraces = rawTraces } - trc, err := h.QueryService.GetTrace(r.Context(), request) - if h.tryHandleError(w, err, http.StatusInternalServerError) { - return - } - h.returnSpans(trc.Spans, w) + getTracesIter := h.QueryService.GetTraces(r.Context(), request) + trc, err := iter.FlattenWithErrors(getTracesIter) + h.returnTraces(trc, err, w) } func (h *HTTPGateway) findTraces(w http.ResponseWriter, r *http.Request) { @@ -179,21 +200,14 @@ func (h *HTTPGateway) findTraces(w http.ResponseWriter, r *http.Request) { return } - traces, err := h.QueryService.FindTraces(r.Context(), queryParams) - // TODO how do we distinguish internal error from bad parameters for FindTrace? - if h.tryHandleError(w, err, http.StatusInternalServerError) { - return - } - var spans []*model.Span - for _, t := range traces { - spans = append(spans, t.Spans...) - } - h.returnSpans(spans, w) + findTracesIter := h.QueryService.FindTraces(r.Context(), *queryParams) + traces, err := iter.FlattenWithErrors(findTracesIter) + h.returnTraces(traces, err, w) } -func (h *HTTPGateway) parseFindTracesQuery(q url.Values, w http.ResponseWriter) (*querysvc.TraceQueryParameters, bool) { - queryParams := &querysvc.TraceQueryParameters{ - TraceQueryParameters: spanstore.TraceQueryParameters{ +func (h *HTTPGateway) parseFindTracesQuery(q url.Values, w http.ResponseWriter) (*querysvc.TraceQueryParams, bool) { + queryParams := &querysvc.TraceQueryParams{ + TraceQueryParams: tracestore.TraceQueryParams{ ServiceName: q.Get(paramServiceName), OperationName: q.Get(paramOperationName), Tags: nil, // most curiously not supported by grpc-gateway @@ -262,7 +276,7 @@ func (h *HTTPGateway) getServices(w http.ResponseWriter, r *http.Request) { func (h *HTTPGateway) getOperations(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() - queryParams := spanstore.OperationQueryParameters{ + queryParams := tracestore.OperationQueryParams{ ServiceName: query.Get("service"), SpanKind: query.Get("span_kind"), } diff --git a/cmd/query/app/apiv3/http_gateway_test.go b/cmd/query/app/apiv3/http_gateway_test.go index 37eee29d8e9..c42e8118d20 100644 --- a/cmd/query/app/apiv3/http_gateway_test.go +++ b/cmd/query/app/apiv3/http_gateway_test.go @@ -14,17 +14,19 @@ import ( "github.com/gorilla/mux" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/ptrace" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" - "github.com/jaegertracing/jaeger/model" + "github.com/jaegertracing/jaeger/cmd/query/app/querysvc/v2/querysvc" + "github.com/jaegertracing/jaeger/pkg/iter" "github.com/jaegertracing/jaeger/pkg/jtracer" "github.com/jaegertracing/jaeger/pkg/testutils" "github.com/jaegertracing/jaeger/storage/spanstore" - spanstoremocks "github.com/jaegertracing/jaeger/storage/spanstore/mocks" dependencyStoreMocks "github.com/jaegertracing/jaeger/storage_v2/depstore/mocks" - "github.com/jaegertracing/jaeger/storage_v2/v1adapter" + "github.com/jaegertracing/jaeger/storage_v2/tracestore" + tracestoremocks "github.com/jaegertracing/jaeger/storage_v2/tracestore/mocks" ) func setupHTTPGatewayNoServer( @@ -32,10 +34,10 @@ func setupHTTPGatewayNoServer( basePath string, ) *testGateway { gw := &testGateway{ - reader: &spanstoremocks.Reader{}, + reader: &tracestoremocks.Reader{}, } - q := querysvc.NewQueryService(v1adapter.NewTraceReader(gw.reader), + q := querysvc.NewQueryService(gw.reader, &dependencyStoreMocks.Reader{}, querysvc.QueryServiceOptions{}, ) @@ -92,17 +94,16 @@ func TestHTTPGatewayTryHandleError(t *testing.T) { } func TestHTTPGatewayGetTrace(t *testing.T) { - traceId, _ := model.TraceIDFromString("123") testCases := []struct { name string params map[string]string - expectedQuery spanstore.GetTraceParameters + expectedQuery tracestore.GetTraceParams }{ { name: "TestGetTrace", params: map[string]string{}, - expectedQuery: spanstore.GetTraceParameters{ - TraceID: traceId, + expectedQuery: tracestore.GetTraceParams{ + TraceID: traceID, }, }, { @@ -111,22 +112,25 @@ func TestHTTPGatewayGetTrace(t *testing.T) { "start_time": "2000-01-02T12:30:08.999999998Z", "end_time": "2000-04-05T21:55:16.999999992+08:00", }, - expectedQuery: spanstore.GetTraceParameters{ - TraceID: traceId, - StartTime: time.Date(2000, time.January, 0o2, 12, 30, 8, 999999998, time.UTC), - EndTime: time.Date(2000, time.April, 0o5, 13, 55, 16, 999999992, time.UTC), + expectedQuery: tracestore.GetTraceParams{ + TraceID: traceID, + Start: time.Date(2000, time.January, 0o2, 12, 30, 8, 999999998, time.UTC), + End: time.Date(2000, time.April, 0o5, 13, 55, 16, 999999992, time.UTC), }, }, } - testUri := "/api/v3/traces/123" + testUri := "/api/v3/traces/1" for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { gw := setupHTTPGatewayNoServer(t, "") + gw.reader. - On("GetTrace", matchContext, tc.expectedQuery). - Return(&model.Trace{}, nil).Once() + On("GetTraces", matchContext, tc.expectedQuery). + Return(iter.Seq2[[]ptrace.Traces, error](func(yield func([]ptrace.Traces, error) bool) { + yield([]ptrace.Traces{makeTestTraceV2()}, nil) + })).Once() q := url.Values{} for k, v := range tc.params { @@ -141,11 +145,44 @@ func TestHTTPGatewayGetTrace(t *testing.T) { require.NoError(t, err) w := httptest.NewRecorder() gw.router.ServeHTTP(w, r) - gw.reader.AssertCalled(t, "GetTrace", matchContext, tc.expectedQuery) + gw.reader.AssertCalled(t, "GetTraces", matchContext, tc.expectedQuery) }) } } +func TestHTTPGatewayGetTraceEmptyResponse(t *testing.T) { + gw := setupHTTPGatewayNoServer(t, "") + gw.reader.On("GetTraces", matchContext, mock.AnythingOfType("tracestore.GetTraceParams")). + Return(iter.Seq2[[]ptrace.Traces, error](func(yield func([]ptrace.Traces, error) bool) { + yield([]ptrace.Traces{}, nil) + })).Once() + + r, err := http.NewRequest(http.MethodGet, "/api/v3/traces/1", nil) + require.NoError(t, err) + w := httptest.NewRecorder() + gw.router.ServeHTTP(w, r) + assert.Equal(t, http.StatusNotFound, w.Code) + assert.Contains(t, w.Body.String(), "No traces found") +} + +func TestHTTPGatewayFindTracesEmptyResponse(t *testing.T) { + q, qp := mockFindQueries() + r, err := http.NewRequest(http.MethodGet, "/api/v3/traces?"+q.Encode(), nil) + require.NoError(t, err) + w := httptest.NewRecorder() + + gw := setupHTTPGatewayNoServer(t, "") + gw.reader. + On("FindTraces", matchContext, qp). + Return(iter.Seq2[[]ptrace.Traces, error](func(yield func([]ptrace.Traces, error) bool) { + yield([]ptrace.Traces{}, nil) + })).Once() + + gw.router.ServeHTTP(w, r) + assert.Equal(t, http.StatusNotFound, w.Code) + assert.Contains(t, w.Body.String(), "No traces found") +} + func TestHTTPGatewayGetTraceMalformedInputErrors(t *testing.T) { testCases := []struct { name string @@ -159,17 +196,17 @@ func TestHTTPGatewayGetTraceMalformedInputErrors(t *testing.T) { }, { name: "TestGetTraceWithInvalidStartTime", - requestUrl: "/api/v3/traces/123?start_time=abc", + requestUrl: "/api/v3/traces/1?start_time=abc", expectedError: "malformed parameter start_time", }, { name: "TestGetTraceWithInvalidEndTime", - requestUrl: "/api/v3/traces/123?end_time=xyz", + requestUrl: "/api/v3/traces/1?end_time=xyz", expectedError: "malformed parameter end_time", }, { name: "TestGetTraceWithInvalidRawTraces", - requestUrl: "/api/v3/traces/123?raw_traces=foobar", + requestUrl: "/api/v3/traces/1?raw_traces=foobar", expectedError: "malformed parameter raw_traces", }, } @@ -177,9 +214,10 @@ func TestHTTPGatewayGetTraceMalformedInputErrors(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { gw := setupHTTPGatewayNoServer(t, "") - gw.reader. - On("GetTrace", matchContext, matchGetTraceParameters). - Return(&model.Trace{}, nil).Once() + gw.reader.On("GetTraces", matchContext, mock.AnythingOfType("tracestore.GetTraceParams")). + Return(iter.Seq2[[]ptrace.Traces, error](func(yield func([]ptrace.Traces, error) bool) { + yield([]ptrace.Traces{}, nil) + })).Once() r, err := http.NewRequest(http.MethodGet, tc.requestUrl, nil) require.NoError(t, err) @@ -192,18 +230,19 @@ func TestHTTPGatewayGetTraceMalformedInputErrors(t *testing.T) { func TestHTTPGatewayGetTraceInternalErrors(t *testing.T) { gw := setupHTTPGatewayNoServer(t, "") - gw.reader. - On("GetTrace", matchContext, matchGetTraceParameters). - Return(nil, assert.AnError).Once() + gw.reader.On("GetTraces", matchContext, mock.AnythingOfType("tracestore.GetTraceParams")). + Return(iter.Seq2[[]ptrace.Traces, error](func(yield func([]ptrace.Traces, error) bool) { + yield([]ptrace.Traces{}, assert.AnError) + })).Once() - r, err := http.NewRequest(http.MethodGet, "/api/v3/traces/123", nil) + r, err := http.NewRequest(http.MethodGet, "/api/v3/traces/1", nil) require.NoError(t, err) w := httptest.NewRecorder() gw.router.ServeHTTP(w, r) assert.Contains(t, w.Body.String(), assert.AnError.Error()) } -func mockFindQueries() (url.Values, *spanstore.TraceQueryParameters) { +func mockFindQueries() (url.Values, tracestore.TraceQueryParams) { // mock performs deep comparison of the timestamps and can fail // if they are different in the timezone or the monotonic clocks. // To void that we truncate monotonic clock and force UTC timezone. @@ -218,7 +257,7 @@ func mockFindQueries() (url.Values, *spanstore.TraceQueryParameters) { q.Set(paramDurationMax, "2s") q.Set(paramNumTraces, "10") - return q, &spanstore.TraceQueryParameters{ + return q, tracestore.TraceQueryParams{ ServiceName: "foo", OperationName: "bar", StartTimeMin: time1, @@ -306,7 +345,6 @@ func TestHTTPGatewayFindTracesErrors(t *testing.T) { } t.Run("span reader error", func(t *testing.T) { q, qp := mockFindQueries() - const simErr = "simulated error" r, err := http.NewRequest(http.MethodGet, "/api/v3/traces?"+q.Encode(), nil) require.NoError(t, err) w := httptest.NewRecorder() @@ -314,40 +352,40 @@ func TestHTTPGatewayFindTracesErrors(t *testing.T) { gw := setupHTTPGatewayNoServer(t, "") gw.reader. On("FindTraces", matchContext, qp). - Return(nil, errors.New(simErr)).Once() + Return(iter.Seq2[[]ptrace.Traces, error](func(yield func([]ptrace.Traces, error) bool) { + yield(nil, assert.AnError) + })).Once() gw.router.ServeHTTP(w, r) - assert.Contains(t, w.Body.String(), simErr) + assert.Contains(t, w.Body.String(), assert.AnError.Error()) }) } func TestHTTPGatewayGetServicesErrors(t *testing.T) { gw := setupHTTPGatewayNoServer(t, "") - const simErr = "simulated error" gw.reader. On("GetServices", matchContext). - Return(nil, errors.New(simErr)).Once() + Return(nil, assert.AnError).Once() r, err := http.NewRequest(http.MethodGet, "/api/v3/services", nil) require.NoError(t, err) w := httptest.NewRecorder() gw.router.ServeHTTP(w, r) - assert.Contains(t, w.Body.String(), simErr) + assert.Contains(t, w.Body.String(), assert.AnError.Error()) } func TestHTTPGatewayGetOperationsErrors(t *testing.T) { gw := setupHTTPGatewayNoServer(t, "") - qp := spanstore.OperationQueryParameters{ServiceName: "foo", SpanKind: "server"} - const simErr = "simulated error" + qp := tracestore.OperationQueryParams{ServiceName: "foo", SpanKind: "server"} gw.reader. On("GetOperations", matchContext, qp). - Return(nil, errors.New(simErr)).Once() + Return(nil, assert.AnError).Once() r, err := http.NewRequest(http.MethodGet, "/api/v3/operations?service=foo&span_kind=server", nil) require.NoError(t, err) w := httptest.NewRecorder() gw.router.ServeHTTP(w, r) - assert.Contains(t, w.Body.String(), simErr) + assert.Contains(t, w.Body.String(), assert.AnError.Error()) } diff --git a/cmd/query/app/apiv3/otlp_translator.go b/cmd/query/app/apiv3/otlp_translator.go deleted file mode 100644 index 1d1bba2f4cc..00000000000 --- a/cmd/query/app/apiv3/otlp_translator.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2021 The Jaeger Authors. -// SPDX-License-Identifier: Apache-2.0 - -package apiv3 - -import ( - "go.opentelemetry.io/collector/pdata/ptrace" - - "github.com/jaegertracing/jaeger/model" - "github.com/jaegertracing/jaeger/storage_v2/v1adapter" -) - -func modelToOTLP(spans []*model.Span) ptrace.Traces { - batch := &model.Batch{Spans: spans} - tr := v1adapter.V1BatchesToTraces([]*model.Batch{batch}) - return tr -} diff --git a/cmd/query/app/apiv3/snapshots/FindTraces.json b/cmd/query/app/apiv3/snapshots/FindTraces.json index f9676a145f0..423bb446eeb 100644 --- a/cmd/query/app/apiv3/snapshots/FindTraces.json +++ b/cmd/query/app/apiv3/snapshots/FindTraces.json @@ -8,16 +8,14 @@ "scope": {}, "spans": [ { - "endTimeUnixNano": "11651379494838206464", "kind": 2, "name": "foobar", "parentSpanId": "", - "spanId": "00000000000000b4", - "startTimeUnixNano": "11651379494838206464", + "spanId": "0000000000000002", "status": { "code": 2 }, - "traceId": "000000000000009600000000000000a0" + "traceId": "00000000000000000000000000000001" } ] } diff --git a/cmd/query/app/apiv3/snapshots/GetTrace.json b/cmd/query/app/apiv3/snapshots/GetTrace.json index f9676a145f0..423bb446eeb 100644 --- a/cmd/query/app/apiv3/snapshots/GetTrace.json +++ b/cmd/query/app/apiv3/snapshots/GetTrace.json @@ -8,16 +8,14 @@ "scope": {}, "spans": [ { - "endTimeUnixNano": "11651379494838206464", "kind": 2, "name": "foobar", "parentSpanId": "", - "spanId": "00000000000000b4", - "startTimeUnixNano": "11651379494838206464", + "spanId": "0000000000000002", "status": { "code": 2 }, - "traceId": "000000000000009600000000000000a0" + "traceId": "00000000000000000000000000000001" } ] } diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index b6a992ad8ef..db33dfc5d83 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -28,7 +28,7 @@ import ( "github.com/jaegertracing/jaeger/cmd/query/app/apiv3" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" - querysvcv2 "github.com/jaegertracing/jaeger/cmd/query/app/querysvc/v2/querysvc" + v2querysvc "github.com/jaegertracing/jaeger/cmd/query/app/querysvc/v2/querysvc" "github.com/jaegertracing/jaeger/internal/proto/api_v3" "github.com/jaegertracing/jaeger/pkg/bearertoken" "github.com/jaegertracing/jaeger/pkg/netutils" @@ -59,7 +59,7 @@ type Server struct { func NewServer( ctx context.Context, querySvc *querysvc.QueryService, - v2QuerySvc *querysvcv2.QueryService, + v2QuerySvc *v2querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, @@ -84,7 +84,7 @@ func NewServer( return nil, err } registerGRPCHandlers(grpcServer, querySvc, v2QuerySvc, metricsQuerySvc, telset) - httpServer, err := createHTTPServer(ctx, querySvc, metricsQuerySvc, options, tm, telset) + httpServer, err := createHTTPServer(ctx, querySvc, v2QuerySvc, metricsQuerySvc, options, tm, telset) if err != nil { return nil, err } @@ -102,7 +102,7 @@ func NewServer( func registerGRPCHandlers( server *grpc.Server, querySvc *querysvc.QueryService, - v2QuerySvc *querysvcv2.QueryService, + v2QuerySvc *v2querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, telset telemetry.Settings, ) { @@ -167,6 +167,7 @@ var _ io.Closer = (*httpServer)(nil) func initRouter( querySvc *querysvc.QueryService, + v2QuerySvc *v2querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, queryOpts *QueryOptions, tenancyMgr *tenancy.Manager, @@ -187,7 +188,7 @@ func initRouter( } (&apiv3.HTTPGateway{ - QueryService: querySvc, + QueryService: v2QuerySvc, Logger: telset.Logger, Tracer: telset.TracerProvider, }).RegisterRoutes(r) @@ -209,12 +210,13 @@ func initRouter( func createHTTPServer( ctx context.Context, querySvc *querysvc.QueryService, + v2QuerySvc *v2querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, queryOpts *QueryOptions, tm *tenancy.Manager, telset telemetry.Settings, ) (*httpServer, error) { - handler, staticHandlerCloser := initRouter(querySvc, metricsQuerySvc, queryOpts, tm, telset) + handler, staticHandlerCloser := initRouter(querySvc, v2QuerySvc, metricsQuerySvc, queryOpts, tm, telset) handler = recoveryhandler.NewRecoveryHandler(telset.Logger, true)(handler) hs, err := queryOpts.HTTP.ToServer( ctx,