From b0349a6518637bc163a1a723fb3ec5b597c22f6d Mon Sep 17 00:00:00 2001 From: xvrl Date: Thu, 7 Mar 2013 11:31:36 -0800 Subject: [PATCH] move objectMapper into requestLogger --- .../src/main/java/com/metamx/druid/QueryableNode.java | 2 +- .../java/com/metamx/druid/http/FileRequestLogger.java | 8 ++++++-- .../main/java/com/metamx/druid/http/QueryServlet.java | 2 +- .../java/com/metamx/druid/http/RequestLogLine.java | 10 ++++++---- .../metamx/druid/initialization/Initialization.java | 3 ++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/client/src/main/java/com/metamx/druid/QueryableNode.java b/client/src/main/java/com/metamx/druid/QueryableNode.java index 749b2bd8b40..a9a97ec64af 100644 --- a/client/src/main/java/com/metamx/druid/QueryableNode.java +++ b/client/src/main/java/com/metamx/druid/QueryableNode.java @@ -248,7 +248,7 @@ public abstract class QueryableNode extends Registering { if (requestLogger == null) { try { - setRequestLogger(Initialization.makeRequestLogger(getScheduledExecutorFactory(), getProps())); + setRequestLogger(Initialization.makeRequestLogger(getJsonMapper(), getScheduledExecutorFactory(), getProps())); } catch (IOException e) { throw Throwables.propagate(e); diff --git a/client/src/main/java/com/metamx/druid/http/FileRequestLogger.java b/client/src/main/java/com/metamx/druid/http/FileRequestLogger.java index 20425f9eb37..110e72f1c6f 100644 --- a/client/src/main/java/com/metamx/druid/http/FileRequestLogger.java +++ b/client/src/main/java/com/metamx/druid/http/FileRequestLogger.java @@ -19,6 +19,7 @@ package com.metamx.druid.http; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Throwables; import com.google.common.io.Closeables; import com.metamx.common.concurrent.ScheduledExecutors; @@ -38,6 +39,7 @@ import java.util.concurrent.ScheduledExecutorService; */ public class FileRequestLogger implements RequestLogger { + private final ObjectMapper objectMapper; private final ScheduledExecutorService exec; private final File baseDir; @@ -46,9 +48,11 @@ public class FileRequestLogger implements RequestLogger private volatile DateTime currentDay; private volatile FileWriter fileWriter; - public FileRequestLogger(ScheduledExecutorService exec, File baseDir) + + public FileRequestLogger(ObjectMapper objectMapper, ScheduledExecutorService exec, File baseDir) { this.exec = exec; + this.objectMapper = objectMapper; this.baseDir = baseDir; } @@ -110,7 +114,7 @@ public class FileRequestLogger implements RequestLogger { synchronized (lock) { fileWriter.write( - String.format("%s%n", requestLogLine.getLine()) + String.format("%s%n", requestLogLine.getLine(objectMapper)) ); fileWriter.flush(); } diff --git a/client/src/main/java/com/metamx/druid/http/QueryServlet.java b/client/src/main/java/com/metamx/druid/http/QueryServlet.java index 32ae1009dc6..bed59a8b525 100644 --- a/client/src/main/java/com/metamx/druid/http/QueryServlet.java +++ b/client/src/main/java/com/metamx/druid/http/QueryServlet.java @@ -93,7 +93,7 @@ public class QueryServlet extends HttpServlet query = objectMapper.readValue(requestQuery, Query.class); requestLogger.log( - new RequestLogLine(new DateTime(), req.getRemoteAddr(), jsonMapper.writer().writeValueAsString(query)) + new RequestLogLine(new DateTime(), req.getRemoteAddr(), query) ); Sequence results = query.run(texasRanger); diff --git a/client/src/main/java/com/metamx/druid/http/RequestLogLine.java b/client/src/main/java/com/metamx/druid/http/RequestLogLine.java index bf3b5b3294c..452bd65656e 100644 --- a/client/src/main/java/com/metamx/druid/http/RequestLogLine.java +++ b/client/src/main/java/com/metamx/druid/http/RequestLogLine.java @@ -19,6 +19,8 @@ package com.metamx.druid.http; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Joiner; import com.metamx.druid.Query; import org.joda.time.DateTime; @@ -31,22 +33,22 @@ public class RequestLogLine private final DateTime timestamp; private final String remoteAddr; - private final String query; + private final Query query; - public RequestLogLine(DateTime timestamp, String remoteAddr, String query) + public RequestLogLine(DateTime timestamp, String remoteAddr, Query query) { this.timestamp = timestamp; this.remoteAddr = remoteAddr; this.query = query; } - public String getLine() + public String getLine(ObjectMapper objectMapper) throws JsonProcessingException { return JOINER.join( Arrays.asList( timestamp, remoteAddr, - query + objectMapper.writeValueAsString(query) ) ); } diff --git a/client/src/main/java/com/metamx/druid/initialization/Initialization.java b/client/src/main/java/com/metamx/druid/initialization/Initialization.java index ba3b42d56e1..d173f5a95f7 100644 --- a/client/src/main/java/com/metamx/druid/initialization/Initialization.java +++ b/client/src/main/java/com/metamx/druid/initialization/Initialization.java @@ -348,9 +348,10 @@ public class Initialization return serviceProvider; } - public static RequestLogger makeRequestLogger(ScheduledExecutorFactory factory, Properties props) throws IOException + public static RequestLogger makeRequestLogger(ObjectMapper objectMapper, ScheduledExecutorFactory factory, Properties props) throws IOException { return new FileRequestLogger( + objectMapper, factory.create(1, "RequestLogger-%s"), new File(PropUtils.getProperty(props, "druid.request.logging.dir")) );