Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[split] [Fix/Resubmit] Flush span in finagle if timeout occurs

Flush span in finagle if timeout occurs. Resubmitted to
fix typo
  • Loading branch information...
commit 64e6310268ea9124182b2e68b0ab0cc86210bddf 1 parent 6b761a9
Franklin Hu authored
5 finagle-b3/src/main/scala/com/twitter/finagle/b3/thrift/BigBrotherBirdTracer.scala
View
@@ -17,6 +17,7 @@ import com.twitter.finagle.thrift.{ThriftClientFramedCodec, ThriftClientRequest,
import collection.mutable.{ArrayBuffer, HashMap, SynchronizedMap}
import scala.collection.JavaConversions._
import com.twitter.finagle.{Service, SimpleFilter, tracing}
+import com.twitter.finagle.service.TimeoutFilter
object BigBrotherBirdTracer {
// to make sure we only create one instance of the tracer
@@ -168,7 +169,9 @@ private[thrift] class BigBrotherBirdTracer(
// if either two "end annotations" exists we send off the span
if (span.annotations.exists { a =>
- a.value.equals(thrift.Constants.CLIENT_RECV) || a.value.equals(thrift.Constants.SERVER_SEND)
+ a.value.equals(thrift.Constants.CLIENT_RECV) ||
+ a.value.equals(thrift.Constants.SERVER_SEND) ||
+ a.value.equals(TimeoutFilter.TimeoutAnnotation)
}) {
spanMap.remove(traceId)
logSpan(span)
20 finagle-b3/src/test/scala/com/twitter/finagle/b3/thrift/BigBrotherBirdTracerSpec.scala
View
@@ -12,6 +12,7 @@ import com.twitter.finagle.stats.{StatsReceiver, NullStatsReceiver}
import org.mockito.Matchers._
import java.nio.ByteBuffer
import java.net.{InetAddress, InetSocketAddress}
+import com.twitter.finagle.service.TimeoutFilter
object BigBrotherBirdTracerSpec extends Specification with Mockito {
@@ -91,5 +92,24 @@ object BigBrotherBirdTracerSpec extends Specification with Mockito {
// tracer.release() should set client to null
tracer.client must beNull
}
+
+ "logSpan if a timeout occurs" in {
+ val ann1 = Annotation.Message("some_message")
+ val ann2 = Annotation.Rpcname("some_service", "rpc_name")
+ val ann3 = Annotation.Message(TimeoutFilter.TimeoutAnnotation)
+
+ val tracer = new BigBrotherBirdTracer("localhost", 1463, NullStatsReceiver, 1)
+ tracer.client = mock[scribe.ServiceToClient]
+
+ tracer.client.Log(anyObject()) returns Future(ResultCode.OK)
+
+ Timer.default.acquire()
+ tracer.record(Record(traceId, Time.fromSeconds(1), ann1))
+ tracer.record(Record(traceId, Time.fromSeconds(2), ann2))
+ tracer.record(Record(traceId, Time.fromSeconds(3), ann3))
+
+ // scribe Log method is in java
+ there was one(tracer.client).Log(any[java.util.List[LogEntry]])
+ }
}
}
6 finagle-core/src/main/scala/com/twitter/finagle/service/TimeoutFilter.scala
View
@@ -24,8 +24,12 @@ class TimeoutFilter[Req, Rep](
res.within(timer, timeout) rescue {
case _: java.util.concurrent.TimeoutException =>
res.cancel()
- Trace.record("finagle.timeout")
+ Trace.record(TimeoutFilter.TimeoutAnnotation)
Future.exception(exception)
}
}
}
+
+object TimeoutFilter {
+ val TimeoutAnnotation = "finagle.timeout"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.