{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/219786991","pull_request_review_id":158041111,"id":219786991,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxOTc4Njk5MQ==","diff_hunk":"@@ -0,0 +1,75 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  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+package org.apache.spark.network.yarn\n+\n+import scala.collection.JavaConverters._\n+\n+import org.apache.hadoop.metrics2.MetricsRecordBuilder\n+import org.mockito.Matchers._\n+import org.mockito.Mockito.{mock, times, verify, when}\n+import org.scalatest.Matchers\n+\n+import org.apache.spark.SparkFunSuite\n+import org.apache.spark.network.server.OneForOneStreamManager\n+import org.apache.spark.network.shuffle.{ExternalShuffleBlockHandler, ExternalShuffleBlockResolver}\n+\n+class YarnShuffleServiceMetricsSuite extends SparkFunSuite with Matchers {\n+\n+  val streamManager = mock(classOf[OneForOneStreamManager])\n+  val blockResolver = mock(classOf[ExternalShuffleBlockResolver])\n+  when(blockResolver.getRegisteredExecutorsSize).thenReturn(42)\n+\n+  val metrics = new ExternalShuffleBlockHandler(streamManager, blockResolver).getAllMetrics\n+\n+  test(\"metrics named as expected\") {\n+    val allMetrics = Set(\n+      \"openBlockRequestLatencyMillis\", \"registerExecutorRequestLatencyMillis\",\n+      \"blockTransferRateBytes\", \"registeredExecutorsSize\")\n+\n+    metrics.getMetrics.keySet().asScala should be (allMetrics)\n+  }\n+\n+  // these three metrics have the same effect on the collector\n+  for (testname <- Seq(\"openBlockRequestLatencyMillis\",\n+      \"registerExecutorRequestLatencyMillis\",\n+      \"blockTransferRateBytes\")) {\n+    test(s\"$testname - collector receives correct types\") {\n+      val builder = mock(classOf[MetricsRecordBuilder])\n+      when(builder.addCounter(any(), anyLong())).thenReturn(builder)\n+      when(builder.addGauge(any(), anyDouble())).thenReturn(builder)\n+\n+      YarnShuffleServiceMetrics.collectMetric(builder, testname,\n+        metrics.getMetrics.get(testname))\n+\n+      verify(builder).addCounter(anyObject(), anyLong())\n+      verify(builder, times(4)).addGauge(anyObject(), anyDouble())\n+    }\n+  }\n+\n+  // this metric writes only one gauge to the collector\n+  test(\"registeredExecutorsSize - collector receives correct types\") {\n+    val builder = mock(classOf[MetricsRecordBuilder])\n+    when(builder.addCounter(any(), anyLong())).thenReturn(builder)\n+    when(builder.addGauge(any(), anyDouble())).thenReturn(builder)\n+\n+    YarnShuffleServiceMetrics.collectMetric(builder, \"registeredExecutorsSize\",","path":"resource-managers/yarn/src/test/scala/org/apache/spark/network/yarn/YarnShuffleServiceMetricsSuite.scala","position":null,"original_position":69,"commit_id":"764404a89eacc58898a3fff2e49b00ac2c1a01b3","original_commit_id":"6c96397536af57a8bbe8dd2529547427f643512b","user":{"login":"mareksimunek","id":8159699,"node_id":"MDQ6VXNlcjgxNTk2OTk=","avatar_url":"https://avatars3.githubusercontent.com/u/8159699?v=4","gravatar_id":"","url":"https://api.github.com/users/mareksimunek","html_url":"https://github.com/mareksimunek","followers_url":"https://api.github.com/users/mareksimunek/followers","following_url":"https://api.github.com/users/mareksimunek/following{/other_user}","gists_url":"https://api.github.com/users/mareksimunek/gists{/gist_id}","starred_url":"https://api.github.com/users/mareksimunek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mareksimunek/subscriptions","organizations_url":"https://api.github.com/users/mareksimunek/orgs","repos_url":"https://api.github.com/users/mareksimunek/repos","events_url":"https://api.github.com/users/mareksimunek/events{/privacy}","received_events_url":"https://api.github.com/users/mareksimunek/received_events","type":"User","site_admin":false},"body":"fixed","created_at":"2018-09-24T10:14:23Z","updated_at":"2018-09-24T10:14:23Z","html_url":"https://github.com/apache/spark/pull/22485#discussion_r219786991","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/22485","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/219786991"},"html":{"href":"https://github.com/apache/spark/pull/22485#discussion_r219786991"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/22485"}},"in_reply_to_id":219508537},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/22485","id":216878833,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE2ODc4ODMz","html_url":"https://github.com/apache/spark/pull/22485","diff_url":"https://github.com/apache/spark/pull/22485.diff","patch_url":"https://github.com/apache/spark/pull/22485.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/22485","number":22485,"state":"open","locked":false,"title":"[SPARK-18364][YARN] Expose metrics for YarnShuffleService","user":{"login":"mareksimunek","id":8159699,"node_id":"MDQ6VXNlcjgxNTk2OTk=","avatar_url":"https://avatars3.githubusercontent.com/u/8159699?v=4","gravatar_id":"","url":"https://api.github.com/users/mareksimunek","html_url":"https://github.com/mareksimunek","followers_url":"https://api.github.com/users/mareksimunek/followers","following_url":"https://api.github.com/users/mareksimunek/following{/other_user}","gists_url":"https://api.github.com/users/mareksimunek/gists{/gist_id}","starred_url":"https://api.github.com/users/mareksimunek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mareksimunek/subscriptions","organizations_url":"https://api.github.com/users/mareksimunek/orgs","repos_url":"https://api.github.com/users/mareksimunek/repos","events_url":"https://api.github.com/users/mareksimunek/events{/privacy}","received_events_url":"https://api.github.com/users/mareksimunek/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nThis PR is follow-up of closed  https://github.com/apache/spark/pull/17401 which only ended due to of inactivity, but its still nice feature to have.\r\nGiven review by @jerryshao taken in consideration and edited:\r\n- @VisibleForTesting deleted because of dependency conflicts\r\n- removed unnecessary reflection for `MetricsSystemImpl`\r\n- added more available types for gauge\r\n\r\n## How was this patch tested?\r\n\r\nManual deploy of new yarn-shuffle jar into a Node Manager and verifying that the metrics appear in the Node Manager-standard location. This is JMX with an query endpoint running on `hostname:port`\r\n\r\nResulting metrics look like this:\r\n```\r\ncurl -sk -XGET hostname:port |  grep -v '#' | grep 'shuffleService'\r\nhadoop_nodemanager_openblockrequestlatencymillis_rate15{name=\"shuffleService\",} 0.31428910657834713\r\nhadoop_nodemanager_blocktransferratebytes_rate15{name=\"shuffleService\",} 566144.9983653595\r\nhadoop_nodemanager_blocktransferratebytes_ratemean{name=\"shuffleService\",} 2464409.9678099006\r\nhadoop_nodemanager_openblockrequestlatencymillis_rate1{name=\"shuffleService\",} 1.2893844732240272\r\nhadoop_nodemanager_registeredexecutorssize{name=\"shuffleService\",} 2.0\r\nhadoop_nodemanager_openblockrequestlatencymillis_ratemean{name=\"shuffleService\",} 1.255574678369966\r\nhadoop_nodemanager_openblockrequestlatencymillis_count{name=\"shuffleService\",} 315.0\r\nhadoop_nodemanager_openblockrequestlatencymillis_rate5{name=\"shuffleService\",} 0.7661929192569739\r\nhadoop_nodemanager_registerexecutorrequestlatencymillis_ratemean{name=\"shuffleService\",} 0.0\r\nhadoop_nodemanager_registerexecutorrequestlatencymillis_count{name=\"shuffleService\",} 0.0\r\nhadoop_nodemanager_registerexecutorrequestlatencymillis_rate1{name=\"shuffleService\",} 0.0\r\nhadoop_nodemanager_registerexecutorrequestlatencymillis_rate5{name=\"shuffleService\",} 0.0\r\nhadoop_nodemanager_blocktransferratebytes_count{name=\"shuffleService\",} 6.18271213E8\r\nhadoop_nodemanager_registerexecutorrequestlatencymillis_rate15{name=\"shuffleService\",} 0.0\r\nhadoop_nodemanager_blocktransferratebytes_rate5{name=\"shuffleService\",} 1154114.4881816586\r\nhadoop_nodemanager_blocktransferratebytes_rate1{name=\"shuffleService\",} 574745.0749848988\r\n```","created_at":"2018-09-20T08:04:14Z","updated_at":"2018-09-24T10:14:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a0a187016778b4127490ee7cb02c03b417b809bc","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/22485/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/22485/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/22485/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/764404a89eacc58898a3fff2e49b00ac2c1a01b3","head":{"label":"mareksimunek:SPARK-18364","ref":"SPARK-18364","sha":"764404a89eacc58898a3fff2e49b00ac2c1a01b3","user":{"login":"mareksimunek","id":8159699,"node_id":"MDQ6VXNlcjgxNTk2OTk=","avatar_url":"https://avatars3.githubusercontent.com/u/8159699?v=4","gravatar_id":"","url":"https://api.github.com/users/mareksimunek","html_url":"https://github.com/mareksimunek","followers_url":"https://api.github.com/users/mareksimunek/followers","following_url":"https://api.github.com/users/mareksimunek/following{/other_user}","gists_url":"https://api.github.com/users/mareksimunek/gists{/gist_id}","starred_url":"https://api.github.com/users/mareksimunek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mareksimunek/subscriptions","organizations_url":"https://api.github.com/users/mareksimunek/orgs","repos_url":"https://api.github.com/users/mareksimunek/repos","events_url":"https://api.github.com/users/mareksimunek/events{/privacy}","received_events_url":"https://api.github.com/users/mareksimunek/received_events","type":"User","site_admin":false},"repo":{"id":149449932,"node_id":"MDEwOlJlcG9zaXRvcnkxNDk0NDk5MzI=","name":"spark","full_name":"mareksimunek/spark","private":false,"owner":{"login":"mareksimunek","id":8159699,"node_id":"MDQ6VXNlcjgxNTk2OTk=","avatar_url":"https://avatars3.githubusercontent.com/u/8159699?v=4","gravatar_id":"","url":"https://api.github.com/users/mareksimunek","html_url":"https://github.com/mareksimunek","followers_url":"https://api.github.com/users/mareksimunek/followers","following_url":"https://api.github.com/users/mareksimunek/following{/other_user}","gists_url":"https://api.github.com/users/mareksimunek/gists{/gist_id}","starred_url":"https://api.github.com/users/mareksimunek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mareksimunek/subscriptions","organizations_url":"https://api.github.com/users/mareksimunek/orgs","repos_url":"https://api.github.com/users/mareksimunek/repos","events_url":"https://api.github.com/users/mareksimunek/events{/privacy}","received_events_url":"https://api.github.com/users/mareksimunek/received_events","type":"User","site_admin":false},"html_url":"https://github.com/mareksimunek/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/mareksimunek/spark","forks_url":"https://api.github.com/repos/mareksimunek/spark/forks","keys_url":"https://api.github.com/repos/mareksimunek/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mareksimunek/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mareksimunek/spark/teams","hooks_url":"https://api.github.com/repos/mareksimunek/spark/hooks","issue_events_url":"https://api.github.com/repos/mareksimunek/spark/issues/events{/number}","events_url":"https://api.github.com/repos/mareksimunek/spark/events","assignees_url":"https://api.github.com/repos/mareksimunek/spark/assignees{/user}","branches_url":"https://api.github.com/repos/mareksimunek/spark/branches{/branch}","tags_url":"https://api.github.com/repos/mareksimunek/spark/tags","blobs_url":"https://api.github.com/repos/mareksimunek/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mareksimunek/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mareksimunek/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/mareksimunek/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mareksimunek/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/mareksimunek/spark/languages","stargazers_url":"https://api.github.com/repos/mareksimunek/spark/stargazers","contributors_url":"https://api.github.com/repos/mareksimunek/spark/contributors","subscribers_url":"https://api.github.com/repos/mareksimunek/spark/subscribers","subscription_url":"https://api.github.com/repos/mareksimunek/spark/subscription","commits_url":"https://api.github.com/repos/mareksimunek/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/mareksimunek/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/mareksimunek/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/mareksimunek/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/mareksimunek/spark/contents/{+path}","compare_url":"https://api.github.com/repos/mareksimunek/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mareksimunek/spark/merges","archive_url":"https://api.github.com/repos/mareksimunek/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mareksimunek/spark/downloads","issues_url":"https://api.github.com/repos/mareksimunek/spark/issues{/number}","pulls_url":"https://api.github.com/repos/mareksimunek/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/mareksimunek/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/mareksimunek/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mareksimunek/spark/labels{/name}","releases_url":"https://api.github.com/repos/mareksimunek/spark/releases{/id}","deployments_url":"https://api.github.com/repos/mareksimunek/spark/deployments","created_at":"2018-09-19T12:49:24Z","updated_at":"2018-09-19T12:49:51Z","pushed_at":"2018-09-24T10:11:42Z","git_url":"git://github.com/mareksimunek/spark.git","ssh_url":"git@github.com:mareksimunek/spark.git","clone_url":"https://github.com/mareksimunek/spark.git","svn_url":"https://github.com/mareksimunek/spark","homepage":null,"size":282136,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"7ff5386ed934190344b2cda1069bde4bc68a3e63","user":{"login":"apache","id":47359,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5","avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"node_id":"MDEwOlJlcG9zaXRvcnkxNzE2NTY1OA==","name":"spark","full_name":"apache/spark","private":false,"owner":{"login":"apache","id":47359,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5","avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2018-09-24T09:32:19Z","pushed_at":"2018-09-24T10:11:46Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":282715,"stargazers_count":18877,"watchers_count":18877,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":16986,"mirror_url":null,"archived":false,"open_issues_count":517,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":16986,"open_issues":517,"watchers":18877,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/22485"},"html":{"href":"https://github.com/apache/spark/pull/22485"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/22485"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/22485/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/22485/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/22485/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/764404a89eacc58898a3fff2e49b00ac2c1a01b3"}},"author_association":"NONE"}}
{"actor":{"display_login":"mareksimunek"}}