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