Search in sources :

Example 1 with StubServiceEmitter

use of org.apache.druid.java.util.metrics.StubServiceEmitter in project druid by druid-io.

the class ShuffleMonitorTest method testDoMonitor.

@Test
public void testDoMonitor() {
    final ShuffleMetrics shuffleMetrics = Mockito.mock(ShuffleMetrics.class);
    final PerDatasourceShuffleMetrics perDatasourceShuffleMetrics = new PerDatasourceShuffleMetrics();
    perDatasourceShuffleMetrics.accumulate(100);
    perDatasourceShuffleMetrics.accumulate(200);
    perDatasourceShuffleMetrics.accumulate(10);
    Mockito.when(shuffleMetrics.snapshotAndReset()).thenReturn(ImmutableMap.of("supervisor", perDatasourceShuffleMetrics));
    final StubServiceEmitter emitter = new StubServiceEmitter("service", "host");
    final ShuffleMonitor monitor = new ShuffleMonitor();
    monitor.setShuffleMetrics(shuffleMetrics);
    Assert.assertTrue(monitor.doMonitor(emitter));
    final List<Event> events = emitter.getEvents();
    Assert.assertEquals(2, events.size());
    Assert.assertSame(ServiceMetricEvent.class, events.get(0).getClass());
    ServiceMetricEvent event = (ServiceMetricEvent) events.get(0);
    Assert.assertEquals(ShuffleMonitor.SHUFFLE_BYTES_KEY, event.getMetric());
    Assert.assertEquals(310L, event.getValue());
    Assert.assertEquals(ImmutableMap.of(ShuffleMonitor.SUPERVISOR_TASK_ID_DIMENSION, "supervisor"), event.getUserDims());
    Assert.assertSame(ServiceMetricEvent.class, events.get(1).getClass());
    event = (ServiceMetricEvent) events.get(1);
    Assert.assertEquals(ShuffleMonitor.SHUFFLE_REQUESTS_KEY, event.getMetric());
    Assert.assertEquals(3, event.getValue());
    Assert.assertEquals(ImmutableMap.of(ShuffleMonitor.SUPERVISOR_TASK_ID_DIMENSION, "supervisor"), event.getUserDims());
}
Also used : StubServiceEmitter(org.apache.druid.java.util.metrics.StubServiceEmitter) PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Event(org.apache.druid.java.util.emitter.core.Event) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) Test(org.junit.Test)

Example 2 with StubServiceEmitter

use of org.apache.druid.java.util.metrics.StubServiceEmitter in project druid by druid-io.

the class CPUTimeMetricQueryRunnerTest method testCpuTimeMetric.

@Test
public void testCpuTimeMetric() {
    final StubServiceEmitter emitter = new StubServiceEmitter("s", "h");
    final AtomicLong accumulator = new AtomicLong();
    final List<Result<TimeseriesResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2000-01-01"), new TimeseriesResultValue(ImmutableMap.of("x", "y"))));
    final QueryRunner<Result<TimeseriesResultValue>> runner = CPUTimeMetricQueryRunner.safeBuild((queryPlus, responseContext) -> Sequences.simple(expectedResults), new TimeseriesQueryQueryToolChest(), emitter, accumulator, true);
    final Sequence<Result<TimeseriesResultValue>> results = runner.run(QueryPlus.wrap(Druids.newTimeseriesQueryBuilder().dataSource("foo").intervals("2000/2001").build()).withQueryMetrics(new TimeseriesQueryQueryToolChest()));
    Assert.assertEquals(expectedResults, results.toList());
    Assert.assertEquals(1, emitter.getEvents().size());
    final Event event = Iterables.getOnlyElement(emitter.getEvents());
    Assert.assertEquals("metrics", event.toMap().get("feed"));
    Assert.assertEquals("query/cpu/time", event.toMap().get("metric"));
    final Object value = event.toMap().get("value");
    Assert.assertThat(value, CoreMatchers.instanceOf(Long.class));
    Assert.assertTrue((long) value > 0);
}
Also used : StubServiceEmitter(org.apache.druid.java.util.metrics.StubServiceEmitter) TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Event(org.apache.druid.java.util.emitter.core.Event) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) Test(org.junit.Test)

Example 3 with StubServiceEmitter

use of org.apache.druid.java.util.metrics.StubServiceEmitter in project druid by druid-io.

the class TaskCountStatsMonitorTest method testMonitor.

@Test
public void testMonitor() {
    final TaskCountStatsMonitor monitor = new TaskCountStatsMonitor(statsProvider);
    final StubServiceEmitter emitter = new StubServiceEmitter("service", "host");
    monitor.doMonitor(emitter);
    Assert.assertEquals(5, emitter.getEvents().size());
    Assert.assertEquals("task/success/count", emitter.getEvents().get(0).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(0).toMap().get("value"));
    Assert.assertEquals("task/failed/count", emitter.getEvents().get(1).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(1).toMap().get("value"));
    Assert.assertEquals("task/running/count", emitter.getEvents().get(2).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(2).toMap().get("value"));
    Assert.assertEquals("task/pending/count", emitter.getEvents().get(3).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(3).toMap().get("value"));
    Assert.assertEquals("task/waiting/count", emitter.getEvents().get(4).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(4).toMap().get("value"));
}
Also used : StubServiceEmitter(org.apache.druid.java.util.metrics.StubServiceEmitter) Test(org.junit.Test)

Example 4 with StubServiceEmitter

use of org.apache.druid.java.util.metrics.StubServiceEmitter in project druid by druid-io.

the class QueryCountStatsMonitorTest method testMonitor.

@Test
public void testMonitor() {
    final QueryCountStatsMonitor monitor = new QueryCountStatsMonitor(queryCountStatsProvider);
    final StubServiceEmitter emitter = new StubServiceEmitter("service", "host");
    monitor.doMonitor(emitter);
    // Trigger metric emission
    monitor.doMonitor(emitter);
    Map<String, Long> resultMap = emitter.getEvents().stream().collect(Collectors.toMap(event -> (String) event.toMap().get("metric"), event -> (Long) event.toMap().get("value")));
    Assert.assertEquals(5, resultMap.size());
    Assert.assertEquals(1L, (long) resultMap.get("query/success/count"));
    Assert.assertEquals(2L, (long) resultMap.get("query/failed/count"));
    Assert.assertEquals(3L, (long) resultMap.get("query/interrupted/count"));
    Assert.assertEquals(4L, (long) resultMap.get("query/timeout/count"));
    Assert.assertEquals(10L, (long) resultMap.get("query/count"));
}
Also used : StubServiceEmitter(org.apache.druid.java.util.metrics.StubServiceEmitter) Map(java.util.Map) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) StubServiceEmitter(org.apache.druid.java.util.metrics.StubServiceEmitter) Before(org.junit.Before) Test(org.junit.Test)

Example 5 with StubServiceEmitter

use of org.apache.druid.java.util.metrics.StubServiceEmitter in project druid by druid-io.

the class TaskSlotCountStatsMonitorTest method testMonitor.

@Test
public void testMonitor() {
    final TaskSlotCountStatsMonitor monitor = new TaskSlotCountStatsMonitor(statsProvider);
    final StubServiceEmitter emitter = new StubServiceEmitter("service", "host");
    monitor.doMonitor(emitter);
    Assert.assertEquals(5, emitter.getEvents().size());
    Assert.assertEquals("taskSlot/total/count", emitter.getEvents().get(0).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(0).toMap().get("value"));
    Assert.assertEquals("taskSlot/idle/count", emitter.getEvents().get(1).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(1).toMap().get("value"));
    Assert.assertEquals("taskSlot/used/count", emitter.getEvents().get(2).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(2).toMap().get("value"));
    Assert.assertEquals("taskSlot/lazy/count", emitter.getEvents().get(3).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(3).toMap().get("value"));
    Assert.assertEquals("taskSlot/blacklisted/count", emitter.getEvents().get(4).toMap().get("metric"));
    Assert.assertEquals(1L, emitter.getEvents().get(4).toMap().get("value"));
}
Also used : StubServiceEmitter(org.apache.druid.java.util.metrics.StubServiceEmitter) Test(org.junit.Test)

Aggregations

StubServiceEmitter (org.apache.druid.java.util.metrics.StubServiceEmitter)5 Test (org.junit.Test)5 Event (org.apache.druid.java.util.emitter.core.Event)2 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 PerDatasourceShuffleMetrics (org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics)1 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)1 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)1 TimeseriesResultValue (org.apache.druid.query.timeseries.TimeseriesResultValue)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1