Search in sources :

Example 1 with ServiceEmitter

use of org.apache.druid.java.util.emitter.service.ServiceEmitter in project druid by druid-io.

the class KillAuditLog method run.

@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
    long currentTimeMillis = System.currentTimeMillis();
    if ((lastKillTime + period) < currentTimeMillis) {
        lastKillTime = currentTimeMillis;
        long timestamp = currentTimeMillis - retainDuration;
        try {
            int auditRemoved = auditManager.removeAuditLogsOlderThan(timestamp);
            ServiceEmitter emitter = params.getEmitter();
            emitter.emit(new ServiceMetricEvent.Builder().build("metadata/kill/audit/count", auditRemoved));
            log.info("Finished running KillAuditLog duty. Removed %,d audit logs", auditRemoved);
        } catch (Exception e) {
            log.error(e, "Failed to kill audit log");
        }
    }
    return params;
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter)

Example 2 with ServiceEmitter

use of org.apache.druid.java.util.emitter.service.ServiceEmitter in project druid by druid-io.

the class DefaultGroupByQueryMetricsTest method testDefaultGroupByQueryMetricsMetricNamesAndUnits.

@Test
public void testDefaultGroupByQueryMetricsMetricNamesAndUnits() {
    CachingEmitter cachingEmitter = new CachingEmitter();
    ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
    DefaultGroupByQueryMetrics queryMetrics = new DefaultGroupByQueryMetrics();
    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 3 with ServiceEmitter

use of org.apache.druid.java.util.emitter.service.ServiceEmitter in project druid by druid-io.

the class DefaultGroupByQueryMetricsTest method testDefaultGroupByQueryMetricsQuery.

/**
 * Tests that passed a query {@link DefaultGroupByQueryMetrics} produces events with a certain set of dimensions,
 * no more, no less.
 */
@Test
public void testDefaultGroupByQueryMetricsQuery() {
    CachingEmitter cachingEmitter = new CachingEmitter();
    ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
    DefaultGroupByQueryMetrics queryMetrics = new DefaultGroupByQueryMetrics();
    GroupByQuery.Builder builder = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setInterval("2011-04-02/2011-04-04").setDimensions(new ExtractionDimensionSpec("quality", "alias", new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("mezzanine", "mezzanine0"), false), false, null, true, false))).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(new PeriodGranularity(new Period("P1M"), null, null)).setDimFilter(new SelectorDimFilter("quality", "mezzanine", null)).setContext(ImmutableMap.of(QueryContexts.BY_SEGMENT_KEY, true));
    GroupByQuery query = builder.build();
    queryMetrics.query(query);
    queryMetrics.reportQueryTime(0).emit(serviceEmitter);
    Map<String, Object> actualEvent = cachingEmitter.getLastEmittedEvent().toMap();
    Assert.assertEquals(16, actualEvent.size());
    Assert.assertTrue(actualEvent.containsKey("feed"));
    Assert.assertTrue(actualEvent.containsKey("timestamp"));
    Assert.assertEquals("", actualEvent.get("host"));
    Assert.assertEquals("", actualEvent.get("service"));
    Assert.assertEquals(QueryRunnerTestHelper.DATA_SOURCE, actualEvent.get(DruidMetrics.DATASOURCE));
    Assert.assertEquals(query.getType(), actualEvent.get(DruidMetrics.TYPE));
    Interval expectedInterval = Intervals.of("2011-04-02/2011-04-04");
    Assert.assertEquals(Collections.singletonList(expectedInterval.toString()), actualEvent.get(DruidMetrics.INTERVAL));
    Assert.assertEquals("true", actualEvent.get("hasFilters"));
    Assert.assertEquals(expectedInterval.toDuration().toString(), actualEvent.get("duration"));
    Assert.assertEquals("", actualEvent.get(DruidMetrics.ID));
    Assert.assertEquals(ImmutableMap.of(QueryContexts.BY_SEGMENT_KEY, true), actualEvent.get("context"));
    // GroupBy-specific dimensions
    Assert.assertEquals("1", actualEvent.get("numDimensions"));
    Assert.assertEquals("2", 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) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) CachingEmitter(org.apache.druid.query.CachingEmitter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Interval(org.joda.time.Interval) DefaultQueryMetricsTest(org.apache.druid.query.DefaultQueryMetricsTest) Test(org.junit.Test)

Example 4 with ServiceEmitter

use of org.apache.druid.java.util.emitter.service.ServiceEmitter in project druid by druid-io.

the class DefaultTopNQueryMetricsTest method testDefaultTopNQueryMetricsMetricNamesAndUnits.

@Test
public void testDefaultTopNQueryMetricsMetricNamesAndUnits() {
    CachingEmitter cachingEmitter = new CachingEmitter();
    ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
    DefaultTopNQueryMetrics queryMetrics = new DefaultTopNQueryMetrics();
    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 5 with ServiceEmitter

use of org.apache.druid.java.util.emitter.service.ServiceEmitter in project druid by druid-io.

the class DefaultSearchQueryMetricsTest method testDefaultSearchQueryMetricsQuery.

/**
 * Tests that passed a query {@link DefaultSearchQueryMetrics} produces events with a certain set of dimensions.
 */
@Test
public void testDefaultSearchQueryMetricsQuery() {
    CachingEmitter cachingEmitter = new CachingEmitter();
    ServiceEmitter serviceEmitter = new ServiceEmitter("", "", cachingEmitter);
    SearchQuery query = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.DAY_GRAN).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).dimensions(new ListFilteredDimensionSpec(new DefaultDimensionSpec("tags", "tags"), ImmutableSet.of("t3"), null)).context(ImmutableMap.of("testKey", "testValue")).build();
    SearchQueryMetrics queryMetrics = DefaultSearchQueryMetricsFactory.instance().makeMetrics(query);
    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(QueryRunnerTestHelper.DATA_SOURCE, 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("false", 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"));
    // 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) ListFilteredDimensionSpec(org.apache.druid.query.dimension.ListFilteredDimensionSpec) CachingEmitter(org.apache.druid.query.CachingEmitter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) 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)45 Test (org.junit.Test)24 Before (org.junit.Before)9 Event (org.apache.druid.java.util.emitter.core.Event)8 CachingEmitter (org.apache.druid.query.CachingEmitter)8 DefaultQueryMetricsTest (org.apache.druid.query.DefaultQueryMetricsTest)8 ArrayList (java.util.ArrayList)7 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)7 Map (java.util.Map)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 List (java.util.List)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)5 DruidNode (org.apache.druid.server.DruidNode)5 DataSegment (org.apache.druid.timeline.DataSegment)5 Interval (org.joda.time.Interval)5 ImmutableSet (com.google.common.collect.ImmutableSet)4