{"action":"created","comment":{"url":"https://api.github.com/repos/paypal/squbs/pulls/comments/87459499","pull_request_review_id":8072459,"id":87459499,"diff_hunk":"@@ -0,0 +1,223 @@\n+/*\n+ * Copyright 2015 PayPal\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.squbs.metrics\n+\n+import java.lang.management.ManagementFactory\n+import javax.management.ObjectName\n+\n+import akka.actor.ActorSystem\n+import akka.http.scaladsl.Http\n+import akka.http.scaladsl.model.ws.PeerClosedConnectionException\n+import akka.http.scaladsl.model.{RequestTimeoutException, HttpResponse, StatusCodes, HttpRequest}\n+import akka.stream.ActorMaterializer\n+import akka.stream.scaladsl.{BidiFlow, Flow, Sink, Source}\n+import com.typesafe.config.ConfigFactory\n+import org.scalatest.{AsyncFlatSpec, BeforeAndAfterAll, Matchers}\n+import org.squbs.endpoint.{EndpointResolverRegistry, Endpoint, EndpointResolver}\n+import org.squbs.env.Environment\n+import org.squbs.httpclient.ClientFlow\n+import org.squbs.pipeline.streaming._\n+import org.squbs.testkit.Timeouts._\n+\n+import scala.concurrent.{Future, Await}\n+import scala.util.{Failure, Success}\n+\n+object MetricsFlowSpec {\n+\n+  val config = ConfigFactory.parseString(\n+    s\"\"\"\n+       |preFlow {\n+       |  type = squbs.pipelineflow\n+       |  factory = org.squbs.metrics.DefaultFlow\n+       |}\n+       |\n+       |squbs.pipeline.streaming.defaults {\n+       |  pre-flow =  preFlow\n+       |}\n+       |\n+       |sampleClient {\n+       |  type = squbs.httpclient\n+       |}\n+       |\n+       |sampleClient6 {\n+       |  type = squbs.httpclient\n+       |  pipeline = failure\n+       |}\n+       |\n+       |failure {\n+       |  type = squbs.pipelineflow\n+       |  factory = org.squbs.metrics.FailureFlow\n+       |}\n+    \"\"\".stripMargin\n+  )\n+\n+  implicit val system: ActorSystem = ActorSystem(\"MetricFlowSpec\", config)\n+  implicit val materializer = ActorMaterializer()\n+  import system.dispatcher\n+  import akka.http.scaladsl.server.Directives._\n+\n+  val route =\n+    path(\"hello\") {\n+      get {\n+        complete(\"Hello World!\")\n+      }\n+    } ~ path(\"redirect\") {\n+      get {\n+        complete(HttpResponse(status = StatusCodes.Found))\n+      }\n+    } ~ path(\"internalservererror\") {\n+      get {\n+        complete(HttpResponse(status = StatusCodes.InternalServerError))\n+      }\n+    }\n+\n+  val serverBinding = Await.result(Http().bindAndHandle(route, \"localhost\", 0), awaitMax)\n+  val port = serverBinding.localAddress.getPort\n+}\n+\n+class MetricsFlowSpec extends AsyncFlatSpec with Matchers with BeforeAndAfterAll {\n+\n+  import MetricsFlowSpec._\n+  import system.dispatcher\n+\n+  override def afterAll: Unit = {\n+    serverBinding.unbind() map {_ => system.terminate()}\n+  }\n+\n+  EndpointResolverRegistry(system).register(new EndpointResolver {\n+    override def name: String = \"LocalhostEndpointResolver\"\n+    override def resolve(svcName: String, env: Environment) = Some(Endpoint(s\"http://localhost:$port\"))\n+  })\n+\n+  it should \"collect request count and time metrics\" in {\n+    val f = for(i <- 0 until 5) yield callService(\"sampleClient\", \"/hello\")\n+\n+    callServiceTwice(\"sampleClient\", \"/hello\") flatMap { _ => Future.sequence(f) } map { _ =>\n+      assertJmxValue(\"sampleClient-request-count\", \"Count\", 7)\n+      assertJmxValue(\"sampleClient-request-time\", \"Count\", 7)\n+      assertJmxEntryExists(\"sampleClient-request-time\", \"FifteenMinuteRate\")\n+    }\n+  }\n+\n+  it should \"collect metrics per http status code category\" in {\n+    val f = for {\n+      hello <- callServiceTwice(\"sampleClient2\", \"/hello\")\n+      redirect <- callService(\"sampleClient2\", \"/redirect\")\n+      notFound <- callService(\"sampleClient2\", \"/notfound\")\n+      internalServerError <- callServiceTwice(\"sampleClient2\", \"/internalservererror\")\n+    } yield List(hello, redirect, notFound, internalServerError)\n+\n+    f map { _ =>\n+      assertJmxValue(\"sampleClient2-request-count\", \"Count\", 6)\n+      assertJmxValue(\"sampleClient2-2XX-count\", \"Count\", 2)\n+      assertJmxValue(\"sampleClient2-3XX-count\", \"Count\", 1)\n+      assertJmxValue(\"sampleClient2-4XX-count\", \"Count\", 1)\n+      assertJmxValue(\"sampleClient2-5XX-count\", \"Count\", 2)\n+    }\n+  }\n+\n+  it should \"collect metrics for multiple clients\" in {\n+    val f = for {\n+      hello <- callServiceTwice(\"sampleClient3\", \"/hello\")\n+      redirect <- callService(\"sampleClient4\", \"/redirect\")\n+      notFound <- callService(\"sampleClient5\", \"/notfound\")\n+      internalServerError <- callServiceTwice(\"sampleClient3\", \"/internalservererror\")\n+    } yield List(hello, redirect, notFound, internalServerError)\n+\n+    f map { _ =>\n+      assertJmxValue(\"sampleClient3-request-count\", \"Count\", 4)\n+      assertJmxValue(\"sampleClient3-2XX-count\", \"Count\", 2)\n+      assertJmxValue(\"sampleClient3-5XX-count\", \"Count\", 2)\n+\n+      assertJmxValue(\"sampleClient4-request-count\", \"Count\", 1)\n+      assertJmxValue(\"sampleClient4-3XX-count\", \"Count\", 1)\n+\n+      assertJmxValue(\"sampleClient5-request-count\", \"Count\", 1)\n+      assertJmxValue(\"sampleClient5-4XX-count\", \"Count\", 1)\n+    }\n+  }\n+\n+  it should \"collect metrics for exceptions\" in {\n+    val f = for {\n+      hello <- callServiceTwice(\"sampleClient6\", \"/hello\")\n+      connectionException <- callService(\"sampleClient6\", \"/connectionException\")\n+      connectionException2 <- callService(\"sampleClient6\", \"/connectionException\")\n+      timeoutException <- callServiceTwice(\"sampleClient6\", \"/timeoutException\")","path":"squbs-httpclient/src/test/scala/org/squbs/metrics/MetricsFlowSpec.scala","position":159,"original_position":159,"commit_id":"d8be9fd58ea7f2941d6cc857eccd799b7e4b45dd","original_commit_id":"fb4c55b0d3d42b70e7a0b572ef0ef82eaba989c7","user":{"login":"anilgursel","id":3316621,"avatar_url":"https://avatars.githubusercontent.com/u/3316621?v=3","gravatar_id":"","url":"https://api.github.com/users/anilgursel","html_url":"https://github.com/anilgursel","followers_url":"https://api.github.com/users/anilgursel/followers","following_url":"https://api.github.com/users/anilgursel/following{/other_user}","gists_url":"https://api.github.com/users/anilgursel/gists{/gist_id}","starred_url":"https://api.github.com/users/anilgursel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anilgursel/subscriptions","organizations_url":"https://api.github.com/users/anilgursel/orgs","repos_url":"https://api.github.com/users/anilgursel/repos","events_url":"https://api.github.com/users/anilgursel/events{/privacy}","received_events_url":"https://api.github.com/users/anilgursel/received_events","type":"User","site_admin":false},"body":"I see, you are talking about the server side.\r\n\r\nI do not think we can catch an exception in the pipeline.  We can register a default `decider` for the flow though that can create a `Try` and send it as a message.  Then, we can try to integrate exception mappers..  Basically, if failed, instead of just doing 500, we can try to first do a mapping.\r\n\r\nI think it deserves an issue https://github.com/paypal/squbs/issues/312.","created_at":"2016-11-10T18:47:08Z","updated_at":"2016-11-10T18:47:08Z","html_url":"https://github.com/paypal/squbs/pull/303#discussion_r87459499","pull_request_url":"https://api.github.com/repos/paypal/squbs/pulls/303","_links":{"self":{"href":"https://api.github.com/repos/paypal/squbs/pulls/comments/87459499"},"html":{"href":"https://github.com/paypal/squbs/pull/303#discussion_r87459499"},"pull_request":{"href":"https://api.github.com/repos/paypal/squbs/pulls/303"}}},"pull_request":{"url":"https://api.github.com/repos/paypal/squbs/pulls/303","id":92673291,"html_url":"https://github.com/paypal/squbs/pull/303","diff_url":"https://github.com/paypal/squbs/pull/303.diff","patch_url":"https://github.com/paypal/squbs/pull/303.patch","issue_url":"https://api.github.com/repos/paypal/squbs/issues/303","number":303,"state":"open","locked":false,"title":"Akka http client","user":{"login":"anilgursel","id":3316621,"avatar_url":"https://avatars.githubusercontent.com/u/3316621?v=3","gravatar_id":"","url":"https://api.github.com/users/anilgursel","html_url":"https://github.com/anilgursel","followers_url":"https://api.github.com/users/anilgursel/followers","following_url":"https://api.github.com/users/anilgursel/following{/other_user}","gists_url":"https://api.github.com/users/anilgursel/gists{/gist_id}","starred_url":"https://api.github.com/users/anilgursel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anilgursel/subscriptions","organizations_url":"https://api.github.com/users/anilgursel/orgs","repos_url":"https://api.github.com/users/anilgursel/repos","events_url":"https://api.github.com/users/anilgursel/events{/privacy}","received_events_url":"https://api.github.com/users/anilgursel/received_events","type":"User","site_admin":false},"body":"Thanks for your pull request.  Please review the following guidelines.\r\n\r\n- [x] Title includes issue id.\r\n- [x] Description of the change added.\r\n- [x] Commits are squashed.\r\n- [x] Tests added.\r\n- [ ] Documentation added/updated.\r\n- [x] Also please review [CONTRIBUTING.md](https://github.com/paypal/squbs/blob/master/CONTRIBUTING.md).\r\n","created_at":"2016-11-07T22:00:50Z","updated_at":"2016-11-10T18:47:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"236cce67a2dd456bb97195db7208103ef3b6ecf0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/paypal/squbs/pulls/303/commits","review_comments_url":"https://api.github.com/repos/paypal/squbs/pulls/303/comments","review_comment_url":"https://api.github.com/repos/paypal/squbs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/paypal/squbs/issues/303/comments","statuses_url":"https://api.github.com/repos/paypal/squbs/statuses/d8be9fd58ea7f2941d6cc857eccd799b7e4b45dd","head":{"label":"anilgursel:akka-http-client","ref":"akka-http-client","sha":"d8be9fd58ea7f2941d6cc857eccd799b7e4b45dd","user":{"login":"anilgursel","id":3316621,"avatar_url":"https://avatars.githubusercontent.com/u/3316621?v=3","gravatar_id":"","url":"https://api.github.com/users/anilgursel","html_url":"https://github.com/anilgursel","followers_url":"https://api.github.com/users/anilgursel/followers","following_url":"https://api.github.com/users/anilgursel/following{/other_user}","gists_url":"https://api.github.com/users/anilgursel/gists{/gist_id}","starred_url":"https://api.github.com/users/anilgursel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anilgursel/subscriptions","organizations_url":"https://api.github.com/users/anilgursel/orgs","repos_url":"https://api.github.com/users/anilgursel/repos","events_url":"https://api.github.com/users/anilgursel/events{/privacy}","received_events_url":"https://api.github.com/users/anilgursel/received_events","type":"User","site_admin":false},"repo":{"id":45846928,"name":"squbs","full_name":"anilgursel/squbs","owner":{"login":"anilgursel","id":3316621,"avatar_url":"https://avatars.githubusercontent.com/u/3316621?v=3","gravatar_id":"","url":"https://api.github.com/users/anilgursel","html_url":"https://github.com/anilgursel","followers_url":"https://api.github.com/users/anilgursel/followers","following_url":"https://api.github.com/users/anilgursel/following{/other_user}","gists_url":"https://api.github.com/users/anilgursel/gists{/gist_id}","starred_url":"https://api.github.com/users/anilgursel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anilgursel/subscriptions","organizations_url":"https://api.github.com/users/anilgursel/orgs","repos_url":"https://api.github.com/users/anilgursel/repos","events_url":"https://api.github.com/users/anilgursel/events{/privacy}","received_events_url":"https://api.github.com/users/anilgursel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anilgursel/squbs","description":"Akka/Spray for Large-Scale Production Deployments","fork":true,"url":"https://api.github.com/repos/anilgursel/squbs","forks_url":"https://api.github.com/repos/anilgursel/squbs/forks","keys_url":"https://api.github.com/repos/anilgursel/squbs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anilgursel/squbs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anilgursel/squbs/teams","hooks_url":"https://api.github.com/repos/anilgursel/squbs/hooks","issue_events_url":"https://api.github.com/repos/anilgursel/squbs/issues/events{/number}","events_url":"https://api.github.com/repos/anilgursel/squbs/events","assignees_url":"https://api.github.com/repos/anilgursel/squbs/assignees{/user}","branches_url":"https://api.github.com/repos/anilgursel/squbs/branches{/branch}","tags_url":"https://api.github.com/repos/anilgursel/squbs/tags","blobs_url":"https://api.github.com/repos/anilgursel/squbs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anilgursel/squbs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anilgursel/squbs/git/refs{/sha}","trees_url":"https://api.github.com/repos/anilgursel/squbs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anilgursel/squbs/statuses/{sha}","languages_url":"https://api.github.com/repos/anilgursel/squbs/languages","stargazers_url":"https://api.github.com/repos/anilgursel/squbs/stargazers","contributors_url":"https://api.github.com/repos/anilgursel/squbs/contributors","subscribers_url":"https://api.github.com/repos/anilgursel/squbs/subscribers","subscription_url":"https://api.github.com/repos/anilgursel/squbs/subscription","commits_url":"https://api.github.com/repos/anilgursel/squbs/commits{/sha}","git_commits_url":"https://api.github.com/repos/anilgursel/squbs/git/commits{/sha}","comments_url":"https://api.github.com/repos/anilgursel/squbs/comments{/number}","issue_comment_url":"https://api.github.com/repos/anilgursel/squbs/issues/comments{/number}","contents_url":"https://api.github.com/repos/anilgursel/squbs/contents/{+path}","compare_url":"https://api.github.com/repos/anilgursel/squbs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anilgursel/squbs/merges","archive_url":"https://api.github.com/repos/anilgursel/squbs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anilgursel/squbs/downloads","issues_url":"https://api.github.com/repos/anilgursel/squbs/issues{/number}","pulls_url":"https://api.github.com/repos/anilgursel/squbs/pulls{/number}","milestones_url":"https://api.github.com/repos/anilgursel/squbs/milestones{/number}","notifications_url":"https://api.github.com/repos/anilgursel/squbs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anilgursel/squbs/labels{/name}","releases_url":"https://api.github.com/repos/anilgursel/squbs/releases{/id}","deployments_url":"https://api.github.com/repos/anilgursel/squbs/deployments","created_at":"2015-11-09T15:27:04Z","updated_at":"2016-02-29T13:50:05Z","pushed_at":"2016-11-10T16:54:39Z","git_url":"git://github.com/anilgursel/squbs.git","ssh_url":"git@github.com:anilgursel/squbs.git","clone_url":"https://github.com/anilgursel/squbs.git","svn_url":"https://github.com/anilgursel/squbs","homepage":"","size":6668,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"paypal:master","ref":"master","sha":"8d5bc02c6a98968de957607e60fcae5b920d3e83","user":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"repo":{"id":38714007,"name":"squbs","full_name":"paypal/squbs","owner":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paypal/squbs","description":"Akka/Spray for Large-Scale Production Deployments","fork":false,"url":"https://api.github.com/repos/paypal/squbs","forks_url":"https://api.github.com/repos/paypal/squbs/forks","keys_url":"https://api.github.com/repos/paypal/squbs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paypal/squbs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paypal/squbs/teams","hooks_url":"https://api.github.com/repos/paypal/squbs/hooks","issue_events_url":"https://api.github.com/repos/paypal/squbs/issues/events{/number}","events_url":"https://api.github.com/repos/paypal/squbs/events","assignees_url":"https://api.github.com/repos/paypal/squbs/assignees{/user}","branches_url":"https://api.github.com/repos/paypal/squbs/branches{/branch}","tags_url":"https://api.github.com/repos/paypal/squbs/tags","blobs_url":"https://api.github.com/repos/paypal/squbs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paypal/squbs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paypal/squbs/git/refs{/sha}","trees_url":"https://api.github.com/repos/paypal/squbs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paypal/squbs/statuses/{sha}","languages_url":"https://api.github.com/repos/paypal/squbs/languages","stargazers_url":"https://api.github.com/repos/paypal/squbs/stargazers","contributors_url":"https://api.github.com/repos/paypal/squbs/contributors","subscribers_url":"https://api.github.com/repos/paypal/squbs/subscribers","subscription_url":"https://api.github.com/repos/paypal/squbs/subscription","commits_url":"https://api.github.com/repos/paypal/squbs/commits{/sha}","git_commits_url":"https://api.github.com/repos/paypal/squbs/git/commits{/sha}","comments_url":"https://api.github.com/repos/paypal/squbs/comments{/number}","issue_comment_url":"https://api.github.com/repos/paypal/squbs/issues/comments{/number}","contents_url":"https://api.github.com/repos/paypal/squbs/contents/{+path}","compare_url":"https://api.github.com/repos/paypal/squbs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paypal/squbs/merges","archive_url":"https://api.github.com/repos/paypal/squbs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paypal/squbs/downloads","issues_url":"https://api.github.com/repos/paypal/squbs/issues{/number}","pulls_url":"https://api.github.com/repos/paypal/squbs/pulls{/number}","milestones_url":"https://api.github.com/repos/paypal/squbs/milestones{/number}","notifications_url":"https://api.github.com/repos/paypal/squbs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paypal/squbs/labels{/name}","releases_url":"https://api.github.com/repos/paypal/squbs/releases{/id}","deployments_url":"https://api.github.com/repos/paypal/squbs/deployments","created_at":"2015-07-07T20:48:12Z","updated_at":"2016-11-10T07:05:32Z","pushed_at":"2016-11-10T18:38:19Z","git_url":"git://github.com/paypal/squbs.git","ssh_url":"git@github.com:paypal/squbs.git","clone_url":"https://github.com/paypal/squbs.git","svn_url":"https://github.com/paypal/squbs","homepage":"http://paypal.github.io/squbs","size":6605,"stargazers_count":706,"watchers_count":706,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":113,"mirror_url":null,"open_issues_count":38,"forks":113,"open_issues":38,"watchers":706,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/paypal/squbs/pulls/303"},"html":{"href":"https://github.com/paypal/squbs/pull/303"},"issue":{"href":"https://api.github.com/repos/paypal/squbs/issues/303"},"comments":{"href":"https://api.github.com/repos/paypal/squbs/issues/303/comments"},"review_comments":{"href":"https://api.github.com/repos/paypal/squbs/pulls/303/comments"},"review_comment":{"href":"https://api.github.com/repos/paypal/squbs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/paypal/squbs/pulls/303/commits"},"statuses":{"href":"https://api.github.com/repos/paypal/squbs/statuses/d8be9fd58ea7f2941d6cc857eccd799b7e4b45dd"}}}}
{"actor":{"display_login":"anilgursel"}}