Search in sources :

Example 1 with PerDatasourceShuffleMetrics

use of org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics in project druid by druid-io.

the class ShuffleMonitor method doMonitor.

@Override
public boolean doMonitor(ServiceEmitter emitter) {
    if (shuffleMetrics != null) {
        final Map<String, PerDatasourceShuffleMetrics> snapshot = shuffleMetrics.snapshotAndReset();
        snapshot.forEach((supervisorTaskId, perDatasourceShuffleMetrics) -> {
            final Builder metricBuilder = ServiceMetricEvent.builder().setDimension(SUPERVISOR_TASK_ID_DIMENSION, supervisorTaskId);
            emitter.emit(metricBuilder.build(SHUFFLE_BYTES_KEY, perDatasourceShuffleMetrics.getShuffleBytes()));
            emitter.emit(metricBuilder.build(SHUFFLE_REQUESTS_KEY, perDatasourceShuffleMetrics.getShuffleRequests()));
        });
    }
    return true;
}
Also used : Builder(org.apache.druid.java.util.emitter.service.ServiceMetricEvent.Builder) PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics)

Example 2 with PerDatasourceShuffleMetrics

use of org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics in project druid by druid-io.

the class ShuffleMetricsTest method testSnapshotUnmodifiable.

@Test
public void testSnapshotUnmodifiable() {
    expectedException.expect(UnsupportedOperationException.class);
    new ShuffleMetrics().snapshotAndReset().put("k", new PerDatasourceShuffleMetrics());
}
Also used : PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) Test(org.junit.Test)

Example 3 with PerDatasourceShuffleMetrics

use of org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics 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 4 with PerDatasourceShuffleMetrics

use of org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics in project druid by druid-io.

the class ShuffleResourceTest method testGetPartitionWithValidParamsReturnOk.

@Test
public void testGetPartitionWithValidParamsReturnOk() throws IOException {
    final String supervisorTaskId = "supervisorTask";
    final String subtaskId = "subtaskId";
    final Interval interval = Intervals.of("2020-01-01/P1D");
    final DataSegment segment = newSegment(interval);
    final File segmentDir = generateSegmentDir("test");
    intermediaryDataManager.addSegment(supervisorTaskId, subtaskId, segment, segmentDir);
    final Response response = shuffleResource.getPartition(supervisorTaskId, subtaskId, interval.getStart().toString(), interval.getEnd().toString(), segment.getId().getPartitionNum());
    final Map<String, PerDatasourceShuffleMetrics> snapshot = shuffleMetrics.snapshotAndReset();
    Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
    Assert.assertEquals(1, snapshot.get(supervisorTaskId).getShuffleRequests());
    Assert.assertEquals(254, snapshot.get(supervisorTaskId).getShuffleBytes());
}
Also used : Response(javax.ws.rs.core.Response) DataSegment(org.apache.druid.timeline.DataSegment) File(java.io.File) Interval(org.joda.time.Interval) PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) Test(org.junit.Test)

Example 5 with PerDatasourceShuffleMetrics

use of org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics in project druid by druid-io.

the class ShuffleMetricsTest method testShuffleRequested.

@Test
public void testShuffleRequested() {
    final ShuffleMetrics metrics = new ShuffleMetrics();
    final String supervisorTask1 = "supervisor1";
    final String supervisorTask2 = "supervisor2";
    final String supervisorTask3 = "supervisor3";
    metrics.shuffleRequested(supervisorTask1, 1024);
    metrics.shuffleRequested(supervisorTask2, 10);
    metrics.shuffleRequested(supervisorTask1, 512);
    metrics.shuffleRequested(supervisorTask3, 10000);
    metrics.shuffleRequested(supervisorTask2, 30);
    final Map<String, PerDatasourceShuffleMetrics> snapshot = metrics.snapshotAndReset();
    Assert.assertEquals(ImmutableSet.of(supervisorTask1, supervisorTask2, supervisorTask3), snapshot.keySet());
    PerDatasourceShuffleMetrics perDatasourceShuffleMetrics = snapshot.get(supervisorTask1);
    Assert.assertEquals(2, perDatasourceShuffleMetrics.getShuffleRequests());
    Assert.assertEquals(1536, perDatasourceShuffleMetrics.getShuffleBytes());
    perDatasourceShuffleMetrics = snapshot.get(supervisorTask2);
    Assert.assertEquals(2, perDatasourceShuffleMetrics.getShuffleRequests());
    Assert.assertEquals(40, perDatasourceShuffleMetrics.getShuffleBytes());
    perDatasourceShuffleMetrics = snapshot.get(supervisorTask3);
    Assert.assertEquals(1, perDatasourceShuffleMetrics.getShuffleRequests());
    Assert.assertEquals(10000, perDatasourceShuffleMetrics.getShuffleBytes());
}
Also used : PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) PerDatasourceShuffleMetrics(org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics) Test(org.junit.Test)

Aggregations

PerDatasourceShuffleMetrics (org.apache.druid.indexing.worker.shuffle.ShuffleMetrics.PerDatasourceShuffleMetrics)6 Test (org.junit.Test)5 File (java.io.File)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Response (javax.ws.rs.core.Response)1 Event (org.apache.druid.java.util.emitter.core.Event)1 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)1 Builder (org.apache.druid.java.util.emitter.service.ServiceMetricEvent.Builder)1 StubServiceEmitter (org.apache.druid.java.util.metrics.StubServiceEmitter)1 DataSegment (org.apache.druid.timeline.DataSegment)1 Interval (org.joda.time.Interval)1