{"action":"created","comment":{"url":"https://api.github.com/repos/ifwe/redecs/pulls/comments/87907424","pull_request_review_id":8498286,"id":87907424,"diff_hunk":"@@ -0,0 +1,144 @@\n+package main\n+\n+// Originally adapted from https://github.com/awslabs/service-discovery-ecs-dns\n+// This service is intended to run on AWS ECS instances. It will look for special\n+// SERVICE environment variables and add those services to a Redis ZSET with the\n+// the timestamp as the key. The accompanying service, red53_agent will check this\n+// set and write changes to AWS Route53.\n+\n+import (\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"os\"\n+\tlog \"github.com/Sirupsen/logrus\"\n+\t\"github.com/aws/aws-sdk-go/aws/ec2metadata\"\n+\t\"github.com/aws/aws-sdk-go/aws/session\"\n+\t\"github.com/fsouza/go-dockerclient\"\n+\t\"gopkg.in/redis.v5\"\n+\t\"time\"\n+\t\"strings\"\n+\t\"strconv\"\n+)\n+\n+type config struct {\n+\tEcsCluster   string\n+\tRegion       string\n+\tLocalIp      string\n+\tRedisHost    string\n+}\n+\n+var configuration config\n+\n+func logErrorAndFail(err error) {\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+}\n+\n+func logErrorNoFatal(err error) {\n+\tif err != nil {\n+\t\tlog.Error(err)\n+\t}\n+}\n+\n+var dockerClient *docker.Client\n+var redisClient *redis.Client\n+\n+func reportServiceActive(serviceName string) {\n+\tlog.Debug(\"Reporting \" + serviceName + \" as active with IP \" + configuration.LocalIp)\n+\t// write {timestamp => SERVICENAME_IP} to ecssd:service_pings\n+\tredisClient.ZAdd(\"redecs:service_pings\", redis.Z{float64(time.Now().Unix()), serviceName + \"_\" + configuration.LocalIp})\n+}\n+\n+func getServiceName(container *docker.Container) string {\n+\t// One of the environment variables should be SERVICE_<port>_NAME = <name of the service>\n+\t// We look for this environment variable doing a split in the \"=\" and another one in the \"_\"\n+\t// So envEval = [SERVICE_<port>_NAME, <name>]\n+\t// nameEval = [SERVICE, <port>, NAME]\n+\tfor _, env := range container.Config.Env {\n+\t\tenvEval := strings.Split(env, \"=\")\n+\t\tnameEval := strings.Split(envEval[0], \"_\")\n+\t\tif len(envEval) == 2 && len(nameEval) == 3 && nameEval[0] == \"SERVICE\"  && nameEval[2] == \"NAME\" {\n+\t\t\tif _, err := strconv.Atoi(nameEval[1]); err == nil {\n+\t\t\t\treturn envEval[1]\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn \"\"\n+}\n+\n+func processContainers() {\n+\tlog.Debug(\"Listing active containers...\")\n+\n+\t// only get running ones\n+\tcontainers, err := dockerClient.ListContainers(docker.ListContainersOptions{All: false})\n+\t// bail out completely if we can't list containers.\n+\tlogErrorAndFail(err)\n+\tfor _, containerEntry := range containers {\n+\t\t// have to inspect to get the environment variable\n+\t\tcontainer, err := dockerClient.InspectContainer(containerEntry.ID)\n+\t\t// retry logic?\n+\t\tlogErrorAndFail(err)\n+\t\tserviceName := getServiceName(container)\n+\t\tif serviceName != \"\" {\n+\t\t\treportServiceActive(serviceName)\n+\t\t}\n+\t}\n+\n+\tlog.Debug(\"Done checking active containers\")\n+}\n+\n+func main() {\n+\tvar err error\n+\tif len(os.Args) < 2 {\n+\t\terr = errors.New(fmt.Sprintf(\"Usage: %s [Redis host] {host IP (for testing)}\\n\", os.Args[0]))\n+\t\tlogErrorAndFail(err)\n+\t}\n+\tif len (os.Args) == 3 {","path":"redecs_agent.go","position":97,"original_position":97,"commit_id":"e7256b794b4ed097f6cd63d71b5c1500e3abcf51","original_commit_id":"e7256b794b4ed097f6cd63d71b5c1500e3abcf51","user":{"login":"TysonAndre","id":1904430,"avatar_url":"https://avatars.githubusercontent.com/u/1904430?v=3","gravatar_id":"","url":"https://api.github.com/users/TysonAndre","html_url":"https://github.com/TysonAndre","followers_url":"https://api.github.com/users/TysonAndre/followers","following_url":"https://api.github.com/users/TysonAndre/following{/other_user}","gists_url":"https://api.github.com/users/TysonAndre/gists{/gist_id}","starred_url":"https://api.github.com/users/TysonAndre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TysonAndre/subscriptions","organizations_url":"https://api.github.com/users/TysonAndre/orgs","repos_url":"https://api.github.com/users/TysonAndre/repos","events_url":"https://api.github.com/users/TysonAndre/events{/privacy}","received_events_url":"https://api.github.com/users/TysonAndre/received_events","type":"User","site_admin":false},"body":"Also emit an error if len > 3\r\n\r\n","created_at":"2016-11-14T22:26:06Z","updated_at":"2016-11-14T22:26:06Z","html_url":"https://github.com/ifwe/redecs/pull/1#discussion_r87907424","pull_request_url":"https://api.github.com/repos/ifwe/redecs/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/ifwe/redecs/pulls/comments/87907424"},"html":{"href":"https://github.com/ifwe/redecs/pull/1#discussion_r87907424"},"pull_request":{"href":"https://api.github.com/repos/ifwe/redecs/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/ifwe/redecs/pulls/1","id":93657056,"html_url":"https://github.com/ifwe/redecs/pull/1","diff_url":"https://github.com/ifwe/redecs/pull/1.diff","patch_url":"https://github.com/ifwe/redecs/pull/1.patch","issue_url":"https://api.github.com/repos/ifwe/redecs/issues/1","number":1,"state":"open","locked":false,"title":"Add redecs_agent.go","user":{"login":"mishan","id":788577,"avatar_url":"https://avatars.githubusercontent.com/u/788577?v=3","gravatar_id":"","url":"https://api.github.com/users/mishan","html_url":"https://github.com/mishan","followers_url":"https://api.github.com/users/mishan/followers","following_url":"https://api.github.com/users/mishan/following{/other_user}","gists_url":"https://api.github.com/users/mishan/gists{/gist_id}","starred_url":"https://api.github.com/users/mishan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mishan/subscriptions","organizations_url":"https://api.github.com/users/mishan/orgs","repos_url":"https://api.github.com/users/mishan/repos","events_url":"https://api.github.com/users/mishan/events{/privacy}","received_events_url":"https://api.github.com/users/mishan/received_events","type":"User","site_admin":false},"body":"- This sits on AWS ECS instances, scrapes their Docker containers, and reports active services to a Redis server\r\n\r\nStill finishing up the accompanying piece, red53_agent.go -- nearly done with it.\r\n\r\n@TysonAndre ","created_at":"2016-11-14T21:59:34Z","updated_at":"2016-11-14T22:33:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"53c9dcd5120e5d86e372b868a54afd1a5da1ef17","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ifwe/redecs/pulls/1/commits","review_comments_url":"https://api.github.com/repos/ifwe/redecs/pulls/1/comments","review_comment_url":"https://api.github.com/repos/ifwe/redecs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ifwe/redecs/issues/1/comments","statuses_url":"https://api.github.com/repos/ifwe/redecs/statuses/e7256b794b4ed097f6cd63d71b5c1500e3abcf51","head":{"label":"ifwe:add-redecs-agent","ref":"add-redecs-agent","sha":"e7256b794b4ed097f6cd63d71b5c1500e3abcf51","user":{"login":"ifwe","id":8762479,"avatar_url":"https://avatars.githubusercontent.com/u/8762479?v=3","gravatar_id":"","url":"https://api.github.com/users/ifwe","html_url":"https://github.com/ifwe","followers_url":"https://api.github.com/users/ifwe/followers","following_url":"https://api.github.com/users/ifwe/following{/other_user}","gists_url":"https://api.github.com/users/ifwe/gists{/gist_id}","starred_url":"https://api.github.com/users/ifwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ifwe/subscriptions","organizations_url":"https://api.github.com/users/ifwe/orgs","repos_url":"https://api.github.com/users/ifwe/repos","events_url":"https://api.github.com/users/ifwe/events{/privacy}","received_events_url":"https://api.github.com/users/ifwe/received_events","type":"Organization","site_admin":false},"repo":{"id":73750556,"name":"redecs","full_name":"ifwe/redecs","owner":{"login":"ifwe","id":8762479,"avatar_url":"https://avatars.githubusercontent.com/u/8762479?v=3","gravatar_id":"","url":"https://api.github.com/users/ifwe","html_url":"https://github.com/ifwe","followers_url":"https://api.github.com/users/ifwe/followers","following_url":"https://api.github.com/users/ifwe/following{/other_user}","gists_url":"https://api.github.com/users/ifwe/gists{/gist_id}","starred_url":"https://api.github.com/users/ifwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ifwe/subscriptions","organizations_url":"https://api.github.com/users/ifwe/orgs","repos_url":"https://api.github.com/users/ifwe/repos","events_url":"https://api.github.com/users/ifwe/events{/privacy}","received_events_url":"https://api.github.com/users/ifwe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ifwe/redecs","description":"A service discovery system for AWS ECS","fork":false,"url":"https://api.github.com/repos/ifwe/redecs","forks_url":"https://api.github.com/repos/ifwe/redecs/forks","keys_url":"https://api.github.com/repos/ifwe/redecs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ifwe/redecs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ifwe/redecs/teams","hooks_url":"https://api.github.com/repos/ifwe/redecs/hooks","issue_events_url":"https://api.github.com/repos/ifwe/redecs/issues/events{/number}","events_url":"https://api.github.com/repos/ifwe/redecs/events","assignees_url":"https://api.github.com/repos/ifwe/redecs/assignees{/user}","branches_url":"https://api.github.com/repos/ifwe/redecs/branches{/branch}","tags_url":"https://api.github.com/repos/ifwe/redecs/tags","blobs_url":"https://api.github.com/repos/ifwe/redecs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ifwe/redecs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ifwe/redecs/git/refs{/sha}","trees_url":"https://api.github.com/repos/ifwe/redecs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ifwe/redecs/statuses/{sha}","languages_url":"https://api.github.com/repos/ifwe/redecs/languages","stargazers_url":"https://api.github.com/repos/ifwe/redecs/stargazers","contributors_url":"https://api.github.com/repos/ifwe/redecs/contributors","subscribers_url":"https://api.github.com/repos/ifwe/redecs/subscribers","subscription_url":"https://api.github.com/repos/ifwe/redecs/subscription","commits_url":"https://api.github.com/repos/ifwe/redecs/commits{/sha}","git_commits_url":"https://api.github.com/repos/ifwe/redecs/git/commits{/sha}","comments_url":"https://api.github.com/repos/ifwe/redecs/comments{/number}","issue_comment_url":"https://api.github.com/repos/ifwe/redecs/issues/comments{/number}","contents_url":"https://api.github.com/repos/ifwe/redecs/contents/{+path}","compare_url":"https://api.github.com/repos/ifwe/redecs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ifwe/redecs/merges","archive_url":"https://api.github.com/repos/ifwe/redecs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ifwe/redecs/downloads","issues_url":"https://api.github.com/repos/ifwe/redecs/issues{/number}","pulls_url":"https://api.github.com/repos/ifwe/redecs/pulls{/number}","milestones_url":"https://api.github.com/repos/ifwe/redecs/milestones{/number}","notifications_url":"https://api.github.com/repos/ifwe/redecs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ifwe/redecs/labels{/name}","releases_url":"https://api.github.com/repos/ifwe/redecs/releases{/id}","deployments_url":"https://api.github.com/repos/ifwe/redecs/deployments","created_at":"2016-11-14T21:57:34Z","updated_at":"2016-11-14T21:57:34Z","pushed_at":"2016-11-14T21:59:34Z","git_url":"git://github.com/ifwe/redecs.git","ssh_url":"git@github.com:ifwe/redecs.git","clone_url":"https://github.com/ifwe/redecs.git","svn_url":"https://github.com/ifwe/redecs","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ifwe:master","ref":"master","sha":"2b27c81fe6c60c88067a01279da4a98a2b97b0b7","user":{"login":"ifwe","id":8762479,"avatar_url":"https://avatars.githubusercontent.com/u/8762479?v=3","gravatar_id":"","url":"https://api.github.com/users/ifwe","html_url":"https://github.com/ifwe","followers_url":"https://api.github.com/users/ifwe/followers","following_url":"https://api.github.com/users/ifwe/following{/other_user}","gists_url":"https://api.github.com/users/ifwe/gists{/gist_id}","starred_url":"https://api.github.com/users/ifwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ifwe/subscriptions","organizations_url":"https://api.github.com/users/ifwe/orgs","repos_url":"https://api.github.com/users/ifwe/repos","events_url":"https://api.github.com/users/ifwe/events{/privacy}","received_events_url":"https://api.github.com/users/ifwe/received_events","type":"Organization","site_admin":false},"repo":{"id":73750556,"name":"redecs","full_name":"ifwe/redecs","owner":{"login":"ifwe","id":8762479,"avatar_url":"https://avatars.githubusercontent.com/u/8762479?v=3","gravatar_id":"","url":"https://api.github.com/users/ifwe","html_url":"https://github.com/ifwe","followers_url":"https://api.github.com/users/ifwe/followers","following_url":"https://api.github.com/users/ifwe/following{/other_user}","gists_url":"https://api.github.com/users/ifwe/gists{/gist_id}","starred_url":"https://api.github.com/users/ifwe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ifwe/subscriptions","organizations_url":"https://api.github.com/users/ifwe/orgs","repos_url":"https://api.github.com/users/ifwe/repos","events_url":"https://api.github.com/users/ifwe/events{/privacy}","received_events_url":"https://api.github.com/users/ifwe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ifwe/redecs","description":"A service discovery system for AWS ECS","fork":false,"url":"https://api.github.com/repos/ifwe/redecs","forks_url":"https://api.github.com/repos/ifwe/redecs/forks","keys_url":"https://api.github.com/repos/ifwe/redecs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ifwe/redecs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ifwe/redecs/teams","hooks_url":"https://api.github.com/repos/ifwe/redecs/hooks","issue_events_url":"https://api.github.com/repos/ifwe/redecs/issues/events{/number}","events_url":"https://api.github.com/repos/ifwe/redecs/events","assignees_url":"https://api.github.com/repos/ifwe/redecs/assignees{/user}","branches_url":"https://api.github.com/repos/ifwe/redecs/branches{/branch}","tags_url":"https://api.github.com/repos/ifwe/redecs/tags","blobs_url":"https://api.github.com/repos/ifwe/redecs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ifwe/redecs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ifwe/redecs/git/refs{/sha}","trees_url":"https://api.github.com/repos/ifwe/redecs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ifwe/redecs/statuses/{sha}","languages_url":"https://api.github.com/repos/ifwe/redecs/languages","stargazers_url":"https://api.github.com/repos/ifwe/redecs/stargazers","contributors_url":"https://api.github.com/repos/ifwe/redecs/contributors","subscribers_url":"https://api.github.com/repos/ifwe/redecs/subscribers","subscription_url":"https://api.github.com/repos/ifwe/redecs/subscription","commits_url":"https://api.github.com/repos/ifwe/redecs/commits{/sha}","git_commits_url":"https://api.github.com/repos/ifwe/redecs/git/commits{/sha}","comments_url":"https://api.github.com/repos/ifwe/redecs/comments{/number}","issue_comment_url":"https://api.github.com/repos/ifwe/redecs/issues/comments{/number}","contents_url":"https://api.github.com/repos/ifwe/redecs/contents/{+path}","compare_url":"https://api.github.com/repos/ifwe/redecs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ifwe/redecs/merges","archive_url":"https://api.github.com/repos/ifwe/redecs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ifwe/redecs/downloads","issues_url":"https://api.github.com/repos/ifwe/redecs/issues{/number}","pulls_url":"https://api.github.com/repos/ifwe/redecs/pulls{/number}","milestones_url":"https://api.github.com/repos/ifwe/redecs/milestones{/number}","notifications_url":"https://api.github.com/repos/ifwe/redecs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ifwe/redecs/labels{/name}","releases_url":"https://api.github.com/repos/ifwe/redecs/releases{/id}","deployments_url":"https://api.github.com/repos/ifwe/redecs/deployments","created_at":"2016-11-14T21:57:34Z","updated_at":"2016-11-14T21:57:34Z","pushed_at":"2016-11-14T21:59:34Z","git_url":"git://github.com/ifwe/redecs.git","ssh_url":"git@github.com:ifwe/redecs.git","clone_url":"https://github.com/ifwe/redecs.git","svn_url":"https://github.com/ifwe/redecs","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ifwe/redecs/pulls/1"},"html":{"href":"https://github.com/ifwe/redecs/pull/1"},"issue":{"href":"https://api.github.com/repos/ifwe/redecs/issues/1"},"comments":{"href":"https://api.github.com/repos/ifwe/redecs/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/ifwe/redecs/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/ifwe/redecs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ifwe/redecs/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/ifwe/redecs/statuses/e7256b794b4ed097f6cd63d71b5c1500e3abcf51"}}}}
{"actor":{"display_login":"TysonAndre"}}