use of org.apache.druid.server.RequestLogLine in project druid by druid-io.
the class FilteredRequestLoggerTest method testNotFilterAboveThresholdSkipSegmentMetadata.
@Test
public void testNotFilterAboveThresholdSkipSegmentMetadata() throws IOException {
RequestLogger delegate = EasyMock.createStrictMock(RequestLogger.class);
delegate.logNativeQuery(EasyMock.anyObject());
EasyMock.expectLastCall().andThrow(new IOException());
delegate.logSqlQuery(EasyMock.anyObject());
EasyMock.expectLastCall().andThrow(new IOException());
FilteredRequestLoggerProvider.FilteredRequestLogger logger = new FilteredRequestLoggerProvider.FilteredRequestLogger(delegate, 1000, 2000, ImmutableList.of(Query.SEGMENT_METADATA));
RequestLogLine nativeRequestLogLine = EasyMock.createMock(RequestLogLine.class);
EasyMock.expect(nativeRequestLogLine.getQueryStats()).andReturn(new QueryStats(ImmutableMap.of("query/time", 10000))).once();
EasyMock.expect(nativeRequestLogLine.getQuery()).andReturn(testSegmentMetadataQuery).once();
RequestLogLine sqlRequestLogLine = EasyMock.createMock(RequestLogLine.class);
EasyMock.expect(sqlRequestLogLine.getQueryStats()).andReturn(new QueryStats(ImmutableMap.of("sqlQuery/time", 10000))).once();
EasyMock.expect(sqlRequestLogLine.getQuery()).andReturn(testSegmentMetadataQuery).once();
EasyMock.replay(nativeRequestLogLine, sqlRequestLogLine, delegate);
logger.logNativeQuery(nativeRequestLogLine);
logger.logSqlQuery(sqlRequestLogLine);
}
use of org.apache.druid.server.RequestLogLine in project druid by druid-io.
the class FileRequestLoggerTest method testLog.
@Test
public void testLog() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
DateTime dateTime = DateTimes.nowUtc();
File logDir = temporaryFolder.newFolder();
String nativeQueryLogString = dateTime + "\t" + HOST + "\t" + "native";
String sqlQueryLogString = dateTime + "\t" + HOST + "\t" + "sql";
FileRequestLogger fileRequestLogger = new FileRequestLogger(objectMapper, scheduler, logDir, "yyyy-MM-dd'.log'");
fileRequestLogger.start();
RequestLogLine nativeRequestLogLine = EasyMock.createMock(RequestLogLine.class);
EasyMock.expect(nativeRequestLogLine.getNativeQueryLine(EasyMock.anyObject())).andReturn(nativeQueryLogString).anyTimes();
RequestLogLine sqlRequestLogLine = EasyMock.createMock(RequestLogLine.class);
EasyMock.expect(sqlRequestLogLine.getSqlQueryLine(EasyMock.anyObject())).andReturn(sqlQueryLogString).anyTimes();
EasyMock.replay(nativeRequestLogLine, sqlRequestLogLine);
fileRequestLogger.logNativeQuery(nativeRequestLogLine);
fileRequestLogger.logSqlQuery(sqlRequestLogLine);
File logFile = new File(logDir, dateTime.toString("yyyy-MM-dd'.log'"));
String logString = CharStreams.toString(Files.newBufferedReader(logFile.toPath(), StandardCharsets.UTF_8));
Assert.assertTrue(logString.contains(nativeQueryLogString + "\n" + sqlQueryLogString + "\n"));
fileRequestLogger.stop();
}
use of org.apache.druid.server.RequestLogLine in project druid by druid-io.
the class DruidAvaticaHandlerTest method testSqlRequestLog.
@Test
@SuppressWarnings("unchecked")
public void testSqlRequestLog() throws Exception {
// valid sql
for (int i = 0; i < 3; i++) {
client.createStatement().executeQuery("SELECT COUNT(*) AS cnt FROM druid.foo");
}
Assert.assertEquals(3, testRequestLogger.getSqlQueryLogs().size());
for (RequestLogLine logLine : testRequestLogger.getSqlQueryLogs()) {
final Map<String, Object> stats = logLine.getQueryStats().getStats();
Assert.assertEquals(true, stats.get("success"));
Assert.assertEquals("regularUser", stats.get("identity"));
Assert.assertTrue(stats.containsKey("sqlQuery/time"));
Assert.assertTrue(stats.containsKey("sqlQuery/bytes"));
}
// invalid sql
testRequestLogger.clear();
try {
client.createStatement().executeQuery("SELECT notexist FROM druid.foo");
Assert.fail("invalid SQL should throw SQLException");
} catch (SQLException e) {
}
Assert.assertEquals(1, testRequestLogger.getSqlQueryLogs().size());
final Map<String, Object> stats = testRequestLogger.getSqlQueryLogs().get(0).getQueryStats().getStats();
Assert.assertEquals(false, stats.get("success"));
Assert.assertEquals("regularUser", stats.get("identity"));
Assert.assertTrue(stats.containsKey("exception"));
// unauthorized sql
testRequestLogger.clear();
try {
client.createStatement().executeQuery("SELECT count(*) FROM druid.forbiddenDatasource");
Assert.fail("unauthorzed SQL should throw SQLException");
} catch (SQLException e) {
}
Assert.assertEquals(0, testRequestLogger.getSqlQueryLogs().size());
}
Aggregations