Search in sources :

Example 1 with RequestLogLine

use of org.apache.druid.server.RequestLogLine in project druid by druid-io.

the class DefaultRequestLogEventTest method testDefaultRequestLogEventSerde.

@Test
public void testDefaultRequestLogEventSerde() throws Exception {
    RequestLogLine nativeLine = RequestLogLine.forNative(new TimeseriesQuery(new TableDataSource("dummy"), new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2015-01-01/2015-01-02"))), true, VirtualColumns.EMPTY, null, Granularities.ALL, ImmutableList.of(), ImmutableList.of(), 5, ImmutableMap.of("key", "value")), DateTimes.of(2019, 12, 12, 3, 1), "127.0.0.1", new QueryStats(ImmutableMap.of("query/time", 13L, "query/bytes", 10L, "success", true, "identity", "allowAll")));
    DefaultRequestLogEvent defaultRequestLogEvent = new DefaultRequestLogEvent(ImmutableMap.of("service", "druid-service", "host", "127.0.0.1"), "feed", nativeLine);
    String logEventJson = objectMapper.writeValueAsString(defaultRequestLogEvent);
    String expected = "{\"feed\":\"feed\",\"query\":{\"queryType\":\"timeseries\",\"dataSource\":{\"type\":\"table\",\"name\":\"dummy\"},\"intervals\":{\"type\":\"intervals\",\"intervals\":[\"2015-01-01T00:00:00.000Z/2015-01-02T00:00:00.000Z\"]},\"descending\":true,\"virtualColumns\":[],\"filter\":null,\"granularity\":{\"type\":\"all\"},\"aggregations\":[],\"postAggregations\":[],\"limit\":5,\"context\":{\"key\":\"value\"}},\"host\":\"127.0.0.1\",\"timestamp\":\"2019-12-12T03:01:00.000Z\",\"service\":\"druid-service\",\"sql\":null,\"sqlQueryContext\":{},\"remoteAddr\":\"127.0.0.1\",\"queryStats\":{\"query/time\":13,\"query/bytes\":10,\"success\":true,\"identity\":\"allowAll\"}}";
    Assert.assertEquals(objectMapper.readTree(expected), objectMapper.readTree(logEventJson));
}
Also used : TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) TableDataSource(org.apache.druid.query.TableDataSource) QueryStats(org.apache.druid.server.QueryStats) RequestLogLine(org.apache.druid.server.RequestLogLine) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) Test(org.junit.Test)

Example 2 with RequestLogLine

use of org.apache.druid.server.RequestLogLine in project druid by druid-io.

the class FilteredRequestLoggerTest method testNotFilterAboveThreshold.

@Test
public void testNotFilterAboveThreshold() throws IOException {
    RequestLogger delegate = EasyMock.createStrictMock(RequestLogger.class);
    delegate.logNativeQuery(EasyMock.anyObject());
    EasyMock.expectLastCall().times(2);
    delegate.logSqlQuery(EasyMock.anyObject());
    EasyMock.expectLastCall().times(2);
    FilteredRequestLoggerProvider.FilteredRequestLogger logger = new FilteredRequestLoggerProvider.FilteredRequestLogger(delegate, 1000, 2000, ImmutableList.of());
    RequestLogLine nativeRequestLogLine = EasyMock.createMock(RequestLogLine.class);
    EasyMock.expect(nativeRequestLogLine.getQueryStats()).andReturn(new QueryStats(ImmutableMap.of("query/time", 10000))).once();
    EasyMock.expect(nativeRequestLogLine.getQueryStats()).andReturn(new QueryStats(ImmutableMap.of("query/time", 1000))).once();
    EasyMock.expect(nativeRequestLogLine.getQuery()).andReturn(testSegmentMetadataQuery).times(2);
    RequestLogLine sqlRequestLogLine = EasyMock.createMock(RequestLogLine.class);
    EasyMock.expect(sqlRequestLogLine.getQueryStats()).andReturn(new QueryStats(ImmutableMap.of("sqlQuery/time", 10000))).once();
    EasyMock.expect(sqlRequestLogLine.getQueryStats()).andReturn(new QueryStats(ImmutableMap.of("sqlQuery/time", 2000))).once();
    EasyMock.expect(sqlRequestLogLine.getQuery()).andReturn(testSegmentMetadataQuery).times(2);
    EasyMock.replay(nativeRequestLogLine, sqlRequestLogLine, delegate);
    logger.logNativeQuery(nativeRequestLogLine);
    logger.logNativeQuery(nativeRequestLogLine);
    logger.logSqlQuery(sqlRequestLogLine);
    logger.logSqlQuery(sqlRequestLogLine);
    EasyMock.verify(nativeRequestLogLine, sqlRequestLogLine, delegate);
}
Also used : QueryStats(org.apache.druid.server.QueryStats) RequestLogLine(org.apache.druid.server.RequestLogLine) Test(org.junit.Test)

Example 3 with RequestLogLine

use of org.apache.druid.server.RequestLogLine in project druid by druid-io.

the class FilteredRequestLoggerTest method testFilterBelowThreshold.

@Test
public void testFilterBelowThreshold() 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());
    RequestLogLine nativeRequestLogLine = EasyMock.createMock(RequestLogLine.class);
    EasyMock.expect(nativeRequestLogLine.getQueryStats()).andReturn(new QueryStats(ImmutableMap.of("query/time", 100))).once();
    RequestLogLine sqlRequestLogLine = EasyMock.createMock(RequestLogLine.class);
    EasyMock.expect(sqlRequestLogLine.getQueryStats()).andReturn(new QueryStats(ImmutableMap.of("sqlQuery/time", 1000)));
    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 4 with RequestLogLine

use of org.apache.druid.server.RequestLogLine in project druid by druid-io.

the class DefaultRequestLogEventTest method testDefaultRequestLogEventToMapSQL.

@Test
public void testDefaultRequestLogEventToMapSQL() {
    final String feed = "test";
    final DateTime timestamp = DateTimes.of(2019, 12, 12, 3, 1);
    final String service = "druid-service";
    final String host = "127.0.0.1";
    final String sql = "select * from 1337";
    final QueryStats queryStats = new QueryStats(ImmutableMap.of("sqlQuery/time", 13L, "sqlQuery/bytes", 10L, "success", true, "identity", "allowAll"));
    RequestLogLine nativeLine = RequestLogLine.forSql(sql, ImmutableMap.of(), timestamp, host, queryStats);
    DefaultRequestLogEvent defaultRequestLogEvent = new DefaultRequestLogEvent(ImmutableMap.of("service", service, "host", host), feed, nativeLine);
    final Map<String, Object> expected = new HashMap<>();
    expected.put("feed", feed);
    expected.put("timestamp", timestamp);
    expected.put("service", service);
    expected.put("host", host);
    expected.put("sql", sql);
    expected.put("sqlQueryContext", ImmutableMap.of());
    expected.put("remoteAddr", host);
    expected.put("queryStats", queryStats);
    Assert.assertEquals(expected, defaultRequestLogEvent.toMap());
}
Also used : QueryStats(org.apache.druid.server.QueryStats) HashMap(java.util.HashMap) RequestLogLine(org.apache.druid.server.RequestLogLine) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with RequestLogLine

use of org.apache.druid.server.RequestLogLine in project druid by druid-io.

the class DefaultRequestLogEventTest method testDefaultRequestLogEventToMap.

@Test
public void testDefaultRequestLogEventToMap() {
    final String feed = "test";
    final DateTime timestamp = DateTimes.of(2019, 12, 12, 3, 1);
    final String service = "druid-service";
    final String host = "127.0.0.1";
    final Query query = new TimeseriesQuery(new TableDataSource("dummy"), new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2015-01-01/2015-01-02"))), true, VirtualColumns.EMPTY, null, Granularities.ALL, ImmutableList.of(), ImmutableList.of(), 5, ImmutableMap.of("key", "value"));
    final QueryStats queryStats = new QueryStats(ImmutableMap.of("query/time", 13L, "query/bytes", 10L, "success", true, "identity", "allowAll"));
    RequestLogLine nativeLine = RequestLogLine.forNative(query, timestamp, host, queryStats);
    DefaultRequestLogEvent defaultRequestLogEvent = new DefaultRequestLogEvent(ImmutableMap.of("service", service, "host", host), feed, nativeLine);
    final Map<String, Object> expected = new HashMap<>();
    expected.put("feed", feed);
    expected.put("timestamp", timestamp);
    expected.put("service", service);
    expected.put("host", host);
    expected.put("query", query);
    expected.put("remoteAddr", host);
    expected.put("queryStats", queryStats);
    Assert.assertEquals(expected, defaultRequestLogEvent.toMap());
}
Also used : TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) Query(org.apache.druid.query.Query) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) TableDataSource(org.apache.druid.query.TableDataSource) QueryStats(org.apache.druid.server.QueryStats) HashMap(java.util.HashMap) RequestLogLine(org.apache.druid.server.RequestLogLine) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) DateTime(org.joda.time.DateTime) 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