{"action":"created","comment":{"url":"https://api.github.com/repos/fluent/fluentd/pulls/comments/73822776","id":73822776,"diff_hunk":"@@ -30,22 +30,62 @@ class Filter < Base\n \n       helpers :event_emitter\n \n+      def initialize\n+        super\n+        @has_filter_with_time = has_filter_with_time?\n+      end\n+\n       def filter(tag, time, record)\n         raise NotImplementedError, \"BUG: filter plugins MUST implement this method\"\n       end\n \n+      def filter_with_time(tag, time, record)\n+        raise NotImplementedError, \"BUG: filter plugins MUST implement this method\"\n+      end\n+\n       def filter_stream(tag, es)\n         new_es = MultiEventStream.new\n-        es.each do |time, record|\n-          begin\n-            filtered_record = filter(tag, time, record)\n-            new_es.add(time, filtered_record) if filtered_record\n-          rescue => e\n-            router.emit_error_event(tag, time, record, e)\n+        if @has_filter_with_time\n+          es.each do |time, record|\n+            begin\n+              filtered_time, filtered_record = filter_with_time(tag, time, record)\n+              new_es.add(filtered_time, filtered_record) if filtered_time && filtered_record\n+            rescue => e\n+              router.emit_error_event(tag, time, record, e)\n+            end\n+          end\n+        else\n+          es.each do |time, record|\n+            begin\n+              filtered_record = filter(tag, time, record)\n+              new_es.add(time, filtered_record) if filtered_record\n+            rescue => e\n+              router.emit_error_event(tag, time, record, e)\n+            end\n           end\n         end\n         new_es\n       end\n+\n+      private\n+\n+      def has_filter_with_time?\n+        implmented_methods = self.class.instance_methods(false)\n+        # Plugins that override `filter_stream` don't need check,\n+        # because they may not call `filter` or `filter_with_time`\n+        # for example fluentd/lib/fluent/plugin/filter_record_transformer.rb\n+        return if implmented_methods.include?(:filter_stream)","path":"lib/fluent/plugin/filter.rb","position":54,"original_position":54,"commit_id":"3db34c4a4a6d1bf30cd340f7912005b67a816131","original_commit_id":"3db34c4a4a6d1bf30cd340f7912005b67a816131","user":{"login":"tagomoris","id":230654,"avatar_url":"https://avatars.githubusercontent.com/u/230654?v=3","gravatar_id":"","url":"https://api.github.com/users/tagomoris","html_url":"https://github.com/tagomoris","followers_url":"https://api.github.com/users/tagomoris/followers","following_url":"https://api.github.com/users/tagomoris/following{/other_user}","gists_url":"https://api.github.com/users/tagomoris/gists{/gist_id}","starred_url":"https://api.github.com/users/tagomoris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tagomoris/subscriptions","organizations_url":"https://api.github.com/users/tagomoris/orgs","repos_url":"https://api.github.com/users/tagomoris/repos","events_url":"https://api.github.com/users/tagomoris/events{/privacy}","received_events_url":"https://api.github.com/users/tagomoris/received_events","type":"User","site_admin":false},"body":"Returning without any value looks not good manner for this method... What is set into `@has_filter_with_time?`?\r\nIt's better to return `nil` or something else explicitly.\r\nCode comment looks very good.","created_at":"2016-08-08T05:06:56Z","updated_at":"2016-08-08T05:06:56Z","html_url":"https://github.com/fluent/fluentd/pull/1140#discussion_r73822776","pull_request_url":"https://api.github.com/repos/fluent/fluentd/pulls/1140","_links":{"self":{"href":"https://api.github.com/repos/fluent/fluentd/pulls/comments/73822776"},"html":{"href":"https://github.com/fluent/fluentd/pull/1140#discussion_r73822776"},"pull_request":{"href":"https://api.github.com/repos/fluent/fluentd/pulls/1140"}}},"pull_request":{"url":"https://api.github.com/repos/fluent/fluentd/pulls/1140","id":80027780,"html_url":"https://github.com/fluent/fluentd/pull/1140","diff_url":"https://github.com/fluent/fluentd/pull/1140.diff","patch_url":"https://github.com/fluent/fluentd/pull/1140.patch","issue_url":"https://api.github.com/repos/fluent/fluentd/issues/1140","number":1140,"state":"open","locked":false,"title":"Add `filter_with_time` to `Fluent::Plugin::Filter`","user":{"login":"ganmacs","id":5616899,"avatar_url":"https://avatars.githubusercontent.com/u/5616899?v=3","gravatar_id":"","url":"https://api.github.com/users/ganmacs","html_url":"https://github.com/ganmacs","followers_url":"https://api.github.com/users/ganmacs/followers","following_url":"https://api.github.com/users/ganmacs/following{/other_user}","gists_url":"https://api.github.com/users/ganmacs/gists{/gist_id}","starred_url":"https://api.github.com/users/ganmacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ganmacs/subscriptions","organizations_url":"https://api.github.com/users/ganmacs/orgs","repos_url":"https://api.github.com/users/ganmacs/repos","events_url":"https://api.github.com/users/ganmacs/events{/privacy}","received_events_url":"https://api.github.com/users/ganmacs/received_events","type":"User","site_admin":false},"body":"This is for plugins that updates times when filtering.\r\n\r\nref: https://github.com/fluent/fluentd/issues/1139","created_at":"2016-08-04T07:02:35Z","updated_at":"2016-08-08T05:06:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0f8bb9896a775cc39e0229d7813b97641329fda","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/fluent/fluentd/pulls/1140/commits","review_comments_url":"https://api.github.com/repos/fluent/fluentd/pulls/1140/comments","review_comment_url":"https://api.github.com/repos/fluent/fluentd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fluent/fluentd/issues/1140/comments","statuses_url":"https://api.github.com/repos/fluent/fluentd/statuses/3db34c4a4a6d1bf30cd340f7912005b67a816131","head":{"label":"ganmacs:add-new-method-to-filter","ref":"add-new-method-to-filter","sha":"3db34c4a4a6d1bf30cd340f7912005b67a816131","user":{"login":"ganmacs","id":5616899,"avatar_url":"https://avatars.githubusercontent.com/u/5616899?v=3","gravatar_id":"","url":"https://api.github.com/users/ganmacs","html_url":"https://github.com/ganmacs","followers_url":"https://api.github.com/users/ganmacs/followers","following_url":"https://api.github.com/users/ganmacs/following{/other_user}","gists_url":"https://api.github.com/users/ganmacs/gists{/gist_id}","starred_url":"https://api.github.com/users/ganmacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ganmacs/subscriptions","organizations_url":"https://api.github.com/users/ganmacs/orgs","repos_url":"https://api.github.com/users/ganmacs/repos","events_url":"https://api.github.com/users/ganmacs/events{/privacy}","received_events_url":"https://api.github.com/users/ganmacs/received_events","type":"User","site_admin":false},"repo":{"id":64659272,"name":"fluentd","full_name":"ganmacs/fluentd","owner":{"login":"ganmacs","id":5616899,"avatar_url":"https://avatars.githubusercontent.com/u/5616899?v=3","gravatar_id":"","url":"https://api.github.com/users/ganmacs","html_url":"https://github.com/ganmacs","followers_url":"https://api.github.com/users/ganmacs/followers","following_url":"https://api.github.com/users/ganmacs/following{/other_user}","gists_url":"https://api.github.com/users/ganmacs/gists{/gist_id}","starred_url":"https://api.github.com/users/ganmacs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ganmacs/subscriptions","organizations_url":"https://api.github.com/users/ganmacs/orgs","repos_url":"https://api.github.com/users/ganmacs/repos","events_url":"https://api.github.com/users/ganmacs/events{/privacy}","received_events_url":"https://api.github.com/users/ganmacs/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ganmacs/fluentd","description":"Fluentd data collector","fork":true,"url":"https://api.github.com/repos/ganmacs/fluentd","forks_url":"https://api.github.com/repos/ganmacs/fluentd/forks","keys_url":"https://api.github.com/repos/ganmacs/fluentd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ganmacs/fluentd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ganmacs/fluentd/teams","hooks_url":"https://api.github.com/repos/ganmacs/fluentd/hooks","issue_events_url":"https://api.github.com/repos/ganmacs/fluentd/issues/events{/number}","events_url":"https://api.github.com/repos/ganmacs/fluentd/events","assignees_url":"https://api.github.com/repos/ganmacs/fluentd/assignees{/user}","branches_url":"https://api.github.com/repos/ganmacs/fluentd/branches{/branch}","tags_url":"https://api.github.com/repos/ganmacs/fluentd/tags","blobs_url":"https://api.github.com/repos/ganmacs/fluentd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ganmacs/fluentd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ganmacs/fluentd/git/refs{/sha}","trees_url":"https://api.github.com/repos/ganmacs/fluentd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ganmacs/fluentd/statuses/{sha}","languages_url":"https://api.github.com/repos/ganmacs/fluentd/languages","stargazers_url":"https://api.github.com/repos/ganmacs/fluentd/stargazers","contributors_url":"https://api.github.com/repos/ganmacs/fluentd/contributors","subscribers_url":"https://api.github.com/repos/ganmacs/fluentd/subscribers","subscription_url":"https://api.github.com/repos/ganmacs/fluentd/subscription","commits_url":"https://api.github.com/repos/ganmacs/fluentd/commits{/sha}","git_commits_url":"https://api.github.com/repos/ganmacs/fluentd/git/commits{/sha}","comments_url":"https://api.github.com/repos/ganmacs/fluentd/comments{/number}","issue_comment_url":"https://api.github.com/repos/ganmacs/fluentd/issues/comments{/number}","contents_url":"https://api.github.com/repos/ganmacs/fluentd/contents/{+path}","compare_url":"https://api.github.com/repos/ganmacs/fluentd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ganmacs/fluentd/merges","archive_url":"https://api.github.com/repos/ganmacs/fluentd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ganmacs/fluentd/downloads","issues_url":"https://api.github.com/repos/ganmacs/fluentd/issues{/number}","pulls_url":"https://api.github.com/repos/ganmacs/fluentd/pulls{/number}","milestones_url":"https://api.github.com/repos/ganmacs/fluentd/milestones{/number}","notifications_url":"https://api.github.com/repos/ganmacs/fluentd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ganmacs/fluentd/labels{/name}","releases_url":"https://api.github.com/repos/ganmacs/fluentd/releases{/id}","deployments_url":"https://api.github.com/repos/ganmacs/fluentd/deployments","created_at":"2016-08-01T10:46:27Z","updated_at":"2016-08-01T10:46:30Z","pushed_at":"2016-08-08T02:15:22Z","git_url":"git://github.com/ganmacs/fluentd.git","ssh_url":"git@github.com:ganmacs/fluentd.git","clone_url":"https://github.com/ganmacs/fluentd.git","svn_url":"https://github.com/ganmacs/fluentd","homepage":"http://www.fluentd.org/","size":13741,"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":"fluent:master","ref":"master","sha":"c8f5b7a6dd678a6dd84d2c2d0c9888c57f8b4ff5","user":{"login":"fluent","id":859518,"avatar_url":"https://avatars.githubusercontent.com/u/859518?v=3","gravatar_id":"","url":"https://api.github.com/users/fluent","html_url":"https://github.com/fluent","followers_url":"https://api.github.com/users/fluent/followers","following_url":"https://api.github.com/users/fluent/following{/other_user}","gists_url":"https://api.github.com/users/fluent/gists{/gist_id}","starred_url":"https://api.github.com/users/fluent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fluent/subscriptions","organizations_url":"https://api.github.com/users/fluent/orgs","repos_url":"https://api.github.com/users/fluent/repos","events_url":"https://api.github.com/users/fluent/events{/privacy}","received_events_url":"https://api.github.com/users/fluent/received_events","type":"Organization","site_admin":false},"repo":{"id":1918677,"name":"fluentd","full_name":"fluent/fluentd","owner":{"login":"fluent","id":859518,"avatar_url":"https://avatars.githubusercontent.com/u/859518?v=3","gravatar_id":"","url":"https://api.github.com/users/fluent","html_url":"https://github.com/fluent","followers_url":"https://api.github.com/users/fluent/followers","following_url":"https://api.github.com/users/fluent/following{/other_user}","gists_url":"https://api.github.com/users/fluent/gists{/gist_id}","starred_url":"https://api.github.com/users/fluent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fluent/subscriptions","organizations_url":"https://api.github.com/users/fluent/orgs","repos_url":"https://api.github.com/users/fluent/repos","events_url":"https://api.github.com/users/fluent/events{/privacy}","received_events_url":"https://api.github.com/users/fluent/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fluent/fluentd","description":"Fluentd data collector","fork":false,"url":"https://api.github.com/repos/fluent/fluentd","forks_url":"https://api.github.com/repos/fluent/fluentd/forks","keys_url":"https://api.github.com/repos/fluent/fluentd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fluent/fluentd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fluent/fluentd/teams","hooks_url":"https://api.github.com/repos/fluent/fluentd/hooks","issue_events_url":"https://api.github.com/repos/fluent/fluentd/issues/events{/number}","events_url":"https://api.github.com/repos/fluent/fluentd/events","assignees_url":"https://api.github.com/repos/fluent/fluentd/assignees{/user}","branches_url":"https://api.github.com/repos/fluent/fluentd/branches{/branch}","tags_url":"https://api.github.com/repos/fluent/fluentd/tags","blobs_url":"https://api.github.com/repos/fluent/fluentd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fluent/fluentd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fluent/fluentd/git/refs{/sha}","trees_url":"https://api.github.com/repos/fluent/fluentd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fluent/fluentd/statuses/{sha}","languages_url":"https://api.github.com/repos/fluent/fluentd/languages","stargazers_url":"https://api.github.com/repos/fluent/fluentd/stargazers","contributors_url":"https://api.github.com/repos/fluent/fluentd/contributors","subscribers_url":"https://api.github.com/repos/fluent/fluentd/subscribers","subscription_url":"https://api.github.com/repos/fluent/fluentd/subscription","commits_url":"https://api.github.com/repos/fluent/fluentd/commits{/sha}","git_commits_url":"https://api.github.com/repos/fluent/fluentd/git/commits{/sha}","comments_url":"https://api.github.com/repos/fluent/fluentd/comments{/number}","issue_comment_url":"https://api.github.com/repos/fluent/fluentd/issues/comments{/number}","contents_url":"https://api.github.com/repos/fluent/fluentd/contents/{+path}","compare_url":"https://api.github.com/repos/fluent/fluentd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fluent/fluentd/merges","archive_url":"https://api.github.com/repos/fluent/fluentd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fluent/fluentd/downloads","issues_url":"https://api.github.com/repos/fluent/fluentd/issues{/number}","pulls_url":"https://api.github.com/repos/fluent/fluentd/pulls{/number}","milestones_url":"https://api.github.com/repos/fluent/fluentd/milestones{/number}","notifications_url":"https://api.github.com/repos/fluent/fluentd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fluent/fluentd/labels{/name}","releases_url":"https://api.github.com/repos/fluent/fluentd/releases{/id}","deployments_url":"https://api.github.com/repos/fluent/fluentd/deployments","created_at":"2011-06-19T08:41:40Z","updated_at":"2016-08-08T03:25:14Z","pushed_at":"2016-08-08T02:15:24Z","git_url":"git://github.com/fluent/fluentd.git","ssh_url":"git@github.com:fluent/fluentd.git","clone_url":"https://github.com/fluent/fluentd.git","svn_url":"https://github.com/fluent/fluentd","homepage":"http://www.fluentd.org/","size":18519,"stargazers_count":4379,"watchers_count":4379,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":519,"mirror_url":null,"open_issues_count":62,"forks":519,"open_issues":62,"watchers":4379,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fluent/fluentd/pulls/1140"},"html":{"href":"https://github.com/fluent/fluentd/pull/1140"},"issue":{"href":"https://api.github.com/repos/fluent/fluentd/issues/1140"},"comments":{"href":"https://api.github.com/repos/fluent/fluentd/issues/1140/comments"},"review_comments":{"href":"https://api.github.com/repos/fluent/fluentd/pulls/1140/comments"},"review_comment":{"href":"https://api.github.com/repos/fluent/fluentd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fluent/fluentd/pulls/1140/commits"},"statuses":{"href":"https://api.github.com/repos/fluent/fluentd/statuses/3db34c4a4a6d1bf30cd340f7912005b67a816131"}}}}
{"actor":{"display_login":"tagomoris"}}