{"action":"created","comment":{"url":"https://api.github.com/repos/square/p2/pulls/comments/83904219","pull_request_review_id":4716457,"id":83904219,"diff_hunk":"@@ -0,0 +1,88 @@\n+package labels\n+\n+import (\n+\t\"fmt\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"github.com/rcrowley/go-metrics\"\n+\tp2metrics \"github.com/square/p2/pkg/metrics\"\n+)\n+\n+type Batcher struct {\n+\tcreateBatcherMux sync.Mutex\n+\tapplicator       Applicator\n+\tholdTime         time.Duration\n+\ttypeBatchers     map[Type]*TypeBatcher\n+}\n+\n+func NewBatcher(applicator Applicator, holdTime time.Duration) Batcher {\n+\treturn Batcher{\n+\t\tapplicator:   applicator,\n+\t\tholdTime:     holdTime,\n+\t\ttypeBatchers: make(map[Type]*TypeBatcher),\n+\t}\n+}\n+\n+func (b *Batcher) ForType(labelType Type) *TypeBatcher {\n+\tb.createBatcherMux.Lock()\n+\tdefer b.createBatcherMux.Unlock()\n+\tbatcher, ok := b.typeBatchers[labelType]\n+\tif !ok {\n+\t\tbatcher = &TypeBatcher{\n+\t\t\tapplicator:      b.applicator,\n+\t\t\tholdTime:        b.holdTime,\n+\t\t\tlabelType:       labelType,\n+\t\t\tpending:         []chan []Labeled{},\n+\t\t\tqueriesPerBatch: metrics.NewRegisteredHistogram(fmt.Sprintf(\"queries-per-%v-batch\", labelType), p2metrics.Registry, metrics.NewUniformSample(1000)),\n+\t\t}\n+\t\tb.typeBatchers[labelType] = batcher\n+\t}\n+\treturn batcher\n+}\n+\n+// Batches a single label type\n+type TypeBatcher struct {\n+\tapplicator Applicator\n+\tcreateMux  sync.Mutex\n+\tlabelType  Type\n+\n+\tholdTime        time.Duration\n+\tpending         []chan []Labeled\n+\tbatchInProgress bool\n+\tqueriesPerBatch metrics.Histogram\n+}\n+\n+func (b *TypeBatcher) handleBatch() {\n+\tafter := time.After(b.holdTime)\n+\tallLabels, err := b.applicator.ListLabels(b.labelType)\n+\t<-after\n+\tb.createMux.Lock()\n+\tdefer b.createMux.Unlock()\n+\tb.queriesPerBatch.Update(int64(len(b.pending)))\n+\tfor _, ch := range b.pending {\n+\t\tif err != nil {\n+\t\t\tclose(ch)\n+\t\t} else {\n+\t\t\tch <- allLabels","path":"pkg/labels/batcher.go","position":67,"original_position":67,"commit_id":"af22118fda0f2288a42fd650deb87ff2e39e6eb1","original_commit_id":"564dc60260b2ec95df73b69dde4dbd1ad0157ea3","user":{"login":"mpuncel","id":1444855,"avatar_url":"https://avatars.githubusercontent.com/u/1444855?v=3","gravatar_id":"","url":"https://api.github.com/users/mpuncel","html_url":"https://github.com/mpuncel","followers_url":"https://api.github.com/users/mpuncel/followers","following_url":"https://api.github.com/users/mpuncel/following{/other_user}","gists_url":"https://api.github.com/users/mpuncel/gists{/gist_id}","starred_url":"https://api.github.com/users/mpuncel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpuncel/subscriptions","organizations_url":"https://api.github.com/users/mpuncel/orgs","repos_url":"https://api.github.com/users/mpuncel/repos","events_url":"https://api.github.com/users/mpuncel/events{/privacy}","received_events_url":"https://api.github.com/users/mpuncel/received_events","type":"User","site_admin":false},"body":"you should `close(ch)` here as well","created_at":"2016-10-18T17:14:20Z","updated_at":"2016-10-18T17:45:52Z","html_url":"https://github.com/square/p2/pull/681#discussion_r83904219","pull_request_url":"https://api.github.com/repos/square/p2/pulls/681","_links":{"self":{"href":"https://api.github.com/repos/square/p2/pulls/comments/83904219"},"html":{"href":"https://github.com/square/p2/pull/681#discussion_r83904219"},"pull_request":{"href":"https://api.github.com/repos/square/p2/pulls/681"}}},"pull_request":{"url":"https://api.github.com/repos/square/p2/pulls/681","id":89731640,"html_url":"https://github.com/square/p2/pull/681","diff_url":"https://github.com/square/p2/pull/681.diff","patch_url":"https://github.com/square/p2/pull/681.patch","issue_url":"https://api.github.com/repos/square/p2/issues/681","number":681,"state":"open","locked":false,"title":"Implement HTTP applicator endpoints and simple server.","user":{"login":"anthonybishopric","id":540783,"avatar_url":"https://avatars.githubusercontent.com/u/540783?v=3","gravatar_id":"","url":"https://api.github.com/users/anthonybishopric","html_url":"https://github.com/anthonybishopric","followers_url":"https://api.github.com/users/anthonybishopric/followers","following_url":"https://api.github.com/users/anthonybishopric/following{/other_user}","gists_url":"https://api.github.com/users/anthonybishopric/gists{/gist_id}","starred_url":"https://api.github.com/users/anthonybishopric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthonybishopric/subscriptions","organizations_url":"https://api.github.com/users/anthonybishopric/orgs","repos_url":"https://api.github.com/users/anthonybishopric/repos","events_url":"https://api.github.com/users/anthonybishopric/events{/privacy}","received_events_url":"https://api.github.com/users/anthonybishopric/received_events","type":"User","site_admin":false},"body":"This change introduces many more endpoints implemented in the\r\nHTTP label applicator as well as a simple server that clients\r\ncan use.\r\n\r\nThis change also adds the Gorilla multiplexer.","created_at":"2016-10-18T01:20:43Z","updated_at":"2016-10-18T17:45:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3f23913490a27dc7ec405a3e7b5c256c15ab47ea","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/square/p2/pulls/681/commits","review_comments_url":"https://api.github.com/repos/square/p2/pulls/681/comments","review_comment_url":"https://api.github.com/repos/square/p2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/square/p2/issues/681/comments","statuses_url":"https://api.github.com/repos/square/p2/statuses/af22118fda0f2288a42fd650deb87ff2e39e6eb1","head":{"label":"anthonybishopric:abishopric/httplabels","ref":"abishopric/httplabels","sha":"af22118fda0f2288a42fd650deb87ff2e39e6eb1","user":{"login":"anthonybishopric","id":540783,"avatar_url":"https://avatars.githubusercontent.com/u/540783?v=3","gravatar_id":"","url":"https://api.github.com/users/anthonybishopric","html_url":"https://github.com/anthonybishopric","followers_url":"https://api.github.com/users/anthonybishopric/followers","following_url":"https://api.github.com/users/anthonybishopric/following{/other_user}","gists_url":"https://api.github.com/users/anthonybishopric/gists{/gist_id}","starred_url":"https://api.github.com/users/anthonybishopric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthonybishopric/subscriptions","organizations_url":"https://api.github.com/users/anthonybishopric/orgs","repos_url":"https://api.github.com/users/anthonybishopric/repos","events_url":"https://api.github.com/users/anthonybishopric/events{/privacy}","received_events_url":"https://api.github.com/users/anthonybishopric/received_events","type":"User","site_admin":false},"repo":{"id":25321022,"name":"p2","full_name":"anthonybishopric/p2","owner":{"login":"anthonybishopric","id":540783,"avatar_url":"https://avatars.githubusercontent.com/u/540783?v=3","gravatar_id":"","url":"https://api.github.com/users/anthonybishopric","html_url":"https://github.com/anthonybishopric","followers_url":"https://api.github.com/users/anthonybishopric/followers","following_url":"https://api.github.com/users/anthonybishopric/following{/other_user}","gists_url":"https://api.github.com/users/anthonybishopric/gists{/gist_id}","starred_url":"https://api.github.com/users/anthonybishopric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthonybishopric/subscriptions","organizations_url":"https://api.github.com/users/anthonybishopric/orgs","repos_url":"https://api.github.com/users/anthonybishopric/repos","events_url":"https://api.github.com/users/anthonybishopric/events{/privacy}","received_events_url":"https://api.github.com/users/anthonybishopric/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anthonybishopric/p2","description":"Platypus Platform: Tools for Scalable Deployment","fork":true,"url":"https://api.github.com/repos/anthonybishopric/p2","forks_url":"https://api.github.com/repos/anthonybishopric/p2/forks","keys_url":"https://api.github.com/repos/anthonybishopric/p2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anthonybishopric/p2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anthonybishopric/p2/teams","hooks_url":"https://api.github.com/repos/anthonybishopric/p2/hooks","issue_events_url":"https://api.github.com/repos/anthonybishopric/p2/issues/events{/number}","events_url":"https://api.github.com/repos/anthonybishopric/p2/events","assignees_url":"https://api.github.com/repos/anthonybishopric/p2/assignees{/user}","branches_url":"https://api.github.com/repos/anthonybishopric/p2/branches{/branch}","tags_url":"https://api.github.com/repos/anthonybishopric/p2/tags","blobs_url":"https://api.github.com/repos/anthonybishopric/p2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anthonybishopric/p2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anthonybishopric/p2/git/refs{/sha}","trees_url":"https://api.github.com/repos/anthonybishopric/p2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anthonybishopric/p2/statuses/{sha}","languages_url":"https://api.github.com/repos/anthonybishopric/p2/languages","stargazers_url":"https://api.github.com/repos/anthonybishopric/p2/stargazers","contributors_url":"https://api.github.com/repos/anthonybishopric/p2/contributors","subscribers_url":"https://api.github.com/repos/anthonybishopric/p2/subscribers","subscription_url":"https://api.github.com/repos/anthonybishopric/p2/subscription","commits_url":"https://api.github.com/repos/anthonybishopric/p2/commits{/sha}","git_commits_url":"https://api.github.com/repos/anthonybishopric/p2/git/commits{/sha}","comments_url":"https://api.github.com/repos/anthonybishopric/p2/comments{/number}","issue_comment_url":"https://api.github.com/repos/anthonybishopric/p2/issues/comments{/number}","contents_url":"https://api.github.com/repos/anthonybishopric/p2/contents/{+path}","compare_url":"https://api.github.com/repos/anthonybishopric/p2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anthonybishopric/p2/merges","archive_url":"https://api.github.com/repos/anthonybishopric/p2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anthonybishopric/p2/downloads","issues_url":"https://api.github.com/repos/anthonybishopric/p2/issues{/number}","pulls_url":"https://api.github.com/repos/anthonybishopric/p2/pulls{/number}","milestones_url":"https://api.github.com/repos/anthonybishopric/p2/milestones{/number}","notifications_url":"https://api.github.com/repos/anthonybishopric/p2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anthonybishopric/p2/labels{/name}","releases_url":"https://api.github.com/repos/anthonybishopric/p2/releases{/id}","deployments_url":"https://api.github.com/repos/anthonybishopric/p2/deployments","created_at":"2014-10-16T20:45:38Z","updated_at":"2016-02-10T18:14:28Z","pushed_at":"2016-10-18T16:48:00Z","git_url":"git://github.com/anthonybishopric/p2.git","ssh_url":"git@github.com:anthonybishopric/p2.git","clone_url":"https://github.com/anthonybishopric/p2.git","svn_url":"https://github.com/anthonybishopric/p2","homepage":"","size":41254,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"square:master","ref":"master","sha":"5be27ac05e551d557c1127424f32be2413f3bcfb","user":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"repo":{"id":25320424,"name":"p2","full_name":"square/p2","owner":{"login":"square","id":82592,"avatar_url":"https://avatars.githubusercontent.com/u/82592?v=3","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/square/p2","description":"Platypus Platform: Tools for Scalable Deployment","fork":false,"url":"https://api.github.com/repos/square/p2","forks_url":"https://api.github.com/repos/square/p2/forks","keys_url":"https://api.github.com/repos/square/p2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/square/p2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/square/p2/teams","hooks_url":"https://api.github.com/repos/square/p2/hooks","issue_events_url":"https://api.github.com/repos/square/p2/issues/events{/number}","events_url":"https://api.github.com/repos/square/p2/events","assignees_url":"https://api.github.com/repos/square/p2/assignees{/user}","branches_url":"https://api.github.com/repos/square/p2/branches{/branch}","tags_url":"https://api.github.com/repos/square/p2/tags","blobs_url":"https://api.github.com/repos/square/p2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/square/p2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/square/p2/git/refs{/sha}","trees_url":"https://api.github.com/repos/square/p2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/square/p2/statuses/{sha}","languages_url":"https://api.github.com/repos/square/p2/languages","stargazers_url":"https://api.github.com/repos/square/p2/stargazers","contributors_url":"https://api.github.com/repos/square/p2/contributors","subscribers_url":"https://api.github.com/repos/square/p2/subscribers","subscription_url":"https://api.github.com/repos/square/p2/subscription","commits_url":"https://api.github.com/repos/square/p2/commits{/sha}","git_commits_url":"https://api.github.com/repos/square/p2/git/commits{/sha}","comments_url":"https://api.github.com/repos/square/p2/comments{/number}","issue_comment_url":"https://api.github.com/repos/square/p2/issues/comments{/number}","contents_url":"https://api.github.com/repos/square/p2/contents/{+path}","compare_url":"https://api.github.com/repos/square/p2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/square/p2/merges","archive_url":"https://api.github.com/repos/square/p2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/square/p2/downloads","issues_url":"https://api.github.com/repos/square/p2/issues{/number}","pulls_url":"https://api.github.com/repos/square/p2/pulls{/number}","milestones_url":"https://api.github.com/repos/square/p2/milestones{/number}","notifications_url":"https://api.github.com/repos/square/p2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/square/p2/labels{/name}","releases_url":"https://api.github.com/repos/square/p2/releases{/id}","deployments_url":"https://api.github.com/repos/square/p2/deployments","created_at":"2014-10-16T20:31:12Z","updated_at":"2016-10-12T06:09:22Z","pushed_at":"2016-10-18T16:48:01Z","git_url":"git://github.com/square/p2.git","ssh_url":"git@github.com:square/p2.git","clone_url":"https://github.com/square/p2.git","svn_url":"https://github.com/square/p2","homepage":"","size":44158,"stargazers_count":126,"watchers_count":126,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":10,"forks":23,"open_issues":10,"watchers":126,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/square/p2/pulls/681"},"html":{"href":"https://github.com/square/p2/pull/681"},"issue":{"href":"https://api.github.com/repos/square/p2/issues/681"},"comments":{"href":"https://api.github.com/repos/square/p2/issues/681/comments"},"review_comments":{"href":"https://api.github.com/repos/square/p2/pulls/681/comments"},"review_comment":{"href":"https://api.github.com/repos/square/p2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/square/p2/pulls/681/commits"},"statuses":{"href":"https://api.github.com/repos/square/p2/statuses/af22118fda0f2288a42fd650deb87ff2e39e6eb1"}}}}
{"actor":{"display_login":"mpuncel"}}