{"action":"created","comment":{"url":"https://api.github.com/repos/DataDog/integrations-core/pulls/comments/215619538","pull_request_review_id":152922451,"id":215619538,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNTYxOTUzOA==","diff_hunk":"@@ -0,0 +1,121 @@\n+# (C) Datadog, Inc. 2010-2017\n+# All rights reserved\n+# Licensed under Simplified BSD License (see LICENSE)\n+import threading\n+import time\n+\n+\n+class MorNotFoundError(Exception):\n+    pass\n+\n+\n+class MorCache:\n+    \"\"\"\n+    Implements a thread safe storage for Mor objects.\n+    For each instance key, the cache maps: mor_name --> mor_dict_object\n+    \"\"\"\n+    def __init__(self):\n+        self._mor = {}\n+        self._mor_lock = threading.RLock()\n+\n+    def init_instance(self, key):\n+        \"\"\"\n+        Create an empty instance if it doesn't exist.\n+        If the instance already exists, this is a noop.\n+        \"\"\"\n+        with self._mor_lock:\n+            if key not in self._mor:\n+                self._mor[key] = {}\n+\n+    def contains(self, key):\n+        \"\"\"\n+        Return whether an instance key is present.\n+        \"\"\"\n+        with self._mor_lock:\n+            return key in self._mor\n+\n+    def instance_size(self, key):\n+        \"\"\"\n+        Return how many Mor objects are stored for the given instance.\n+        If the key is not in the cache, raises a KeyError.\n+        \"\"\"\n+        with self._mor_lock:\n+            return len(self._mor[key])\n+\n+    def set_mor(self, key, name, mor):\n+        \"\"\"\n+        Store a Mor object in the cache with the given name.\n+        If the key is not in the cache, raises a KeyError.\n+        \"\"\"\n+        with self._mor_lock:\n+            self._mor[key][name] = mor\n+            self._mor[key][name]['creation_time'] = time.time()\n+\n+    def get_mor(self, key, name):\n+        \"\"\"\n+        Return the Mor object identified by `name` for the given instance key.\n+        If the key is not in the cache, raises a KeyError.\n+        If there's no Mor with the given name, raises a MorNotFoundError.\n+        \"\"\"\n+        with self._mor_lock:\n+            mors = self._mor[key]\n+            try:\n+                return mors[name]\n+            except KeyError:\n+                raise MorNotFoundError(\"Mor object '{}' is not in the cache.\".format(name))\n+\n+    def set_metrics(self, key, name, metrics):\n+        \"\"\"\n+        Store a list of metric identifiers for the given instance key and Mor\n+        object name.\n+        If the key is not in the cache, raises a KeyError.\n+        If the Mor object is not in the cache, raises a MorNotFoundError\n+        \"\"\"\n+        with self._mor_lock:\n+            mor = self._mor[key].get(name)\n+            if mor is None:\n+                raise MorNotFoundError(\"Mor object '{}' is not in the cache.\".format(name))\n+            mor['metrics'] = metrics\n+\n+    def mors(self, key):\n+        \"\"\"\n+        Generator returning all the mors in the cache for the given instance key.\n+        \"\"\"\n+        with self._mor_lock:\n+            for k, v in self._mor.get(key, {}).iteritems():\n+                yield k, v\n+\n+    def mors_batch(self, key, batch_size):\n+        \"\"\"\n+        \"\"\"\n+        with self._mor_lock:\n+            mors_dict = self._mor.get(key)","path":"vsphere/datadog_checks/vsphere/mor_cache.py","position":92,"original_position":92,"commit_id":"484d83f8a74cdb185456338c1c7533a450553453","original_commit_id":"484d83f8a74cdb185456338c1c7533a450553453","user":{"login":"masci","id":7241,"node_id":"MDQ6VXNlcjcyNDE=","avatar_url":"https://avatars3.githubusercontent.com/u/7241?v=4","gravatar_id":"","url":"https://api.github.com/users/masci","html_url":"https://github.com/masci","followers_url":"https://api.github.com/users/masci/followers","following_url":"https://api.github.com/users/masci/following{/other_user}","gists_url":"https://api.github.com/users/masci/gists{/gist_id}","starred_url":"https://api.github.com/users/masci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/masci/subscriptions","organizations_url":"https://api.github.com/users/masci/orgs","repos_url":"https://api.github.com/users/masci/repos","events_url":"https://api.github.com/users/masci/events{/privacy}","received_events_url":"https://api.github.com/users/masci/received_events","type":"User","site_admin":false},"body":"Same consideration as above","created_at":"2018-09-06T13:13:56Z","updated_at":"2018-09-06T13:13:56Z","html_url":"https://github.com/DataDog/integrations-core/pull/2173#discussion_r215619538","pull_request_url":"https://api.github.com/repos/DataDog/integrations-core/pulls/2173","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/DataDog/integrations-core/pulls/comments/215619538"},"html":{"href":"https://github.com/DataDog/integrations-core/pull/2173#discussion_r215619538"},"pull_request":{"href":"https://api.github.com/repos/DataDog/integrations-core/pulls/2173"}},"in_reply_to_id":215602952},"pull_request":{"url":"https://api.github.com/repos/DataDog/integrations-core/pulls/2173","id":213289669,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEzMjg5NjY5","html_url":"https://github.com/DataDog/integrations-core/pull/2173","diff_url":"https://github.com/DataDog/integrations-core/pull/2173.diff","patch_url":"https://github.com/DataDog/integrations-core/pull/2173.patch","issue_url":"https://api.github.com/repos/DataDog/integrations-core/issues/2173","number":2173,"state":"open","locked":false,"title":"Rewrite the Mor cache","user":{"login":"masci","id":7241,"node_id":"MDQ6VXNlcjcyNDE=","avatar_url":"https://avatars3.githubusercontent.com/u/7241?v=4","gravatar_id":"","url":"https://api.github.com/users/masci","html_url":"https://github.com/masci","followers_url":"https://api.github.com/users/masci/followers","following_url":"https://api.github.com/users/masci/following{/other_user}","gists_url":"https://api.github.com/users/masci/gists{/gist_id}","starred_url":"https://api.github.com/users/masci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/masci/subscriptions","organizations_url":"https://api.github.com/users/masci/orgs","repos_url":"https://api.github.com/users/masci/repos","events_url":"https://api.github.com/users/masci/events{/privacy}","received_events_url":"https://api.github.com/users/masci/received_events","type":"User","site_admin":false},"body":"### What does this PR do?\r\n\r\n* Changed the cache storing the list of Mors to a thread safe object\r\n* Killed some dead code\r\n* Fixed a couple minor quirks\r\n* The collection logic stays the same\r\n\r\n### Motivation\r\n\r\nMaking the check thread safe\r\n\r\n### Review checklist\r\n\r\n- [ ] PR has a [meaningful title](https://github.com/DataDog/integrations-core/blob/master/CONTRIBUTING.md#pull-request-title) or PR has the `no-changelog` label attached\r\n- [ ] Feature or bugfix has tests\r\n- [ ] Git history is clean\r\n- [ ] If PR impacts documentation, docs team has been notified or an issue has been opened on the [documentation repo](https://github.com/DataDog/documentation/issues/new)\r\n\r\n","created_at":"2018-09-05T13:14:55Z","updated_at":"2018-09-06T13:13:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"00e791a26f0d4c05c6efe18c63357016d6ea1e63","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":937215978,"node_id":"MDU6TGFiZWw5MzcyMTU5Nzg=","url":"https://api.github.com/repos/DataDog/integrations-core/labels/changelog/Changed","name":"changelog/Changed","color":"f2983e","default":false},{"id":936579789,"node_id":"MDU6TGFiZWw5MzY1Nzk3ODk=","url":"https://api.github.com/repos/DataDog/integrations-core/labels/integration/vsphere","name":"integration/vsphere","color":"bfdadc","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/DataDog/integrations-core/pulls/2173/commits","review_comments_url":"https://api.github.com/repos/DataDog/integrations-core/pulls/2173/comments","review_comment_url":"https://api.github.com/repos/DataDog/integrations-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DataDog/integrations-core/issues/2173/comments","statuses_url":"https://api.github.com/repos/DataDog/integrations-core/statuses/484d83f8a74cdb185456338c1c7533a450553453","head":{"label":"DataDog:massi/vsphere","ref":"massi/vsphere","sha":"484d83f8a74cdb185456338c1c7533a450553453","user":{"login":"DataDog","id":365230,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTIzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/365230?v=4","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"repo":{"id":47203045,"node_id":"MDEwOlJlcG9zaXRvcnk0NzIwMzA0NQ==","name":"integrations-core","full_name":"DataDog/integrations-core","owner":{"login":"DataDog","id":365230,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTIzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/365230?v=4","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DataDog/integrations-core","description":"Core integrations of the datadog agent","fork":false,"url":"https://api.github.com/repos/DataDog/integrations-core","forks_url":"https://api.github.com/repos/DataDog/integrations-core/forks","keys_url":"https://api.github.com/repos/DataDog/integrations-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataDog/integrations-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataDog/integrations-core/teams","hooks_url":"https://api.github.com/repos/DataDog/integrations-core/hooks","issue_events_url":"https://api.github.com/repos/DataDog/integrations-core/issues/events{/number}","events_url":"https://api.github.com/repos/DataDog/integrations-core/events","assignees_url":"https://api.github.com/repos/DataDog/integrations-core/assignees{/user}","branches_url":"https://api.github.com/repos/DataDog/integrations-core/branches{/branch}","tags_url":"https://api.github.com/repos/DataDog/integrations-core/tags","blobs_url":"https://api.github.com/repos/DataDog/integrations-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataDog/integrations-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataDog/integrations-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataDog/integrations-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataDog/integrations-core/statuses/{sha}","languages_url":"https://api.github.com/repos/DataDog/integrations-core/languages","stargazers_url":"https://api.github.com/repos/DataDog/integrations-core/stargazers","contributors_url":"https://api.github.com/repos/DataDog/integrations-core/contributors","subscribers_url":"https://api.github.com/repos/DataDog/integrations-core/subscribers","subscription_url":"https://api.github.com/repos/DataDog/integrations-core/subscription","commits_url":"https://api.github.com/repos/DataDog/integrations-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataDog/integrations-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataDog/integrations-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataDog/integrations-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataDog/integrations-core/contents/{+path}","compare_url":"https://api.github.com/repos/DataDog/integrations-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataDog/integrations-core/merges","archive_url":"https://api.github.com/repos/DataDog/integrations-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataDog/integrations-core/downloads","issues_url":"https://api.github.com/repos/DataDog/integrations-core/issues{/number}","pulls_url":"https://api.github.com/repos/DataDog/integrations-core/pulls{/number}","milestones_url":"https://api.github.com/repos/DataDog/integrations-core/milestones{/number}","notifications_url":"https://api.github.com/repos/DataDog/integrations-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataDog/integrations-core/labels{/name}","releases_url":"https://api.github.com/repos/DataDog/integrations-core/releases{/id}","deployments_url":"https://api.github.com/repos/DataDog/integrations-core/deployments","created_at":"2015-12-01T16:41:45Z","updated_at":"2018-09-06T10:33:27Z","pushed_at":"2018-09-06T10:48:01Z","git_url":"git://github.com/DataDog/integrations-core.git","ssh_url":"git@github.com:DataDog/integrations-core.git","clone_url":"https://github.com/DataDog/integrations-core.git","svn_url":"https://github.com/DataDog/integrations-core","homepage":null,"size":28564,"stargazers_count":142,"watchers_count":142,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":312,"mirror_url":null,"archived":false,"open_issues_count":62,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":312,"open_issues":62,"watchers":142,"default_branch":"master"}},"base":{"label":"DataDog:master","ref":"master","sha":"08b4cbc30df186c030b6b3031a5f91229aed8a13","user":{"login":"DataDog","id":365230,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTIzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/365230?v=4","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"repo":{"id":47203045,"node_id":"MDEwOlJlcG9zaXRvcnk0NzIwMzA0NQ==","name":"integrations-core","full_name":"DataDog/integrations-core","owner":{"login":"DataDog","id":365230,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NTIzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/365230?v=4","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DataDog/integrations-core","description":"Core integrations of the datadog agent","fork":false,"url":"https://api.github.com/repos/DataDog/integrations-core","forks_url":"https://api.github.com/repos/DataDog/integrations-core/forks","keys_url":"https://api.github.com/repos/DataDog/integrations-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataDog/integrations-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataDog/integrations-core/teams","hooks_url":"https://api.github.com/repos/DataDog/integrations-core/hooks","issue_events_url":"https://api.github.com/repos/DataDog/integrations-core/issues/events{/number}","events_url":"https://api.github.com/repos/DataDog/integrations-core/events","assignees_url":"https://api.github.com/repos/DataDog/integrations-core/assignees{/user}","branches_url":"https://api.github.com/repos/DataDog/integrations-core/branches{/branch}","tags_url":"https://api.github.com/repos/DataDog/integrations-core/tags","blobs_url":"https://api.github.com/repos/DataDog/integrations-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataDog/integrations-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataDog/integrations-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataDog/integrations-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataDog/integrations-core/statuses/{sha}","languages_url":"https://api.github.com/repos/DataDog/integrations-core/languages","stargazers_url":"https://api.github.com/repos/DataDog/integrations-core/stargazers","contributors_url":"https://api.github.com/repos/DataDog/integrations-core/contributors","subscribers_url":"https://api.github.com/repos/DataDog/integrations-core/subscribers","subscription_url":"https://api.github.com/repos/DataDog/integrations-core/subscription","commits_url":"https://api.github.com/repos/DataDog/integrations-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataDog/integrations-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataDog/integrations-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataDog/integrations-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataDog/integrations-core/contents/{+path}","compare_url":"https://api.github.com/repos/DataDog/integrations-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataDog/integrations-core/merges","archive_url":"https://api.github.com/repos/DataDog/integrations-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataDog/integrations-core/downloads","issues_url":"https://api.github.com/repos/DataDog/integrations-core/issues{/number}","pulls_url":"https://api.github.com/repos/DataDog/integrations-core/pulls{/number}","milestones_url":"https://api.github.com/repos/DataDog/integrations-core/milestones{/number}","notifications_url":"https://api.github.com/repos/DataDog/integrations-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataDog/integrations-core/labels{/name}","releases_url":"https://api.github.com/repos/DataDog/integrations-core/releases{/id}","deployments_url":"https://api.github.com/repos/DataDog/integrations-core/deployments","created_at":"2015-12-01T16:41:45Z","updated_at":"2018-09-06T10:33:27Z","pushed_at":"2018-09-06T10:48:01Z","git_url":"git://github.com/DataDog/integrations-core.git","ssh_url":"git@github.com:DataDog/integrations-core.git","clone_url":"https://github.com/DataDog/integrations-core.git","svn_url":"https://github.com/DataDog/integrations-core","homepage":null,"size":28564,"stargazers_count":142,"watchers_count":142,"language":"Python","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":312,"mirror_url":null,"archived":false,"open_issues_count":62,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":312,"open_issues":62,"watchers":142,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DataDog/integrations-core/pulls/2173"},"html":{"href":"https://github.com/DataDog/integrations-core/pull/2173"},"issue":{"href":"https://api.github.com/repos/DataDog/integrations-core/issues/2173"},"comments":{"href":"https://api.github.com/repos/DataDog/integrations-core/issues/2173/comments"},"review_comments":{"href":"https://api.github.com/repos/DataDog/integrations-core/pulls/2173/comments"},"review_comment":{"href":"https://api.github.com/repos/DataDog/integrations-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DataDog/integrations-core/pulls/2173/commits"},"statuses":{"href":"https://api.github.com/repos/DataDog/integrations-core/statuses/484d83f8a74cdb185456338c1c7533a450553453"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"masci"}}