Skip to content

Commit

Permalink
Fix result wrapping
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay committed Jun 17, 2021
1 parent 6a23519 commit b558778
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 11 additions & 8 deletions cmd/query/app/otel/grpc_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package otel

import (
"bytes"
"encoding/json"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -79,16 +80,18 @@ func TestGRPCGateway(t *testing.T) {
_, err = buf.ReadFrom(response.Body)
require.NoError(t, err)

// The streaming API wraps response objects into '{"result": ...}'
// This has to be removed if we want to parse it into SpansResponseChunk
str := buf.Bytes()[14:]
str = str[:len(str)-2]

var spansResponse api_v3.SpansResponseChunk
jsonpb := &JSONPb{}
err = jsonpb.Unmarshal(str, &spansResponse)
var w resultWrapper
err = json.Unmarshal(buf.Bytes(), &w)
require.NoError(t, err)
var spansResponse api_v3.SpansResponseChunk
err = jsonpb.Unmarshal(w.Result, spansResponse)
require.NoError(t, err)
assert.Equal(t, 1, len(spansResponse.GetResourceSpans()))
assert.Equal(t, uint64ToTraceID(traceID.High, traceID.Low), spansResponse.GetResourceSpans()[0].GetInstrumentationLibrarySpans()[0].GetSpans()[0].TraceId.Bytes())
fmt.Println(response)
}

// see https://github.com/grpc-ecosystem/grpc-gateway/issues/2189
type resultWrapper struct {
Result json.RawMessage `json:"result"`
}
2 changes: 2 additions & 0 deletions proto-gen/api_v3/query_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto-gen/api_v3/query_service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
"title": "OTLP resource spans\nsee https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto"
}
},
"description": "A single response chunk holds a single trace."
"description": "A single response chunk holds a single trace.\nNote that a subsequent request to get a trace might return a different result\nbecause spans are reported in asynchronous chunks."
},
"api_v3TraceQueryParameters": {
"type": "object",
Expand Down

0 comments on commit b558778

Please sign in to comment.