{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/logstash/pulls/comments/51552279","id":51552279,"diff_hunk":"@@ -8,87 +8,102 @@ class MetricNoKeyProvided < MetricException; end\n   class MetricNoBlockProvided < MetricException; end\n   class MetricNoNamespaceProvided < MetricException; end\n \n+  # This class provide the interface between the code, the collector and the format\n+  # of the recorded metric.\n   class Metric\n-    class TimedExecution\n-      MILLISECONDS = 1_000_000.0.freeze\n-\n-      def initialize(metric, key)\n-        @metric = metric\n-        @key = key\n-        start\n-      end\n-\n-      def start\n-        @start_time = current_time\n-      end\n-\n-      def stop\n-        @metric.report_time(@key, (MILLISECONDS * (current_time - @start_time)).to_i)\n-      end\n-\n-      private\n-      def current_time\n-        Time.now\n-      end\n-    end\n-\n-    attr_reader :collector, :namespace_information\n+    attr_reader :collector\n \n-    public\n-    def initialize(collector, namespace = nil)\n+    def initialize(collector)\n       @collector = collector\n-      @namespace_information = Array(namespace).map(&:to_sym)\n     end\n \n-    def increment(key, value = 1)\n+    def increment(namespace, key, value = 1)\n       validate_key!(key)\n-      collector.push(namespace_information, key, :counter, :increment, value)\n+      collector.push(namespace, key, :counter, :increment, value)\n     end\n \n-    def decrement(key, value = 1)\n+    def decrement(namespace, key, value = 1)\n       validate_key!(key)\n-      collector.push(namespace_information, key, :counter, :decrement, value)\n+      collector.push(namespace, key, :counter, :decrement, value)\n     end\n \n-    # might be worth to create a block interface for time based gauge\n-    def gauge(key, value)\n+    def gauge(namespace, key, value)\n       validate_key!(key)\n-      collector.push(namespace_information, key, :gauge, :set, value)\n+      collector.push(namespace, key, :gauge, :set, value)\n     end\n \n-    def time(key)\n+    def time(namespace, key)\n       validate_key!(key)\n \n       if block_given?\n-        timer = TimedExecution.new(self, key)\n+        timer = TimedExecution.new(self, namespace, key)\n         content = yield\n         timer.stop\n         return content\n       else\n-        TimedExecution.new(self, key)\n+        TimedExecution.new(self, namespace, key)\n       end\n     end\n \n-    def report_time(key, duration)\n-      collector.push(namespace_information, key, :mean, :increment, duration)\n+    def report_time(namespace, key, duration)\n+      collector.push(namespace, key, :mean, :increment, duration)\n     end\n \n-    def namespace(sub_namespace)\n-      raise MetricNoNamespaceProvided if sub_namespace.nil? || sub_namespace.empty?\n-\n-      new_namespace = namespace_information.clone\n-      new_namespace << sub_namespace\n-\n-      Metric.new(collector, new_namespace)\n+    # This method return a metric instance tied to a specific namespace\n+    # so instead of specifying the namespace on every call.\n+    #\n+    # Example:\n+    #   metric.increment(:namespace, :mykey, 200)\n+    #   metric.increment(:namespace, :mykey_2, 200)\n+    #\n+    #   namespaced_metric = metric.namespace(:namespace)\n+    #   namespaced_metric.increment(:mykey, 200)\n+    #   namespaced_metric.increment(:mykey_2, 200)\n+    # ```\n+    #\n+    # @param name [Array<String>] Name of the namespace\n+    # @param name [String] Name of the namespace\n+    def namespace(name)\n+      raise MetricNoNamespaceProvided if name.nil? || name.empty?\n+\n+      NamespacedMetric.new(self, name)","path":"logstash-core/lib/logstash/instrument/metric.rb","position":108,"original_position":108,"commit_id":"b603a756e6049a5f5f546f8e51dce5a6c763b953","original_commit_id":"b603a756e6049a5f5f546f8e51dce5a6c763b953","user":{"login":"purbon","id":68540,"avatar_url":"https://avatars.githubusercontent.com/u/68540?v=3","gravatar_id":"","url":"https://api.github.com/users/purbon","html_url":"https://github.com/purbon","followers_url":"https://api.github.com/users/purbon/followers","following_url":"https://api.github.com/users/purbon/following{/other_user}","gists_url":"https://api.github.com/users/purbon/gists{/gist_id}","starred_url":"https://api.github.com/users/purbon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/purbon/subscriptions","organizations_url":"https://api.github.com/users/purbon/orgs","repos_url":"https://api.github.com/users/purbon/repos","events_url":"https://api.github.com/users/purbon/events{/privacy}","received_events_url":"https://api.github.com/users/purbon/received_events","type":"User","site_admin":false},"body":"oh! now I understand changes inside the Metric class, :smile: ","created_at":"2016-02-02T10:48:59Z","updated_at":"2016-02-02T10:48:59Z","html_url":"https://github.com/elastic/logstash/pull/4602#discussion_r51552279","pull_request_url":"https://api.github.com/repos/elastic/logstash/pulls/4602","_links":{"self":{"href":"https://api.github.com/repos/elastic/logstash/pulls/comments/51552279"},"html":{"href":"https://github.com/elastic/logstash/pull/4602#discussion_r51552279"},"pull_request":{"href":"https://api.github.com/repos/elastic/logstash/pulls/4602"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/logstash/pulls/4602","id":57847795,"html_url":"https://github.com/elastic/logstash/pull/4602","diff_url":"https://github.com/elastic/logstash/pull/4602.diff","patch_url":"https://github.com/elastic/logstash/pull/4602.patch","issue_url":"https://api.github.com/repos/elastic/logstash/issues/4602","number":4602,"state":"open","locked":false,"title":"Metrics/flexibility","user":{"login":"ph","id":640,"avatar_url":"https://avatars.githubusercontent.com/u/640?v=3","gravatar_id":"","url":"https://api.github.com/users/ph","html_url":"https://github.com/ph","followers_url":"https://api.github.com/users/ph/followers","following_url":"https://api.github.com/users/ph/following{/other_user}","gists_url":"https://api.github.com/users/ph/gists{/gist_id}","starred_url":"https://api.github.com/users/ph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ph/subscriptions","organizations_url":"https://api.github.com/users/ph/orgs","repos_url":"https://api.github.com/users/ph/repos","events_url":"https://api.github.com/users/ph/events{/privacy}","received_events_url":"https://api.github.com/users/ph/received_events","type":"User","site_admin":false},"body":"Refactoring of the metric:\r\n\r\n- Conform to the metric defined in Follow #4492\r\n- Better filtering of the metrics from the metric store Fixes #4461\r\n- Hide the implementation details of the metric store It return an hash, Fixes #4529\r\n- MetricStore#each now support a path to only fetch a subset on the metrics.","created_at":"2016-02-01T14:42:00Z","updated_at":"2016-02-02T10:48:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"924fd4831b96e0dd65a92b1bad13cb9288b04bb9","assignee":{"login":"purbon","id":68540,"avatar_url":"https://avatars.githubusercontent.com/u/68540?v=3","gravatar_id":"","url":"https://api.github.com/users/purbon","html_url":"https://github.com/purbon","followers_url":"https://api.github.com/users/purbon/followers","following_url":"https://api.github.com/users/purbon/following{/other_user}","gists_url":"https://api.github.com/users/purbon/gists{/gist_id}","starred_url":"https://api.github.com/users/purbon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/purbon/subscriptions","organizations_url":"https://api.github.com/users/purbon/orgs","repos_url":"https://api.github.com/users/purbon/repos","events_url":"https://api.github.com/users/purbon/events{/privacy}","received_events_url":"https://api.github.com/users/purbon/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/elastic/logstash/pulls/4602/commits","review_comments_url":"https://api.github.com/repos/elastic/logstash/pulls/4602/comments","review_comment_url":"https://api.github.com/repos/elastic/logstash/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/logstash/issues/4602/comments","statuses_url":"https://api.github.com/repos/elastic/logstash/statuses/b603a756e6049a5f5f546f8e51dce5a6c763b953","head":{"label":"ph:metrics/flexibility","ref":"metrics/flexibility","sha":"b603a756e6049a5f5f546f8e51dce5a6c763b953","user":{"login":"ph","id":640,"avatar_url":"https://avatars.githubusercontent.com/u/640?v=3","gravatar_id":"","url":"https://api.github.com/users/ph","html_url":"https://github.com/ph","followers_url":"https://api.github.com/users/ph/followers","following_url":"https://api.github.com/users/ph/following{/other_user}","gists_url":"https://api.github.com/users/ph/gists{/gist_id}","starred_url":"https://api.github.com/users/ph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ph/subscriptions","organizations_url":"https://api.github.com/users/ph/orgs","repos_url":"https://api.github.com/users/ph/repos","events_url":"https://api.github.com/users/ph/events{/privacy}","received_events_url":"https://api.github.com/users/ph/received_events","type":"User","site_admin":false},"repo":{"id":24861697,"name":"logstash","full_name":"ph/logstash","owner":{"login":"ph","id":640,"avatar_url":"https://avatars.githubusercontent.com/u/640?v=3","gravatar_id":"","url":"https://api.github.com/users/ph","html_url":"https://github.com/ph","followers_url":"https://api.github.com/users/ph/followers","following_url":"https://api.github.com/users/ph/following{/other_user}","gists_url":"https://api.github.com/users/ph/gists{/gist_id}","starred_url":"https://api.github.com/users/ph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ph/subscriptions","organizations_url":"https://api.github.com/users/ph/orgs","repos_url":"https://api.github.com/users/ph/repos","events_url":"https://api.github.com/users/ph/events{/privacy}","received_events_url":"https://api.github.com/users/ph/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ph/logstash","description":"logstash - logs/event transport, processing, management, search.","fork":true,"url":"https://api.github.com/repos/ph/logstash","forks_url":"https://api.github.com/repos/ph/logstash/forks","keys_url":"https://api.github.com/repos/ph/logstash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ph/logstash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ph/logstash/teams","hooks_url":"https://api.github.com/repos/ph/logstash/hooks","issue_events_url":"https://api.github.com/repos/ph/logstash/issues/events{/number}","events_url":"https://api.github.com/repos/ph/logstash/events","assignees_url":"https://api.github.com/repos/ph/logstash/assignees{/user}","branches_url":"https://api.github.com/repos/ph/logstash/branches{/branch}","tags_url":"https://api.github.com/repos/ph/logstash/tags","blobs_url":"https://api.github.com/repos/ph/logstash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ph/logstash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ph/logstash/git/refs{/sha}","trees_url":"https://api.github.com/repos/ph/logstash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ph/logstash/statuses/{sha}","languages_url":"https://api.github.com/repos/ph/logstash/languages","stargazers_url":"https://api.github.com/repos/ph/logstash/stargazers","contributors_url":"https://api.github.com/repos/ph/logstash/contributors","subscribers_url":"https://api.github.com/repos/ph/logstash/subscribers","subscription_url":"https://api.github.com/repos/ph/logstash/subscription","commits_url":"https://api.github.com/repos/ph/logstash/commits{/sha}","git_commits_url":"https://api.github.com/repos/ph/logstash/git/commits{/sha}","comments_url":"https://api.github.com/repos/ph/logstash/comments{/number}","issue_comment_url":"https://api.github.com/repos/ph/logstash/issues/comments{/number}","contents_url":"https://api.github.com/repos/ph/logstash/contents/{+path}","compare_url":"https://api.github.com/repos/ph/logstash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ph/logstash/merges","archive_url":"https://api.github.com/repos/ph/logstash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ph/logstash/downloads","issues_url":"https://api.github.com/repos/ph/logstash/issues{/number}","pulls_url":"https://api.github.com/repos/ph/logstash/pulls{/number}","milestones_url":"https://api.github.com/repos/ph/logstash/milestones{/number}","notifications_url":"https://api.github.com/repos/ph/logstash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ph/logstash/labels{/name}","releases_url":"https://api.github.com/repos/ph/logstash/releases{/id}","deployments_url":"https://api.github.com/repos/ph/logstash/deployments","created_at":"2014-10-06T19:37:59Z","updated_at":"2015-06-05T14:18:00Z","pushed_at":"2016-02-01T21:04:57Z","git_url":"git://github.com/ph/logstash.git","ssh_url":"git@github.com:ph/logstash.git","clone_url":"https://github.com/ph/logstash.git","svn_url":"https://github.com/ph/logstash","homepage":"http://logstash.net/","size":74184,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"elastic:feature/metrics","ref":"feature/metrics","sha":"ac2e030eca1fd288486088f9e23fec74ddad8cc9","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":1090311,"name":"logstash","full_name":"elastic/logstash","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/logstash","description":"logstash - transport and process your logs, events, or other data","fork":false,"url":"https://api.github.com/repos/elastic/logstash","forks_url":"https://api.github.com/repos/elastic/logstash/forks","keys_url":"https://api.github.com/repos/elastic/logstash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/logstash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/logstash/teams","hooks_url":"https://api.github.com/repos/elastic/logstash/hooks","issue_events_url":"https://api.github.com/repos/elastic/logstash/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/logstash/events","assignees_url":"https://api.github.com/repos/elastic/logstash/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/logstash/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/logstash/tags","blobs_url":"https://api.github.com/repos/elastic/logstash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/logstash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/logstash/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/logstash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/logstash/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/logstash/languages","stargazers_url":"https://api.github.com/repos/elastic/logstash/stargazers","contributors_url":"https://api.github.com/repos/elastic/logstash/contributors","subscribers_url":"https://api.github.com/repos/elastic/logstash/subscribers","subscription_url":"https://api.github.com/repos/elastic/logstash/subscription","commits_url":"https://api.github.com/repos/elastic/logstash/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/logstash/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/logstash/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/logstash/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/logstash/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/logstash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/logstash/merges","archive_url":"https://api.github.com/repos/elastic/logstash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/logstash/downloads","issues_url":"https://api.github.com/repos/elastic/logstash/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/logstash/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/logstash/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/logstash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/logstash/labels{/name}","releases_url":"https://api.github.com/repos/elastic/logstash/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/logstash/deployments","created_at":"2010-11-18T01:31:50Z","updated_at":"2016-02-02T09:47:32Z","pushed_at":"2016-02-02T10:23:28Z","git_url":"git://github.com/elastic/logstash.git","ssh_url":"git@github.com:elastic/logstash.git","clone_url":"https://github.com/elastic/logstash.git","svn_url":"https://github.com/elastic/logstash","homepage":"https://www.elastic.co/products/logstash","size":79040,"stargazers_count":5377,"watchers_count":5377,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1677,"mirror_url":null,"open_issues_count":754,"forks":1677,"open_issues":754,"watchers":5377,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/logstash/pulls/4602"},"html":{"href":"https://github.com/elastic/logstash/pull/4602"},"issue":{"href":"https://api.github.com/repos/elastic/logstash/issues/4602"},"comments":{"href":"https://api.github.com/repos/elastic/logstash/issues/4602/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/logstash/pulls/4602/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/logstash/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/logstash/pulls/4602/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/logstash/statuses/b603a756e6049a5f5f546f8e51dce5a6c763b953"}}}}