{"action":"created","comment":{"url":"https://api.github.com/repos/juju/juju/pulls/comments/180643928","pull_request_review_id":111094359,"id":180643928,"diff_hunk":"@@ -0,0 +1,343 @@\n+// Copyright 2017 Canonical Ltd.\n+// Licensed under the AGPLv3, see LICENCE file for details.\n+\n+// The presence package works on the premise that an agent it alive\n+// if it has a current connection to one of the API servers.\n+//\n+// This package handles all of the logic around collecting an organising\n+// the information around all the connections made to the API servers.\n+package presence\n+\n+import (\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"github.com/juju/errors\"\n+\t\"github.com/juju/utils/set\"\n+)\n+\n+// Recorder records the presence status of every apiserver connection\n+// for the agents.\n+type Recorder interface {\n+\tDisable()\n+\tEnable()\n+\tIsEnabled() bool\n+\n+\tConnect(server, model, agent string, id uint64, controllerAgent bool, userData string)\n+\tDisconnect(server string, id uint64)\n+\tActivity(server string, id uint64)\n+\n+\tServerDown(server string)\n+\tUpdateServer(server string, connections []Value) error\n+\n+\tConnections() Connections\n+}\n+\n+// Connections provides a way to slice the full presence understanding\n+// across various axis like server, model and agent.\n+type Connections interface {\n+\tForModel(model string) Connections\n+\tForServer(server string) Connections\n+\tForAgent(agent string) Connections\n+\n+\tCount() int\n+\n+\tModels() []string\n+\tServers() []string\n+\tAgents() []string\n+\n+\tAgentStatus(agent string) (Status, error)\n+\n+\tValues() []Value\n+}\n+\n+// Status represents the state of a given agent's presence.\n+type Status int\n+\n+const (\n+\tUnknown Status = iota\n+\tMissing\n+\tAlive\n+)\n+\n+// String implements Stringer.\n+func (s Status) String() string {\n+\tswitch s {\n+\tcase Unknown:\n+\t\treturn \"unknown\"\n+\tcase Missing:\n+\t\treturn \"missing\"\n+\tcase Alive:\n+\t\treturn \"alive\"\n+\tdefault:\n+\t\treturn \"\"\n+\t}\n+}\n+\n+// Value holds the information about a single agent connection to an apiserver\n+// machine.\n+type Value struct {\n+\tModel           string\n+\tServer          string\n+\tAgent           string\n+\tControllerAgent bool\n+\tConnectionID    uint64\n+\tStatus          Status\n+\tUserData        string\n+\tLastSeen        time.Time\n+}\n+\n+type connections struct {\n+\tmodel  string\n+\tvalues []Value\n+}\n+\n+// Clock provides an interface for dealing with clocks.\n+type Clock interface {\n+\t// Now returns the current clock time.\n+\tNow() time.Time\n+}\n+\n+// New returns a new empty Recorder.\n+func New(clock Clock) Recorder {\n+\treturn &recorder{clock: clock}\n+}\n+\n+type recorder struct {\n+\tmu      sync.Mutex\n+\tenabled bool\n+\tclock   Clock\n+\tentries []Value\n+}\n+\n+// Disable clears the entries and marks the recorder as disabled.\n+// Note that all agents will have a recorder, but they are only enabled\n+// for API server agents.\n+func (r *recorder) Disable() {\n+\tr.mu.Lock()\n+\tdefer r.mu.Unlock()\n+\tr.enabled = false\n+\tr.entries = nil\n+}\n+\n+// Enable marks the recorder as enabled.\n+func (r *recorder) Enable() {\n+\tr.mu.Lock()\n+\tdefer r.mu.Unlock()\n+\tr.enabled = true\n+\n+}\n+\n+// IsEnabled returns whether or not the recorder is enabled.\n+func (r *recorder) IsEnabled() bool {\n+\tr.mu.Lock()\n+\tdefer r.mu.Unlock()\n+\treturn r.enabled\n+}\n+\n+func (r *recorder) find(server string, id uint64) int {","path":"core/presence/presence.go","position":138,"original_position":138,"commit_id":"9a8e97ee9b778ef0e8e0530d60302facdb4e547a","original_commit_id":"9a8e97ee9b778ef0e8e0530d60302facdb4e547a","user":{"login":"howbazaar","id":1744247,"avatar_url":"https://avatars3.githubusercontent.com/u/1744247?v=4","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":"changed","created_at":"2018-04-11T06:11:40Z","updated_at":"2018-04-11T06:15:54Z","html_url":"https://github.com/juju/juju/pull/8573#discussion_r180643928","pull_request_url":"https://api.github.com/repos/juju/juju/pulls/8573","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/comments/180643928"},"html":{"href":"https://github.com/juju/juju/pull/8573#discussion_r180643928"},"pull_request":{"href":"https://api.github.com/repos/juju/juju/pulls/8573"}},"in_reply_to_id":180635943},"pull_request":{"url":"https://api.github.com/repos/juju/juju/pulls/8573","id":180788644,"html_url":"https://github.com/juju/juju/pull/8573","diff_url":"https://github.com/juju/juju/pull/8573.diff","patch_url":"https://github.com/juju/juju/pull/8573.patch","issue_url":"https://api.github.com/repos/juju/juju/issues/8573","number":8573,"state":"open","locked":false,"title":"Add core/presence package.","user":{"login":"howbazaar","id":1744247,"avatar_url":"https://avatars3.githubusercontent.com/u/1744247?v=4","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":"This is the second part of the new presence implementation.\r\n\r\nAdd a simple package with minimal dependencies to be the in memory presence implementation.\r\n","created_at":"2018-04-11T04:39:59Z","updated_at":"2018-04-11T06:15:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ee1595b280dcf2c4476221bf5c628db89699c3c0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/juju/juju/pulls/8573/commits","review_comments_url":"https://api.github.com/repos/juju/juju/pulls/8573/comments","review_comment_url":"https://api.github.com/repos/juju/juju/pulls/comments{/number}","comments_url":"https://api.github.com/repos/juju/juju/issues/8573/comments","statuses_url":"https://api.github.com/repos/juju/juju/statuses/9a8e97ee9b778ef0e8e0530d60302facdb4e547a","head":{"label":"howbazaar:presence-recorder","ref":"presence-recorder","sha":"9a8e97ee9b778ef0e8e0530d60302facdb4e547a","user":{"login":"howbazaar","id":1744247,"avatar_url":"https://avatars3.githubusercontent.com/u/1744247?v=4","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},"repo":{"id":20467403,"name":"juju","full_name":"howbazaar/juju","owner":{"login":"howbazaar","id":1744247,"avatar_url":"https://avatars3.githubusercontent.com/u/1744247?v=4","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},"private":false,"html_url":"https://github.com/howbazaar/juju","description":"juju is devops distilled","fork":true,"url":"https://api.github.com/repos/howbazaar/juju","forks_url":"https://api.github.com/repos/howbazaar/juju/forks","keys_url":"https://api.github.com/repos/howbazaar/juju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/howbazaar/juju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/howbazaar/juju/teams","hooks_url":"https://api.github.com/repos/howbazaar/juju/hooks","issue_events_url":"https://api.github.com/repos/howbazaar/juju/issues/events{/number}","events_url":"https://api.github.com/repos/howbazaar/juju/events","assignees_url":"https://api.github.com/repos/howbazaar/juju/assignees{/user}","branches_url":"https://api.github.com/repos/howbazaar/juju/branches{/branch}","tags_url":"https://api.github.com/repos/howbazaar/juju/tags","blobs_url":"https://api.github.com/repos/howbazaar/juju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/howbazaar/juju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/howbazaar/juju/git/refs{/sha}","trees_url":"https://api.github.com/repos/howbazaar/juju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/howbazaar/juju/statuses/{sha}","languages_url":"https://api.github.com/repos/howbazaar/juju/languages","stargazers_url":"https://api.github.com/repos/howbazaar/juju/stargazers","contributors_url":"https://api.github.com/repos/howbazaar/juju/contributors","subscribers_url":"https://api.github.com/repos/howbazaar/juju/subscribers","subscription_url":"https://api.github.com/repos/howbazaar/juju/subscription","commits_url":"https://api.github.com/repos/howbazaar/juju/commits{/sha}","git_commits_url":"https://api.github.com/repos/howbazaar/juju/git/commits{/sha}","comments_url":"https://api.github.com/repos/howbazaar/juju/comments{/number}","issue_comment_url":"https://api.github.com/repos/howbazaar/juju/issues/comments{/number}","contents_url":"https://api.github.com/repos/howbazaar/juju/contents/{+path}","compare_url":"https://api.github.com/repos/howbazaar/juju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/howbazaar/juju/merges","archive_url":"https://api.github.com/repos/howbazaar/juju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/howbazaar/juju/downloads","issues_url":"https://api.github.com/repos/howbazaar/juju/issues{/number}","pulls_url":"https://api.github.com/repos/howbazaar/juju/pulls{/number}","milestones_url":"https://api.github.com/repos/howbazaar/juju/milestones{/number}","notifications_url":"https://api.github.com/repos/howbazaar/juju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/howbazaar/juju/labels{/name}","releases_url":"https://api.github.com/repos/howbazaar/juju/releases{/id}","deployments_url":"https://api.github.com/repos/howbazaar/juju/deployments","created_at":"2014-06-04T02:27:18Z","updated_at":"2016-01-15T01:18:35Z","pushed_at":"2018-04-11T04:18:51Z","git_url":"git://github.com/howbazaar/juju.git","ssh_url":"git@github.com:howbazaar/juju.git","clone_url":"https://github.com/howbazaar/juju.git","svn_url":"https://github.com/howbazaar/juju","homepage":null,"size":203972,"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":0,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"juju:develop","ref":"develop","sha":"bcf9774fd012a7c84357528dbd8fbebbd6038e17","user":{"login":"juju","id":4604548,"avatar_url":"https://avatars0.githubusercontent.com/u/4604548?v=4","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://avatars0.githubusercontent.com/u/4604548?v=4","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":"2018-04-11T04:09:42Z","pushed_at":"2018-04-11T06:13:31Z","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":207980,"stargazers_count":1136,"watchers_count":1136,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":263,"mirror_url":null,"archived":false,"open_issues_count":20,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0"},"forks":263,"open_issues":20,"watchers":1136,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/8573"},"html":{"href":"https://github.com/juju/juju/pull/8573"},"issue":{"href":"https://api.github.com/repos/juju/juju/issues/8573"},"comments":{"href":"https://api.github.com/repos/juju/juju/issues/8573/comments"},"review_comments":{"href":"https://api.github.com/repos/juju/juju/pulls/8573/comments"},"review_comment":{"href":"https://api.github.com/repos/juju/juju/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/juju/juju/pulls/8573/commits"},"statuses":{"href":"https://api.github.com/repos/juju/juju/statuses/9a8e97ee9b778ef0e8e0530d60302facdb4e547a"}},"author_association":"OWNER"}}
{"actor":{"display_login":"howbazaar"}}