processing/src/test/java/org/apache/druid/query/DefaultQueryMetricsTest.java
/**
   * Tests that passed a query {@link DefaultQueryMetrics} produces events with a certain set of dimensions, no more,
   * no less.
   */
Tests that passed a query  DefaultQueryMetrics produces events with a certain set of dimensions, no more,
no less.
Tests that passed a query DefaultQueryMetrics produces events with a certain set of dimensions no more no less .
@Test
  public void testDefaultQueryMetricsQuery()
  {
    CachingEmitter cachingEmitter = new CachingEmitter();
    ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
    DefaultQueryMetrics<Query<?>> queryMetrics = new DefaultQueryMetrics<>();
    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(13, 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("query/time", actualEvent.get("metric"));
    Assert.assertEquals(0L, actualEvent.get("value"));
    Assert.assertEquals(ImmutableMap.of("testKey", "testValue"), actualEvent.get("context"));
  }
@ Test public void testDefaultQueryMetricsQuery ( ) { CachingEmitter cachingEmitter = new CachingEmitter ( ) ; ServiceEmitter serviceEmitter = new ServiceEmitter ( "" , "" , cachingEmitter ) ; DefaultQueryMetrics < Query < ? > > queryMetrics = new DefaultQueryMetrics < > ( ) ; 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 ( 13 , 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 ( "query/time" , actualEvent . get ( "metric" ) ) ; Assert . assertEquals ( 0L , actualEvent . get ( "value" ) ) ; Assert . assertEquals ( ImmutableMap . of ( "testKey" , "testValue" ) , actualEvent . get ( "context" ) ) ; }
Tests that passed a query {@link DefaultQueryMetrics} produces events with a certain set of dimensions, no more,
 no less.
Tests that passed a query { @link DefaultQueryMetrics } produces events with a certain set of dimensions no more no less .