{"action":"created","comment":{"url":"https://api.github.com/repos/juju/juju/pulls/comments/88596887","pull_request_review_id":9166356,"id":88596887,"diff_hunk":"@@ -16,23 +15,92 @@ import (\n \t\"github.com/juju/utils\"\n \t\"github.com/juju/version\"\n \t\"golang.org/x/net/websocket\"\n+\t\"gopkg.in/juju/names.v2\"\n \t\"gopkg.in/natefinch/lumberjack.v2\"\n \n \t\"github.com/juju/juju/apiserver/common\"\n \t\"github.com/juju/juju/apiserver/params\"\n \t\"github.com/juju/juju/state\"\n )\n \n-func newLogSinkHandler(h httpContext, w io.Writer) http.Handler {\n-\treturn &logSinkHandler{ctxt: h, fileLogger: w}\n+type LoggingStrategy interface {\n+\tAuthenticate(*http.Request) error\n+\tStart()\n+\tLog(params.LogRecord) bool\n+\tStop()\n }\n \n-func newLogSinkWriter(logDir string) (io.WriteCloser, error) {\n-\tlogPath := filepath.Join(logDir, \"logsink.log\")\n+type AgentLoggingStrategy struct {\n+\tctxt       httpContext\n+\tst         *state.State\n+\tversion    version.Number\n+\tentity     names.Tag\n+\tfilePrefix string\n+\tdbLogger   *state.EntityDbLogger\n+\tfileLogger io.Writer\n+}\n+\n+func (s *AgentLoggingStrategy) Authenticate(req *http.Request) error {\n+\tst, entity, err := s.ctxt.stateForRequestAuthenticatedAgent(req)\n+\tif err != nil {\n+\t\treturn errors.Trace(err)\n+\t}\n+\t// Note that this endpoint is agent-only. Thus the only\n+\t// callers will necessarily provide their Juju version.\n+\t//\n+\t// This would be a problem if non-Juju clients (e.g. the\n+\t// GUI) could use this endpoint since we require that the\n+\t// *Juju* version be provided as part of the request. Any\n+\t// attempt to open this endpoint to broader access must\n+\t// address this caveat appropriately.\n+\tver, err := jujuClientVersionFromReq(req)\n+\tif err != nil {\n+\t\treturn errors.Trace(err)\n+\t}\n+\ts.st = st\n+\ts.version = ver\n+\ts.entity = entity.Tag()\n+\treturn nil\n+}\n+\n+func (s *AgentLoggingStrategy) Start() {","path":"apiserver/logsink.go","position":64,"original_position":64,"commit_id":"91f40cac8f1669fcf0abc3dee84f27223fea1a41","original_commit_id":"91f40cac8f1669fcf0abc3dee84f27223fea1a41","user":{"login":"howbazaar","id":1744247,"avatar_url":"https://avatars.githubusercontent.com/u/1744247?v=3","gravatar_id":"","url":"https://api.github.com/users/howbazaar","html_url":"https://github.com/howbazaar","followers_url":"https://api.github.com/users/howbazaar/followers","following_url":"https://api.github.com/users/howbazaar/following{/other_user}","gists_url":"https://api.github.com/users/howbazaar/gists{/gist_id}","starred_url":"https://api.github.com/users/howbazaar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howbazaar/subscriptions","organizations_url":"https://api.github.com/users/howbazaar/orgs","repos_url":"https://api.github.com/users/howbazaar/repos","events_url":"https://api.github.com/users/howbazaar/events{/privacy}","received_events_url":"https://api.github.com/users/howbazaar/received_events","type":"User","site_admin":false},"body":"Docstring here too.","created_at":"2016-11-18T04:07:30Z","updated_at":"2016-11-18T04:14:28Z","html_url":"https://github.com/juju/juju/pull/6573#discussion_r88596887","pull_request_url":"https://api.github.com/repos/juju/juju/pulls/6573","_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/comments/88596887"},"html":{"href":"https://github.com/juju/juju/pull/6573#discussion_r88596887"},"pull_request":{"href":"https://api.github.com/repos/juju/juju/pulls/6573"}}},"pull_request":{"url":"https://api.github.com/repos/juju/juju/pulls/6573","id":94103969,"html_url":"https://github.com/juju/juju/pull/6573","diff_url":"https://github.com/juju/juju/pull/6573.diff","patch_url":"https://github.com/juju/juju/pull/6573.patch","issue_url":"https://api.github.com/repos/juju/juju/issues/6573","number":6573,"state":"open","locked":false,"title":"Refactor logsink to make it reusable for migration log transfer","user":{"login":"babbageclunk","id":563399,"avatar_url":"https://avatars.githubusercontent.com/u/563399?v=3","gravatar_id":"","url":"https://api.github.com/users/babbageclunk","html_url":"https://github.com/babbageclunk","followers_url":"https://api.github.com/users/babbageclunk/followers","following_url":"https://api.github.com/users/babbageclunk/following{/other_user}","gists_url":"https://api.github.com/users/babbageclunk/gists{/gist_id}","starred_url":"https://api.github.com/users/babbageclunk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babbageclunk/subscriptions","organizations_url":"https://api.github.com/users/babbageclunk/orgs","repos_url":"https://api.github.com/users/babbageclunk/repos","events_url":"https://api.github.com/users/babbageclunk/events{/privacy}","received_events_url":"https://api.github.com/users/babbageclunk/received_events","type":"User","site_admin":false},"body":"Extract the authentication and logging that the logsink handler does into AgentLoggingStrategy. This enables using a different logging strategy for migration log transfer (which will be in a follow-up PR) - in that case the logs won't be coming from a specific machine agent so each record will include the entity that originally logged it.\r\n\r\nThis also slightly changes the format of logsink.log - entity is moved from the line prefix to a normal column in the log file.","created_at":"2016-11-17T05:18:04Z","updated_at":"2016-11-18T04:14:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8b1102cf4c4599500a60d8db9b9d42cbd7f25f8b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/juju/juju/pulls/6573/commits","review_comments_url":"https://api.github.com/repos/juju/juju/pulls/6573/comments","review_comment_url":"https://api.github.com/repos/juju/juju/pulls/comments{/number}","comments_url":"https://api.github.com/repos/juju/juju/issues/6573/comments","statuses_url":"https://api.github.com/repos/juju/juju/statuses/91f40cac8f1669fcf0abc3dee84f27223fea1a41","head":{"label":"babbageclunk:logsink-refactor","ref":"logsink-refactor","sha":"91f40cac8f1669fcf0abc3dee84f27223fea1a41","user":{"login":"babbageclunk","id":563399,"avatar_url":"https://avatars.githubusercontent.com/u/563399?v=3","gravatar_id":"","url":"https://api.github.com/users/babbageclunk","html_url":"https://github.com/babbageclunk","followers_url":"https://api.github.com/users/babbageclunk/followers","following_url":"https://api.github.com/users/babbageclunk/following{/other_user}","gists_url":"https://api.github.com/users/babbageclunk/gists{/gist_id}","starred_url":"https://api.github.com/users/babbageclunk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babbageclunk/subscriptions","organizations_url":"https://api.github.com/users/babbageclunk/orgs","repos_url":"https://api.github.com/users/babbageclunk/repos","events_url":"https://api.github.com/users/babbageclunk/events{/privacy}","received_events_url":"https://api.github.com/users/babbageclunk/received_events","type":"User","site_admin":false},"repo":{"id":54490872,"name":"juju","full_name":"babbageclunk/juju","owner":{"login":"babbageclunk","id":563399,"avatar_url":"https://avatars.githubusercontent.com/u/563399?v=3","gravatar_id":"","url":"https://api.github.com/users/babbageclunk","html_url":"https://github.com/babbageclunk","followers_url":"https://api.github.com/users/babbageclunk/followers","following_url":"https://api.github.com/users/babbageclunk/following{/other_user}","gists_url":"https://api.github.com/users/babbageclunk/gists{/gist_id}","starred_url":"https://api.github.com/users/babbageclunk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/babbageclunk/subscriptions","organizations_url":"https://api.github.com/users/babbageclunk/orgs","repos_url":"https://api.github.com/users/babbageclunk/repos","events_url":"https://api.github.com/users/babbageclunk/events{/privacy}","received_events_url":"https://api.github.com/users/babbageclunk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/babbageclunk/juju","description":"juju is devops distilled","fork":true,"url":"https://api.github.com/repos/babbageclunk/juju","forks_url":"https://api.github.com/repos/babbageclunk/juju/forks","keys_url":"https://api.github.com/repos/babbageclunk/juju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/babbageclunk/juju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/babbageclunk/juju/teams","hooks_url":"https://api.github.com/repos/babbageclunk/juju/hooks","issue_events_url":"https://api.github.com/repos/babbageclunk/juju/issues/events{/number}","events_url":"https://api.github.com/repos/babbageclunk/juju/events","assignees_url":"https://api.github.com/repos/babbageclunk/juju/assignees{/user}","branches_url":"https://api.github.com/repos/babbageclunk/juju/branches{/branch}","tags_url":"https://api.github.com/repos/babbageclunk/juju/tags","blobs_url":"https://api.github.com/repos/babbageclunk/juju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/babbageclunk/juju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/babbageclunk/juju/git/refs{/sha}","trees_url":"https://api.github.com/repos/babbageclunk/juju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/babbageclunk/juju/statuses/{sha}","languages_url":"https://api.github.com/repos/babbageclunk/juju/languages","stargazers_url":"https://api.github.com/repos/babbageclunk/juju/stargazers","contributors_url":"https://api.github.com/repos/babbageclunk/juju/contributors","subscribers_url":"https://api.github.com/repos/babbageclunk/juju/subscribers","subscription_url":"https://api.github.com/repos/babbageclunk/juju/subscription","commits_url":"https://api.github.com/repos/babbageclunk/juju/commits{/sha}","git_commits_url":"https://api.github.com/repos/babbageclunk/juju/git/commits{/sha}","comments_url":"https://api.github.com/repos/babbageclunk/juju/comments{/number}","issue_comment_url":"https://api.github.com/repos/babbageclunk/juju/issues/comments{/number}","contents_url":"https://api.github.com/repos/babbageclunk/juju/contents/{+path}","compare_url":"https://api.github.com/repos/babbageclunk/juju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/babbageclunk/juju/merges","archive_url":"https://api.github.com/repos/babbageclunk/juju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/babbageclunk/juju/downloads","issues_url":"https://api.github.com/repos/babbageclunk/juju/issues{/number}","pulls_url":"https://api.github.com/repos/babbageclunk/juju/pulls{/number}","milestones_url":"https://api.github.com/repos/babbageclunk/juju/milestones{/number}","notifications_url":"https://api.github.com/repos/babbageclunk/juju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/babbageclunk/juju/labels{/name}","releases_url":"https://api.github.com/repos/babbageclunk/juju/releases{/id}","deployments_url":"https://api.github.com/repos/babbageclunk/juju/deployments","created_at":"2016-03-22T16:26:25Z","updated_at":"2016-03-22T16:26:34Z","pushed_at":"2016-11-18T02:31:01Z","git_url":"git://github.com/babbageclunk/juju.git","ssh_url":"git@github.com:babbageclunk/juju.git","clone_url":"https://github.com/babbageclunk/juju.git","svn_url":"https://github.com/babbageclunk/juju","homepage":"juju.ubuntu.com","size":97254,"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":"juju:develop","ref":"develop","sha":"045041638d694d2ebea8227f908eeb84ccabad07","user":{"login":"juju","id":4604548,"avatar_url":"https://avatars.githubusercontent.com/u/4604548?v=3","gravatar_id":"","url":"https://api.github.com/users/juju","html_url":"https://github.com/juju","followers_url":"https://api.github.com/users/juju/followers","following_url":"https://api.github.com/users/juju/following{/other_user}","gists_url":"https://api.github.com/users/juju/gists{/gist_id}","starred_url":"https://api.github.com/users/juju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juju/subscriptions","organizations_url":"https://api.github.com/users/juju/orgs","repos_url":"https://api.github.com/users/juju/repos","events_url":"https://api.github.com/users/juju/events{/privacy}","received_events_url":"https://api.github.com/users/juju/received_events","type":"Organization","site_admin":false},"repo":{"id":20445947,"name":"juju","full_name":"juju/juju","owner":{"login":"juju","id":4604548,"avatar_url":"https://avatars.githubusercontent.com/u/4604548?v=3","gravatar_id":"","url":"https://api.github.com/users/juju","html_url":"https://github.com/juju","followers_url":"https://api.github.com/users/juju/followers","following_url":"https://api.github.com/users/juju/following{/other_user}","gists_url":"https://api.github.com/users/juju/gists{/gist_id}","starred_url":"https://api.github.com/users/juju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juju/subscriptions","organizations_url":"https://api.github.com/users/juju/orgs","repos_url":"https://api.github.com/users/juju/repos","events_url":"https://api.github.com/users/juju/events{/privacy}","received_events_url":"https://api.github.com/users/juju/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/juju/juju","description":"juju is devops distilled","fork":false,"url":"https://api.github.com/repos/juju/juju","forks_url":"https://api.github.com/repos/juju/juju/forks","keys_url":"https://api.github.com/repos/juju/juju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/juju/juju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/juju/juju/teams","hooks_url":"https://api.github.com/repos/juju/juju/hooks","issue_events_url":"https://api.github.com/repos/juju/juju/issues/events{/number}","events_url":"https://api.github.com/repos/juju/juju/events","assignees_url":"https://api.github.com/repos/juju/juju/assignees{/user}","branches_url":"https://api.github.com/repos/juju/juju/branches{/branch}","tags_url":"https://api.github.com/repos/juju/juju/tags","blobs_url":"https://api.github.com/repos/juju/juju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/juju/juju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/juju/juju/git/refs{/sha}","trees_url":"https://api.github.com/repos/juju/juju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/juju/juju/statuses/{sha}","languages_url":"https://api.github.com/repos/juju/juju/languages","stargazers_url":"https://api.github.com/repos/juju/juju/stargazers","contributors_url":"https://api.github.com/repos/juju/juju/contributors","subscribers_url":"https://api.github.com/repos/juju/juju/subscribers","subscription_url":"https://api.github.com/repos/juju/juju/subscription","commits_url":"https://api.github.com/repos/juju/juju/commits{/sha}","git_commits_url":"https://api.github.com/repos/juju/juju/git/commits{/sha}","comments_url":"https://api.github.com/repos/juju/juju/comments{/number}","issue_comment_url":"https://api.github.com/repos/juju/juju/issues/comments{/number}","contents_url":"https://api.github.com/repos/juju/juju/contents/{+path}","compare_url":"https://api.github.com/repos/juju/juju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/juju/juju/merges","archive_url":"https://api.github.com/repos/juju/juju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/juju/juju/downloads","issues_url":"https://api.github.com/repos/juju/juju/issues{/number}","pulls_url":"https://api.github.com/repos/juju/juju/pulls{/number}","milestones_url":"https://api.github.com/repos/juju/juju/milestones{/number}","notifications_url":"https://api.github.com/repos/juju/juju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/juju/juju/labels{/name}","releases_url":"https://api.github.com/repos/juju/juju/releases{/id}","deployments_url":"https://api.github.com/repos/juju/juju/deployments","created_at":"2014-06-03T14:28:10Z","updated_at":"2016-11-16T21:13:07Z","pushed_at":"2016-11-18T03:42:42Z","git_url":"git://github.com/juju/juju.git","ssh_url":"git@github.com:juju/juju.git","clone_url":"https://github.com/juju/juju.git","svn_url":"https://github.com/juju/juju","homepage":"juju.ubuntu.com","size":128651,"stargazers_count":531,"watchers_count":531,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":164,"mirror_url":null,"open_issues_count":22,"forks":164,"open_issues":22,"watchers":531,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/6573"},"html":{"href":"https://github.com/juju/juju/pull/6573"},"issue":{"href":"https://api.github.com/repos/juju/juju/issues/6573"},"comments":{"href":"https://api.github.com/repos/juju/juju/issues/6573/comments"},"review_comments":{"href":"https://api.github.com/repos/juju/juju/pulls/6573/comments"},"review_comment":{"href":"https://api.github.com/repos/juju/juju/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/juju/juju/pulls/6573/commits"},"statuses":{"href":"https://api.github.com/repos/juju/juju/statuses/91f40cac8f1669fcf0abc3dee84f27223fea1a41"}}}}
{"actor":{"display_login":"howbazaar"}}