Search in sources :

Example 6 with QueryStats

use of org.apache.druid.server.QueryStats 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 7 with QueryStats

use of org.apache.druid.server.QueryStats 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)

Example 8 with QueryStats

use of org.apache.druid.server.QueryStats 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)

Aggregations

QueryStats (org.apache.druid.server.QueryStats)8 RequestLogLine (org.apache.druid.server.RequestLogLine)7 Test (org.junit.Test)7 TableDataSource (org.apache.druid.query.TableDataSource)3 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)3 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 DateTime (org.joda.time.DateTime)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Function (com.google.common.base.Function)1 Throwables (com.google.common.base.Throwables)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 MapBasedRow (org.apache.druid.data.input.MapBasedRow)1