-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports reading multiple spans per Kafka message
Kafka messages have binary payloads and no key. The binary contents are serialized TBinaryProtocol thrift messages. This change peeks at thei first bytes to see if it is a List of structs or not, reading accordingly. This approach would need a revision if we ever add a Struct field to Span. However, that is unlikely. At the point we change the structure of Span, we'd likely change other aspects which would make it a different struct completely (see #939). In such case, we'd add a key to the kafka message of the span version, and not hit the code affected in this change. Fixes #979
- Loading branch information
Adrian Cole
committed
Feb 23, 2016
1 parent
95c017e
commit 6f5a378
Showing
5 changed files
with
74 additions
and
36 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
27 changes: 0 additions & 27 deletions
27
zipkin-receiver-kafka/src/main/scala/com/twitter/zipkin/receiver/kafka/SpanCodec.scala
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
zipkin-receiver-kafka/src/main/scala/com/twitter/zipkin/receiver/kafka/SpanDecoder.scala
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,23 @@ | ||
package com.twitter.zipkin.receiver.kafka | ||
|
||
import com.twitter.scrooge.BinaryThriftStructSerializer | ||
import com.twitter.zipkin.conversions.thrift | ||
import com.twitter.zipkin.thriftscala.{Span => ThriftSpan} | ||
import org.apache.thrift.protocol.TType | ||
|
||
class SpanDecoder extends KafkaProcessor.KafkaDecoder { | ||
val deserializer = new BinaryThriftStructSerializer[ThriftSpan] { | ||
def codec = ThriftSpan | ||
} | ||
|
||
// Given the thrift encoding is TBinaryProtocol.. | ||
// .. When serializing a Span (Struct), the first byte will be the type of a field | ||
// .. When serializing a List[ThriftSpan], the first byte is the member type, TType.STRUCT | ||
// Span has no STRUCT fields: we assume that if the first byte is TType.STRUCT is a list. | ||
def fromBytes(bytes: Array[Byte]) = | ||
if (bytes(0) == TType.STRUCT) { | ||
thrift.thriftListToThriftSpans(bytes) | ||
} else { | ||
List(deserializer.fromBytes(bytes)) | ||
} | ||
} |
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