-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ExpensiveEndpoints and test files #58
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
zipkin-hadoop/src/main/scala/com/twitter/zipkin/hadoop/ExpensiveEndpoints.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,64 @@ | ||
/* | ||
* 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.hadoop | ||
|
||
import com.twitter.zipkin.gen.{Constants, SpanServiceName, Annotation} | ||
import cascading.pipe.joiner.LeftJoin | ||
import com.twitter.scalding.{Tsv, DefaultDateRangeJob, Job, Args} | ||
import sources.{PrepTsvSource, Util, PreprocessedSpanSource} | ||
|
||
/** | ||
* Per service call (i.e. pair of services), finds the average run time (in microseconds) of that service call | ||
*/ | ||
class ExpensiveEndpoints(args : Args) extends Job(args) with DefaultDateRangeJob { | ||
|
||
val spanInfo = PreprocessedSpanSource() | ||
.read | ||
.mapTo(0 -> ('id, 'parent_id, 'cService, 'service, 'annotations)) | ||
{ s: SpanServiceName => (s.id, s.parent_id, s.client_service, s.service_name, s.annotations.toList) } | ||
.flatMap('annotations -> 'duration) { | ||
al : List[Annotation] => { | ||
var clientSend : Option[Annotation] = None | ||
var clientReceive : Option[Annotation] = None | ||
var serverReceive : Option[Annotation] = None | ||
var serverSend : Option[Annotation] = None | ||
al.foreach( { | ||
a : Annotation => { | ||
if (a.getHost != null) { | ||
if (Constants.CLIENT_SEND.equals(a.value)) clientSend = Some(a) | ||
else if (Constants.CLIENT_RECV.equals(a.value)) clientReceive = Some(a) | ||
else if (Constants.SERVER_RECV.equals(a.value)) serverReceive = Some(a) | ||
else if (Constants.SERVER_SEND.equals(a.value)) serverSend = Some(a) | ||
} | ||
} | ||
}) | ||
val clientDuration = for (cs <- clientSend; cr <- clientReceive) yield (cr.timestamp - cs.timestamp) | ||
val serverDuration = for (sr <- serverReceive; ss <- serverSend) yield (ss.timestamp - sr.timestamp) | ||
// to deal with the case where there is no server duration | ||
if (clientDuration == None) serverDuration else clientDuration | ||
} | ||
} | ||
|
||
val idName = PrepTsvSource() | ||
.read | ||
/* Join with the original on parent ID to get the parent's service name */ | ||
val spanInfoWithParent = spanInfo | ||
.filter('parent_id){ id : Long => id != 0 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to use the Thrift isSetParent_id (or whatever it is called) here instead? As mentioned the id !=0 is fine as a hack, but if possible we should figure out the correct solution. |
||
.joinWithSmaller('parent_id -> 'id_1, idName) | ||
.groupBy('name_1, 'service){ _.average('duration) } | ||
.write(Tsv(args("output"))) | ||
} |
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
77 changes: 77 additions & 0 deletions
77
zipkin-hadoop/src/test/scala/com/twitter/zipkin/hadoop/ExpensiveEndpointsSpec.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,77 @@ | ||
/* | ||
* 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.hadoop | ||
|
||
import org.specs.Specification | ||
import com.twitter.zipkin.gen | ||
import com.twitter.scalding._ | ||
import com.twitter.zipkin.gen | ||
import gen.AnnotationType | ||
import scala.collection.JavaConverters._ | ||
import collection.mutable.HashMap | ||
import com.twitter.scalding.TupleConversions | ||
import com.twitter.scalding.DateRange | ||
import com.twitter.scalding.RichDate | ||
import com.twitter.zipkin.gen.AnnotationType | ||
import com.twitter.scalding.JobTest | ||
import com.twitter.scalding.Tsv | ||
import sources.{PrepTsvSource, PreprocessedSpanSource, Util} | ||
|
||
/** | ||
* Tests that ExpensiveEndpointSpec finds the average run time of each service | ||
*/ | ||
|
||
class ExpensiveEndpointsSpec extends Specification with TupleConversions { | ||
noDetailedDiffs() | ||
|
||
implicit val dateRange = DateRange(RichDate(123), RichDate(321)) | ||
|
||
val endpoint = new gen.Endpoint(123, 666, "service") | ||
val endpoint1 = new gen.Endpoint(123, 666, "service1") | ||
val endpoint2 = new gen.Endpoint(123, 666, "service2") | ||
val span = new gen.SpanServiceName(12345, "methodcall", 666, | ||
List(new gen.Annotation(2000, "sr").setHost(endpoint), new gen.Annotation(3000, "ss").setHost(endpoint)).asJava, | ||
List[gen.BinaryAnnotation]().asJava, "service", "service") | ||
val span1 = new gen.SpanServiceName(123456, "methodcall", 666, | ||
List(new gen.Annotation(1000, "cs").setHost(endpoint2), new gen.Annotation(1500, "sr").setHost(endpoint2), new gen.Annotation(4500, "ss").setHost(endpoint2), new gen.Annotation(5000, "cr").setHost(endpoint2)).asJava, | ||
List(new gen.BinaryAnnotation("bye", null, AnnotationType.BOOL)).asJava, "service2", "service2") | ||
|
||
val spans = Util.repeatSpan(span, 30, 40, -1) ++ Util.repeatSpan(span1, 30, 100, 40) | ||
|
||
"ExpensiveEndpoints" should { | ||
"Return the most common service calls" in { | ||
JobTest("com.twitter.zipkin.hadoop.ExpensiveEndpoints"). | ||
arg("input", "inputFile"). | ||
arg("output", "outputFile"). | ||
arg("date", "2012-01-01T01:00"). | ||
source(PreprocessedSpanSource(), spans). | ||
source(PrepTsvSource(), Util.getSpanIDtoNames(spans)). | ||
sink[(String, String, Long)](Tsv("outputFile")) { | ||
val result = new HashMap[String, Long]() | ||
result("service, service2") = 0 | ||
outputBuffer => outputBuffer foreach { e => | ||
println(e) | ||
result(e._1 + ", " + e._2) = e._3 | ||
} | ||
// result("Unknown Service Name") mustEqual 3000 | ||
// result("service") mustEqual 2000 | ||
// result("service2") mustEqual 3000 | ||
result("service, service2") mustEqual 4000 | ||
} | ||
}.run.finish | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our code style is to have this on the above line. I know that's slightly different from what IntelliJ reformats to but let's try to stick to our version.