GitHub PullRequestReviewCommentEvent at 2014-08-05 23:02:25
Repository: pushgo
Actor: kitcambridge
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-services/pushgo/pulls/comments/15847876","id":15847876,"diff_hunk":"@@ -1,187 +1,313 @@\n+// HTTP version of the cross machine router\n+// Fetch the servers from etcd, divvy them up into buckets,\n+// proxy the update to the servers, stopping once you've gotten\n+// a successful return.\n+// PROS:\n+//  Very simple to implement\n+//  hosts can autoannounce\n+//  no AWS dependencies\n+// CONS:\n+//  fair bit of cross traffic (try to minimize)\n+\n+// Obviously a PubSub would be better, but might require more server\n+// state management (because of duplicate messages)\n package router\n \n import (\n+\t\"github.com/coreos/go-etcd/etcd\"\n+\tstorage \"mozilla.org/simplepush/storage/mcstorage\"\n+\t\"mozilla.org/util\"\n+\n \t\"bytes\"\n+\t\"crypto/tls\"\n \t\"encoding/json\"\n+\t\"errors\"\n \t\"fmt\"\n-\t\"io\"\n-\t\"log\"\n-\t\"mozilla.org/util\"\n-\t\"net\"\n-\t\"sync\"\n+\t\"math/rand\"\n+\t\"net/http\"\n+\t\"strconv\"\n+\t\"strings\"\n+\t\"text/template\"\n \t\"time\"\n )\n \n+const (\n+\tETCD_DIR = \"push_hosts/\"\n+)\n+\n var (\n-\tNL     []byte = []byte(\"\\n\")\n-\tEOL    []byte = []byte(\"\\x04\\n\")\n-\troutes map[string]*Route\n+\terrNextCastle = errors.New(\"Client not found\")\n )\n \n type Router struct {\n-\tPort   string\n-\tLogger *util.HekaLogger\n-    Metrics *util.Metrics\n-}\n-\n-type Route struct {\n-\tsocket net.Conn\n+\tconfig      *util.MzConfig\n+\tlogger      *util.MzLogger\n+\tmetrics     *util.Metrics\n+\tbucketSize  int64\n+\ttemplate    *template.Template\n+\ttimeout     time.Duration\n+\tdefaultTTL  uint64\n+\tclient      *etcd.Client\n+\tlastRefresh time.Time\n+\tserverList  []string\n+\tstorage     *storage.Storage\n+\tcollider    func(string) bool\n+\thost        string\n+\tscheme      string\n }\n \n-var MuRoutes sync.Mutex\n-\n-type Update struct {\n-\tUaid string    `json:\"uaid\"`\n-\tChid string    `json:\"chid\"`\n-\tVers int64     `json:\"vers\"`\n-\tTime time.Time `json:\"time\"`\n-}\n-\n-type Updater func(*Update, *util.HekaLogger, *util.Metrics) error\n-\n-func (self *Router) HandleUpdates(updater Updater) {\n-\t/* There appears to be a difference in how the connection is specified.\n-\t   \"0.0.0.0:3000\" creates a binding port that blocks any additional\n-\t   connections. \":3000\", however, creates a multiplexing port that allows\n-\t   multiple connections. There are, however, complications. The remote\n-\t   port appears not to be able to see the remote connection terminate.\n-\t   Any future connection will succeed, but will not pass data.\n-\t   This is why I have the explicit \"close command\" in place while I sort\n-\t   out where the hell the bug is in the TCP handler layer.\n-\t*/\n-\tlistener, err := net.Listen(\"tcp\", \":\"+self.Port)\n+// Get the servers from the etcd cluster\n+func (self *Router) getServers() (reply []string, err error) {\n+\tif time.Now().Sub(self.lastRefresh) < (time.Minute * 5) {\n+\t\treturn self.serverList, nil\n+\t}\n+\tnodeList, err := self.client.Get(ETCD_DIR, false, false)\n \tif err != nil {\n-\t\tif self.Logger != nil {\n-\t\t\tself.Logger.Critical(\"router\",\n-\t\t\t\t\"Could not open listener:\"+err.Error(), nil)\n-\t\t} else {\n-\t\t\tlog.Printf(\"error listening %s\", err.Error())\n-\t\t}\n-\t\treturn\n+\t\treturn self.serverList, err\n \t}\n-\tlog.Printf(\"Listening for updates on *:\" + self.Port)\n+\treply = []string{}\n+\tfor _, node := range nodeList.Node.Nodes {\n+\t\treply = append(reply, node.Value)\n+\t}\n+\tself.serverList = reply","path":"src/mozilla.org/simplepush/router/router.go","position":117,"original_position":117,"commit_id":"a702f429eed5bab1df25ed9953136150acdf2ebe","original_commit_id":"a702f429eed5bab1df25ed9953136150acdf2ebe","user":{"login":"kitcambridge","id":243830,"avatar_url":"https://avatars.githubusercontent.com/u/243830?v=2","gravatar_id":"92f971951ab517f93be7866f0cf28777","url":"https://api.github.com/users/kitcambridge","html_url":"https://github.com/kitcambridge","followers_url":"https://api.github.com/users/kitcambridge/followers","following_url":"https://api.github.com/users/kitcambridge/following{/other_user}","gists_url":"https://api.github.com/users/kitcambridge/gists{/gist_id}","starred_url":"https://api.github.com/users/kitcambridge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kitcambridge/subscriptions","organizations_url":"https://api.github.com/users/kitcambridge/orgs","repos_url":"https://api.github.com/users/kitcambridge/repos","events_url":"https://api.github.com/users/kitcambridge/events{/privacy}","received_events_url":"https://api.github.com/users/kitcambridge/received_events","type":"User","site_admin":false},"body":"`self.lastRefresh = time.Now()`?","created_at":"2014-08-05T23:02:25Z","updated_at":"2014-08-05T23:02:25Z","html_url":"https://github.com/mozilla-services/pushgo/pull/26#discussion_r15847876","pull_request_url":"https://api.github.com/repos/mozilla-services/pushgo/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/mozilla-services/pushgo/pulls/comments/15847876"},"html":{"href":"https://github.com/mozilla-services/pushgo/pull/26#discussion_r15847876"},"pull_request":{"href":"https://api.github.com/repos/mozilla-services/pushgo/pulls/26"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla-services/pushgo/pulls/26","id":19370238,"html_url":"https://github.com/mozilla-services/pushgo/pull/26","diff_url":"https://github.com/mozilla-services/pushgo/pull/26.diff","patch_url":"https://github.com/mozilla-services/pushgo/pull/26.patch","issue_url":"https://api.github.com/repos/mozilla-services/pushgo/issues/26","number":26,"state":"open","title":"Added http.mux based routing","user":{"login":"jrconlin","id":35755,"avatar_url":"https://avatars.githubusercontent.com/u/35755?v=2","gravatar_id":"b0ad88743c34ae5c1a3ac93aff088102","url":"https://api.github.com/users/jrconlin","html_url":"https://github.com/jrconlin","followers_url":"https://api.github.com/users/jrconlin/followers","following_url":"https://api.github.com/users/jrconlin/following{/other_user}","gists_url":"https://api.github.com/users/jrconlin/gists{/gist_id}","starred_url":"https://api.github.com/users/jrconlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrconlin/subscriptions","organizations_url":"https://api.github.com/users/jrconlin/orgs","repos_url":"https://api.github.com/users/jrconlin/repos","events_url":"https://api.github.com/users/jrconlin/events{/privacy}","received_events_url":"https://api.github.com/users/jrconlin/received_events","type":"User","site_admin":false},"body":"","created_at":"2014-08-05T21:14:20Z","updated_at":"2014-08-05T23:02:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc4e20d439a29fe907b6ee0a8b9197b49df801a6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-services/pushgo/pulls/26/commits","review_comments_url":"https://api.github.com/repos/mozilla-services/pushgo/pulls/26/comments","review_comment_url":"https://api.github.com/repos/mozilla-services/pushgo/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla-services/pushgo/issues/26/comments","statuses_url":"https://api.github.com/repos/mozilla-services/pushgo/statuses/a702f429eed5bab1df25ed9953136150acdf2ebe","head":{"label":"jrconlin:dev","ref":"dev","sha":"a702f429eed5bab1df25ed9953136150acdf2ebe","user":{"login":"jrconlin","id":35755,"avatar_url":"https://avatars.githubusercontent.com/u/35755?v=2","gravatar_id":"b0ad88743c34ae5c1a3ac93aff088102","url":"https://api.github.com/users/jrconlin","html_url":"https://github.com/jrconlin","followers_url":"https://api.github.com/users/jrconlin/followers","following_url":"https://api.github.com/users/jrconlin/following{/other_user}","gists_url":"https://api.github.com/users/jrconlin/gists{/gist_id}","starred_url":"https://api.github.com/users/jrconlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrconlin/subscriptions","organizations_url":"https://api.github.com/users/jrconlin/orgs","repos_url":"https://api.github.com/users/jrconlin/repos","events_url":"https://api.github.com/users/jrconlin/events{/privacy}","received_events_url":"https://api.github.com/users/jrconlin/received_events","type":"User","site_admin":false},"repo":{"id":9796726,"name":"pushgo","full_name":"jrconlin/pushgo","owner":{"login":"jrconlin","id":35755,"avatar_url":"https://avatars.githubusercontent.com/u/35755?v=2","gravatar_id":"b0ad88743c34ae5c1a3ac93aff088102","url":"https://api.github.com/users/jrconlin","html_url":"https://github.com/jrconlin","followers_url":"https://api.github.com/users/jrconlin/followers","following_url":"https://api.github.com/users/jrconlin/following{/other_user}","gists_url":"https://api.github.com/users/jrconlin/gists{/gist_id}","starred_url":"https://api.github.com/users/jrconlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrconlin/subscriptions","organizations_url":"https://api.github.com/users/jrconlin/orgs","repos_url":"https://api.github.com/users/jrconlin/repos","events_url":"https://api.github.com/users/jrconlin/events{/privacy}","received_events_url":"https://api.github.com/users/jrconlin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jrconlin/pushgo","description":"Go based SimplePush server","fork":false,"url":"https://api.github.com/repos/jrconlin/pushgo","forks_url":"https://api.github.com/repos/jrconlin/pushgo/forks","keys_url":"https://api.github.com/repos/jrconlin/pushgo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jrconlin/pushgo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jrconlin/pushgo/teams","hooks_url":"https://api.github.com/repos/jrconlin/pushgo/hooks","issue_events_url":"https://api.github.com/repos/jrconlin/pushgo/issues/events{/number}","events_url":"https://api.github.com/repos/jrconlin/pushgo/events","assignees_url":"https://api.github.com/repos/jrconlin/pushgo/assignees{/user}","branches_url":"https://api.github.com/repos/jrconlin/pushgo/branches{/branch}","tags_url":"https://api.github.com/repos/jrconlin/pushgo/tags","blobs_url":"https://api.github.com/repos/jrconlin/pushgo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jrconlin/pushgo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jrconlin/pushgo/git/refs{/sha}","trees_url":"https://api.github.com/repos/jrconlin/pushgo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jrconlin/pushgo/statuses/{sha}","languages_url":"https://api.github.com/repos/jrconlin/pushgo/languages","stargazers_url":"https://api.github.com/repos/jrconlin/pushgo/stargazers","contributors_url":"https://api.github.com/repos/jrconlin/pushgo/contributors","subscribers_url":"https://api.github.com/repos/jrconlin/pushgo/subscribers","subscription_url":"https://api.github.com/repos/jrconlin/pushgo/subscription","commits_url":"https://api.github.com/repos/jrconlin/pushgo/commits{/sha}","git_commits_url":"https://api.github.com/repos/jrconlin/pushgo/git/commits{/sha}","comments_url":"https://api.github.com/repos/jrconlin/pushgo/comments{/number}","issue_comment_url":"https://api.github.com/repos/jrconlin/pushgo/issues/comments/{number}","contents_url":"https://api.github.com/repos/jrconlin/pushgo/contents/{+path}","compare_url":"https://api.github.com/repos/jrconlin/pushgo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jrconlin/pushgo/merges","archive_url":"https://api.github.com/repos/jrconlin/pushgo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jrconlin/pushgo/downloads","issues_url":"https://api.github.com/repos/jrconlin/pushgo/issues{/number}","pulls_url":"https://api.github.com/repos/jrconlin/pushgo/pulls{/number}","milestones_url":"https://api.github.com/repos/jrconlin/pushgo/milestones{/number}","notifications_url":"https://api.github.com/repos/jrconlin/pushgo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jrconlin/pushgo/labels{/name}","releases_url":"https://api.github.com/repos/jrconlin/pushgo/releases{/id}","created_at":"2013-05-01T17:59:14Z","updated_at":"2014-07-08T04:42:39Z","pushed_at":"2014-08-05T21:12:11Z","git_url":"git://github.com/jrconlin/pushgo.git","ssh_url":"git@github.com:jrconlin/pushgo.git","clone_url":"https://github.com/jrconlin/pushgo.git","svn_url":"https://github.com/jrconlin/pushgo","homepage":null,"size":2256,"stargazers_count":15,"watchers_count":15,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":15,"mirror_url":null,"open_issues_count":2,"forks":15,"open_issues":2,"watchers":15,"default_branch":"master"}},"base":{"label":"mozilla-services:master","ref":"master","sha":"4b9b0651bbc0159c8e237e66a2ce823f3ab850a4","user":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=2","gravatar_id":"a41a81f9188770933a4b54382c29cae4","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"repo":{"id":11289838,"name":"pushgo","full_name":"mozilla-services/pushgo","owner":{"login":"mozilla-services","id":1066228,"avatar_url":"https://avatars.githubusercontent.com/u/1066228?v=2","gravatar_id":"a41a81f9188770933a4b54382c29cae4","url":"https://api.github.com/users/mozilla-services","html_url":"https://github.com/mozilla-services","followers_url":"https://api.github.com/users/mozilla-services/followers","following_url":"https://api.github.com/users/mozilla-services/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-services/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-services/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-services/subscriptions","organizations_url":"https://api.github.com/users/mozilla-services/orgs","repos_url":"https://api.github.com/users/mozilla-services/repos","events_url":"https://api.github.com/users/mozilla-services/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-services/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla-services/pushgo","description":"Go based SimplePush server","fork":true,"url":"https://api.github.com/repos/mozilla-services/pushgo","forks_url":"https://api.github.com/repos/mozilla-services/pushgo/forks","keys_url":"https://api.github.com/repos/mozilla-services/pushgo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-services/pushgo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-services/pushgo/teams","hooks_url":"https://api.github.com/repos/mozilla-services/pushgo/hooks","issue_events_url":"https://api.github.com/repos/mozilla-services/pushgo/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-services/pushgo/events","assignees_url":"https://api.github.com/repos/mozilla-services/pushgo/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-services/pushgo/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-services/pushgo/tags","blobs_url":"https://api.github.com/repos/mozilla-services/pushgo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-services/pushgo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-services/pushgo/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-services/pushgo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-services/pushgo/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-services/pushgo/languages","stargazers_url":"https://api.github.com/repos/mozilla-services/pushgo/stargazers","contributors_url":"https://api.github.com/repos/mozilla-services/pushgo/contributors","subscribers_url":"https://api.github.com/repos/mozilla-services/pushgo/subscribers","subscription_url":"https://api.github.com/repos/mozilla-services/pushgo/subscription","commits_url":"https://api.github.com/repos/mozilla-services/pushgo/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-services/pushgo/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-services/pushgo/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-services/pushgo/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla-services/pushgo/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-services/pushgo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-services/pushgo/merges","archive_url":"https://api.github.com/repos/mozilla-services/pushgo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-services/pushgo/downloads","issues_url":"https://api.github.com/repos/mozilla-services/pushgo/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-services/pushgo/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-services/pushgo/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-services/pushgo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-services/pushgo/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-services/pushgo/releases{/id}","created_at":"2013-07-09T18:06:52Z","updated_at":"2014-07-26T05:44:59Z","pushed_at":"2014-08-04T22:32:15Z","git_url":"git://github.com/mozilla-services/pushgo.git","ssh_url":"git@github.com:mozilla-services/pushgo.git","clone_url":"https://github.com/mozilla-services/pushgo.git","svn_url":"https://github.com/mozilla-services/pushgo","homepage":null,"size":1530,"stargazers_count":9,"watchers_count":9,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":3,"mirror_url":null,"open_issues_count":3,"forks":3,"open_issues":3,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-services/pushgo/pulls/26"},"html":{"href":"https://github.com/mozilla-services/pushgo/pull/26"},"issue":{"href":"https://api.github.com/repos/mozilla-services/pushgo/issues/26"},"comments":{"href":"https://api.github.com/repos/mozilla-services/pushgo/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-services/pushgo/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-services/pushgo/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla-services/pushgo/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-services/pushgo/statuses/a702f429eed5bab1df25ed9953136150acdf2ebe"}}}}