Search in sources :

Example 6 with CachingEmitter

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);
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) CachingEmitter(org.apache.druid.query.CachingEmitter) DefaultQueryMetricsTest(org.apache.druid.query.DefaultQueryMetricsTest) Test(org.junit.Test)

Example 7 with CachingEmitter

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);
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) CachingEmitter(org.apache.druid.query.CachingEmitter) DefaultQueryMetricsTest(org.apache.druid.query.DefaultQueryMetricsTest) Test(org.junit.Test)

Example 8 with CachingEmitter

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"));
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ListFilteredDimensionSpec(org.apache.druid.query.dimension.ListFilteredDimensionSpec) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) CachingEmitter(org.apache.druid.query.CachingEmitter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Interval(org.joda.time.Interval) DefaultQueryMetricsTest(org.apache.druid.query.DefaultQueryMetricsTest) Test(org.junit.Test)

Aggregations

ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)8 CachingEmitter (org.apache.druid.query.CachingEmitter)8 DefaultQueryMetricsTest (org.apache.druid.query.DefaultQueryMetricsTest)8 Test (org.junit.Test)8 Interval (org.joda.time.Interval)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)2 ListFilteredDimensionSpec (org.apache.druid.query.dimension.ListFilteredDimensionSpec)2 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)2 PeriodGranularity (org.apache.druid.java.util.common.granularity.PeriodGranularity)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)1 MapLookupExtractor (org.apache.druid.query.extraction.MapLookupExtractor)1 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)1 Period (org.joda.time.Period)1