Skip to content

Commit

Permalink
update formatting settings
Browse files Browse the repository at this point in the history
  • Loading branch information
levkhomich committed Aug 16, 2017
1 parent ffde442 commit 2704d83
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 64 deletions.
Expand Up @@ -32,20 +32,17 @@ import scala.concurrent.ExecutionContext
trait BaseTracingDirectives {

/**
* Completes the request using the given function. The input to the function is
* produced with the in-scope entity unmarshaller and the result value of the
* function is marshalled with the in-scope marshaller. Unmarshalled entity is
* sampled for tracing and can be used thereafter to add trace annotations.
* RPC name is set to unmarshalled entity simple class name.
* After marshalling step, trace is automatically closed and sent to collector service.
* tracedHandleWith can be a convenient method combining entity with complete.
*
* @param service service name to be added to trace
*/
def tracedHandleWith[A <: TracingSupport, B](service: String)(f: A => B)
(implicit um: FromRequestUnmarshaller[A],
m: ToResponseMarshaller[B],
ec: ExecutionContext): Route = {
* Completes the request using the given function. The input to the function is
* produced with the in-scope entity unmarshaller and the result value of the
* function is marshalled with the in-scope marshaller. Unmarshalled entity is
* sampled for tracing and can be used thereafter to add trace annotations.
* RPC name is set to unmarshalled entity simple class name.
* After marshalling step, trace is automatically closed and sent to collector service.
* tracedHandleWith can be a convenient method combining entity with complete.
*
* @param service service name to be added to trace
*/
def tracedHandleWith[A <: TracingSupport, B](service: String)(f: A => B)(implicit um: FromRequestUnmarshaller[A], m: ToResponseMarshaller[B], ec: ExecutionContext): Route = {
tracedEntity(service)(um).tapply {
case Tuple1(ts) =>
StandardRoute { ctx =>
Expand Down Expand Up @@ -109,9 +106,7 @@ trait TracingDirectives extends BaseTracingDirectives { this: Actor with ActorTr
* and sent to collector service. tracedHandleWith can be a convenient method
* combining entity with complete.
*/
def tracedHandleWith[A <: TracingSupport, B](f: A => B)(implicit um: FromRequestUnmarshaller[A],
m: ToResponseMarshaller[B],
executionContext: ExecutionContext): Route =
def tracedHandleWith[A <: TracingSupport, B](f: A => B)(implicit um: FromRequestUnmarshaller[A], m: ToResponseMarshaller[B], executionContext: ExecutionContext): Route =
tracedHandleWith(self.path.name)(f)

}
Expand Up @@ -29,12 +29,11 @@ trait Specs2FrameworkInterface extends RouteTest with TestFrameworkInterface { t
}

implicit def um: FromRequestUnmarshaller[TestMessage] =
Unmarshaller { implicit ctx =>
request: HttpRequest =>
import scala.concurrent.duration._
request.entity.toStrict(FiniteDuration(100, MILLISECONDS)).map { v =>
TestMessage(v.toString)
}
Unmarshaller { implicit ctx => request: HttpRequest =>
import scala.concurrent.duration._
request.entity.toStrict(FiniteDuration(100, MILLISECONDS)).map { v =>
TestMessage(v.toString)
}
}

}
Expand Up @@ -68,7 +68,7 @@ class TracingDirectivesSpec extends Specification with TracingTestCommons
}

"annotate sampled requests (query params, headers)" in {
Get(Uri.from(path = testPath, queryString = Some("key=value"))).withHeaders(
Get(Uri.from(path = testPath, queryString = Some("key=value"))).withHeaders(
`Content-Encoding`(HttpEncodings.identity)
) ~> tracedHandleWithRoute ~> check {
response.status mustEqual StatusCodes.OK
Expand Down Expand Up @@ -115,9 +115,8 @@ class TracingDirectivesSpec extends Specification with TracingTestCommons

def testRejection(error: Exception, statusCode: StatusCode): MatchResult[_] = {
implicit def um: Unmarshaller[HttpRequest, TestMessage] =
Unmarshaller { ctx =>
request: HttpRequest =>
Future.failed(error)
Unmarshaller { ctx => request: HttpRequest =>
Future.failed(error)
}
val route =
handleRejections(RejectionHandler.default) {
Expand Down
5 changes: 3 additions & 2 deletions build.sbt
Expand Up @@ -49,7 +49,7 @@ lazy val `akka-tracing-http` = (project in file("akka-http")).settings(commonSet
libraryDependencies ++= Dependencies.http ++ Dependencies.test(scalaVersion.value)
).dependsOn(`akka-tracing-core` % passTestDeps)

lazy val commonSettings = projectInfo ++ compilationSettings ++ testSettings ++ publicationSettings ++ scalariformSettings
lazy val commonSettings = projectInfo ++ compilationSettings ++ testSettings ++ publicationSettings

lazy val compilationSettings =
Seq(
Expand Down Expand Up @@ -95,9 +95,10 @@ lazy val publicationSettings = Seq(
com.typesafe.sbt.SbtScalariform.ScalariformKeys.preferences := {
import scalariform.formatter.preferences._
FormattingPreferences()
.setPreference(AlignArguments, true)
.setPreference(AlignParameters, true)
.setPreference(DanglingCloseParenthesis, Preserve)
.setPreference(DoubleIndentClassDeclaration, true)
.setPreference(PreserveDanglingCloseParenthesis, true)
.setPreference(PreserveSpaceBeforeArguments, true)
}
)
Expand Down
Expand Up @@ -50,13 +50,13 @@ final case class SpanMetadata(traceId: Long, spanId: Long, parentId: Option[Long

object SpanMetadata {

private[this] val lookup: Array[Array[Char]] = (
private[this] val lookup: Array[Array[Char]] = {
for (b <- Short.MinValue to Short.MaxValue) yield {
val bb = if (b < 0) b - Short.MinValue * 2 else b
val s = "%04x".format(bb)
Array(s.charAt(0), s.charAt(1), s.charAt(2), s.charAt(3))
}
).toArray
}.toArray

private[this] def asChars(b: Long) =
lookup((b & 0xffff).toShort - Short.MinValue)
Expand Down
Expand Up @@ -57,9 +57,7 @@ class TracingExtensionImpl(system: ActorSystem) extends Extension {

system.actorOf(Props({
val holder = new SpanHolder()
val transport = new TFramedTransport(
new TSocket(config.getString(AkkaTracingHost), config.getInt(AkkaTracingPort))
)
val transport = new TFramedTransport(new TSocket(config.getString(AkkaTracingHost), config.getInt(AkkaTracingPort)))
val submitter = holder.context.actorOf(Props(classOf[SpanSubmitter], transport, maxSpansPerSecond), "spanSubmitter")
ActorPublisher(holder.self).subscribe(ActorSubscriber(submitter))
holder
Expand Down
Expand Up @@ -60,10 +60,8 @@ class PerformanceSpec extends Specification with TracingTestCommons
val actualCount = getSpanCount

val spansPerSecond = actualCount * 1000 / processingTime
println(
s"benchmark result: $spansPerSecond SPS, " +
s"${100 - actualCount * 100 / expectedCount}% dropped by backpressure"
)
println(s"benchmark result: $spansPerSecond SPS, " +
s"${100 - actualCount * 100 / expectedCount}% dropped by backpressure")

spansPerSecond * sampleRate must beGreaterThanOrEqualTo(ExpectedMPS.toLong)
}
Expand All @@ -87,9 +85,7 @@ class PerformanceSpec extends Specification with TracingTestCommons
case ((zt, zf), (t, f)) => (zt + t) -> (zf + f)
}

println(
s"benchmark result: ${time / ExpectedMPS} ns metadata availability, $failures retries"
)
println(s"benchmark result: ${time / ExpectedMPS} ns metadata availability, $failures retries")

failures mustEqual 0
}
Expand Down
Expand Up @@ -127,11 +127,8 @@ class SpanMetadataSpec extends Specification with TracingTestCommons {
"provide serialization interop with Brave" in {
def check(original: SpanMetadata): Unit = {
val serialized = original.toByteArray
val braveSerialized = new SpanId(
original.traceId,
original.parentId.getOrElse(original.spanId), original.spanId, original.flags
).bytes()
serialized shouldEqual braveSerialized
val brave = new SpanId(original.traceId, original.parentId.getOrElse(original.spanId), original.spanId, original.flags)
serialized shouldEqual brave.bytes()
}
for {
traceId <- LongValues
Expand All @@ -144,10 +141,7 @@ class SpanMetadataSpec extends Specification with TracingTestCommons {

"provide deserialization interop with Brave" in {
def check(original: SpanMetadata): Unit = {
val brave = new SpanId(
original.traceId,
original.parentId.getOrElse(original.spanId), original.spanId, original.flags
)
val brave = new SpanId(original.traceId, original.parentId.getOrElse(original.spanId), original.spanId, original.flags)
SpanMetadata.fromByteArray(brave.bytes()) match {
case None => failure
case Some(metadata) =>
Expand Down
Expand Up @@ -41,7 +41,7 @@ trait TracingTestCommons { this: SpecificationLike =>
def testConfig(sampleRate: Int = 1, settings: Map[String, AnyRef] = Map.empty, maxSpansPerSecond: Long = 10000L,
tracingHost: Option[String] = Some(DefaultTracingHost)): Config =
ConfigFactory.parseMap(scala.collection.JavaConversions.mapAsJavaMap(
Map(
settings ++ tracingHost.map(TracingExtension.AkkaTracingHost -> _).toMap ++ Map(
TracingExtension.AkkaTracingSampleRate -> sampleRate,
TracingExtension.AkkaTracingMaxSpansPerSecond -> maxSpansPerSecond,
TracingExtension.AkkaTracingPort -> (this match {
Expand All @@ -52,7 +52,7 @@ trait TracingTestCommons { this: SpecificationLike =>
}),
"akka.test.default-timeout" -> "2000 ms",
"akka.test.timefactor" -> (if (ciEnvironment) "4" else "1")
) ++ settings ++ tracingHost.map(TracingExtension.AkkaTracingHost -> _).toMap
)
))

def testActorSystem(sampleRate: Int = 1, settings: Map[String, AnyRef] = Map.empty, maxSpansPerSecond: Long = 10000L,
Expand Down
Expand Up @@ -33,7 +33,7 @@ class TReusableTransportSpec extends Specification {
val WriteBatchSize = 73
val ReadBatchSize = 91
val dataset = new Array[Byte](DatasetSize)
(0 until DatasetSize).foreach(dataset(_) = Random.nextInt.toByte)
(0 until DatasetSize).foreach(dataset(_)= Random.nextInt.toByte)

"not support open() and close()" in {
transport.open() must throwA[UnsupportedOperationException]
Expand Down
Expand Up @@ -61,7 +61,7 @@ class TracingFilter @Inject() (system: ActorSystem)(implicit ec: ExecutionContex
case Right(None) =>
case Right(Some(span)) =>
trace.sample(TracingAnnotations.ServerReceived, request.tracingId, span.spanId,
span.parentId, span.traceId, system.name, request.spanName, span.forceSampling)
span.parentId, span.traceId, system.name, request.spanName, span.forceSampling)
case Left(_) =>
trace.sample(request.tracingId, system.name, request.spanName)
}
Expand Down
Expand Up @@ -38,8 +38,7 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc

val configuration: Map[String, Any] = Map(
TracingExtension.AkkaTracingHost -> DefaultTracingHost,
TracingExtension.AkkaTracingPort -> collectorPort
)
TracingExtension.AkkaTracingPort -> collectorPort)
val TestPath = "/request"
val routes: PartialFunction[(String, String), Handler] = {
case ("GET", TestPath) =>
Expand Down Expand Up @@ -132,7 +131,9 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc
}

"honour upstream's Debug flag" in new WithApplication(disabledLocalSamplingApplication) {
val result = route(app, FakeRequest("GET", TestPath,
val result = route(app, FakeRequest(
"GET",
TestPath,
FakeHeaders(Seq(
TracingHeaders.Flags -> "1"
)), AnyContentAsEmpty)).map(Await.result(_, defaultAwaitTimeout.duration))
Expand All @@ -141,7 +142,9 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc
}

"user regular sampling if X-B3-Flags does not contain Debug flag" in new WithApplication(disabledLocalSamplingApplication) {
val result = route(app, FakeRequest("GET", TestPath,
val result = route(app, FakeRequest(
"GET",
TestPath,
FakeHeaders(Seq(
TracingHeaders.Flags -> "2"
)), AnyContentAsEmpty)).map(Await.result(_, defaultAwaitTimeout.duration))
Expand All @@ -150,7 +153,9 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc
}

"ignore malformed X-B3-Flags header" in new WithApplication(disabledLocalSamplingApplication) {
val result = route(app, FakeRequest("GET", TestPath,
val result = route(app, FakeRequest(
"GET",
TestPath,
FakeHeaders(Seq(
TracingHeaders.Flags -> "malformed"
)), AnyContentAsEmpty)).map(Await.result(_, defaultAwaitTimeout.duration))
Expand All @@ -159,7 +164,9 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc
}

"ignore malformed X-B3-TraceId header" in new WithApplication(fakeApplication) {
val result = route(app, FakeRequest("GET", TestPath,
val result = route(app, FakeRequest(
"GET",
TestPath,
FakeHeaders(Seq(
TracingHeaders.TraceId -> "malformed"
)), AnyContentAsEmpty)).map(Await.result(_, defaultAwaitTimeout.duration))
Expand All @@ -170,7 +177,9 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc
"ignore malformed X-B3-SpanId header" in new WithApplication(fakeApplication) {
val traceId = Random.nextLong

val result = route(app, FakeRequest("GET", TestPath,
val result = route(app, FakeRequest(
"GET",
TestPath,
FakeHeaders(Seq(
TracingHeaders.TraceId -> SpanMetadata.idToString(traceId),
TracingHeaders.SpanId -> "malformed"
Expand All @@ -183,7 +192,9 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc
"ignore malformed X-B3-ParentSpanId header" in new WithApplication(fakeApplication) {
val traceId = Random.nextLong

val result = route(app, FakeRequest("GET", TestPath,
val result = route(app, FakeRequest(
"GET",
TestPath,
FakeHeaders(Seq(
TracingHeaders.TraceId -> SpanMetadata.idToString(traceId),
TracingHeaders.ParentSpanId -> "malformed"
Expand Down
3 changes: 2 additions & 1 deletion project/Dependencies.scala
Expand Up @@ -6,6 +6,7 @@ object Dependencies {
val AkkaVersion = "2.4.17"
val AkkaHttpVersion = "10.0.5"

// format: OFF
object Compile {
val akkaActor = "com.typesafe.akka" %% "akka-actor" % AkkaVersion
val akkaAgent = "com.typesafe.akka" %% "akka-agent" % AkkaVersion
Expand Down Expand Up @@ -35,7 +36,7 @@ object Dependencies {

def test(scalaVersion: String): Seq[ModuleID] =
Seq(Test.specs, Test.finagle, Test.braveCore, Test.akkaTest,
Test.akkaHttpTest, Test.akkaRemote, Test.akkaSlf4j, Test.logback)
Test.akkaHttpTest, Test.akkaRemote, Test.akkaSlf4j, Test.logback)

def testPlay(scalaVersion: String): Seq[ModuleID] =
test(scalaVersion) :+ Test.playSpecs2
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Expand Up @@ -8,4 +8,4 @@ addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.1.0")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.7")

addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0")
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.0")

0 comments on commit 2704d83

Please sign in to comment.