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());
}
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);
}
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"));
}
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"));
}
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"));
}
Aggregations