{"action":"created","comment":{"url":"https://api.github.com/repos/square/p2/pulls/comments/36466618","id":36466618,"diff_hunk":"@@ -64,69 +77,178 @@ func MonitorPodHealth(config *preparer.PreparerConfig, logger *logging.Logger, s\n \t\t\tWithField(\"inner_err\", err).\n \t\t\tFatalf(\"error creating health monitor KV store\")\n \t}\n+\t// if GetClient fails it means the certfile/keyfile/cafile were\n+\t// invalid or did not exist. It makes sense to throw a fatal error\n+\tclient, err := config.GetClient()\n+\tif err != nil {\n+\t\tlogger.\n+\t\t\tWithField(\"inner_err\", err).\n+\t\t\tFatalln(\"failed to get http client for this preparer\")\n+\t}\n \n \tnode := config.NodeName\n \tpods := []PodWatch{}\n-\tpods = updateHealthMonitors(store, pods, node, logger)\n+\tpods = updateHealthMonitors(store, client, pods, node, logger)\n \tfor {\n \t\tselect {\n \t\tcase <-time.After(POLL_KV_FOR_PODS):\n \t\t\t// check if pods have been added or removed\n \t\t\t// starts monitor routine for new pods\n \t\t\t// kills monitor routine for removed pods\n-\t\t\tpods = updateHealthMonitors(store, pods, node, logger)\n+\t\t\tpods = updateHealthMonitors(store, client, pods, node, logger)\n \t\tcase <-shutdownCh:\n \t\t\treturn\n \t\t}\n \t}\n }\n \n+// Determines what pods should be running (by checking reality store)\n+// Creates new PodWatch for any pod not being monitored and kills\n+// PodWatches of pods that have been removed from the reality store\n+func updateHealthMonitors(store kp.Store,\n+\tclient *http.Client,\n+\twatchedPods []PodWatch,\n+\tnode string,\n+\tlogger *logging.Logger) []PodWatch {\n+\tpath := kp.RealityPath(node)\n+\treality, _, err := store.ListPods(path)\n+\tif err != nil {\n+\t\tlogger.WithField(\"inner_err\", err).Warningln(\"failed to get pods from reality store\")\n+\t}\n+\n+\treturn updatePods(store, client, watchedPods, reality, node, logger)\n+}\n+\n+// compares services being monitored with services that\n+// need to be monitored.\n+func updatePods(store kp.Store,\n+\tclient *http.Client,\n+\tcurrent []PodWatch,\n+\treality []kp.ManifestResult,\n+\tnode string,\n+\tlogger *logging.Logger) []PodWatch {\n+\tnewCurrent := []PodWatch{}\n+\t// for pod in current if pod not in reality: kill\n+\tfor _, pod := range current {\n+\t\tinReality := false\n+\t\tfor _, man := range reality {\n+\t\t\tif man.Manifest.Id == pod.manifest.Id {\n+\t\t\t\tinReality = true\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t}\n+\n+\t\t// if this podwatch is not in the reality store kill its go routine\n+\t\t// else add this podwatch to newCurrent\n+\t\tif inReality == false {\n+\t\t\tpod.shutdownCh <- true\n+\t\t} else {\n+\t\t\tnewCurrent = append(newCurrent, pod)\n+\t\t}\n+\t}\n+\t// for pod in reality if pod not in current: create podwatch and\n+\t// append to current\n+\tfor _, man := range reality {\n+\t\tmissing := true\n+\t\tfor _, pod := range newCurrent {\n+\t\t\tif man.Manifest.Id == pod.manifest.Id {\n+\t\t\t\tmissing = false\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t}\n+\n+\t\t// if a manifest is in reality but not current a podwatch is created\n+\t\t// with that manifest and added to newCurrent\n+\t\tif missing && man.Manifest.StatusPort != 0 {\n+\t\t\tsc := StatusChecker{\n+\t\t\t\tID:     man.Manifest.Id,\n+\t\t\t\tNode:   node,\n+\t\t\t\tClient: client,\n+\t\t\t}\n+\t\t\tif man.Manifest.StatusHTTP {\n+\t\t\t\tsc.URI = fmt.Sprintf(\"https://%s:%d/_status\", node, man.Manifest.StatusPort)","path":"pkg/watch/health.go","position":131,"original_position":131,"commit_id":"ed1543ac82210963542d7c0d479b96256e898c16","original_commit_id":"ed1543ac82210963542d7c0d479b96256e898c16","user":{"login":"bwester","id":1501338,"avatar_url":"https://avatars.githubusercontent.com/u/1501338?v=3","gravatar_id":"","url":"https://api.github.com/users/bwester","html_url":"https://github.com/bwester","followers_url":"https://api.github.com/users/bwester/followers","following_url":"https://api.github.com/users/bwester/following{/other_user}","gists_url":"https://api.github.com/users/bwester/gists{/gist_id}","starred_url":"https://api.github.com/users/bwester/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bwester/subscriptions","organizations_url":"https://api.github.com/users/bwester/orgs","repos_url":"https://api.github.com/users/bwester/repos","events_url":"https://api.github.com/users/bwester/events{/privacy}","received_events_url":"https://api.github.com/users/bwester/received_events","type":"User","site_admin":false},"body":"NO!!!!","created_at":"2015-08-06T21:14:43Z","updated_at":"2015-08-06T21:14:43Z","html_url":"https://github.com/square/p2/pull/214#discussion_r36466618","pull_request_url":"https://api.github.com/repos/square/p2/pulls/214","_links":{"self":{"href":"https://api.github.com/repos/square/p2/pulls/comments/36466618"},"html":{"href":"https://github.com/square/p2/pull/214#discussion_r36466618"},"pull_request":{"href":"https://api.github.com/repos/square/p2/pulls/214"}}},"pull_request":{"url":"https://api.github.com/repos/square/p2/pulls/214","id":41722547,"html_url":"https://github.com/square/p2/pull/214","diff_url":"https://github.com/square/p2/pull/214.diff","patch_url":"https://github.com/square/p2/pull/214.patch","issue_url":"https://api.github.com/repos/square/p2/issues/214","number":214,"state":"closed","locked":false,"title":"KV health checks now use https when the statusHttp field is set","user":{"login":"robertabbott","id":7033685,"avatar_url":"https://avatars.githubusercontent.com/u/7033685?v=3","gravatar_id":"","url":"https://api.github.com/users/robertabbott","html_url":"https://github.com/robertabbott","followers_url":"https://api.github.com/users/robertabbott/followers","following_url":"https://api.github.com/users/robertabbott/following{/other_user}","gists_url":"https://api.github.com/users/robertabbott/gists{/gist_id}","starred_url":"https://api.github.com/users/robertabbott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertabbott/subscriptions","organizations_url":"https://api.github.com/users/robertabbott/orgs","repos_url":"https://api.github.com/users/robertabbott/repos","events_url":"https://api.github.com/users/robertabbott/events{/privacy}","received_events_url":"https://api.github.com/users/robertabbott/received_events","type":"User","site_admin":false},"body":"The preparer creates http client from config. This is passed to\r\nthe go routines that monitor pods that require https.","created_at":"2015-08-05T20:30:57Z","updated_at":"2015-08-06T21:14:43Z","closed_at":"2015-08-06T21:11:27Z","merged_at":"2015-08-06T21:11:27Z","merge_commit_sha":"074866a3fb2eb8e81e9c0516be04a1f731508879","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/square/p2/pulls/214/commits","review_comments_url":"https://api.github.com/repos/square/p2/pulls/214/comments","review_comment_url":"https://api.github.com/repos/square/p2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/square/p2/issues/214/comments","statuses_url":"https://api.github.com/repos/square/p2/statuses/ed1543ac82210963542d7c0d479b96256e898c16","head":{"label":"robertabbott:abbott/fixHttpInKVChecks","ref":"abbott/fixHttpInKVChecks","sha":"ed1543ac82210963542d7c0d479b96256e898c16","user":{"login":"robertabbott","id":7033685,"avatar_url":"https://avatars.githubusercontent.com/u/7033685?v=3","gravatar_id":"","url":"https://api.github.com/users/robertabbott","html_url":"https://github.com/robertabbott","followers_url":"https://api.github.com/users/robertabbott/followers","following_url":"https://api.github.com/users/robertabbott/following{/other_user}","gists_url":"https://api.github.com/users/robertabbott/gists{/gist_id}","starred_url":"https://api.github.com/users/robertabbott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertabbott/subscriptions","organizations_url":"https://api.github.com/users/robertabbott/orgs","repos_url":"https://api.github.com/users/robertabbott/repos","events_url":"https://api.github.com/users/robertabbott/events{/privacy}","received_events_url":"https://api.github.com/users/robertabbott/received_events","type":"User","site_admin":false},"repo":{"id":38002902,"name":"p2","full_name":"robertabbott/p2","owner":{"login":"robertabbott","id":7033685,"avatar_url":"https://avatars.githubusercontent.com/u/7033685?v=3","gravatar_id":"","url":"https://api.github.com/users/robertabbott","html_url":"https://github.com/robertabbott","followers_url":"https://api.github.com/users/robertabbott/followers","following_url":"https://api.github.com/users/robertabbott/following{/other_user}","gists_url":"https://api.github.com/users/robertabbott/gists{/gist_id}","starred_url":"https://api.github.com/users/robertabbott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertabbott/subscriptions","organizations_url":"https://api.github.com/users/robertabbott/orgs","repos_url":"https://api.github.com/users/robertabbott/repos","events_url":"https://api.github.com/users/robertabbott/events{/privacy}","received_events_url":"https://api.github.com/users/robertabbott/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/robertabbott/p2","description":"Platypus Platform: Tools for Scalable Deployment","fork":true,"url":"https://api.github.com/repos/robertabbott/p2","forks_url":"https://api.github.com/repos/robertabbott/p2/forks","keys_url":"https://api.github.com/repos/robertabbott/p2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/robertabbott/p2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/robertabbott/p2/teams","hooks_url":"https://api.github.com/repos/robertabbott/p2/hooks","issue_events_url":"https://api.github.com/repos/robertabbott/p2/issues/events{/number}","events_url":"https://api.github.com/repos/robertabbott/p2/events","assignees_url":"https://api.github.com/repos/robertabbott/p2/assignees{/user}","branches_url":"https://api.github.com/repos/robertabbott/p2/branches{/branch}","tags_url":"https://api.github.com/repos/robertabbott/p2/tags","blobs_url":"https://api.github.com/repos/robertabbott/p2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/robertabbott/p2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/robertabbott/p2/git/refs{/sha}","trees_url":"https://api.github.com/repos/robertabbott/p2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/robertabbott/p2/statuses/{sha}","languages_url":"https://api.github.com/repos/robertabbott/p2/languages","stargazers_url":"https://api.github.com/repos/robertabbott/p2/stargazers","contributors_url":"https://api.github.com/repos/robertabbott/p2/contributors","subscribers_url":"https://api.github.com/repos/robertabbott/p2/subscribers","subscription_url":"https://api.github.com/repos/robertabbott/p2/subscription","commits_url":"https://api.github.com/repos/robertabbott/p2/commits{/sha}","git_commits_url":"https://api.github.com/repos/robertabbott/p2/git/commits{/sha}","comments_url":"https://api.github.com/repos/robertabbott/p2/comments{/number}","issue_comment_url":"https://api.github.com/repos/robertabbott/p2/issues/comments{/number}","contents_url":"https://api.github.com/repos/robertabbott/p2/contents/{+path}","compare_url":"https://api.github.com/repos/robertabbott/p2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/robertabbott/p2/merges","archive_url":"https://api.github.com/repos/robertabbott/p2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/robertabbott/p2/downloads","issues_url":"https://api.github.com/repos/robertabbott/p2/issues{/number}","pulls_url":"https://api.github.com/repos/robertabbott/p2/pulls{/number}","milestones_url":"https://api.github.com/repos/robertabbott/p2/milestones{/number}","notifications_url":"https://api.github.com/repos/robertabbott/p2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/robertabbott/p2/labels{/name}","releases_url":"https://api.github.com/repos/robertabbott/p2/releases{/id}","created_at":"2015-06-24T18:21:15Z","updated_at":"2015-06-24T18:21:16Z","pushed_at":"2015-08-06T20:57:56Z","git_url":"git://github.com/robertabbott/p2.git","ssh_url":"git@github.com:robertabbott/p2.git","clone_url":"https://github.com/robertabbott/p2.git","svn_url":"https://github.com/robertabbott/p2","homepage":"","size":24354,"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":"3043ea5a90225f169805ce66adb027958d8af4fd","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}","created_at":"2014-10-16T20:31:12Z","updated_at":"2015-07-26T19:10:25Z","pushed_at":"2015-08-06T21:11:27Z","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":30171,"stargazers_count":60,"watchers_count":60,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":1,"forks":12,"open_issues":1,"watchers":60,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/square/p2/pulls/214"},"html":{"href":"https://github.com/square/p2/pull/214"},"issue":{"href":"https://api.github.com/repos/square/p2/issues/214"},"comments":{"href":"https://api.github.com/repos/square/p2/issues/214/comments"},"review_comments":{"href":"https://api.github.com/repos/square/p2/pulls/214/comments"},"review_comment":{"href":"https://api.github.com/repos/square/p2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/square/p2/pulls/214/commits"},"statuses":{"href":"https://api.github.com/repos/square/p2/statuses/ed1543ac82210963542d7c0d479b96256e898c16"}}}}