Merge pull request #103 from metamx/request-logs

make request logs machine-readable
This commit is contained in:
cheddar 2013-03-07 13:35:48 -08:00
commit a1cd3c3905
4 changed files with 14 additions and 7 deletions

View File

@ -248,7 +248,7 @@ public abstract class QueryableNode<T extends 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);

View File

@ -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();
}

View File

@ -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;
@ -40,14 +42,14 @@ public class RequestLogLine
this.query = query;
}
public String getLine()
public String getLine(ObjectMapper objectMapper) throws JsonProcessingException
{
return JOINER.join(
Arrays.asList(
timestamp,
remoteAddr,
query
objectMapper.writeValueAsString(query)
)
);
}
}
}

View File

@ -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"))
);