-
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.
Modularize remaining collector Scribe dependencies
This change makes it easier to extend the collector to accept different input types. Doing so would only require writing an `Adapter` and a `ProcessFilter`. Changes: - Add `ProcessorFilter` - Composable filter on top of `Processor`s that can transform the input data type - Move all deserialization and extraction of data from `CollectorService` and `WriteQueueWorker` to Scribe related `ProcessFilter` and `Processor`. - `WriteQueueWorker` now takes only one `Processor` rather than a sequence of them. - Add `FanoutProcessor` to blast work to multiple `Processor`s - Update README with module diagram Author: @franklinhu Pull Request: #31 URL: #31
- Loading branch information
Franklin Hu
committed
Jun 14, 2012
1 parent
0a3d75e
commit 9e5c223
Showing
25 changed files
with
486 additions
and
137 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
File renamed without changes.
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
63 changes: 63 additions & 0 deletions
63
...-scribe/src/main/scala/com/twitter/zipkin/collector/processor/ScribeProcessorFilter.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,63 @@ | ||
/* | ||
* Copyright 2012 Twitter 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 com.twitter.zipkin.collector.processor | ||
|
||
import com.twitter.logging.Logger | ||
import com.twitter.ostrich.stats.Stats | ||
import com.twitter.scrooge.BinaryThriftStructSerializer | ||
import com.twitter.zipkin.adapter.ThriftAdapter | ||
import com.twitter.zipkin.common.Span | ||
import com.twitter.zipkin.gen | ||
|
||
/** | ||
* Transforms a `Seq[gen.LogEntry]` to `Seq[Span]` for a collector service to consume. | ||
* Assumes: | ||
* - the Scribe struct contains a `message` that is the Base64 encoded Thrift Span struct. | ||
* - the sequence of `LogEntry`s only contains messages we want to pass on (already filtered | ||
* by category) | ||
*/ | ||
class ScribeProcessorFilter extends ProcessorFilter[Seq[gen.LogEntry], Seq[Span]] { | ||
|
||
private val log = Logger.get | ||
|
||
val deserializer = new BinaryThriftStructSerializer[gen.Span] { | ||
def codec = gen.Span | ||
} | ||
|
||
def apply(logEntries: Seq[gen.LogEntry]): Seq[Span] = { | ||
logEntries.map { | ||
_.`message` | ||
}.flatMap { | ||
msg => | ||
try { | ||
val span = Stats.time("deserializeSpan") { | ||
deserializer.fromString(msg) | ||
} | ||
log.ifDebug("Processing span: " + span + " from " + msg) | ||
Some(ThriftAdapter(span)) | ||
} catch { | ||
case e: Exception => { | ||
// scribe doesn't have any ResultCode.ERROR or similar | ||
// let's just swallow this invalid msg | ||
log.warning(e, "Invalid msg: %s", msg) | ||
Stats.incr("collector.invalid_msg") | ||
None | ||
} | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
zipkin-scribe/src/main/scala/com/twitter/zipkin/config/ScribeZipkinCollectorConfig.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 |
---|---|---|
@@ -1,7 +1,28 @@ | ||
/* | ||
* Copyright 2012 Twitter 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 com.twitter.zipkin.config | ||
|
||
import com.twitter.zipkin.collector.processor.ScribeProcessorFilter | ||
import com.twitter.zipkin.config.collector.CollectorServerConfig | ||
import com.twitter.zipkin.gen | ||
|
||
trait ScribeZipkinCollectorConfig extends ZipkinCollectorConfig { | ||
type T = Seq[gen.LogEntry] | ||
val serverConfig: CollectorServerConfig = new ScribeCollectorServerConfig(this) | ||
|
||
def rawDataFilter = new ScribeProcessorFilter | ||
} |
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
55 changes: 55 additions & 0 deletions
55
...ibe/src/test/scala/com/twitter/zipkin/collector/processor/ScribeProcessorFilterSpec.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,55 @@ | ||
/* | ||
* Copyright 2012 Twitter 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 com.twitter.zipkin.collector.processor | ||
|
||
import com.twitter.scrooge.BinaryThriftStructSerializer | ||
import com.twitter.zipkin.adapter.ThriftAdapter | ||
import com.twitter.zipkin.common.{Annotation, Span} | ||
import com.twitter.zipkin.gen | ||
import org.specs.Specification | ||
|
||
class ScribeProcessorFilterSpec extends Specification { | ||
val serializer = new BinaryThriftStructSerializer[gen.Span] { | ||
def codec = gen.Span | ||
} | ||
|
||
"ScribeProcessorFilter" should { | ||
val category = "zipkin" | ||
|
||
val base64 = "CgABAAAAAAAAAHsLAAMAAAADYm9vCgAEAAAAAAAAAcgPAAYMAAAAAQoAAQAAAAAAAAABCwACAAAAA2JhaAAPAAgMAAAAAAA=" | ||
|
||
val validSpan = Span(123, "boo", 456, None, List(new Annotation(1, "bah", None)), Nil) | ||
val serialized = serializer.toString(ThriftAdapter(validSpan)) | ||
|
||
val base64LogEntries = Seq(gen.LogEntry(category, base64)) | ||
val serializedLogEntries = Seq(gen.LogEntry(category, serialized)) | ||
|
||
val badLogEntries = Seq(gen.LogEntry(category, "garbage!")) | ||
val filter = new ScribeProcessorFilter | ||
|
||
"convert gen.LogEntry to Span" in { | ||
filter.apply(base64LogEntries) mustEqual Seq(validSpan) | ||
} | ||
|
||
"convert serialized thrift to Span" in { | ||
filter.apply(serializedLogEntries) mustEqual Seq(validSpan) | ||
} | ||
|
||
"deal with garbage" in { | ||
filter.apply(badLogEntries) mustEqual Seq.empty[Span] | ||
} | ||
} | ||
} |
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.