{"action":"created","comment":{"url":"https://api.github.com/repos/QubitProducts/bamboo/pulls/comments/35491376","id":35491376,"diff_hunk":"@@ -171,6 +180,67 @@ func listenToZookeeper(conf configuration.Configuration, eventBus *event_bus.Eve\n \treturn serviceConn\n }\n \n+func listenToEventStream(conf configuration.Configuration, eventBus *event_bus.EventBus) {\n+\tclient := &http.Client{}\n+\tclient.Timeout = 0 * time.Second\n+\n+\tfor _, marathon := range conf.Marathon.Endpoints() {\n+\t\tgo func() {\n+\t\t\tfor {\n+\t\t\t\treq, err := http.NewRequest(\"GET\", marathon+\"/v2/events\", nil)\n+\t\t\t\treq.Header.Set(\"Accept\", \"text/event-stream\")\n+\t\t\t\tif err != nil {\n+\t\t\t\t\terrorMsg := \"An error occurred while creating request to Marathon events system: %s\\n\"\n+\t\t\t\t\tlog.Printf(errorMsg, err)\n+\t\t\t\t\tcontinue\n+\t\t\t\t}\n+\n+\t\t\t\tresp, err := client.Do(req)\n+\t\t\t\tif err != nil {\n+\t\t\t\t\tcontinue","path":"main/bamboo/bamboo.go","position":53,"original_position":53,"commit_id":"040d1648615c6881a95dd920b72abdc91d70147a","original_commit_id":"040d1648615c6881a95dd920b72abdc91d70147a","user":{"login":"bluepeppers","id":78389,"avatar_url":"https://avatars.githubusercontent.com/u/78389?v=3","gravatar_id":"","url":"https://api.github.com/users/bluepeppers","html_url":"https://github.com/bluepeppers","followers_url":"https://api.github.com/users/bluepeppers/followers","following_url":"https://api.github.com/users/bluepeppers/following{/other_user}","gists_url":"https://api.github.com/users/bluepeppers/gists{/gist_id}","starred_url":"https://api.github.com/users/bluepeppers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluepeppers/subscriptions","organizations_url":"https://api.github.com/users/bluepeppers/orgs","repos_url":"https://api.github.com/users/bluepeppers/repos","events_url":"https://api.github.com/users/bluepeppers/events{/privacy}","received_events_url":"https://api.github.com/users/bluepeppers/received_events","type":"User","site_admin":false},"body":"Using a ticker, if the connection stayed up more than 1 second, the next reconnection would be instant. It limits but keep the standard case of a random drop/server restart very fast.","created_at":"2015-07-26T10:38:29Z","updated_at":"2015-07-26T10:38:29Z","html_url":"https://github.com/QubitProducts/bamboo/pull/151#discussion_r35491376","pull_request_url":"https://api.github.com/repos/QubitProducts/bamboo/pulls/151","_links":{"self":{"href":"https://api.github.com/repos/QubitProducts/bamboo/pulls/comments/35491376"},"html":{"href":"https://github.com/QubitProducts/bamboo/pull/151#discussion_r35491376"},"pull_request":{"href":"https://api.github.com/repos/QubitProducts/bamboo/pulls/151"}}},"pull_request":{"url":"https://api.github.com/repos/QubitProducts/bamboo/pulls/151","id":40838442,"html_url":"https://github.com/QubitProducts/bamboo/pull/151","diff_url":"https://github.com/QubitProducts/bamboo/pull/151.diff","patch_url":"https://github.com/QubitProducts/bamboo/pull/151.patch","issue_url":"https://api.github.com/repos/QubitProducts/bamboo/issues/151","number":151,"state":"open","locked":false,"title":"re #149 support event streaming","user":{"login":"bsideup","id":1050762,"avatar_url":"https://avatars.githubusercontent.com/u/1050762?v=3","gravatar_id":"","url":"https://api.github.com/users/bsideup","html_url":"https://github.com/bsideup","followers_url":"https://api.github.com/users/bsideup/followers","following_url":"https://api.github.com/users/bsideup/following{/other_user}","gists_url":"https://api.github.com/users/bsideup/gists{/gist_id}","starred_url":"https://api.github.com/users/bsideup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsideup/subscriptions","organizations_url":"https://api.github.com/users/bsideup/orgs","repos_url":"https://api.github.com/users/bsideup/repos","events_url":"https://api.github.com/users/bsideup/events{/privacy}","received_events_url":"https://api.github.com/users/bsideup/received_events","type":"User","site_admin":false},"body":"I'm happy to contribute this small, but very helpful improvement - event stream listener.\r\n\r\nStarting from Marathon 0.9.0 it provides /v2/events endpoint, which is implementation of Server-sent Events. It's much better compared to event callbacks since there is no need to register Bamboo as callback on Marathon. \r\n\r\nImplementation is backward compatible with 0.7.0 because this mode is disabled by default. It could be enabled in config like that:\r\n```js\r\n{\r\n  \"Marathon: {\r\n    \"Endpoint\": \"...\",\r\n    \"UseEventStream\": true\r\n  }\r\n}\r\n```\r\n\r\nNB: if \"UseEventStream\" is enabled then callbacks are not auto-registered. \r\n\r\nWhen Bamboo will drop support for Marathon < 0.9.0 then this property could be `true` by default.\r\n\r\n\r\nImplementation was tested with Marathon 0.9.0, covered cases:\r\n1. Listening for events\r\n2. Re-connection when Marathon is not responding\r\n3. Bad data from Marathon\r\n4. Many events at a time","created_at":"2015-07-25T15:30:17Z","updated_at":"2015-07-26T10:38:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94564356a309069aad269b43543f84c7b1ee5ea9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/QubitProducts/bamboo/pulls/151/commits","review_comments_url":"https://api.github.com/repos/QubitProducts/bamboo/pulls/151/comments","review_comment_url":"https://api.github.com/repos/QubitProducts/bamboo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/QubitProducts/bamboo/issues/151/comments","statuses_url":"https://api.github.com/repos/QubitProducts/bamboo/statuses/040d1648615c6881a95dd920b72abdc91d70147a","head":{"label":"bsideup:events_stream","ref":"events_stream","sha":"040d1648615c6881a95dd920b72abdc91d70147a","user":{"login":"bsideup","id":1050762,"avatar_url":"https://avatars.githubusercontent.com/u/1050762?v=3","gravatar_id":"","url":"https://api.github.com/users/bsideup","html_url":"https://github.com/bsideup","followers_url":"https://api.github.com/users/bsideup/followers","following_url":"https://api.github.com/users/bsideup/following{/other_user}","gists_url":"https://api.github.com/users/bsideup/gists{/gist_id}","starred_url":"https://api.github.com/users/bsideup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsideup/subscriptions","organizations_url":"https://api.github.com/users/bsideup/orgs","repos_url":"https://api.github.com/users/bsideup/repos","events_url":"https://api.github.com/users/bsideup/events{/privacy}","received_events_url":"https://api.github.com/users/bsideup/received_events","type":"User","site_admin":false},"repo":{"id":39689731,"name":"bamboo","full_name":"bsideup/bamboo","owner":{"login":"bsideup","id":1050762,"avatar_url":"https://avatars.githubusercontent.com/u/1050762?v=3","gravatar_id":"","url":"https://api.github.com/users/bsideup","html_url":"https://github.com/bsideup","followers_url":"https://api.github.com/users/bsideup/followers","following_url":"https://api.github.com/users/bsideup/following{/other_user}","gists_url":"https://api.github.com/users/bsideup/gists{/gist_id}","starred_url":"https://api.github.com/users/bsideup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsideup/subscriptions","organizations_url":"https://api.github.com/users/bsideup/orgs","repos_url":"https://api.github.com/users/bsideup/repos","events_url":"https://api.github.com/users/bsideup/events{/privacy}","received_events_url":"https://api.github.com/users/bsideup/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bsideup/bamboo","description":"HAProxy auto configuration and auto service discovery for Mesos Marathon","fork":true,"url":"https://api.github.com/repos/bsideup/bamboo","forks_url":"https://api.github.com/repos/bsideup/bamboo/forks","keys_url":"https://api.github.com/repos/bsideup/bamboo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bsideup/bamboo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bsideup/bamboo/teams","hooks_url":"https://api.github.com/repos/bsideup/bamboo/hooks","issue_events_url":"https://api.github.com/repos/bsideup/bamboo/issues/events{/number}","events_url":"https://api.github.com/repos/bsideup/bamboo/events","assignees_url":"https://api.github.com/repos/bsideup/bamboo/assignees{/user}","branches_url":"https://api.github.com/repos/bsideup/bamboo/branches{/branch}","tags_url":"https://api.github.com/repos/bsideup/bamboo/tags","blobs_url":"https://api.github.com/repos/bsideup/bamboo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bsideup/bamboo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bsideup/bamboo/git/refs{/sha}","trees_url":"https://api.github.com/repos/bsideup/bamboo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bsideup/bamboo/statuses/{sha}","languages_url":"https://api.github.com/repos/bsideup/bamboo/languages","stargazers_url":"https://api.github.com/repos/bsideup/bamboo/stargazers","contributors_url":"https://api.github.com/repos/bsideup/bamboo/contributors","subscribers_url":"https://api.github.com/repos/bsideup/bamboo/subscribers","subscription_url":"https://api.github.com/repos/bsideup/bamboo/subscription","commits_url":"https://api.github.com/repos/bsideup/bamboo/commits{/sha}","git_commits_url":"https://api.github.com/repos/bsideup/bamboo/git/commits{/sha}","comments_url":"https://api.github.com/repos/bsideup/bamboo/comments{/number}","issue_comment_url":"https://api.github.com/repos/bsideup/bamboo/issues/comments{/number}","contents_url":"https://api.github.com/repos/bsideup/bamboo/contents/{+path}","compare_url":"https://api.github.com/repos/bsideup/bamboo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bsideup/bamboo/merges","archive_url":"https://api.github.com/repos/bsideup/bamboo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bsideup/bamboo/downloads","issues_url":"https://api.github.com/repos/bsideup/bamboo/issues{/number}","pulls_url":"https://api.github.com/repos/bsideup/bamboo/pulls{/number}","milestones_url":"https://api.github.com/repos/bsideup/bamboo/milestones{/number}","notifications_url":"https://api.github.com/repos/bsideup/bamboo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bsideup/bamboo/labels{/name}","releases_url":"https://api.github.com/repos/bsideup/bamboo/releases{/id}","created_at":"2015-07-25T14:48:25Z","updated_at":"2015-07-25T14:48:26Z","pushed_at":"2015-07-25T15:21:05Z","git_url":"git://github.com/bsideup/bamboo.git","ssh_url":"git@github.com:bsideup/bamboo.git","clone_url":"https://github.com/bsideup/bamboo.git","svn_url":"https://github.com/bsideup/bamboo","homepage":"","size":2182,"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":"QubitProducts:master","ref":"master","sha":"fa6ab66d45b6929f6dd8923e396f83f66a297d93","user":{"login":"QubitProducts","id":827777,"avatar_url":"https://avatars.githubusercontent.com/u/827777?v=3","gravatar_id":"","url":"https://api.github.com/users/QubitProducts","html_url":"https://github.com/QubitProducts","followers_url":"https://api.github.com/users/QubitProducts/followers","following_url":"https://api.github.com/users/QubitProducts/following{/other_user}","gists_url":"https://api.github.com/users/QubitProducts/gists{/gist_id}","starred_url":"https://api.github.com/users/QubitProducts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QubitProducts/subscriptions","organizations_url":"https://api.github.com/users/QubitProducts/orgs","repos_url":"https://api.github.com/users/QubitProducts/repos","events_url":"https://api.github.com/users/QubitProducts/events{/privacy}","received_events_url":"https://api.github.com/users/QubitProducts/received_events","type":"Organization","site_admin":false},"repo":{"id":23346910,"name":"bamboo","full_name":"QubitProducts/bamboo","owner":{"login":"QubitProducts","id":827777,"avatar_url":"https://avatars.githubusercontent.com/u/827777?v=3","gravatar_id":"","url":"https://api.github.com/users/QubitProducts","html_url":"https://github.com/QubitProducts","followers_url":"https://api.github.com/users/QubitProducts/followers","following_url":"https://api.github.com/users/QubitProducts/following{/other_user}","gists_url":"https://api.github.com/users/QubitProducts/gists{/gist_id}","starred_url":"https://api.github.com/users/QubitProducts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QubitProducts/subscriptions","organizations_url":"https://api.github.com/users/QubitProducts/orgs","repos_url":"https://api.github.com/users/QubitProducts/repos","events_url":"https://api.github.com/users/QubitProducts/events{/privacy}","received_events_url":"https://api.github.com/users/QubitProducts/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/QubitProducts/bamboo","description":"HAProxy auto configuration and auto service discovery for Mesos Marathon","fork":false,"url":"https://api.github.com/repos/QubitProducts/bamboo","forks_url":"https://api.github.com/repos/QubitProducts/bamboo/forks","keys_url":"https://api.github.com/repos/QubitProducts/bamboo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/QubitProducts/bamboo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/QubitProducts/bamboo/teams","hooks_url":"https://api.github.com/repos/QubitProducts/bamboo/hooks","issue_events_url":"https://api.github.com/repos/QubitProducts/bamboo/issues/events{/number}","events_url":"https://api.github.com/repos/QubitProducts/bamboo/events","assignees_url":"https://api.github.com/repos/QubitProducts/bamboo/assignees{/user}","branches_url":"https://api.github.com/repos/QubitProducts/bamboo/branches{/branch}","tags_url":"https://api.github.com/repos/QubitProducts/bamboo/tags","blobs_url":"https://api.github.com/repos/QubitProducts/bamboo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/QubitProducts/bamboo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/QubitProducts/bamboo/git/refs{/sha}","trees_url":"https://api.github.com/repos/QubitProducts/bamboo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/QubitProducts/bamboo/statuses/{sha}","languages_url":"https://api.github.com/repos/QubitProducts/bamboo/languages","stargazers_url":"https://api.github.com/repos/QubitProducts/bamboo/stargazers","contributors_url":"https://api.github.com/repos/QubitProducts/bamboo/contributors","subscribers_url":"https://api.github.com/repos/QubitProducts/bamboo/subscribers","subscription_url":"https://api.github.com/repos/QubitProducts/bamboo/subscription","commits_url":"https://api.github.com/repos/QubitProducts/bamboo/commits{/sha}","git_commits_url":"https://api.github.com/repos/QubitProducts/bamboo/git/commits{/sha}","comments_url":"https://api.github.com/repos/QubitProducts/bamboo/comments{/number}","issue_comment_url":"https://api.github.com/repos/QubitProducts/bamboo/issues/comments{/number}","contents_url":"https://api.github.com/repos/QubitProducts/bamboo/contents/{+path}","compare_url":"https://api.github.com/repos/QubitProducts/bamboo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/QubitProducts/bamboo/merges","archive_url":"https://api.github.com/repos/QubitProducts/bamboo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/QubitProducts/bamboo/downloads","issues_url":"https://api.github.com/repos/QubitProducts/bamboo/issues{/number}","pulls_url":"https://api.github.com/repos/QubitProducts/bamboo/pulls{/number}","milestones_url":"https://api.github.com/repos/QubitProducts/bamboo/milestones{/number}","notifications_url":"https://api.github.com/repos/QubitProducts/bamboo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/QubitProducts/bamboo/labels{/name}","releases_url":"https://api.github.com/repos/QubitProducts/bamboo/releases{/id}","created_at":"2014-08-26T09:50:54Z","updated_at":"2015-07-25T06:45:36Z","pushed_at":"2015-07-25T15:30:17Z","git_url":"git://github.com/QubitProducts/bamboo.git","ssh_url":"git@github.com:QubitProducts/bamboo.git","clone_url":"https://github.com/QubitProducts/bamboo.git","svn_url":"https://github.com/QubitProducts/bamboo","homepage":"","size":2182,"stargazers_count":401,"watchers_count":401,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":99,"mirror_url":null,"open_issues_count":26,"forks":99,"open_issues":26,"watchers":401,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/QubitProducts/bamboo/pulls/151"},"html":{"href":"https://github.com/QubitProducts/bamboo/pull/151"},"issue":{"href":"https://api.github.com/repos/QubitProducts/bamboo/issues/151"},"comments":{"href":"https://api.github.com/repos/QubitProducts/bamboo/issues/151/comments"},"review_comments":{"href":"https://api.github.com/repos/QubitProducts/bamboo/pulls/151/comments"},"review_comment":{"href":"https://api.github.com/repos/QubitProducts/bamboo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/QubitProducts/bamboo/pulls/151/commits"},"statuses":{"href":"https://api.github.com/repos/QubitProducts/bamboo/statuses/040d1648615c6881a95dd920b72abdc91d70147a"}}}}