Search in sources :

Example 6 with RequestLogLine

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);
}
Also used : QueryStats(org.apache.druid.server.QueryStats) RequestLogLine(org.apache.druid.server.RequestLogLine) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with RequestLogLine

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();
}
Also used : RequestLogLine(org.apache.druid.server.RequestLogLine) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with RequestLogLine

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());
}
Also used : SQLException(java.sql.SQLException) RequestLogLine(org.apache.druid.server.RequestLogLine) Test(org.junit.Test)

Aggregations

RequestLogLine (org.apache.druid.server.RequestLogLine)8 Test (org.junit.Test)8 QueryStats (org.apache.druid.server.QueryStats)6 DateTime (org.joda.time.DateTime)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 TableDataSource (org.apache.druid.query.TableDataSource)2 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)2 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 SQLException (java.sql.SQLException)1 Query (org.apache.druid.query.Query)1