Skip to content

Commit

Permalink
Change zipkin translator to not use consumerdata (#2509)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Feb 19, 2021
1 parent dba4edb commit ba720d8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
29 changes: 29 additions & 0 deletions translator/trace/zipkin/consumerdata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package zipkin

import (
commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
)

// traceData helper struct for zipkin conversion.
// TODO: Remove this when zipkin translates directly to pdata.
type traceData struct {
Node *commonpb.Node
Resource *resourcepb.Resource
Spans []*tracepb.Span
}
3 changes: 1 addition & 2 deletions translator/trace/zipkin/zipkinv1_thrift_to_protospan.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ import (
"github.com/jaegertracing/jaeger/thrift-gen/zipkincore"
"google.golang.org/protobuf/types/known/timestamppb"

"go.opentelemetry.io/collector/consumer/consumerdata"
tracetranslator "go.opentelemetry.io/collector/translator/trace"
)

// v1ThriftBatchToOCProto converts Zipkin v1 spans to OC Proto.
func v1ThriftBatchToOCProto(zSpans []*zipkincore.Span) ([]consumerdata.TraceData, error) {
func v1ThriftBatchToOCProto(zSpans []*zipkincore.Span) ([]traceData, error) {
ocSpansAndParsedAnnotations := make([]ocSpanAndParsedAnnotations, 0, len(zSpans))
for _, zSpan := range zSpans {
ocSpan, parsedAnnotations := zipkinV1ThriftToOCSpan(zSpan)
Expand Down
13 changes: 6 additions & 7 deletions translator/trace/zipkin/zipkinv1_to_protospan.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/jaegertracing/jaeger/thrift-gen/zipkincore"
"google.golang.org/protobuf/types/known/timestamppb"

"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/consumer/pdata"
tracetranslator "go.opentelemetry.io/collector/translator/trace"
)
Expand Down Expand Up @@ -86,7 +85,7 @@ type binaryAnnotation struct {
}

// v1JSONBatchToOCProto converts a JSON blob with a list of Zipkin v1 spans to OC Proto.
func v1JSONBatchToOCProto(blob []byte, parseStringTags bool) ([]consumerdata.TraceData, error) {
func v1JSONBatchToOCProto(blob []byte, parseStringTags bool) ([]traceData, error) {
var zSpans []*zipkinV1Span
if err := json.Unmarshal(blob, &zSpans); err != nil {
return nil, fmt.Errorf("%s: %w", msgZipkinV1JSONUnmarshalError, err)
Expand All @@ -113,15 +112,15 @@ type ocSpanAndParsedAnnotations struct {
parsedAnnotations *annotationParseResult
}

func zipkinToOCProtoBatch(ocSpansAndParsedAnnotations []ocSpanAndParsedAnnotations) ([]consumerdata.TraceData, error) {
func zipkinToOCProtoBatch(ocSpansAndParsedAnnotations []ocSpanAndParsedAnnotations) ([]traceData, error) {
// Service to batch maps the service name to the trace request with the corresponding node.
svcToTD := make(map[string]*consumerdata.TraceData)
svcToTD := make(map[string]*traceData)
for _, curr := range ocSpansAndParsedAnnotations {
req := getOrCreateNodeRequest(svcToTD, curr.parsedAnnotations.Endpoint)
req.Spans = append(req.Spans, curr.ocSpan)
}

tds := make([]consumerdata.TraceData, 0, len(svcToTD))
tds := make([]traceData, 0, len(svcToTD))
for _, v := range svcToTD {
tds = append(tds, *v)
}
Expand Down Expand Up @@ -448,7 +447,7 @@ func epochMicrosecondsToTimestamp(msecs int64) *timestamppb.Timestamp {
return t
}

func getOrCreateNodeRequest(m map[string]*consumerdata.TraceData, endpoint *endpoint) *consumerdata.TraceData {
func getOrCreateNodeRequest(m map[string]*traceData, endpoint *endpoint) *traceData {
// this private function assumes that the caller never passes an nil endpoint
nodeKey := endpoint.string()
req := m[nodeKey]
Expand All @@ -457,7 +456,7 @@ func getOrCreateNodeRequest(m map[string]*consumerdata.TraceData, endpoint *endp
return req
}

req = &consumerdata.TraceData{
req = &traceData{
Node: &commonpb.Node{
ServiceInfo: &commonpb.ServiceInfo{Name: endpoint.ServiceName},
},
Expand Down
9 changes: 4 additions & 5 deletions translator/trace/zipkin/zipkinv1_to_protospan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/timestamppb"

"go.opentelemetry.io/collector/consumer/consumerdata"
tracetranslator "go.opentelemetry.io/collector/translator/trace"
)

Expand Down Expand Up @@ -174,8 +173,8 @@ func TestMultipleJSONV1BatchesToOCProto(t *testing.T) {
err = json.Unmarshal(blob, &batches)
require.NoError(t, err, "Failed to load the batches")

nodeToTraceReqs := make(map[string]*consumerdata.TraceData)
var got []consumerdata.TraceData
nodeToTraceReqs := make(map[string]*traceData)
var got []traceData
for _, batch := range batches {
jsonBatch, err := json.Marshal(batch)
require.NoError(t, err, "Failed to marshal interface back to blob")
Expand Down Expand Up @@ -209,7 +208,7 @@ func TestMultipleJSONV1BatchesToOCProto(t *testing.T) {
}
}

func sortTraceByNodeName(trace []consumerdata.TraceData) {
func sortTraceByNodeName(trace []traceData) {
sort.Slice(trace, func(i, j int) bool {
return trace[i].Node.ServiceInfo.Name < trace[j].Node.ServiceInfo.Name
})
Expand Down Expand Up @@ -581,7 +580,7 @@ func TestJSONHTTPToGRPCStatusCode(t *testing.T) {

// ocBatches has the OpenCensus proto batches used in the test. They are hard coded because
// structs like tracepb.AttributeMap cannot be ready from JSON.
var ocBatchesFromZipkinV1 = []consumerdata.TraceData{
var ocBatchesFromZipkinV1 = []traceData{
{
Node: &commonpb.Node{
ServiceInfo: &commonpb.ServiceInfo{Name: "front-proxy"},
Expand Down

0 comments on commit ba720d8

Please sign in to comment.