{"action":"created","comment":{"url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/comments/92947277","pull_request_review_id":13468763,"id":92947277,"diff_hunk":"@@ -0,0 +1,156 @@\n+/*\n+ * Copyright (c) 2016, Uber Technologies, Inc\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+package com.uber.jaeger.samplers;\n+\n+import static org.junit.Assert.assertEquals;\n+import static org.junit.Assert.assertNotNull;\n+import static org.junit.Assert.assertTrue;\n+import static org.mockito.Mockito.mock;\n+import static org.mockito.Mockito.verify;\n+import static org.mockito.Mockito.verifyNoMoreInteractions;\n+import static org.mockito.Mockito.when;\n+\n+import com.uber.jaeger.samplers.http.OperationSamplingParameters;\n+import com.uber.jaeger.samplers.http.PerOperationSamplingParameters;\n+import com.uber.jaeger.samplers.http.ProbabilisticSamplingStrategy;\n+import org.junit.After;\n+import org.junit.Before;\n+import org.junit.Test;\n+import org.junit.runner.RunWith;\n+import org.mockito.Mock;\n+import org.mockito.junit.MockitoJUnitRunner;\n+\n+import java.util.ArrayList;\n+import java.util.HashMap;\n+import java.util.List;\n+\n+@RunWith(MockitoJUnitRunner.class)\n+public class PerOperationSamplerTest {\n+\n+  private final double SAMPLING_RATE = 0.31415;\n+  private final double DEFAULT_SAMPLING_PROBABILITY = 0.512;\n+  private final double DEFAULT_LOWER_BOUND_TRACES_PER_SECOND = 2.0;\n+  private final int MAX_OPERATIONS = 100;\n+  private final long traceId = 1L;\n+  private final String operation = \"some operation\";\n+\n+  @Mock private ProbabilisticSampler defaultProbabilisticSampler;\n+  private HashMap<String, GuaranteedThroughputSampler>  operationToSamplers = new HashMap<>();\n+  private PerOperationSampler undertest;\n+\n+  @Before\n+  public void setUp(){\n+    undertest = new PerOperationSampler(MAX_OPERATIONS, operationToSamplers, defaultProbabilisticSampler);\n+    when(defaultProbabilisticSampler.sample(operation, traceId)).thenReturn(SamplingStatus.of(true, new HashMap<String, Object>()));\n+  }\n+\n+  @After\n+  public void tearDown() {\n+    undertest.close();\n+  }\n+\n+  @Test\n+  public void testFallbackToDefaultProbabilisticSampler() {\n+    undertest = new PerOperationSampler(0, operationToSamplers, defaultProbabilisticSampler);\n+    SamplingStatus samplingStatus = undertest.sample(operation, traceId);\n+    assertTrue(samplingStatus.isSampled());\n+    verify(defaultProbabilisticSampler).sample(operation, traceId);\n+  }\n+\n+  @Test\n+  public void testCreateGuaranteedSamplerOnSample() {\n+    String newOperation = \"new operation\";\n+    undertest.sample(newOperation, traceId);\n+    assertEquals(new GuaranteedThroughputSampler(0, 0), operationToSamplers.get(newOperation));\n+  }\n+\n+  @Test\n+  public void testPerOperationSampler() {\n+    GuaranteedThroughputSampler guaranteedThroughputSampler = mock(GuaranteedThroughputSampler.class);\n+    operationToSamplers.put(operation, guaranteedThroughputSampler);\n+\n+    when(guaranteedThroughputSampler.sample(operation, traceId)).thenReturn(SamplingStatus.of(true, new HashMap<String, Object>()));\n+\n+    SamplingStatus samplingStatus = undertest.sample(operation, traceId);\n+    assertTrue(samplingStatus.isSampled());\n+    verify(guaranteedThroughputSampler).sample(operation, traceId);\n+    verifyNoMoreInteractions(defaultProbabilisticSampler);","path":"jaeger-core/src/test/java/com/uber/jaeger/samplers/PerOperationSamplerTest.java","position":96,"original_position":96,"commit_id":"7c5b4b0abd999593cfddfde97bd4dc1e9c303df8","original_commit_id":"7c5b4b0abd999593cfddfde97bd4dc1e9c303df8","user":{"login":"yurishkuro","id":3523016,"avatar_url":"https://avatars.githubusercontent.com/u/3523016?v=3","gravatar_id":"","url":"https://api.github.com/users/yurishkuro","html_url":"https://github.com/yurishkuro","followers_url":"https://api.github.com/users/yurishkuro/followers","following_url":"https://api.github.com/users/yurishkuro/following{/other_user}","gists_url":"https://api.github.com/users/yurishkuro/gists{/gist_id}","starred_url":"https://api.github.com/users/yurishkuro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yurishkuro/subscriptions","organizations_url":"https://api.github.com/users/yurishkuro/orgs","repos_url":"https://api.github.com/users/yurishkuro/repos","events_url":"https://api.github.com/users/yurishkuro/events{/privacy}","received_events_url":"https://api.github.com/users/yurishkuro/received_events","type":"User","site_admin":false},"body":"+1, but conversely a test is missing when you do fall back onto default sampler (when maxOps limit is reached)","created_at":"2016-12-18T18:20:44Z","updated_at":"2016-12-18T18:20:44Z","html_url":"https://github.com/uber/jaeger-client-java/pull/112#discussion_r92947277","pull_request_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/112","_links":{"self":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/comments/92947277"},"html":{"href":"https://github.com/uber/jaeger-client-java/pull/112#discussion_r92947277"},"pull_request":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/112"}}},"pull_request":{"url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/112","id":98022984,"html_url":"https://github.com/uber/jaeger-client-java/pull/112","diff_url":"https://github.com/uber/jaeger-client-java/pull/112.diff","patch_url":"https://github.com/uber/jaeger-client-java/pull/112.patch","issue_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/112","number":112,"state":"open","locked":false,"title":"Support per operation sampling","user":{"login":"vprithvi","id":833009,"avatar_url":"https://avatars.githubusercontent.com/u/833009?v=3","gravatar_id":"","url":"https://api.github.com/users/vprithvi","html_url":"https://github.com/vprithvi","followers_url":"https://api.github.com/users/vprithvi/followers","following_url":"https://api.github.com/users/vprithvi/following{/other_user}","gists_url":"https://api.github.com/users/vprithvi/gists{/gist_id}","starred_url":"https://api.github.com/users/vprithvi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vprithvi/subscriptions","organizations_url":"https://api.github.com/users/vprithvi/orgs","repos_url":"https://api.github.com/users/vprithvi/repos","events_url":"https://api.github.com/users/vprithvi/events{/privacy}","received_events_url":"https://api.github.com/users/vprithvi/received_events","type":"User","site_admin":false},"body":"Add a PerOperationSampler that maintains a sampling probability for every operation","created_at":"2016-12-14T19:50:42Z","updated_at":"2016-12-18T18:23:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4077010e6ca1e421823b8a64d91dffdb75c755e2","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/112/commits","review_comments_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/112/comments","review_comment_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/112/comments","statuses_url":"https://api.github.com/repos/uber/jaeger-client-java/statuses/7c5b4b0abd999593cfddfde97bd4dc1e9c303df8","head":{"label":"uber:adaptive_sampling_3","ref":"adaptive_sampling_3","sha":"7c5b4b0abd999593cfddfde97bd4dc1e9c303df8","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":56551000,"name":"jaeger-client-java","full_name":"uber/jaeger-client-java","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/jaeger-client-java","description":"Jaeger Bindings for Java OpenTracing API","fork":false,"url":"https://api.github.com/repos/uber/jaeger-client-java","forks_url":"https://api.github.com/repos/uber/jaeger-client-java/forks","keys_url":"https://api.github.com/repos/uber/jaeger-client-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/jaeger-client-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/jaeger-client-java/teams","hooks_url":"https://api.github.com/repos/uber/jaeger-client-java/hooks","issue_events_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/events{/number}","events_url":"https://api.github.com/repos/uber/jaeger-client-java/events","assignees_url":"https://api.github.com/repos/uber/jaeger-client-java/assignees{/user}","branches_url":"https://api.github.com/repos/uber/jaeger-client-java/branches{/branch}","tags_url":"https://api.github.com/repos/uber/jaeger-client-java/tags","blobs_url":"https://api.github.com/repos/uber/jaeger-client-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/jaeger-client-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/jaeger-client-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/jaeger-client-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/jaeger-client-java/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/jaeger-client-java/languages","stargazers_url":"https://api.github.com/repos/uber/jaeger-client-java/stargazers","contributors_url":"https://api.github.com/repos/uber/jaeger-client-java/contributors","subscribers_url":"https://api.github.com/repos/uber/jaeger-client-java/subscribers","subscription_url":"https://api.github.com/repos/uber/jaeger-client-java/subscription","commits_url":"https://api.github.com/repos/uber/jaeger-client-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/jaeger-client-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/jaeger-client-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/jaeger-client-java/contents/{+path}","compare_url":"https://api.github.com/repos/uber/jaeger-client-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/jaeger-client-java/merges","archive_url":"https://api.github.com/repos/uber/jaeger-client-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/jaeger-client-java/downloads","issues_url":"https://api.github.com/repos/uber/jaeger-client-java/issues{/number}","pulls_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/jaeger-client-java/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/jaeger-client-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/jaeger-client-java/labels{/name}","releases_url":"https://api.github.com/repos/uber/jaeger-client-java/releases{/id}","deployments_url":"https://api.github.com/repos/uber/jaeger-client-java/deployments","created_at":"2016-04-19T00:10:02Z","updated_at":"2016-12-08T10:16:20Z","pushed_at":"2016-12-16T22:18:57Z","git_url":"git://github.com/uber/jaeger-client-java.git","ssh_url":"git@github.com:uber/jaeger-client-java.git","clone_url":"https://github.com/uber/jaeger-client-java.git","svn_url":"https://github.com/uber/jaeger-client-java","homepage":"http://uber.github.io/jaeger/","size":538,"stargazers_count":13,"watchers_count":13,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":20,"forks":7,"open_issues":20,"watchers":13,"default_branch":"master"}},"base":{"label":"uber:master","ref":"master","sha":"d2d7ded057d52e3df733091ff5a597afcbbb1efb","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":56551000,"name":"jaeger-client-java","full_name":"uber/jaeger-client-java","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/jaeger-client-java","description":"Jaeger Bindings for Java OpenTracing API","fork":false,"url":"https://api.github.com/repos/uber/jaeger-client-java","forks_url":"https://api.github.com/repos/uber/jaeger-client-java/forks","keys_url":"https://api.github.com/repos/uber/jaeger-client-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/jaeger-client-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/jaeger-client-java/teams","hooks_url":"https://api.github.com/repos/uber/jaeger-client-java/hooks","issue_events_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/events{/number}","events_url":"https://api.github.com/repos/uber/jaeger-client-java/events","assignees_url":"https://api.github.com/repos/uber/jaeger-client-java/assignees{/user}","branches_url":"https://api.github.com/repos/uber/jaeger-client-java/branches{/branch}","tags_url":"https://api.github.com/repos/uber/jaeger-client-java/tags","blobs_url":"https://api.github.com/repos/uber/jaeger-client-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/jaeger-client-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/jaeger-client-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/jaeger-client-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/jaeger-client-java/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/jaeger-client-java/languages","stargazers_url":"https://api.github.com/repos/uber/jaeger-client-java/stargazers","contributors_url":"https://api.github.com/repos/uber/jaeger-client-java/contributors","subscribers_url":"https://api.github.com/repos/uber/jaeger-client-java/subscribers","subscription_url":"https://api.github.com/repos/uber/jaeger-client-java/subscription","commits_url":"https://api.github.com/repos/uber/jaeger-client-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/jaeger-client-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/jaeger-client-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/jaeger-client-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/jaeger-client-java/contents/{+path}","compare_url":"https://api.github.com/repos/uber/jaeger-client-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/jaeger-client-java/merges","archive_url":"https://api.github.com/repos/uber/jaeger-client-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/jaeger-client-java/downloads","issues_url":"https://api.github.com/repos/uber/jaeger-client-java/issues{/number}","pulls_url":"https://api.github.com/repos/uber/jaeger-client-java/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/jaeger-client-java/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/jaeger-client-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/jaeger-client-java/labels{/name}","releases_url":"https://api.github.com/repos/uber/jaeger-client-java/releases{/id}","deployments_url":"https://api.github.com/repos/uber/jaeger-client-java/deployments","created_at":"2016-04-19T00:10:02Z","updated_at":"2016-12-08T10:16:20Z","pushed_at":"2016-12-16T22:18:57Z","git_url":"git://github.com/uber/jaeger-client-java.git","ssh_url":"git@github.com:uber/jaeger-client-java.git","clone_url":"https://github.com/uber/jaeger-client-java.git","svn_url":"https://github.com/uber/jaeger-client-java","homepage":"http://uber.github.io/jaeger/","size":538,"stargazers_count":13,"watchers_count":13,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":20,"forks":7,"open_issues":20,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/112"},"html":{"href":"https://github.com/uber/jaeger-client-java/pull/112"},"issue":{"href":"https://api.github.com/repos/uber/jaeger-client-java/issues/112"},"comments":{"href":"https://api.github.com/repos/uber/jaeger-client-java/issues/112/comments"},"review_comments":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/112/comments"},"review_comment":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber/jaeger-client-java/pulls/112/commits"},"statuses":{"href":"https://api.github.com/repos/uber/jaeger-client-java/statuses/7c5b4b0abd999593cfddfde97bd4dc1e9c303df8"}}}}
{"actor":{"display_login":"yurishkuro"}}