{"action":"created","comment":{"url":"https://api.github.com/repos/chef/chef/pulls/comments/37923940","id":37923940,"diff_hunk":"@@ -0,0 +1,71 @@\n+#\n+# Author:: Ranjib Dey (<ranjib@linux.com>)\n+# Copyright:: Copyright (c) 2015 Chef Inc.\n+# License:: Apache License, Version 2.0\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+#     http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+\n+#\n+# Telemetry::Processor class provides API for chef run related metrics gathering\n+#\n+\n+class Chef\n+  module Telemetry\n+    class Processor\n+      class Metric < Struct.new(:name, :hook, :value); end\n+\n+      attr_reader :metrics\n+      attr_reader :publishers\n+\n+      def initialize\n+        @metrics = []\n+        @publishers = []\n+      end\n+\n+      def add_metric(name, &block)\n+        @metrics << Metric.new(name, block)\n+      end\n+\n+      def add_publisher(publisher)\n+        @publishers << publisher\n+      end\n+\n+      def gather\n+        @metrics.each do |metric|\n+          metric.value = metric.hook.call\n+        end\n+      end\n+\n+      def publish\n+        @publishers.each do |publisher|\n+          publisher.publish(@metrics)\n+        end\n+      end\n+\n+      def self.create(publishers)\n+        processor = Chef::Telemetry::Processor.new\n+        publishers.each do |publisher|\n+          processor.add_publisher(publisher)\n+        end\n+        Chef.event_handler do","path":"lib/chef/telemetry/processor.rb","position":61,"original_position":61,"commit_id":"9f636381c1d32076257c564592ddbf082f9ad67a","original_commit_id":"9f636381c1d32076257c564592ddbf082f9ad67a","user":{"login":"ranjib","id":316306,"avatar_url":"https://avatars.githubusercontent.com/u/316306?v=3","gravatar_id":"","url":"https://api.github.com/users/ranjib","html_url":"https://github.com/ranjib","followers_url":"https://api.github.com/users/ranjib/followers","following_url":"https://api.github.com/users/ranjib/following{/other_user}","gists_url":"https://api.github.com/users/ranjib/gists{/gist_id}","starred_url":"https://api.github.com/users/ranjib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ranjib/subscriptions","organizations_url":"https://api.github.com/users/ranjib/orgs","repos_url":"https://api.github.com/users/ranjib/repos","events_url":"https://api.github.com/users/ranjib/events{/privacy}","received_events_url":"https://api.github.com/users/ranjib/received_events","type":"User","site_admin":false},"body":"why? All Chef.* class based API are global, and they are the public facing API. It also ensures that event handler registration done properly. Event handler was implemented to ease this type of use cases. Can you provide an example on what would be better?\r\n\r\nI can move this logic to a dedicated event handler, similar to doc and other formatter, and then register its if telemetry is enabled, similar to formatter injection. Is that what you looking for? This is similar to that but implemented using the event handler API ","created_at":"2015-08-25T21:47:40Z","updated_at":"2015-08-25T21:47:40Z","html_url":"https://github.com/chef/chef/pull/3818#discussion_r37923940","pull_request_url":"https://api.github.com/repos/chef/chef/pulls/3818","_links":{"self":{"href":"https://api.github.com/repos/chef/chef/pulls/comments/37923940"},"html":{"href":"https://github.com/chef/chef/pull/3818#discussion_r37923940"},"pull_request":{"href":"https://api.github.com/repos/chef/chef/pulls/3818"}}},"pull_request":{"url":"https://api.github.com/repos/chef/chef/pulls/3818","id":43253339,"html_url":"https://github.com/chef/chef/pull/3818","diff_url":"https://github.com/chef/chef/pull/3818.diff","patch_url":"https://github.com/chef/chef/pull/3818.patch","issue_url":"https://api.github.com/repos/chef/chef/issues/3818","number":3818,"state":"open","locked":false,"title":"[RFC-051] Telemetry system","user":{"login":"ranjib","id":316306,"avatar_url":"https://avatars.githubusercontent.com/u/316306?v=3","gravatar_id":"","url":"https://api.github.com/users/ranjib","html_url":"https://github.com/ranjib","followers_url":"https://api.github.com/users/ranjib/followers","following_url":"https://api.github.com/users/ranjib/following{/other_user}","gists_url":"https://api.github.com/users/ranjib/gists{/gist_id}","starred_url":"https://api.github.com/users/ranjib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ranjib/subscriptions","organizations_url":"https://api.github.com/users/ranjib/orgs","repos_url":"https://api.github.com/users/ranjib/repos","events_url":"https://api.github.com/users/ranjib/events{/privacy}","received_events_url":"https://api.github.com/users/ranjib/received_events","type":"User","site_admin":false},"body":":construction: \r\nThis is first pass towards implementing [RFC-051](https://github.com/chef/chef-rfc/blob/master/rfc051-telemetry.md). It contains the main structural components, like the API for adding custom metrics, and couple of built in metrics (time spent on resource, recipe, cookbook etc).\r\nIf i get a review of this it will be easier to implement the rest (or i dont have to rewrite a lot of things after implementing, as rest of the components will reuse this work.\r\n\r\nThings that are still left are:\r\n- [] statsd based publishing mechanism\r\n- [] node attribute based publishing mechanism\r\n- [] GC based metrics\r\n- [] Chef client run metrics\r\n- [] process based metrics (only for *nix platform)","created_at":"2015-08-25T06:21:25Z","updated_at":"2015-08-25T21:47:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"89b23069037a17b66be609385634ea2450668f11","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/chef/chef/pulls/3818/commits","review_comments_url":"https://api.github.com/repos/chef/chef/pulls/3818/comments","review_comment_url":"https://api.github.com/repos/chef/chef/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chef/chef/issues/3818/comments","statuses_url":"https://api.github.com/repos/chef/chef/statuses/9f636381c1d32076257c564592ddbf082f9ad67a","head":{"label":"ranjib:rfc_051","ref":"rfc_051","sha":"9f636381c1d32076257c564592ddbf082f9ad67a","user":{"login":"ranjib","id":316306,"avatar_url":"https://avatars.githubusercontent.com/u/316306?v=3","gravatar_id":"","url":"https://api.github.com/users/ranjib","html_url":"https://github.com/ranjib","followers_url":"https://api.github.com/users/ranjib/followers","following_url":"https://api.github.com/users/ranjib/following{/other_user}","gists_url":"https://api.github.com/users/ranjib/gists{/gist_id}","starred_url":"https://api.github.com/users/ranjib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ranjib/subscriptions","organizations_url":"https://api.github.com/users/ranjib/orgs","repos_url":"https://api.github.com/users/ranjib/repos","events_url":"https://api.github.com/users/ranjib/events{/privacy}","received_events_url":"https://api.github.com/users/ranjib/received_events","type":"User","site_admin":false},"repo":{"id":8191757,"name":"chef","full_name":"ranjib/chef","owner":{"login":"ranjib","id":316306,"avatar_url":"https://avatars.githubusercontent.com/u/316306?v=3","gravatar_id":"","url":"https://api.github.com/users/ranjib","html_url":"https://github.com/ranjib","followers_url":"https://api.github.com/users/ranjib/followers","following_url":"https://api.github.com/users/ranjib/following{/other_user}","gists_url":"https://api.github.com/users/ranjib/gists{/gist_id}","starred_url":"https://api.github.com/users/ranjib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ranjib/subscriptions","organizations_url":"https://api.github.com/users/ranjib/orgs","repos_url":"https://api.github.com/users/ranjib/repos","events_url":"https://api.github.com/users/ranjib/events{/privacy}","received_events_url":"https://api.github.com/users/ranjib/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ranjib/chef","description":"A systems integration framework, built to bring the benefits of configuration management to your entire infrastructure.","fork":true,"url":"https://api.github.com/repos/ranjib/chef","forks_url":"https://api.github.com/repos/ranjib/chef/forks","keys_url":"https://api.github.com/repos/ranjib/chef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ranjib/chef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ranjib/chef/teams","hooks_url":"https://api.github.com/repos/ranjib/chef/hooks","issue_events_url":"https://api.github.com/repos/ranjib/chef/issues/events{/number}","events_url":"https://api.github.com/repos/ranjib/chef/events","assignees_url":"https://api.github.com/repos/ranjib/chef/assignees{/user}","branches_url":"https://api.github.com/repos/ranjib/chef/branches{/branch}","tags_url":"https://api.github.com/repos/ranjib/chef/tags","blobs_url":"https://api.github.com/repos/ranjib/chef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ranjib/chef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ranjib/chef/git/refs{/sha}","trees_url":"https://api.github.com/repos/ranjib/chef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ranjib/chef/statuses/{sha}","languages_url":"https://api.github.com/repos/ranjib/chef/languages","stargazers_url":"https://api.github.com/repos/ranjib/chef/stargazers","contributors_url":"https://api.github.com/repos/ranjib/chef/contributors","subscribers_url":"https://api.github.com/repos/ranjib/chef/subscribers","subscription_url":"https://api.github.com/repos/ranjib/chef/subscription","commits_url":"https://api.github.com/repos/ranjib/chef/commits{/sha}","git_commits_url":"https://api.github.com/repos/ranjib/chef/git/commits{/sha}","comments_url":"https://api.github.com/repos/ranjib/chef/comments{/number}","issue_comment_url":"https://api.github.com/repos/ranjib/chef/issues/comments{/number}","contents_url":"https://api.github.com/repos/ranjib/chef/contents/{+path}","compare_url":"https://api.github.com/repos/ranjib/chef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ranjib/chef/merges","archive_url":"https://api.github.com/repos/ranjib/chef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ranjib/chef/downloads","issues_url":"https://api.github.com/repos/ranjib/chef/issues{/number}","pulls_url":"https://api.github.com/repos/ranjib/chef/pulls{/number}","milestones_url":"https://api.github.com/repos/ranjib/chef/milestones{/number}","notifications_url":"https://api.github.com/repos/ranjib/chef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ranjib/chef/labels{/name}","releases_url":"https://api.github.com/repos/ranjib/chef/releases{/id}","created_at":"2013-02-14T01:31:20Z","updated_at":"2015-04-19T00:07:26Z","pushed_at":"2015-08-25T06:51:26Z","git_url":"git://github.com/ranjib/chef.git","ssh_url":"git@github.com:ranjib/chef.git","clone_url":"https://github.com/ranjib/chef.git","svn_url":"https://github.com/ranjib/chef","homepage":"http://www.opscode.com/chef/","size":79845,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"chef:master","ref":"master","sha":"aa3f1647a7bc30708378319c71c97e4f1af2c5f4","user":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"repo":{"id":108278,"name":"chef","full_name":"chef/chef","owner":{"login":"chef","id":29740,"avatar_url":"https://avatars.githubusercontent.com/u/29740?v=3","gravatar_id":"","url":"https://api.github.com/users/chef","html_url":"https://github.com/chef","followers_url":"https://api.github.com/users/chef/followers","following_url":"https://api.github.com/users/chef/following{/other_user}","gists_url":"https://api.github.com/users/chef/gists{/gist_id}","starred_url":"https://api.github.com/users/chef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef/subscriptions","organizations_url":"https://api.github.com/users/chef/orgs","repos_url":"https://api.github.com/users/chef/repos","events_url":"https://api.github.com/users/chef/events{/privacy}","received_events_url":"https://api.github.com/users/chef/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chef/chef","description":"A systems integration framework, built to bring the benefits of configuration management to your entire infrastructure.","fork":false,"url":"https://api.github.com/repos/chef/chef","forks_url":"https://api.github.com/repos/chef/chef/forks","keys_url":"https://api.github.com/repos/chef/chef/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chef/chef/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chef/chef/teams","hooks_url":"https://api.github.com/repos/chef/chef/hooks","issue_events_url":"https://api.github.com/repos/chef/chef/issues/events{/number}","events_url":"https://api.github.com/repos/chef/chef/events","assignees_url":"https://api.github.com/repos/chef/chef/assignees{/user}","branches_url":"https://api.github.com/repos/chef/chef/branches{/branch}","tags_url":"https://api.github.com/repos/chef/chef/tags","blobs_url":"https://api.github.com/repos/chef/chef/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chef/chef/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chef/chef/git/refs{/sha}","trees_url":"https://api.github.com/repos/chef/chef/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chef/chef/statuses/{sha}","languages_url":"https://api.github.com/repos/chef/chef/languages","stargazers_url":"https://api.github.com/repos/chef/chef/stargazers","contributors_url":"https://api.github.com/repos/chef/chef/contributors","subscribers_url":"https://api.github.com/repos/chef/chef/subscribers","subscription_url":"https://api.github.com/repos/chef/chef/subscription","commits_url":"https://api.github.com/repos/chef/chef/commits{/sha}","git_commits_url":"https://api.github.com/repos/chef/chef/git/commits{/sha}","comments_url":"https://api.github.com/repos/chef/chef/comments{/number}","issue_comment_url":"https://api.github.com/repos/chef/chef/issues/comments{/number}","contents_url":"https://api.github.com/repos/chef/chef/contents/{+path}","compare_url":"https://api.github.com/repos/chef/chef/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chef/chef/merges","archive_url":"https://api.github.com/repos/chef/chef/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chef/chef/downloads","issues_url":"https://api.github.com/repos/chef/chef/issues{/number}","pulls_url":"https://api.github.com/repos/chef/chef/pulls{/number}","milestones_url":"https://api.github.com/repos/chef/chef/milestones{/number}","notifications_url":"https://api.github.com/repos/chef/chef/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chef/chef/labels{/name}","releases_url":"https://api.github.com/repos/chef/chef/releases{/id}","created_at":"2009-01-15T20:40:48Z","updated_at":"2015-08-25T06:13:20Z","pushed_at":"2015-08-25T20:58:04Z","git_url":"git://github.com/chef/chef.git","ssh_url":"git@github.com:chef/chef.git","clone_url":"https://github.com/chef/chef.git","svn_url":"https://github.com/chef/chef","homepage":"http://www.chef.io/chef/","size":181822,"stargazers_count":3785,"watchers_count":3785,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1551,"mirror_url":null,"open_issues_count":412,"forks":1551,"open_issues":412,"watchers":3785,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chef/chef/pulls/3818"},"html":{"href":"https://github.com/chef/chef/pull/3818"},"issue":{"href":"https://api.github.com/repos/chef/chef/issues/3818"},"comments":{"href":"https://api.github.com/repos/chef/chef/issues/3818/comments"},"review_comments":{"href":"https://api.github.com/repos/chef/chef/pulls/3818/comments"},"review_comment":{"href":"https://api.github.com/repos/chef/chef/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chef/chef/pulls/3818/commits"},"statuses":{"href":"https://api.github.com/repos/chef/chef/statuses/9f636381c1d32076257c564592ddbf082f9ad67a"}}}}