aboutsummaryrefslogtreecommitdiff
path: root/kamon-spray/src/test/scala/kamon/spray
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2014-07-29 00:56:39 -0300
committerIvan Topolnjak <ivantopo@gmail.com>2014-07-29 00:56:39 -0300
commit96f31cbac82bf350db61e4b48ea95bb2706cc02b (patch)
tree482a479a898e77f2484a48daeafae962613bd468 /kamon-spray/src/test/scala/kamon/spray
parentec97bccd2346aa8c50997ec1f198a5eb6c79eab5 (diff)
parente83babb5f88e91661bec2f1013fcb6b03612bea9 (diff)
downloadKamon-96f31cbac82bf350db61e4b48ea95bb2706cc02b.tar.gz
Kamon-96f31cbac82bf350db61e4b48ea95bb2706cc02b.tar.bz2
Kamon-96f31cbac82bf350db61e4b48ea95bb2706cc02b.zip
Merge branch 'master' into release-0.3_scala-2.11
Conflicts: .travis.yml project/Settings.scala
Diffstat (limited to 'kamon-spray/src/test/scala/kamon/spray')
-rw-r--r--kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala15
-rw-r--r--kamon-spray/src/test/scala/kamon/spray/SprayServerMetricsSpec.scala91
-rw-r--r--kamon-spray/src/test/scala/kamon/spray/SprayServerTracingSpec.scala (renamed from kamon-spray/src/test/scala/kamon/spray/ServerRequestInstrumentationSpec.scala)40
-rw-r--r--kamon-spray/src/test/scala/kamon/spray/TestServer.scala11
4 files changed, 107 insertions, 50 deletions
diff --git a/kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala b/kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala
index 9469924a..54329645 100644
--- a/kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala
+++ b/kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala
@@ -26,13 +26,12 @@ import com.typesafe.config.ConfigFactory
import spray.can.Http
import spray.http.HttpHeaders.RawHeader
import kamon.Kamon
-import kamon.metrics.{ TraceMetrics, Metrics }
+import kamon.metric.{ TraceMetrics, Metrics }
import spray.client.pipelining
-import kamon.metrics.Subscriptions.TickMetricSnapshot
-import spray.can.client.ClientRequestInstrumentation
+import kamon.metric.Subscriptions.TickMetricSnapshot
import scala.concurrent.duration._
import akka.pattern.pipe
-import kamon.metrics.TraceMetrics.TraceMetricSnapshot
+import kamon.metric.TraceMetrics.{ HttpClientRequest, TraceMetricsSnapshot }
class ClientRequestInstrumentationSpec extends TestKitBase with WordSpecLike with Matchers with RequestBuilding with TestServer {
implicit lazy val system: ActorSystem = ActorSystem("client-request-instrumentation-spec", ConfigFactory.parseString(
@@ -149,7 +148,7 @@ class ClientRequestInstrumentationSpec extends TestKitBase with WordSpecLike wit
val traceMetrics = expectTraceMetrics("pipelining-strategy-client-request", metricListener, 3 seconds)
traceMetrics.elapsedTime.numberOfMeasurements should be(1L)
traceMetrics.segments should not be empty
- val recordedSegment = traceMetrics.segments.find { case (k, v) ⇒ k.tag == ClientRequestInstrumentation.UserTime } map (_._2)
+ val recordedSegment = traceMetrics.segments.find { case (k, v) ⇒ k.isInstanceOf[HttpClientRequest] } map (_._2)
recordedSegment should not be empty
recordedSegment map { segmentMetrics ⇒
segmentMetrics.numberOfMeasurements should be(1L)
@@ -190,7 +189,7 @@ class ClientRequestInstrumentationSpec extends TestKitBase with WordSpecLike wit
val traceMetrics = expectTraceMetrics("internal-strategy-client-request", metricListener, 3 seconds)
traceMetrics.elapsedTime.numberOfMeasurements should be(1L)
traceMetrics.segments should not be empty
- val recordedSegment = traceMetrics.segments.find { case (k, v) ⇒ k.tag == ClientRequestInstrumentation.SprayTime } map (_._2)
+ val recordedSegment = traceMetrics.segments.find { case (k, v) ⇒ k.isInstanceOf[HttpClientRequest] } map (_._2)
recordedSegment should not be empty
recordedSegment map { segmentMetrics ⇒
segmentMetrics.numberOfMeasurements should be(1L)
@@ -199,14 +198,14 @@ class ClientRequestInstrumentationSpec extends TestKitBase with WordSpecLike wit
}
}
- def expectTraceMetrics(traceName: String, listener: TestProbe, timeout: FiniteDuration): TraceMetricSnapshot = {
+ def expectTraceMetrics(traceName: String, listener: TestProbe, timeout: FiniteDuration): TraceMetricsSnapshot = {
val tickSnapshot = within(timeout) {
listener.expectMsgType[TickMetricSnapshot]
}
val metricsOption = tickSnapshot.metrics.get(TraceMetrics(traceName))
metricsOption should not be empty
- metricsOption.get.asInstanceOf[TraceMetricSnapshot]
+ metricsOption.get.asInstanceOf[TraceMetricsSnapshot]
}
def enableInternalSegmentCollectionStrategy(): Unit = setSegmentCollectionStrategy(ClientSegmentCollectionStrategy.Internal)
diff --git a/kamon-spray/src/test/scala/kamon/spray/SprayServerMetricsSpec.scala b/kamon-spray/src/test/scala/kamon/spray/SprayServerMetricsSpec.scala
new file mode 100644
index 00000000..c4b370d7
--- /dev/null
+++ b/kamon-spray/src/test/scala/kamon/spray/SprayServerMetricsSpec.scala
@@ -0,0 +1,91 @@
+package kamon.spray
+
+import akka.actor.ActorSystem
+import akka.testkit.{ TestProbe, TestKitBase }
+import com.typesafe.config.ConfigFactory
+import kamon.Kamon
+import kamon.http.HttpServerMetrics
+import kamon.metric._
+import org.scalatest.concurrent.{ PatienceConfiguration, ScalaFutures }
+import org.scalatest.{ Matchers, WordSpecLike }
+import spray.http.{ StatusCodes, HttpResponse, HttpRequest }
+import spray.httpx.RequestBuilding
+
+class SprayServerMetricsSpec extends TestKitBase with WordSpecLike with Matchers with RequestBuilding
+ with ScalaFutures with PatienceConfiguration with TestServer {
+
+ val collectionContext = CollectionContext(100)
+
+ implicit lazy val system: ActorSystem = ActorSystem("spray-server-metrics-spec", ConfigFactory.parseString(
+ """
+ |akka {
+ | loglevel = ERROR
+ |}
+ |
+ |kamon {
+ | metrics {
+ | tick-interval = 1 hour
+ |
+ | filters = [
+ | {
+ | trace {
+ | includes = [ "*" ]
+ | excludes = []
+ | }
+ | }
+ | ]
+ | }
+ |}
+ """.stripMargin))
+
+ "the Spray Server metrics instrumentation" should {
+ "record trace metrics for requests received" in {
+ Kamon(Metrics)(system).register(TraceMetrics("GET: /record-trace-metrics"), TraceMetrics.Factory).get.collect(collectionContext)
+ val (connection, server) = buildClientConnectionAndServer
+ val client = TestProbe()
+
+ for (repetition ← 1 to 10) {
+ client.send(connection, Get("/record-trace-metrics"))
+ server.expectMsgType[HttpRequest]
+ server.reply(HttpResponse(entity = "ok"))
+ client.expectMsgType[HttpResponse]
+ }
+
+ for (repetition ← 1 to 5) {
+ client.send(connection, Get("/record-trace-metrics"))
+ server.expectMsgType[HttpRequest]
+ server.reply(HttpResponse(entity = "bad-request", status = StatusCodes.BadRequest))
+ client.expectMsgType[HttpResponse]
+ }
+
+ val snapshot = Kamon(Metrics)(system).register(TraceMetrics("GET: /record-trace-metrics"), TraceMetrics.Factory).get.collect(collectionContext)
+ snapshot.elapsedTime.numberOfMeasurements should be(15)
+ }
+
+ "record http serve metrics for all the requests" in {
+ Kamon(Metrics)(system).register(HttpServerMetrics, HttpServerMetrics.Factory).get.collect(collectionContext)
+ val (connection, server) = buildClientConnectionAndServer
+ val client = TestProbe()
+
+ for (repetition ← 1 to 10) {
+ client.send(connection, Get("/record-http-metrics"))
+ server.expectMsgType[HttpRequest]
+ server.reply(HttpResponse(entity = "ok"))
+ client.expectMsgType[HttpResponse]
+ }
+
+ for (repetition ← 1 to 5) {
+ client.send(connection, Get("/record-http-metrics"))
+ server.expectMsgType[HttpRequest]
+ server.reply(HttpResponse(entity = "bad-request", status = StatusCodes.BadRequest))
+ client.expectMsgType[HttpResponse]
+ }
+
+ val snapshot = Kamon(Metrics)(system).register(HttpServerMetrics, HttpServerMetrics.Factory).get.collect(collectionContext)
+ snapshot.countsPerTraceAndStatusCode("GET: /record-http-metrics")("200").count should be(10)
+ snapshot.countsPerTraceAndStatusCode("GET: /record-http-metrics")("400").count should be(5)
+ snapshot.countsPerStatusCode("200").count should be(10)
+ snapshot.countsPerStatusCode("400").count should be(5)
+ }
+ }
+}
diff --git a/kamon-spray/src/test/scala/kamon/spray/ServerRequestInstrumentationSpec.scala b/kamon-spray/src/test/scala/kamon/spray/SprayServerTracingSpec.scala
index 7edbbe11..48253b1d 100644
--- a/kamon-spray/src/test/scala/kamon/spray/ServerRequestInstrumentationSpec.scala
+++ b/kamon-spray/src/test/scala/kamon/spray/SprayServerTracingSpec.scala
@@ -24,15 +24,16 @@ import kamon.Kamon
import org.scalatest.concurrent.{ PatienceConfiguration, ScalaFutures }
import spray.http.HttpHeaders.RawHeader
import spray.http.{ HttpResponse, HttpRequest }
-import kamon.metrics.{ TraceMetrics, Metrics }
-import kamon.metrics.Subscriptions.TickMetricSnapshot
+import kamon.metric.{ TraceMetrics, Metrics }
+import kamon.metric.Subscriptions.TickMetricSnapshot
import com.typesafe.config.ConfigFactory
-import kamon.metrics.TraceMetrics.ElapsedTime
+import kamon.metric.TraceMetrics.ElapsedTime
+import kamon.metric.instrument.Histogram
-class ServerRequestInstrumentationSpec extends TestKitBase with WordSpecLike with Matchers with RequestBuilding
+class SprayServerTracingSpec extends TestKitBase with WordSpecLike with Matchers with RequestBuilding
with ScalaFutures with PatienceConfiguration with TestServer {
- implicit lazy val system: ActorSystem = ActorSystem("client-pipelining-segment-strategy-instrumentation-spec", ConfigFactory.parseString(
+ implicit lazy val system: ActorSystem = ActorSystem("spray-server-tracing-spec", ConfigFactory.parseString(
"""
|akka {
| loglevel = ERROR
@@ -51,12 +52,6 @@ class ServerRequestInstrumentationSpec extends TestKitBase with WordSpecLike wit
| }
| ]
| }
- |
- | spray {
- | client {
- | segment-collection-strategy = internal
- | }
- | }
|}
""".stripMargin))
@@ -103,29 +98,6 @@ class ServerRequestInstrumentationSpec extends TestKitBase with WordSpecLike wit
response.headers should not contain (RawHeader(Kamon(Spray).traceTokenHeaderName, "propagation-disabled"))
}
-
- "open and finish a trace during the lifetime of a request" in {
- val (connection, server) = buildClientConnectionAndServer
- val client = TestProbe()
-
- val metricListener = TestProbe()
- Kamon(Metrics)(system).subscribe(TraceMetrics, "*", metricListener.ref, permanently = true)
- metricListener.expectMsgType[TickMetricSnapshot]
-
- client.send(connection, Get("/open-and-finish"))
- server.expectMsgType[HttpRequest]
- server.reply(HttpResponse(entity = "ok"))
- client.expectMsgType[HttpResponse]
-
- val tickSnapshot = metricListener.expectMsgType[TickMetricSnapshot]
- val traceMetrics = tickSnapshot.metrics.find { case (k, v) ⇒ k.name.contains("open-and-finish") } map (_._2.metrics)
- traceMetrics should not be empty
-
- traceMetrics map { metrics ⇒
- metrics(ElapsedTime).numberOfMeasurements should be(1L)
- }
- }
-
}
def enableAutomaticTraceTokenPropagation(): Unit = setIncludeTraceToken(true)
diff --git a/kamon-spray/src/test/scala/kamon/spray/TestServer.scala b/kamon-spray/src/test/scala/kamon/spray/TestServer.scala
index 81242133..65506770 100644
--- a/kamon-spray/src/test/scala/kamon/spray/TestServer.scala
+++ b/kamon-spray/src/test/scala/kamon/spray/TestServer.scala
@@ -29,11 +29,9 @@ trait TestServer {
def buildClientConnectionAndServer: (ActorRef, TestProbe) = {
val serverHandler = TestProbe()
IO(Http).tell(Http.Bind(listener = serverHandler.ref, interface = "127.0.0.1", port = 0), serverHandler.ref)
- val bound = within(10 seconds) {
- serverHandler.expectMsgType[Bound]
- }
-
+ val bound = serverHandler.expectMsgType[Bound](10 seconds)
val client = clientConnection(bound)
+
serverHandler.expectMsgType[Http.Connected]
serverHandler.reply(Http.Register(serverHandler.ref))
@@ -50,10 +48,7 @@ trait TestServer {
def buildSHostConnectorAndServer: (ActorRef, TestProbe) = {
val serverHandler = TestProbe()
IO(Http).tell(Http.Bind(listener = serverHandler.ref, interface = "127.0.0.1", port = 0), serverHandler.ref)
- val bound = within(10 seconds) {
- serverHandler.expectMsgType[Bound]
- }
-
+ val bound = serverHandler.expectMsgType[Bound](10 seconds)
val client = httpHostConnector(bound)
(client, serverHandler)