{"action":"created","comment":{"url":"https://api.github.com/repos/twitter-forks/presto/pulls/comments/57368122","id":57368122,"diff_hunk":"@@ -0,0 +1,94 @@\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+package com.facebook.presto.twitter.logging;\n+\n+import com.facebook.presto.event.query.QueryCompletionEvent;\n+import com.facebook.presto.spi.StandardErrorCode;\n+import io.airlift.event.client.AbstractEventClient;\n+import io.airlift.event.client.EventType;\n+import io.airlift.log.Logger;\n+import io.airlift.units.Duration;\n+\n+import java.io.IOException;\n+import java.util.concurrent.TimeUnit;\n+\n+/**\n+ * Class that listens for query completion events and logs them to a file\n+ */\n+public class QueryLogger extends AbstractEventClient\n+{\n+    private static final int MAX_QUERY_LENGTH = 1000;\n+    private static final String DASH = \"-\";\n+    private static final String COLON = \":\";\n+    private static final String SPACE = \" \";\n+    private static final String ELIPSIS = \"...\";\n+\n+    private static final Logger log = Logger.get(QueryLogger.class);\n+\n+    @Override\n+    protected <T> void postEvent(T event)\n+            throws IOException\n+    {\n+        EventType eventTypeAnnotation = event.getClass().getAnnotation(EventType.class);\n+        if (eventTypeAnnotation == null) {\n+            return;\n+        }\n+\n+        // other event types exist, like QueryCreatedEvent and SplitCompletionEvent\n+        if (eventTypeAnnotation.value().equals(\"QueryCompletion\")) {\n+            logQueryComplete((QueryCompletionEvent) event);\n+        }\n+    }\n+\n+    private static void logQueryComplete(QueryCompletionEvent event)\n+    {\n+        String errorType = DASH;\n+        String errorCode = DASH;\n+        if (event.getErrorCode() != null) {\n+            errorType = StandardErrorCode.toErrorType(event.getErrorCode()).toString();\n+            if (event.getErrorCodeName() != null) {\n+                errorCode = event.getErrorCodeName() + COLON + event.getErrorCode();\n+            }\n+        }\n+\n+        Duration duration = (new Duration(\n+                event.getEndTime().getMillis() -\n+                event.getCreateTime().getMillis(), TimeUnit.MILLISECONDS))\n+                .convertToMostSuccinctTimeUnit();\n+\n+        log.info(String.format(\"Query complete\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\\t%s\",","path":"presto-main/src/main/java/com/facebook/presto/twitter/logging/QueryLogger.java","position":70,"original_position":70,"commit_id":"251db4d7c15df61b8e86eb1bd3e21ad904ecac04","original_commit_id":"251db4d7c15df61b8e86eb1bd3e21ad904ecac04","user":{"login":"saileshmittal","id":423065,"avatar_url":"https://avatars.githubusercontent.com/u/423065?v=3","gravatar_id":"","url":"https://api.github.com/users/saileshmittal","html_url":"https://github.com/saileshmittal","followers_url":"https://api.github.com/users/saileshmittal/followers","following_url":"https://api.github.com/users/saileshmittal/following{/other_user}","gists_url":"https://api.github.com/users/saileshmittal/gists{/gist_id}","starred_url":"https://api.github.com/users/saileshmittal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saileshmittal/subscriptions","organizations_url":"https://api.github.com/users/saileshmittal/orgs","repos_url":"https://api.github.com/users/saileshmittal/repos","events_url":"https://api.github.com/users/saileshmittal/events{/privacy}","received_events_url":"https://api.github.com/users/saileshmittal/received_events","type":"User","site_admin":false},"body":"Probably should use the \"QueryCompletion\"? Just for consistency sake, because we are logging an event. In future, if we log more event, it will be easier to just reuse the const string.","created_at":"2016-03-24T18:47:05Z","updated_at":"2016-03-24T18:47:05Z","html_url":"https://github.com/twitter-forks/presto/pull/36#discussion_r57368122","pull_request_url":"https://api.github.com/repos/twitter-forks/presto/pulls/36","_links":{"self":{"href":"https://api.github.com/repos/twitter-forks/presto/pulls/comments/57368122"},"html":{"href":"https://github.com/twitter-forks/presto/pull/36#discussion_r57368122"},"pull_request":{"href":"https://api.github.com/repos/twitter-forks/presto/pulls/36"}}},"pull_request":{"url":"https://api.github.com/repos/twitter-forks/presto/pulls/36","id":64062074,"html_url":"https://github.com/twitter-forks/presto/pull/36","diff_url":"https://github.com/twitter-forks/presto/pull/36.diff","patch_url":"https://github.com/twitter-forks/presto/pull/36.patch","issue_url":"https://api.github.com/repos/twitter-forks/presto/issues/36","number":36,"state":"open","locked":false,"title":"Use modules and query events for logging","user":{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false},"body":"This minimizes our impact on the Presto OS codebase to 1 line in ```PrestoServer``` which is intended to be patched.","created_at":"2016-03-24T16:38:21Z","updated_at":"2016-03-24T18:47:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5693b3bcc97efbcb1c132c67c5032a9a83d4217e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/twitter-forks/presto/pulls/36/commits","review_comments_url":"https://api.github.com/repos/twitter-forks/presto/pulls/36/comments","review_comment_url":"https://api.github.com/repos/twitter-forks/presto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twitter-forks/presto/issues/36/comments","statuses_url":"https://api.github.com/repos/twitter-forks/presto/statuses/251db4d7c15df61b8e86eb1bd3e21ad904ecac04","head":{"label":"billonahill:billg/IQ-192_refactor_logging","ref":"billg/IQ-192_refactor_logging","sha":"251db4d7c15df61b8e86eb1bd3e21ad904ecac04","user":{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false},"repo":{"id":44402011,"name":"presto","full_name":"billonahill/presto","owner":{"login":"billonahill","id":23758,"avatar_url":"https://avatars.githubusercontent.com/u/23758?v=3","gravatar_id":"","url":"https://api.github.com/users/billonahill","html_url":"https://github.com/billonahill","followers_url":"https://api.github.com/users/billonahill/followers","following_url":"https://api.github.com/users/billonahill/following{/other_user}","gists_url":"https://api.github.com/users/billonahill/gists{/gist_id}","starred_url":"https://api.github.com/users/billonahill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billonahill/subscriptions","organizations_url":"https://api.github.com/users/billonahill/orgs","repos_url":"https://api.github.com/users/billonahill/repos","events_url":"https://api.github.com/users/billonahill/events{/privacy}","received_events_url":"https://api.github.com/users/billonahill/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/billonahill/presto","description":"Distributed SQL query engine for running interactive analytic queries against big data sources.","fork":true,"url":"https://api.github.com/repos/billonahill/presto","forks_url":"https://api.github.com/repos/billonahill/presto/forks","keys_url":"https://api.github.com/repos/billonahill/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/billonahill/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/billonahill/presto/teams","hooks_url":"https://api.github.com/repos/billonahill/presto/hooks","issue_events_url":"https://api.github.com/repos/billonahill/presto/issues/events{/number}","events_url":"https://api.github.com/repos/billonahill/presto/events","assignees_url":"https://api.github.com/repos/billonahill/presto/assignees{/user}","branches_url":"https://api.github.com/repos/billonahill/presto/branches{/branch}","tags_url":"https://api.github.com/repos/billonahill/presto/tags","blobs_url":"https://api.github.com/repos/billonahill/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/billonahill/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/billonahill/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/billonahill/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/billonahill/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/billonahill/presto/languages","stargazers_url":"https://api.github.com/repos/billonahill/presto/stargazers","contributors_url":"https://api.github.com/repos/billonahill/presto/contributors","subscribers_url":"https://api.github.com/repos/billonahill/presto/subscribers","subscription_url":"https://api.github.com/repos/billonahill/presto/subscription","commits_url":"https://api.github.com/repos/billonahill/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/billonahill/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/billonahill/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/billonahill/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/billonahill/presto/contents/{+path}","compare_url":"https://api.github.com/repos/billonahill/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/billonahill/presto/merges","archive_url":"https://api.github.com/repos/billonahill/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/billonahill/presto/downloads","issues_url":"https://api.github.com/repos/billonahill/presto/issues{/number}","pulls_url":"https://api.github.com/repos/billonahill/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/billonahill/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/billonahill/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/billonahill/presto/labels{/name}","releases_url":"https://api.github.com/repos/billonahill/presto/releases{/id}","deployments_url":"https://api.github.com/repos/billonahill/presto/deployments","created_at":"2015-10-16T17:58:24Z","updated_at":"2016-03-18T00:24:52Z","pushed_at":"2016-03-24T18:01:05Z","git_url":"git://github.com/billonahill/presto.git","ssh_url":"git@github.com:billonahill/presto.git","clone_url":"https://github.com/billonahill/presto.git","svn_url":"https://github.com/billonahill/presto","homepage":"https://prestodb.io","size":59028,"stargazers_count":0,"watchers_count":0,"language":"Java","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":"twitter-forks:twitter-master","ref":"twitter-master","sha":"dc6bebec841ad12b8d6a1163b2add633a7ea8252","user":{"login":"twitter-forks","id":5349157,"avatar_url":"https://avatars.githubusercontent.com/u/5349157?v=3","gravatar_id":"","url":"https://api.github.com/users/twitter-forks","html_url":"https://github.com/twitter-forks","followers_url":"https://api.github.com/users/twitter-forks/followers","following_url":"https://api.github.com/users/twitter-forks/following{/other_user}","gists_url":"https://api.github.com/users/twitter-forks/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter-forks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter-forks/subscriptions","organizations_url":"https://api.github.com/users/twitter-forks/orgs","repos_url":"https://api.github.com/users/twitter-forks/repos","events_url":"https://api.github.com/users/twitter-forks/events{/privacy}","received_events_url":"https://api.github.com/users/twitter-forks/received_events","type":"Organization","site_admin":false},"repo":{"id":41683679,"name":"presto","full_name":"twitter-forks/presto","owner":{"login":"twitter-forks","id":5349157,"avatar_url":"https://avatars.githubusercontent.com/u/5349157?v=3","gravatar_id":"","url":"https://api.github.com/users/twitter-forks","html_url":"https://github.com/twitter-forks","followers_url":"https://api.github.com/users/twitter-forks/followers","following_url":"https://api.github.com/users/twitter-forks/following{/other_user}","gists_url":"https://api.github.com/users/twitter-forks/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter-forks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter-forks/subscriptions","organizations_url":"https://api.github.com/users/twitter-forks/orgs","repos_url":"https://api.github.com/users/twitter-forks/repos","events_url":"https://api.github.com/users/twitter-forks/events{/privacy}","received_events_url":"https://api.github.com/users/twitter-forks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twitter-forks/presto","description":"Distributed SQL query engine for running interactive analytic queries against big data sources.","fork":true,"url":"https://api.github.com/repos/twitter-forks/presto","forks_url":"https://api.github.com/repos/twitter-forks/presto/forks","keys_url":"https://api.github.com/repos/twitter-forks/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twitter-forks/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twitter-forks/presto/teams","hooks_url":"https://api.github.com/repos/twitter-forks/presto/hooks","issue_events_url":"https://api.github.com/repos/twitter-forks/presto/issues/events{/number}","events_url":"https://api.github.com/repos/twitter-forks/presto/events","assignees_url":"https://api.github.com/repos/twitter-forks/presto/assignees{/user}","branches_url":"https://api.github.com/repos/twitter-forks/presto/branches{/branch}","tags_url":"https://api.github.com/repos/twitter-forks/presto/tags","blobs_url":"https://api.github.com/repos/twitter-forks/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twitter-forks/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twitter-forks/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/twitter-forks/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twitter-forks/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/twitter-forks/presto/languages","stargazers_url":"https://api.github.com/repos/twitter-forks/presto/stargazers","contributors_url":"https://api.github.com/repos/twitter-forks/presto/contributors","subscribers_url":"https://api.github.com/repos/twitter-forks/presto/subscribers","subscription_url":"https://api.github.com/repos/twitter-forks/presto/subscription","commits_url":"https://api.github.com/repos/twitter-forks/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/twitter-forks/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/twitter-forks/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/twitter-forks/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/twitter-forks/presto/contents/{+path}","compare_url":"https://api.github.com/repos/twitter-forks/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twitter-forks/presto/merges","archive_url":"https://api.github.com/repos/twitter-forks/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twitter-forks/presto/downloads","issues_url":"https://api.github.com/repos/twitter-forks/presto/issues{/number}","pulls_url":"https://api.github.com/repos/twitter-forks/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/twitter-forks/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/twitter-forks/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twitter-forks/presto/labels{/name}","releases_url":"https://api.github.com/repos/twitter-forks/presto/releases{/id}","deployments_url":"https://api.github.com/repos/twitter-forks/presto/deployments","created_at":"2015-08-31T15:28:01Z","updated_at":"2016-01-14T20:50:34Z","pushed_at":"2016-03-24T18:01:06Z","git_url":"git://github.com/twitter-forks/presto.git","ssh_url":"git@github.com:twitter-forks/presto.git","clone_url":"https://github.com/twitter-forks/presto.git","svn_url":"https://github.com/twitter-forks/presto","homepage":"https://prestodb.io","size":56682,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twitter-forks/presto/pulls/36"},"html":{"href":"https://github.com/twitter-forks/presto/pull/36"},"issue":{"href":"https://api.github.com/repos/twitter-forks/presto/issues/36"},"comments":{"href":"https://api.github.com/repos/twitter-forks/presto/issues/36/comments"},"review_comments":{"href":"https://api.github.com/repos/twitter-forks/presto/pulls/36/comments"},"review_comment":{"href":"https://api.github.com/repos/twitter-forks/presto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twitter-forks/presto/pulls/36/commits"},"statuses":{"href":"https://api.github.com/repos/twitter-forks/presto/statuses/251db4d7c15df61b8e86eb1bd3e21ad904ecac04"}}}}