{"action":"created","comment":{"url":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/comments/188456828","pull_request_review_id":120439517,"id":188456828,"diff_hunk":"@@ -40,35 +40,69 @@ func init() {\n \n // StatsdClient is a client library to send events to StatsD\n type StatsdClient struct {\n-\tconn             net.Conn\n-\taddr             string\n-\tprefix           string\n-\teventStringTpl   string\n-\tLogger           Logger\n-\tconn_type        string\n-\treconnect_ticker *time.Ticker\n+\tconn            net.Conn\n+\taddr            string\n+\tprefix          string\n+\teventStringTpl  string\n+\tLogger          Logger\n+\tconnType        string\n+\treconnectTicker *time.Ticker\n }\n \n-// NewStatsdClient - Factory\n-func NewStatsdClient(addr string, prefix string) *StatsdClient {\n+// ConfigurationFunc is a typedef for a function that configures some aspect of\n+// a StatsdClient instance\n+type ConfigurationFunc func(*StatsdClient)\n+\n+// AutoReconnect returns a ConfigurationFunc that causes the StatsdClient to automatically\n+// recreate its underlying connection on the specified interval.\n+func AutoReconnect(interval time.Duration) ConfigurationFunc {\n+\treturn func(client *StatsdClient) {\n+\t\tif interval > 0 {\n+\t\t\tclient.reconnectTicker = time.NewTicker(interval)\n+\t\t}\n+\t}\n+}\n+\n+// UseLogger returns a ConfigurationFunc that makes the StatsdClient use the specified Logger\n+// implementation, rather than the default implementation.\n+func UseLogger(logger Logger) ConfigurationFunc {\n+\treturn func(client *StatsdClient) {\n+\t\tclient.Logger = logger\n+\t}\n+}\n+\n+// NewStatsdClient is a factory func that creates a StatsdClient that sends to\n+// the configured address and prefixes all stats with the given prefix name.\n+func NewStatsdClient(addr string, prefix string, options ...ConfigurationFunc) *StatsdClient {\n \t// allow %HOST% in the prefix string\n \tprefix = strings.Replace(prefix, \"%HOST%\", Hostname, 1)\n \tclient := &StatsdClient{\n-\t\taddr:             addr,\n-\t\tprefix:           prefix,\n-\t\tLogger:           log.New(os.Stdout, \"[StatsdClient] \", log.Ldate|log.Ltime),\n-\t\teventStringTpl:   \"%s%s:%s\",\n-\t\treconnect_ticker: time.NewTicker(30 * time.Second),\n+\t\taddr:           addr,\n+\t\tprefix:         prefix,\n+\t\teventStringTpl: \"%s%s:%s\",\n \t}\n \n-\tgo func() {\n-\t\tfor range client.reconnect_ticker.C {\n-\t\t\terr := client.Reconnect()\n-\t\t\tif err != nil {\n-\t\t\t\tfmt.Println(err)\n+\t// apply all the configuration functions\n+\tfor _, opt := range options {\n+\t\topt(client)\n+\t}\n+\n+\t// set some defaults, if necessary\n+\tif client.Logger == nil {\n+\t\tclient.Logger = log.New(os.Stdout, \"[StatsdClient] \", log.Ldate|log.Ltime)\n+\t}\n+\n+\tif client.reconnectTicker != nil {\n+\t\tgo func() {","path":"client.go","position":85,"original_position":85,"commit_id":"3a6155897bf6056088fd921d5a9a7489a4a8482d","original_commit_id":"3a6155897bf6056088fd921d5a9a7489a4a8482d","user":{"login":"Jonnymcc","id":1041598,"avatar_url":"https://avatars3.githubusercontent.com/u/1041598?v=4","gravatar_id":"","url":"https://api.github.com/users/Jonnymcc","html_url":"https://github.com/Jonnymcc","followers_url":"https://api.github.com/users/Jonnymcc/followers","following_url":"https://api.github.com/users/Jonnymcc/following{/other_user}","gists_url":"https://api.github.com/users/Jonnymcc/gists{/gist_id}","starred_url":"https://api.github.com/users/Jonnymcc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jonnymcc/subscriptions","organizations_url":"https://api.github.com/users/Jonnymcc/orgs","repos_url":"https://api.github.com/users/Jonnymcc/repos","events_url":"https://api.github.com/users/Jonnymcc/events{/privacy}","received_events_url":"https://api.github.com/users/Jonnymcc/received_events","type":"User","site_admin":false},"body":"So the previous conn needs to be closed before attempting to create the new one?","created_at":"2018-05-15T22:35:21Z","updated_at":"2018-05-15T22:35:21Z","html_url":"https://github.com/HBOCodeLabs/statsd/pull/3#discussion_r188456828","pull_request_url":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/3","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/comments/188456828"},"html":{"href":"https://github.com/HBOCodeLabs/statsd/pull/3#discussion_r188456828"},"pull_request":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/3"}},"in_reply_to_id":188452338},"pull_request":{"url":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/3","id":187955837,"html_url":"https://github.com/HBOCodeLabs/statsd/pull/3","diff_url":"https://github.com/HBOCodeLabs/statsd/pull/3.diff","patch_url":"https://github.com/HBOCodeLabs/statsd/pull/3.patch","issue_url":"https://api.github.com/repos/HBOCodeLabs/statsd/issues/3","number":3,"state":"open","locked":false,"title":"Makes reconnection optional, fixes golint errors","user":{"login":"dcarney","id":563291,"avatar_url":"https://avatars3.githubusercontent.com/u/563291?v=4","gravatar_id":"","url":"https://api.github.com/users/dcarney","html_url":"https://github.com/dcarney","followers_url":"https://api.github.com/users/dcarney/followers","following_url":"https://api.github.com/users/dcarney/following{/other_user}","gists_url":"https://api.github.com/users/dcarney/gists{/gist_id}","starred_url":"https://api.github.com/users/dcarney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcarney/subscriptions","organizations_url":"https://api.github.com/users/dcarney/orgs","repos_url":"https://api.github.com/users/dcarney/repos","events_url":"https://api.github.com/users/dcarney/events{/privacy}","received_events_url":"https://api.github.com/users/dcarney/received_events","type":"User","site_admin":false},"body":"[GAT-22303](https://jira.dp.hbo.com/browse/GAT-22303)\r\n\r\n### Overview\r\nThis PR makes a few changes to the statsd client:\r\n\r\n- it gives the user of the client the ability to configure the reconnect behavior\r\n- it gives the user of the client the ability to control the logging (or lack thereof)\r\n\r\nAdditionally, it performs some code hygiene by fixing some findings from the [golint tool](https://github.com/golang/lint). \r\n\r\n### Details\r\n\r\n#### new configuration options\r\n\r\nThe new `AutoReconnect` function allows a user of this package to specify the desired reconnect behavior by providing a `time.Duration` that specifies how often to reconnect.  \r\n\r\n##### Example:\r\n```\r\nNewStatsdClient(\"localhost:8125\", \"foo\", AutoReconnect(10 * time.Second))\r\n```\r\n\r\nSimilarly, the `UseLogger` function allows a user to control which logger implementation to use when the client needs to log a message.  The previous usages of `fmt.Printf` were replaced with calls to the configured logger, so that the consuming application has the ability to control if/how statsd client messages get logged.\r\n\r\n##### Example:\r\nTo silence any client log messages, a \"null logger\" implementation can be used:\r\n```\r\ntype nullLogger struct{}\r\nfunc(nl nullLogger) Println(v ...interface{}) {}\r\n\r\nNewStatsdClient(\"localhost:8125\", \"foo\", UseLogger(nullLogger{}))\r\n```\r\nTo use any other desired logger, simply pass an instance that conforms to the package's `Logger` interface.\r\n\r\n#### golint fixes\r\n\r\nThe `golint` fixes were all straightforward refactoring that should be performed on any Go codebase. \r\n Some of the specific `golint` error messages being addressed are:\r\n\r\n`client.go:48:2: don't use underscores in Go names; struct field conn_type should be connType`\r\n`client.go:103:1: exported method StatsdClient.Reconnect should have comment or be unexported`\r\n`client.go:27:20: should omit type int from declaration of var UDPPayloadSize; it will be inferred from the right-hand side`\r\n`client.go:272:12: should omit type []string from declaration of var stats; it will be inferred from the right-hand side`\r\n\r\n","created_at":"2018-05-14T21:26:37Z","updated_at":"2018-05-15T22:35:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5ca5bded3002dbb2b69ec4b94947e8389caccfee","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/3/commits","review_comments_url":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/3/comments","review_comment_url":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HBOCodeLabs/statsd/issues/3/comments","statuses_url":"https://api.github.com/repos/HBOCodeLabs/statsd/statuses/3a6155897bf6056088fd921d5a9a7489a4a8482d","head":{"label":"HBOCodeLabs:dcarney/reconnect-logging","ref":"dcarney/reconnect-logging","sha":"3a6155897bf6056088fd921d5a9a7489a4a8482d","user":{"login":"HBOCodeLabs","id":2342721,"avatar_url":"https://avatars1.githubusercontent.com/u/2342721?v=4","gravatar_id":"","url":"https://api.github.com/users/HBOCodeLabs","html_url":"https://github.com/HBOCodeLabs","followers_url":"https://api.github.com/users/HBOCodeLabs/followers","following_url":"https://api.github.com/users/HBOCodeLabs/following{/other_user}","gists_url":"https://api.github.com/users/HBOCodeLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/HBOCodeLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HBOCodeLabs/subscriptions","organizations_url":"https://api.github.com/users/HBOCodeLabs/orgs","repos_url":"https://api.github.com/users/HBOCodeLabs/repos","events_url":"https://api.github.com/users/HBOCodeLabs/events{/privacy}","received_events_url":"https://api.github.com/users/HBOCodeLabs/received_events","type":"Organization","site_admin":false},"repo":{"id":90684479,"name":"statsd","full_name":"HBOCodeLabs/statsd","owner":{"login":"HBOCodeLabs","id":2342721,"avatar_url":"https://avatars1.githubusercontent.com/u/2342721?v=4","gravatar_id":"","url":"https://api.github.com/users/HBOCodeLabs","html_url":"https://github.com/HBOCodeLabs","followers_url":"https://api.github.com/users/HBOCodeLabs/followers","following_url":"https://api.github.com/users/HBOCodeLabs/following{/other_user}","gists_url":"https://api.github.com/users/HBOCodeLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/HBOCodeLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HBOCodeLabs/subscriptions","organizations_url":"https://api.github.com/users/HBOCodeLabs/orgs","repos_url":"https://api.github.com/users/HBOCodeLabs/repos","events_url":"https://api.github.com/users/HBOCodeLabs/events{/privacy}","received_events_url":"https://api.github.com/users/HBOCodeLabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HBOCodeLabs/statsd","description":"Golang StatsD client","fork":true,"url":"https://api.github.com/repos/HBOCodeLabs/statsd","forks_url":"https://api.github.com/repos/HBOCodeLabs/statsd/forks","keys_url":"https://api.github.com/repos/HBOCodeLabs/statsd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HBOCodeLabs/statsd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HBOCodeLabs/statsd/teams","hooks_url":"https://api.github.com/repos/HBOCodeLabs/statsd/hooks","issue_events_url":"https://api.github.com/repos/HBOCodeLabs/statsd/issues/events{/number}","events_url":"https://api.github.com/repos/HBOCodeLabs/statsd/events","assignees_url":"https://api.github.com/repos/HBOCodeLabs/statsd/assignees{/user}","branches_url":"https://api.github.com/repos/HBOCodeLabs/statsd/branches{/branch}","tags_url":"https://api.github.com/repos/HBOCodeLabs/statsd/tags","blobs_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/refs{/sha}","trees_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HBOCodeLabs/statsd/statuses/{sha}","languages_url":"https://api.github.com/repos/HBOCodeLabs/statsd/languages","stargazers_url":"https://api.github.com/repos/HBOCodeLabs/statsd/stargazers","contributors_url":"https://api.github.com/repos/HBOCodeLabs/statsd/contributors","subscribers_url":"https://api.github.com/repos/HBOCodeLabs/statsd/subscribers","subscription_url":"https://api.github.com/repos/HBOCodeLabs/statsd/subscription","commits_url":"https://api.github.com/repos/HBOCodeLabs/statsd/commits{/sha}","git_commits_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/commits{/sha}","comments_url":"https://api.github.com/repos/HBOCodeLabs/statsd/comments{/number}","issue_comment_url":"https://api.github.com/repos/HBOCodeLabs/statsd/issues/comments{/number}","contents_url":"https://api.github.com/repos/HBOCodeLabs/statsd/contents/{+path}","compare_url":"https://api.github.com/repos/HBOCodeLabs/statsd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HBOCodeLabs/statsd/merges","archive_url":"https://api.github.com/repos/HBOCodeLabs/statsd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HBOCodeLabs/statsd/downloads","issues_url":"https://api.github.com/repos/HBOCodeLabs/statsd/issues{/number}","pulls_url":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls{/number}","milestones_url":"https://api.github.com/repos/HBOCodeLabs/statsd/milestones{/number}","notifications_url":"https://api.github.com/repos/HBOCodeLabs/statsd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HBOCodeLabs/statsd/labels{/name}","releases_url":"https://api.github.com/repos/HBOCodeLabs/statsd/releases{/id}","deployments_url":"https://api.github.com/repos/HBOCodeLabs/statsd/deployments","created_at":"2017-05-09T00:25:23Z","updated_at":"2018-03-30T19:21:08Z","pushed_at":"2018-05-15T20:31:01Z","git_url":"git://github.com/HBOCodeLabs/statsd.git","ssh_url":"git@github.com:HBOCodeLabs/statsd.git","clone_url":"https://github.com/HBOCodeLabs/statsd.git","svn_url":"https://github.com/HBOCodeLabs/statsd","homepage":null,"size":127,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"HBOCodeLabs:master","ref":"master","sha":"d7ad6d526e1c71eeeeecbacf1d0212d7378c9b29","user":{"login":"HBOCodeLabs","id":2342721,"avatar_url":"https://avatars1.githubusercontent.com/u/2342721?v=4","gravatar_id":"","url":"https://api.github.com/users/HBOCodeLabs","html_url":"https://github.com/HBOCodeLabs","followers_url":"https://api.github.com/users/HBOCodeLabs/followers","following_url":"https://api.github.com/users/HBOCodeLabs/following{/other_user}","gists_url":"https://api.github.com/users/HBOCodeLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/HBOCodeLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HBOCodeLabs/subscriptions","organizations_url":"https://api.github.com/users/HBOCodeLabs/orgs","repos_url":"https://api.github.com/users/HBOCodeLabs/repos","events_url":"https://api.github.com/users/HBOCodeLabs/events{/privacy}","received_events_url":"https://api.github.com/users/HBOCodeLabs/received_events","type":"Organization","site_admin":false},"repo":{"id":90684479,"name":"statsd","full_name":"HBOCodeLabs/statsd","owner":{"login":"HBOCodeLabs","id":2342721,"avatar_url":"https://avatars1.githubusercontent.com/u/2342721?v=4","gravatar_id":"","url":"https://api.github.com/users/HBOCodeLabs","html_url":"https://github.com/HBOCodeLabs","followers_url":"https://api.github.com/users/HBOCodeLabs/followers","following_url":"https://api.github.com/users/HBOCodeLabs/following{/other_user}","gists_url":"https://api.github.com/users/HBOCodeLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/HBOCodeLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HBOCodeLabs/subscriptions","organizations_url":"https://api.github.com/users/HBOCodeLabs/orgs","repos_url":"https://api.github.com/users/HBOCodeLabs/repos","events_url":"https://api.github.com/users/HBOCodeLabs/events{/privacy}","received_events_url":"https://api.github.com/users/HBOCodeLabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HBOCodeLabs/statsd","description":"Golang StatsD client","fork":true,"url":"https://api.github.com/repos/HBOCodeLabs/statsd","forks_url":"https://api.github.com/repos/HBOCodeLabs/statsd/forks","keys_url":"https://api.github.com/repos/HBOCodeLabs/statsd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HBOCodeLabs/statsd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HBOCodeLabs/statsd/teams","hooks_url":"https://api.github.com/repos/HBOCodeLabs/statsd/hooks","issue_events_url":"https://api.github.com/repos/HBOCodeLabs/statsd/issues/events{/number}","events_url":"https://api.github.com/repos/HBOCodeLabs/statsd/events","assignees_url":"https://api.github.com/repos/HBOCodeLabs/statsd/assignees{/user}","branches_url":"https://api.github.com/repos/HBOCodeLabs/statsd/branches{/branch}","tags_url":"https://api.github.com/repos/HBOCodeLabs/statsd/tags","blobs_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/refs{/sha}","trees_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HBOCodeLabs/statsd/statuses/{sha}","languages_url":"https://api.github.com/repos/HBOCodeLabs/statsd/languages","stargazers_url":"https://api.github.com/repos/HBOCodeLabs/statsd/stargazers","contributors_url":"https://api.github.com/repos/HBOCodeLabs/statsd/contributors","subscribers_url":"https://api.github.com/repos/HBOCodeLabs/statsd/subscribers","subscription_url":"https://api.github.com/repos/HBOCodeLabs/statsd/subscription","commits_url":"https://api.github.com/repos/HBOCodeLabs/statsd/commits{/sha}","git_commits_url":"https://api.github.com/repos/HBOCodeLabs/statsd/git/commits{/sha}","comments_url":"https://api.github.com/repos/HBOCodeLabs/statsd/comments{/number}","issue_comment_url":"https://api.github.com/repos/HBOCodeLabs/statsd/issues/comments{/number}","contents_url":"https://api.github.com/repos/HBOCodeLabs/statsd/contents/{+path}","compare_url":"https://api.github.com/repos/HBOCodeLabs/statsd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HBOCodeLabs/statsd/merges","archive_url":"https://api.github.com/repos/HBOCodeLabs/statsd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HBOCodeLabs/statsd/downloads","issues_url":"https://api.github.com/repos/HBOCodeLabs/statsd/issues{/number}","pulls_url":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls{/number}","milestones_url":"https://api.github.com/repos/HBOCodeLabs/statsd/milestones{/number}","notifications_url":"https://api.github.com/repos/HBOCodeLabs/statsd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HBOCodeLabs/statsd/labels{/name}","releases_url":"https://api.github.com/repos/HBOCodeLabs/statsd/releases{/id}","deployments_url":"https://api.github.com/repos/HBOCodeLabs/statsd/deployments","created_at":"2017-05-09T00:25:23Z","updated_at":"2018-03-30T19:21:08Z","pushed_at":"2018-05-15T20:31:01Z","git_url":"git://github.com/HBOCodeLabs/statsd.git","ssh_url":"git@github.com:HBOCodeLabs/statsd.git","clone_url":"https://github.com/HBOCodeLabs/statsd.git","svn_url":"https://github.com/HBOCodeLabs/statsd","homepage":null,"size":127,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/3"},"html":{"href":"https://github.com/HBOCodeLabs/statsd/pull/3"},"issue":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/issues/3"},"comments":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/HBOCodeLabs/statsd/statuses/3a6155897bf6056088fd921d5a9a7489a4a8482d"}},"author_association":"NONE"}}
{"actor":{"display_login":"Jonnymcc"}}