{"action":"created","comment":{"url":"https://api.github.com/repos/convox/rack/pulls/comments/72147304","id":72147304,"diff_hunk":"@@ -0,0 +1,146 @@\n+package main\n+\n+import (\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"io/ioutil\"\n+\t\"net\"\n+\t\"net/url\"\n+\t\"os\"\n+\t\"strconv\"\n+\t\"strings\"\n+\n+\t\"github.com/aws/aws-sdk-go/aws\"\n+\t\"github.com/aws/aws-sdk-go/aws/session\"\n+\t\"github.com/aws/aws-sdk-go/service/cloudformation\"\n+\t\"github.com/fluent/fluent-logger-golang/fluent\"\n+\t\"github.com/jasonmoo/lambda_proc\"\n+\t\"github.com/mweagle/Sparta/aws/cloudwatchlogs\"\n+)\n+\n+type FluentURL struct {\n+\tHost string\n+\tPort int\n+}\n+\n+func main() {\n+\tlambda_proc.Run(func(context *lambda_proc.Context, eventJSON json.RawMessage) (interface{}, error) {\n+\t\tfluent_url, err := getFluentURL(context.FunctionName)\n+\t\tfmt.Fprintf(os.Stderr, \"fluentd connection config=%s %d\\n\", fluent_url.Host, fluent_url.Port)\n+\n+\t\tlogger, err := fluent.New(fluent.Config{FluentPort: fluent_url.Port, FluentHost: fluent_url.Host})\n+\n+\t\tif err != nil {\n+\t\t\tfmt.Fprintf(os.Stderr, \"fluentd connection error=%s\\n\", err)\n+\t\t\treturn nil, err\n+\t\t}\n+\t\tdefer logger.Close()\n+\n+\t\tvar event cloudwatchlogs.Event\n+\t\terr = json.Unmarshal([]byte(eventJSON), &event)\n+\t\tif err != nil {\n+\t\t\tfmt.Fprintf(os.Stderr, \"json.Unmarshal err=%s\\n\", err)\n+\t\t\treturn nil, err\n+\t\t}\n+\n+\t\td, err := event.AWSLogs.DecodedData()\n+\t\tif err != nil {\n+\t\t\tfmt.Fprintf(os.Stderr, \"AWSLogs.DecodedData err=%s\\n\", err)\n+\t\t\treturn nil, err\n+\t\t}\n+\n+\t\tlogs, errs := 0, 0\n+\t\tfor _, e := range d.LogEvents {\n+\n+\t\t\tfmt.Sprintf(\"Message %s\", e)\n+\t\t\tevent := decodeLogLine(e.Message)\n+\n+\t\t\ttag := fmt.Sprintf(\"%s\", event[\"convox_app\"])\n+\n+\t\t\terr = logger.Post(tag, event)\n+\t\t\tif err != nil {\n+\t\t\t\tfmt.Fprint(os.Stderr, \"FluentD Post: %s\\n\", err)\n+\t\t\t\treturn nil, err\n+\t\t\t}\n+\t\t}\n+\n+\t\treturn fmt.Sprintf(\"LogGroup=%s LogStream=%s MessageType=%s NumLogEvents=%d logs=%d errs=%d\", d.LogGroup, d.LogStream, d.MessageType, len(d.LogEvents), logs, errs), nil\n+\t})\n+}\n+\n+func decodeLogLine(msg string) map[string]interface{} {\n+\ts := strings.Split(msg, \" \")\n+\tlog_group, event := s[0], s[1]\n+\n+\ts = strings.Split(log_group, \":\")\n+\tapp, convox_metadata := s[0], s[1]\n+\n+\ts = strings.Split(convox_metadata, \"/\")\n+\trelease, container_id := s[0], s[1]\n+\n+\tvar decoded_json map[string]interface{}\n+\tjson.Unmarshal([]byte(event), &decoded_json)\n+\n+\tdecoded_json[\"convox_app\"] = app\n+\tdecoded_json[\"convox_release\"] = release\n+\tdecoded_json[\"ecs_container_id\"] = container_id\n+\n+\treturn decoded_json\n+}\n+\n+func parseURL(cf_url string) (string, int) {\n+\tparsed_url, err := url.Parse(cf_url)\n+\tif err != nil {\n+\t\tfmt.Fprintf(os.Stderr, \"url.Parse url=%s\\n\", cf_url)\n+\t}\n+\n+\tfluent_host, fluent_port_string, _ := net.SplitHostPort(parsed_url.Host)","path":"api/provider/aws/lambda/fluentd/main.go","position":97,"original_position":97,"commit_id":"e85588b424e3b732b6683b2eb60a19012702431a","original_commit_id":"e85588b424e3b732b6683b2eb60a19012702431a","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"don't use underscores in Go names; var fluent_host should be fluentHost<br>don't use underscores in Go names; var fluent_port_string should be fluentPortString","created_at":"2016-07-25T21:21:23Z","updated_at":"2016-07-25T21:21:23Z","html_url":"https://github.com/convox/rack/pull/917#discussion_r72147304","pull_request_url":"https://api.github.com/repos/convox/rack/pulls/917","_links":{"self":{"href":"https://api.github.com/repos/convox/rack/pulls/comments/72147304"},"html":{"href":"https://github.com/convox/rack/pull/917#discussion_r72147304"},"pull_request":{"href":"https://api.github.com/repos/convox/rack/pulls/917"}}},"pull_request":{"url":"https://api.github.com/repos/convox/rack/pulls/917","id":78754406,"html_url":"https://github.com/convox/rack/pull/917","diff_url":"https://github.com/convox/rack/pull/917.diff","patch_url":"https://github.com/convox/rack/pull/917.patch","issue_url":"https://api.github.com/repos/convox/rack/issues/917","number":917,"state":"open","locked":false,"title":"Fluentd vendor","user":{"login":"ddollar","id":3308,"avatar_url":"https://avatars.githubusercontent.com/u/3308?v=3","gravatar_id":"","url":"https://api.github.com/users/ddollar","html_url":"https://github.com/ddollar","followers_url":"https://api.github.com/users/ddollar/followers","following_url":"https://api.github.com/users/ddollar/following{/other_user}","gists_url":"https://api.github.com/users/ddollar/gists{/gist_id}","starred_url":"https://api.github.com/users/ddollar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ddollar/subscriptions","organizations_url":"https://api.github.com/users/ddollar/orgs","repos_url":"https://api.github.com/users/ddollar/repos","events_url":"https://api.github.com/users/ddollar/events{/privacy}","received_events_url":"https://api.github.com/users/ddollar/received_events","type":"User","site_admin":false},"body":"Vendor the fluentd lambda function, fixes #916","created_at":"2016-07-25T21:21:13Z","updated_at":"2016-07-25T21:21:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"771215785ba3f96f3fdb4aa6e80a6e06007f1143","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/convox/rack/pulls/917/commits","review_comments_url":"https://api.github.com/repos/convox/rack/pulls/917/comments","review_comment_url":"https://api.github.com/repos/convox/rack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/convox/rack/issues/917/comments","statuses_url":"https://api.github.com/repos/convox/rack/statuses/e85588b424e3b732b6683b2eb60a19012702431a","head":{"label":"convox:fluentd-vendor","ref":"fluentd-vendor","sha":"e85588b424e3b732b6683b2eb60a19012702431a","user":{"login":"convox","id":10547780,"avatar_url":"https://avatars.githubusercontent.com/u/10547780?v=3","gravatar_id":"","url":"https://api.github.com/users/convox","html_url":"https://github.com/convox","followers_url":"https://api.github.com/users/convox/followers","following_url":"https://api.github.com/users/convox/following{/other_user}","gists_url":"https://api.github.com/users/convox/gists{/gist_id}","starred_url":"https://api.github.com/users/convox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/convox/subscriptions","organizations_url":"https://api.github.com/users/convox/orgs","repos_url":"https://api.github.com/users/convox/repos","events_url":"https://api.github.com/users/convox/events{/privacy}","received_events_url":"https://api.github.com/users/convox/received_events","type":"Organization","site_admin":false},"repo":{"id":42454540,"name":"rack","full_name":"convox/rack","owner":{"login":"convox","id":10547780,"avatar_url":"https://avatars.githubusercontent.com/u/10547780?v=3","gravatar_id":"","url":"https://api.github.com/users/convox","html_url":"https://github.com/convox","followers_url":"https://api.github.com/users/convox/followers","following_url":"https://api.github.com/users/convox/following{/other_user}","gists_url":"https://api.github.com/users/convox/gists{/gist_id}","starred_url":"https://api.github.com/users/convox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/convox/subscriptions","organizations_url":"https://api.github.com/users/convox/orgs","repos_url":"https://api.github.com/users/convox/repos","events_url":"https://api.github.com/users/convox/events{/privacy}","received_events_url":"https://api.github.com/users/convox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/convox/rack","description":"Open-source PaaS on AWS","fork":false,"url":"https://api.github.com/repos/convox/rack","forks_url":"https://api.github.com/repos/convox/rack/forks","keys_url":"https://api.github.com/repos/convox/rack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/convox/rack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/convox/rack/teams","hooks_url":"https://api.github.com/repos/convox/rack/hooks","issue_events_url":"https://api.github.com/repos/convox/rack/issues/events{/number}","events_url":"https://api.github.com/repos/convox/rack/events","assignees_url":"https://api.github.com/repos/convox/rack/assignees{/user}","branches_url":"https://api.github.com/repos/convox/rack/branches{/branch}","tags_url":"https://api.github.com/repos/convox/rack/tags","blobs_url":"https://api.github.com/repos/convox/rack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/convox/rack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/convox/rack/git/refs{/sha}","trees_url":"https://api.github.com/repos/convox/rack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/convox/rack/statuses/{sha}","languages_url":"https://api.github.com/repos/convox/rack/languages","stargazers_url":"https://api.github.com/repos/convox/rack/stargazers","contributors_url":"https://api.github.com/repos/convox/rack/contributors","subscribers_url":"https://api.github.com/repos/convox/rack/subscribers","subscription_url":"https://api.github.com/repos/convox/rack/subscription","commits_url":"https://api.github.com/repos/convox/rack/commits{/sha}","git_commits_url":"https://api.github.com/repos/convox/rack/git/commits{/sha}","comments_url":"https://api.github.com/repos/convox/rack/comments{/number}","issue_comment_url":"https://api.github.com/repos/convox/rack/issues/comments{/number}","contents_url":"https://api.github.com/repos/convox/rack/contents/{+path}","compare_url":"https://api.github.com/repos/convox/rack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/convox/rack/merges","archive_url":"https://api.github.com/repos/convox/rack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/convox/rack/downloads","issues_url":"https://api.github.com/repos/convox/rack/issues{/number}","pulls_url":"https://api.github.com/repos/convox/rack/pulls{/number}","milestones_url":"https://api.github.com/repos/convox/rack/milestones{/number}","notifications_url":"https://api.github.com/repos/convox/rack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/convox/rack/labels{/name}","releases_url":"https://api.github.com/repos/convox/rack/releases{/id}","deployments_url":"https://api.github.com/repos/convox/rack/deployments","created_at":"2015-09-14T14:41:30Z","updated_at":"2016-07-25T08:37:55Z","pushed_at":"2016-07-25T21:21:14Z","git_url":"git://github.com/convox/rack.git","ssh_url":"git@github.com:convox/rack.git","clone_url":"https://github.com/convox/rack.git","svn_url":"https://github.com/convox/rack","homepage":"https://convox.com","size":53247,"stargazers_count":1234,"watchers_count":1234,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":81,"mirror_url":null,"open_issues_count":140,"forks":81,"open_issues":140,"watchers":1234,"default_branch":"master"}},"base":{"label":"convox:master","ref":"master","sha":"e16821d35889bcc9aa9227c14de981587550cfea","user":{"login":"convox","id":10547780,"avatar_url":"https://avatars.githubusercontent.com/u/10547780?v=3","gravatar_id":"","url":"https://api.github.com/users/convox","html_url":"https://github.com/convox","followers_url":"https://api.github.com/users/convox/followers","following_url":"https://api.github.com/users/convox/following{/other_user}","gists_url":"https://api.github.com/users/convox/gists{/gist_id}","starred_url":"https://api.github.com/users/convox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/convox/subscriptions","organizations_url":"https://api.github.com/users/convox/orgs","repos_url":"https://api.github.com/users/convox/repos","events_url":"https://api.github.com/users/convox/events{/privacy}","received_events_url":"https://api.github.com/users/convox/received_events","type":"Organization","site_admin":false},"repo":{"id":42454540,"name":"rack","full_name":"convox/rack","owner":{"login":"convox","id":10547780,"avatar_url":"https://avatars.githubusercontent.com/u/10547780?v=3","gravatar_id":"","url":"https://api.github.com/users/convox","html_url":"https://github.com/convox","followers_url":"https://api.github.com/users/convox/followers","following_url":"https://api.github.com/users/convox/following{/other_user}","gists_url":"https://api.github.com/users/convox/gists{/gist_id}","starred_url":"https://api.github.com/users/convox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/convox/subscriptions","organizations_url":"https://api.github.com/users/convox/orgs","repos_url":"https://api.github.com/users/convox/repos","events_url":"https://api.github.com/users/convox/events{/privacy}","received_events_url":"https://api.github.com/users/convox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/convox/rack","description":"Open-source PaaS on AWS","fork":false,"url":"https://api.github.com/repos/convox/rack","forks_url":"https://api.github.com/repos/convox/rack/forks","keys_url":"https://api.github.com/repos/convox/rack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/convox/rack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/convox/rack/teams","hooks_url":"https://api.github.com/repos/convox/rack/hooks","issue_events_url":"https://api.github.com/repos/convox/rack/issues/events{/number}","events_url":"https://api.github.com/repos/convox/rack/events","assignees_url":"https://api.github.com/repos/convox/rack/assignees{/user}","branches_url":"https://api.github.com/repos/convox/rack/branches{/branch}","tags_url":"https://api.github.com/repos/convox/rack/tags","blobs_url":"https://api.github.com/repos/convox/rack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/convox/rack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/convox/rack/git/refs{/sha}","trees_url":"https://api.github.com/repos/convox/rack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/convox/rack/statuses/{sha}","languages_url":"https://api.github.com/repos/convox/rack/languages","stargazers_url":"https://api.github.com/repos/convox/rack/stargazers","contributors_url":"https://api.github.com/repos/convox/rack/contributors","subscribers_url":"https://api.github.com/repos/convox/rack/subscribers","subscription_url":"https://api.github.com/repos/convox/rack/subscription","commits_url":"https://api.github.com/repos/convox/rack/commits{/sha}","git_commits_url":"https://api.github.com/repos/convox/rack/git/commits{/sha}","comments_url":"https://api.github.com/repos/convox/rack/comments{/number}","issue_comment_url":"https://api.github.com/repos/convox/rack/issues/comments{/number}","contents_url":"https://api.github.com/repos/convox/rack/contents/{+path}","compare_url":"https://api.github.com/repos/convox/rack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/convox/rack/merges","archive_url":"https://api.github.com/repos/convox/rack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/convox/rack/downloads","issues_url":"https://api.github.com/repos/convox/rack/issues{/number}","pulls_url":"https://api.github.com/repos/convox/rack/pulls{/number}","milestones_url":"https://api.github.com/repos/convox/rack/milestones{/number}","notifications_url":"https://api.github.com/repos/convox/rack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/convox/rack/labels{/name}","releases_url":"https://api.github.com/repos/convox/rack/releases{/id}","deployments_url":"https://api.github.com/repos/convox/rack/deployments","created_at":"2015-09-14T14:41:30Z","updated_at":"2016-07-25T08:37:55Z","pushed_at":"2016-07-25T21:21:14Z","git_url":"git://github.com/convox/rack.git","ssh_url":"git@github.com:convox/rack.git","clone_url":"https://github.com/convox/rack.git","svn_url":"https://github.com/convox/rack","homepage":"https://convox.com","size":53247,"stargazers_count":1234,"watchers_count":1234,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":81,"mirror_url":null,"open_issues_count":140,"forks":81,"open_issues":140,"watchers":1234,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/convox/rack/pulls/917"},"html":{"href":"https://github.com/convox/rack/pull/917"},"issue":{"href":"https://api.github.com/repos/convox/rack/issues/917"},"comments":{"href":"https://api.github.com/repos/convox/rack/issues/917/comments"},"review_comments":{"href":"https://api.github.com/repos/convox/rack/pulls/917/comments"},"review_comment":{"href":"https://api.github.com/repos/convox/rack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/convox/rack/pulls/917/commits"},"statuses":{"href":"https://api.github.com/repos/convox/rack/statuses/e85588b424e3b732b6683b2eb60a19012702431a"}}}}
{"actor":{"display_login":"houndci-bot"}}