-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Zipkin Thrift as kafka ingestion format (#1256)
* Add Zipkin Thrift as kafka ingestion format Signed-off-by: Geoffrey Beausire <[email protected]> * Fix order import and lint Signed-off-by: Geoffrey Beausire <[email protected]> * Refactor the encoding definition Signed-off-by: Geoffrey Beausire <[email protected]> * Refacto and implement tests Signed-off-by: Geoffrey Beausire <[email protected]> * Improving marshaller testing Signed-off-by: Geoffrey Beausire <[email protected]> * Improving deserializer testing Signed-off-by: Geoffrey Beausire <[email protected]>
- Loading branch information
1 parent
8f809ed
commit d23d18f
Showing
11 changed files
with
190 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// 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 ( | ||
"github.com/apache/thrift/lib/go/thrift" | ||
|
||
"github.com/jaegertracing/jaeger/thrift-gen/zipkincore" | ||
) | ||
|
||
// Function used for testing purposes | ||
func ZipkinSerialize(spans []*zipkincore.Span) []byte { | ||
t := thrift.NewTMemoryBuffer() | ||
p := thrift.NewTBinaryProtocolTransport(t) | ||
p.WriteListBegin(thrift.STRUCT, len(spans)) | ||
for _, s := range spans { | ||
s.Write(p) | ||
} | ||
p.WriteListEnd() | ||
return t.Buffer.Bytes() | ||
} | ||
|
||
func DeserializeThrift(b []byte) ([]*zipkincore.Span, error) { | ||
buffer := thrift.NewTMemoryBuffer() | ||
buffer.Write(b) | ||
|
||
transport := thrift.NewTBinaryProtocolTransport(buffer) | ||
_, size, err := transport.ReadListBegin() // Ignore the returned element type | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// We don't depend on the size returned by ReadListBegin to preallocate the array because it | ||
// sometimes returns a nil error on bad input and provides an unreasonably large int for size | ||
var spans []*zipkincore.Span | ||
for i := 0; i < size; i++ { | ||
zs := &zipkincore.Span{} | ||
if err = zs.Read(transport); err != nil { | ||
return nil, err | ||
} | ||
spans = append(spans, zs) | ||
} | ||
|
||
return spans, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// 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 ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/jaegertracing/jaeger/thrift-gen/zipkincore" | ||
) | ||
|
||
func TestDeserializeWithBadListStart(t *testing.T) { | ||
spanBytes := ZipkinSerialize([]*zipkincore.Span{{}}) | ||
_, err := DeserializeThrift(append([]byte{0, 255, 255}, spanBytes...)) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestDeserializeWithCorruptedList(t *testing.T) { | ||
spanBytes := ZipkinSerialize([]*zipkincore.Span{{}}) | ||
spanBytes[2] = 255 | ||
_, err := DeserializeThrift(spanBytes) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestDeserialize(t *testing.T) { | ||
spanBytes := ZipkinSerialize([]*zipkincore.Span{{}}) | ||
_, err := DeserializeThrift(spanBytes) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.