{"action":"created","comment":{"url":"https://api.github.com/repos/weaveworks/scope/pulls/comments/40060001","id":40060001,"diff_hunk":"@@ -44,41 +63,64 @@ func NewReverseResolver() *ReverseResolver {\n // gcache.NotFoundKeyError error otherwise. Note: it returns one of the\n // possible names that can be obtained for that IP.\n func (r *ReverseResolver) Get(address string) (string, error) {\n-\tval, err := r.cache.Get(address)\n-\tif hostname, ok := val.(string); err == nil && ok {\n-\t\treturn hostname, nil\n-\t}\n-\tif _, ok := val.(struct{}); err == nil && ok {\n-\t\treturn \"\", errNotFound\n-\t}\n-\tif err == gcache.NotFoundKeyError {\n+\tval, found := r.cache.Get(address)\n+\tif !found {\n \t\t// We trigger a asynchronous reverse resolution when not cached\n \t\tselect {\n \t\tcase r.addresses <- address:\n \t\tdefault:\n \t\t}\n+\t\treturn \"\", errNotFound\n+\t}\n+\tif _, ok := val.(struct{}); ok {\n+\t\treturn \"\", errNotFound\n \t}\n-\treturn \"\", errNotFound\n+\tentry, ok := val.(*resolverCacheEntry)\n+\tif !ok {\n+\t\tpanic(fmt.Sprintf(\"unknown entry type in cache: %+v\", val))","path":"probe/endpoint/resolver.go","position":87,"original_position":87,"commit_id":"b93365a0f978968df087d695eab3a22ad3af18d0","original_commit_id":"b93365a0f978968df087d695eab3a22ad3af18d0","user":{"login":"tomwilkie","id":444037,"avatar_url":"https://avatars.githubusercontent.com/u/444037?v=3","gravatar_id":"","url":"https://api.github.com/users/tomwilkie","html_url":"https://github.com/tomwilkie","followers_url":"https://api.github.com/users/tomwilkie/followers","following_url":"https://api.github.com/users/tomwilkie/following{/other_user}","gists_url":"https://api.github.com/users/tomwilkie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomwilkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomwilkie/subscriptions","organizations_url":"https://api.github.com/users/tomwilkie/orgs","repos_url":"https://api.github.com/users/tomwilkie/repos","events_url":"https://api.github.com/users/tomwilkie/events{/privacy}","received_events_url":"https://api.github.com/users/tomwilkie/received_events","type":"User","site_admin":false},"body":"This is a programmer error if this ever happens; just let the val.(*resolverCacheEntry) panic above (ie remove the ok)","created_at":"2015-09-22T07:50:28Z","updated_at":"2015-09-22T07:50:28Z","html_url":"https://github.com/weaveworks/scope/pull/497#discussion_r40060001","pull_request_url":"https://api.github.com/repos/weaveworks/scope/pulls/497","_links":{"self":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/comments/40060001"},"html":{"href":"https://github.com/weaveworks/scope/pull/497#discussion_r40060001"},"pull_request":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/497"}}},"pull_request":{"url":"https://api.github.com/repos/weaveworks/scope/pulls/497","id":45160416,"html_url":"https://github.com/weaveworks/scope/pull/497","diff_url":"https://github.com/weaveworks/scope/pull/497.diff","patch_url":"https://github.com/weaveworks/scope/pull/497.patch","issue_url":"https://api.github.com/repos/weaveworks/scope/issues/497","number":497,"state":"open","locked":false,"title":"Optimize /proc traversal (again)","user":{"login":"inercia","id":1841612,"avatar_url":"https://avatars.githubusercontent.com/u/1841612?v=3","gravatar_id":"","url":"https://api.github.com/users/inercia","html_url":"https://github.com/inercia","followers_url":"https://api.github.com/users/inercia/followers","following_url":"https://api.github.com/users/inercia/following{/other_user}","gists_url":"https://api.github.com/users/inercia/gists{/gist_id}","starred_url":"https://api.github.com/users/inercia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inercia/subscriptions","organizations_url":"https://api.github.com/users/inercia/orgs","repos_url":"https://api.github.com/users/inercia/repos","events_url":"https://api.github.com/users/inercia/events{/privacy}","received_events_url":"https://api.github.com/users/inercia/received_events","type":"User","site_admin":false},"body":"This is the same code found in #450, but replacing the caching library. This should fix #486.\r\n\r\nIn addition to the changes in #450, this PR also caches _some_ file contents. In particular, `/proc/<pid>/[comm, cmdline]`, as they do not change during the lifetime of a process (this is not always true, but I don't think we should care about these corner cases)\r\n\r\n--------------------------\r\n\r\n_From the original #450 description_:\r\n\r\nThe objective of this PR is to reduce the number of syscalls when collecting info from `/proc`. This PR does that by: \r\n\r\n* reading the required files (`/proc/*/[cmdline, comm, stat, fd/*]`, `/proc/net/tcp*`) once per cycle (`spy.interval`), parsing and caching the processes/connections information\r\n* keeping a cache of open files for `/proc/*/[cmdline, comm, stat]` so we do not `open()`/`close()` these files so often.\r\n* removing unnecessary `stat()`s when reading `/proc` directories\r\n\r\nChanges:\r\n\r\n* the required code for reading/parsing `/proc` has been proved from `procspy` to `/probe/proc`\r\n* the `Walker` has been replaced by a `proc.Reader` that provides both `Processes()` and `Connections()`.  Users can walk the list of processes/connections in the same way by providing a function to these functions. A `CachingReader` can be used for caching and getting this info, updated when `Update()`. The code for reading and parsing connection and processes has been simplified.\r\n* a `CachingReader` is initialized in `/probe/main.go` and used in both `endpoint.Reporter` and `process.Reporter` for reporting about processed and connections, and updated periodically by calling `Update()` every `spy.interval` seconds.\r\n* unit tests have been improved by mocking things like file system operations\r\n* things like `Proc` and `Process` have been unified, and many things from `/probe/process` have been moved to `/probe/proc`\r\n\r\nThis is part of the solution to #284 ","created_at":"2015-09-16T11:36:00Z","updated_at":"2015-09-22T07:50:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"435a23fd3806ac9ad7c57f9ca55e1d392b145fc2","assignee":{"login":"tomwilkie","id":444037,"avatar_url":"https://avatars.githubusercontent.com/u/444037?v=3","gravatar_id":"","url":"https://api.github.com/users/tomwilkie","html_url":"https://github.com/tomwilkie","followers_url":"https://api.github.com/users/tomwilkie/followers","following_url":"https://api.github.com/users/tomwilkie/following{/other_user}","gists_url":"https://api.github.com/users/tomwilkie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomwilkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomwilkie/subscriptions","organizations_url":"https://api.github.com/users/tomwilkie/orgs","repos_url":"https://api.github.com/users/tomwilkie/repos","events_url":"https://api.github.com/users/tomwilkie/events{/privacy}","received_events_url":"https://api.github.com/users/tomwilkie/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/weaveworks/scope/pulls/497/commits","review_comments_url":"https://api.github.com/repos/weaveworks/scope/pulls/497/comments","review_comment_url":"https://api.github.com/repos/weaveworks/scope/pulls/comments{/number}","comments_url":"https://api.github.com/repos/weaveworks/scope/issues/497/comments","statuses_url":"https://api.github.com/repos/weaveworks/scope/statuses/b93365a0f978968df087d695eab3a22ad3af18d0","head":{"label":"weaveworks:scope-486","ref":"scope-486","sha":"b93365a0f978968df087d695eab3a22ad3af18d0","user":{"login":"weaveworks","id":9976052,"avatar_url":"https://avatars.githubusercontent.com/u/9976052?v=3","gravatar_id":"","url":"https://api.github.com/users/weaveworks","html_url":"https://github.com/weaveworks","followers_url":"https://api.github.com/users/weaveworks/followers","following_url":"https://api.github.com/users/weaveworks/following{/other_user}","gists_url":"https://api.github.com/users/weaveworks/gists{/gist_id}","starred_url":"https://api.github.com/users/weaveworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaveworks/subscriptions","organizations_url":"https://api.github.com/users/weaveworks/orgs","repos_url":"https://api.github.com/users/weaveworks/repos","events_url":"https://api.github.com/users/weaveworks/events{/privacy}","received_events_url":"https://api.github.com/users/weaveworks/received_events","type":"Organization","site_admin":false},"repo":{"id":34659664,"name":"scope","full_name":"weaveworks/scope","owner":{"login":"weaveworks","id":9976052,"avatar_url":"https://avatars.githubusercontent.com/u/9976052?v=3","gravatar_id":"","url":"https://api.github.com/users/weaveworks","html_url":"https://github.com/weaveworks","followers_url":"https://api.github.com/users/weaveworks/followers","following_url":"https://api.github.com/users/weaveworks/following{/other_user}","gists_url":"https://api.github.com/users/weaveworks/gists{/gist_id}","starred_url":"https://api.github.com/users/weaveworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaveworks/subscriptions","organizations_url":"https://api.github.com/users/weaveworks/orgs","repos_url":"https://api.github.com/users/weaveworks/repos","events_url":"https://api.github.com/users/weaveworks/events{/privacy}","received_events_url":"https://api.github.com/users/weaveworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/weaveworks/scope","description":"Container visibility","fork":false,"url":"https://api.github.com/repos/weaveworks/scope","forks_url":"https://api.github.com/repos/weaveworks/scope/forks","keys_url":"https://api.github.com/repos/weaveworks/scope/keys{/key_id}","collaborators_url":"https://api.github.com/repos/weaveworks/scope/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/weaveworks/scope/teams","hooks_url":"https://api.github.com/repos/weaveworks/scope/hooks","issue_events_url":"https://api.github.com/repos/weaveworks/scope/issues/events{/number}","events_url":"https://api.github.com/repos/weaveworks/scope/events","assignees_url":"https://api.github.com/repos/weaveworks/scope/assignees{/user}","branches_url":"https://api.github.com/repos/weaveworks/scope/branches{/branch}","tags_url":"https://api.github.com/repos/weaveworks/scope/tags","blobs_url":"https://api.github.com/repos/weaveworks/scope/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/weaveworks/scope/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/weaveworks/scope/git/refs{/sha}","trees_url":"https://api.github.com/repos/weaveworks/scope/git/trees{/sha}","statuses_url":"https://api.github.com/repos/weaveworks/scope/statuses/{sha}","languages_url":"https://api.github.com/repos/weaveworks/scope/languages","stargazers_url":"https://api.github.com/repos/weaveworks/scope/stargazers","contributors_url":"https://api.github.com/repos/weaveworks/scope/contributors","subscribers_url":"https://api.github.com/repos/weaveworks/scope/subscribers","subscription_url":"https://api.github.com/repos/weaveworks/scope/subscription","commits_url":"https://api.github.com/repos/weaveworks/scope/commits{/sha}","git_commits_url":"https://api.github.com/repos/weaveworks/scope/git/commits{/sha}","comments_url":"https://api.github.com/repos/weaveworks/scope/comments{/number}","issue_comment_url":"https://api.github.com/repos/weaveworks/scope/issues/comments{/number}","contents_url":"https://api.github.com/repos/weaveworks/scope/contents/{+path}","compare_url":"https://api.github.com/repos/weaveworks/scope/compare/{base}...{head}","merges_url":"https://api.github.com/repos/weaveworks/scope/merges","archive_url":"https://api.github.com/repos/weaveworks/scope/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/weaveworks/scope/downloads","issues_url":"https://api.github.com/repos/weaveworks/scope/issues{/number}","pulls_url":"https://api.github.com/repos/weaveworks/scope/pulls{/number}","milestones_url":"https://api.github.com/repos/weaveworks/scope/milestones{/number}","notifications_url":"https://api.github.com/repos/weaveworks/scope/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/weaveworks/scope/labels{/name}","releases_url":"https://api.github.com/repos/weaveworks/scope/releases{/id}","created_at":"2015-04-27T10:12:35Z","updated_at":"2015-09-20T13:46:29Z","pushed_at":"2015-09-22T05:54:57Z","git_url":"git://github.com/weaveworks/scope.git","ssh_url":"git@github.com:weaveworks/scope.git","clone_url":"https://github.com/weaveworks/scope.git","svn_url":"https://github.com/weaveworks/scope","homepage":"http://weave.works/scope","size":33594,"stargazers_count":369,"watchers_count":369,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":45,"forks":18,"open_issues":45,"watchers":369,"default_branch":"master"}},"base":{"label":"weaveworks:master","ref":"master","sha":"eec00541de9874067a077f37b35b88db52fad84b","user":{"login":"weaveworks","id":9976052,"avatar_url":"https://avatars.githubusercontent.com/u/9976052?v=3","gravatar_id":"","url":"https://api.github.com/users/weaveworks","html_url":"https://github.com/weaveworks","followers_url":"https://api.github.com/users/weaveworks/followers","following_url":"https://api.github.com/users/weaveworks/following{/other_user}","gists_url":"https://api.github.com/users/weaveworks/gists{/gist_id}","starred_url":"https://api.github.com/users/weaveworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaveworks/subscriptions","organizations_url":"https://api.github.com/users/weaveworks/orgs","repos_url":"https://api.github.com/users/weaveworks/repos","events_url":"https://api.github.com/users/weaveworks/events{/privacy}","received_events_url":"https://api.github.com/users/weaveworks/received_events","type":"Organization","site_admin":false},"repo":{"id":34659664,"name":"scope","full_name":"weaveworks/scope","owner":{"login":"weaveworks","id":9976052,"avatar_url":"https://avatars.githubusercontent.com/u/9976052?v=3","gravatar_id":"","url":"https://api.github.com/users/weaveworks","html_url":"https://github.com/weaveworks","followers_url":"https://api.github.com/users/weaveworks/followers","following_url":"https://api.github.com/users/weaveworks/following{/other_user}","gists_url":"https://api.github.com/users/weaveworks/gists{/gist_id}","starred_url":"https://api.github.com/users/weaveworks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaveworks/subscriptions","organizations_url":"https://api.github.com/users/weaveworks/orgs","repos_url":"https://api.github.com/users/weaveworks/repos","events_url":"https://api.github.com/users/weaveworks/events{/privacy}","received_events_url":"https://api.github.com/users/weaveworks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/weaveworks/scope","description":"Container visibility","fork":false,"url":"https://api.github.com/repos/weaveworks/scope","forks_url":"https://api.github.com/repos/weaveworks/scope/forks","keys_url":"https://api.github.com/repos/weaveworks/scope/keys{/key_id}","collaborators_url":"https://api.github.com/repos/weaveworks/scope/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/weaveworks/scope/teams","hooks_url":"https://api.github.com/repos/weaveworks/scope/hooks","issue_events_url":"https://api.github.com/repos/weaveworks/scope/issues/events{/number}","events_url":"https://api.github.com/repos/weaveworks/scope/events","assignees_url":"https://api.github.com/repos/weaveworks/scope/assignees{/user}","branches_url":"https://api.github.com/repos/weaveworks/scope/branches{/branch}","tags_url":"https://api.github.com/repos/weaveworks/scope/tags","blobs_url":"https://api.github.com/repos/weaveworks/scope/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/weaveworks/scope/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/weaveworks/scope/git/refs{/sha}","trees_url":"https://api.github.com/repos/weaveworks/scope/git/trees{/sha}","statuses_url":"https://api.github.com/repos/weaveworks/scope/statuses/{sha}","languages_url":"https://api.github.com/repos/weaveworks/scope/languages","stargazers_url":"https://api.github.com/repos/weaveworks/scope/stargazers","contributors_url":"https://api.github.com/repos/weaveworks/scope/contributors","subscribers_url":"https://api.github.com/repos/weaveworks/scope/subscribers","subscription_url":"https://api.github.com/repos/weaveworks/scope/subscription","commits_url":"https://api.github.com/repos/weaveworks/scope/commits{/sha}","git_commits_url":"https://api.github.com/repos/weaveworks/scope/git/commits{/sha}","comments_url":"https://api.github.com/repos/weaveworks/scope/comments{/number}","issue_comment_url":"https://api.github.com/repos/weaveworks/scope/issues/comments{/number}","contents_url":"https://api.github.com/repos/weaveworks/scope/contents/{+path}","compare_url":"https://api.github.com/repos/weaveworks/scope/compare/{base}...{head}","merges_url":"https://api.github.com/repos/weaveworks/scope/merges","archive_url":"https://api.github.com/repos/weaveworks/scope/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/weaveworks/scope/downloads","issues_url":"https://api.github.com/repos/weaveworks/scope/issues{/number}","pulls_url":"https://api.github.com/repos/weaveworks/scope/pulls{/number}","milestones_url":"https://api.github.com/repos/weaveworks/scope/milestones{/number}","notifications_url":"https://api.github.com/repos/weaveworks/scope/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/weaveworks/scope/labels{/name}","releases_url":"https://api.github.com/repos/weaveworks/scope/releases{/id}","created_at":"2015-04-27T10:12:35Z","updated_at":"2015-09-20T13:46:29Z","pushed_at":"2015-09-22T05:54:57Z","git_url":"git://github.com/weaveworks/scope.git","ssh_url":"git@github.com:weaveworks/scope.git","clone_url":"https://github.com/weaveworks/scope.git","svn_url":"https://github.com/weaveworks/scope","homepage":"http://weave.works/scope","size":33594,"stargazers_count":369,"watchers_count":369,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":45,"forks":18,"open_issues":45,"watchers":369,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/497"},"html":{"href":"https://github.com/weaveworks/scope/pull/497"},"issue":{"href":"https://api.github.com/repos/weaveworks/scope/issues/497"},"comments":{"href":"https://api.github.com/repos/weaveworks/scope/issues/497/comments"},"review_comments":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/497/comments"},"review_comment":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/weaveworks/scope/pulls/497/commits"},"statuses":{"href":"https://api.github.com/repos/weaveworks/scope/statuses/b93365a0f978968df087d695eab3a22ad3af18d0"}}}}