use of org.apache.druid.query.CachingEmitter in project druid by druid-io.
the class DefaultTimeseriesQueryMetricsTest method testDefaultTimeseriesQueryMetricsMetricNamesAndUnits.
@Test
public void testDefaultTimeseriesQueryMetricsMetricNamesAndUnits() {
CachingEmitter cachingEmitter = new CachingEmitter();
ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
DefaultTimeseriesQueryMetrics queryMetrics = new DefaultTimeseriesQueryMetrics();
DefaultQueryMetricsTest.testQueryMetricsDefaultMetricNamesAndUnits(cachingEmitter, serviceEmitter, queryMetrics);
}
use of org.apache.druid.query.CachingEmitter in project druid by druid-io.
the class DefaultSearchQueryMetricsTest method testDefaultSearchQueryMetricsMetricNamesAndUnits.
@Test
public void testDefaultSearchQueryMetricsMetricNamesAndUnits() {
SearchQuery query = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.DAY_GRAN).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).build();
CachingEmitter cachingEmitter = new CachingEmitter();
ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
SearchQueryMetrics queryMetrics = DefaultSearchQueryMetricsFactory.instance().makeMetrics(query);
DefaultQueryMetricsTest.testQueryMetricsDefaultMetricNamesAndUnits(cachingEmitter, serviceEmitter, queryMetrics);
}
use of org.apache.druid.query.CachingEmitter in project druid by druid-io.
the class DefaultTopNQueryMetricsTest method testDefaultTopNQueryMetricsQuery.
/**
* Tests that passed a query {@link DefaultTopNQueryMetrics} produces events with a certain set of dimensions,
* no more, no less.
*/
@Test
public void testDefaultTopNQueryMetricsQuery() {
CachingEmitter cachingEmitter = new CachingEmitter();
ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
DefaultTopNQueryMetrics queryMetrics = new DefaultTopNQueryMetrics();
TopNQuery query = new TopNQueryBuilder().dataSource("xx").granularity(Granularities.ALL).dimension(new ListFilteredDimensionSpec(new DefaultDimensionSpec("tags", "tags"), ImmutableSet.of("t3"), null)).metric("count").intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(new CountAggregatorFactory("count")).threshold(5).filters(new SelectorDimFilter("tags", "t3", null)).context(ImmutableMap.of("testKey", "testValue")).build();
queryMetrics.query(query);
queryMetrics.reportQueryTime(0).emit(serviceEmitter);
Map<String, Object> actualEvent = cachingEmitter.getLastEmittedEvent().toMap();
Assert.assertEquals(17, actualEvent.size());
Assert.assertTrue(actualEvent.containsKey("feed"));
Assert.assertTrue(actualEvent.containsKey("timestamp"));
Assert.assertEquals("", actualEvent.get("host"));
Assert.assertEquals("", actualEvent.get("service"));
Assert.assertEquals("xx", actualEvent.get(DruidMetrics.DATASOURCE));
Assert.assertEquals(query.getType(), actualEvent.get(DruidMetrics.TYPE));
List<Interval> expectedIntervals = QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC.getIntervals();
List<String> expectedStringIntervals = expectedIntervals.stream().map(Interval::toString).collect(Collectors.toList());
Assert.assertEquals(expectedStringIntervals, actualEvent.get(DruidMetrics.INTERVAL));
Assert.assertEquals("true", actualEvent.get("hasFilters"));
Assert.assertEquals(expectedIntervals.get(0).toDuration().toString(), actualEvent.get("duration"));
Assert.assertEquals("", actualEvent.get(DruidMetrics.ID));
Assert.assertEquals(ImmutableMap.of("testKey", "testValue"), actualEvent.get("context"));
// TopN-specific dimensions
Assert.assertEquals("5", actualEvent.get("threshold"));
Assert.assertEquals("tags", actualEvent.get("dimension"));
Assert.assertEquals("1", actualEvent.get("numMetrics"));
Assert.assertEquals("0", actualEvent.get("numComplexMetrics"));
// Metric
Assert.assertEquals("query/time", actualEvent.get("metric"));
Assert.assertEquals(0L, actualEvent.get("value"));
}
Aggregations