Search in sources :

Example 1 with SplitCompletedEvent

use of com.facebook.presto.spi.eventlistener.SplitCompletedEvent in project presto by prestodb.

the class QueryMonitor method splitCompletedEvent.

private void splitCompletedEvent(TaskId taskId, DriverStats driverStats, @Nullable String failureType, @Nullable String failureMessage) {
    Optional<Duration> timeToStart = Optional.empty();
    if (driverStats.getStartTime() != null) {
        timeToStart = Optional.of(ofMillis(driverStats.getStartTime().getMillis() - driverStats.getCreateTime().getMillis()));
    }
    Optional<Duration> timeToEnd = Optional.empty();
    if (driverStats.getEndTime() != null) {
        timeToEnd = Optional.of(ofMillis(driverStats.getEndTime().getMillis() - driverStats.getCreateTime().getMillis()));
    }
    Optional<SplitFailureInfo> splitFailureMetadata = Optional.empty();
    if (failureType != null) {
        splitFailureMetadata = Optional.of(new SplitFailureInfo(failureType, failureMessage != null ? failureMessage : ""));
    }
    try {
        eventListenerManager.splitCompleted(new SplitCompletedEvent(taskId.getQueryId().toString(), taskId.getStageId().toString(), Integer.toString(taskId.getId()), driverStats.getCreateTime().toDate().toInstant(), Optional.ofNullable(driverStats.getStartTime()).map(startTime -> startTime.toDate().toInstant()), Optional.ofNullable(driverStats.getEndTime()).map(endTime -> endTime.toDate().toInstant()), new SplitStatistics(ofMillis(driverStats.getTotalCpuTime().toMillis()), ofMillis(driverStats.getElapsedTime().toMillis()), ofMillis(driverStats.getQueuedTime().toMillis()), ofMillis(driverStats.getTotalUserTime().toMillis()), ofMillis(driverStats.getRawInputReadTime().toMillis()), driverStats.getRawInputPositions(), driverStats.getRawInputDataSize().toBytes(), driverStats.getPeakMemoryReservation().toBytes(), timeToStart, timeToEnd), splitFailureMetadata, objectMapper.writeValueAsString(driverStats)));
    } catch (JsonProcessingException e) {
        log.error(e, "Error processing split completion event for task %s", taskId);
    }
}
Also used : SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) SplitStatistics(com.facebook.presto.spi.eventlistener.SplitStatistics) SplitFailureInfo(com.facebook.presto.spi.eventlistener.SplitFailureInfo) Duration(java.time.Duration) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with SplitCompletedEvent

use of com.facebook.presto.spi.eventlistener.SplitCompletedEvent in project presto by prestodb.

the class SplitMonitor method splitCompletedEvent.

private void splitCompletedEvent(TaskId taskId, DriverStats driverStats, @Nullable String failureType, @Nullable String failureMessage) {
    Optional<Duration> timeToStart = Optional.empty();
    if (driverStats.getStartTime() != null) {
        timeToStart = Optional.of(ofMillis(driverStats.getStartTime().getMillis() - driverStats.getCreateTime().getMillis()));
    }
    Optional<Duration> timeToEnd = Optional.empty();
    if (driverStats.getEndTime() != null) {
        timeToEnd = Optional.of(ofMillis(driverStats.getEndTime().getMillis() - driverStats.getCreateTime().getMillis()));
    }
    Optional<SplitFailureInfo> splitFailureMetadata = Optional.empty();
    if (failureType != null) {
        splitFailureMetadata = Optional.of(new SplitFailureInfo(failureType, failureMessage != null ? failureMessage : ""));
    }
    try {
        eventListenerManager.splitCompleted(new SplitCompletedEvent(taskId.getQueryId().toString(), taskId.getStageExecutionId().getStageId().toString(), taskId.getStageExecutionId().toString(), Integer.toString(taskId.getId()), driverStats.getCreateTime().toDate().toInstant(), Optional.ofNullable(driverStats.getStartTime()).map(startTime -> startTime.toDate().toInstant()), Optional.ofNullable(driverStats.getEndTime()).map(endTime -> endTime.toDate().toInstant()), new SplitStatistics(ofMillis(driverStats.getTotalCpuTime().toMillis()), ofMillis(driverStats.getElapsedTime().toMillis()), ofMillis(driverStats.getQueuedTime().toMillis()), ofMillis(driverStats.getRawInputReadTime().toMillis()), driverStats.getRawInputPositions(), driverStats.getRawInputDataSize().toBytes(), timeToStart, timeToEnd), splitFailureMetadata, objectMapper.writeValueAsString(driverStats)));
    } catch (JsonProcessingException e) {
        log.error(e, "Error processing split completion event for task %s", taskId);
    }
}
Also used : SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) SplitStatistics(com.facebook.presto.spi.eventlistener.SplitStatistics) SplitFailureInfo(com.facebook.presto.spi.eventlistener.SplitFailureInfo) Duration(java.time.Duration) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with SplitCompletedEvent

use of com.facebook.presto.spi.eventlistener.SplitCompletedEvent in project presto by prestodb.

the class TestEventListener method testNormalQuery.

@Test
public void testNormalQuery() throws Exception {
    // We expect the following events
    // QueryCreated: 1, QueryCompleted: 1, Splits: SPLITS_PER_NODE (leaf splits) + LocalExchange[SINGLE] split + Aggregation/Output split
    int expectedEvents = 1 + 1 + SPLITS_PER_NODE + 1 + 1;
    runQueryAndWaitForEvents("SELECT sum(linenumber) FROM lineitem", expectedEvents);
    QueryCreatedEvent queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    assertEquals(queryCreatedEvent.getContext().getServerVersion(), "testversion");
    assertEquals(queryCreatedEvent.getContext().getServerAddress(), "127.0.0.1");
    assertEquals(queryCreatedEvent.getContext().getEnvironment(), "testing");
    assertEquals(queryCreatedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
    assertEquals(queryCreatedEvent.getMetadata().getQuery(), "SELECT sum(linenumber) FROM lineitem");
    assertFalse(queryCreatedEvent.getMetadata().getPreparedQuery().isPresent());
    QueryCompletedEvent queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertTrue(queryCompletedEvent.getContext().getResourceGroupId().isPresent());
    assertEquals(queryCompletedEvent.getContext().getResourceGroupId().get(), createResourceGroupId("global", "user-user"));
    assertEquals(queryCompletedEvent.getIoMetadata().getOutput(), Optional.empty());
    assertEquals(queryCompletedEvent.getIoMetadata().getInputs().size(), 1);
    assertEquals(queryCompletedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
    assertEquals(getOnlyElement(queryCompletedEvent.getIoMetadata().getInputs()).getCatalogName(), "tpch");
    assertEquals(queryCreatedEvent.getMetadata().getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
    assertFalse(queryCompletedEvent.getMetadata().getPreparedQuery().isPresent());
    assertEquals(queryCompletedEvent.getStatistics().getCompletedSplits(), SPLITS_PER_NODE + 2);
    List<SplitCompletedEvent> splitCompletedEvents = generatedEvents.getSplitCompletedEvents();
    // leaf splits + aggregation split
    assertEquals(splitCompletedEvents.size(), SPLITS_PER_NODE + 2);
    // All splits must have the same query ID
    Set<String> actual = splitCompletedEvents.stream().map(SplitCompletedEvent::getQueryId).collect(toSet());
    assertEquals(actual, ImmutableSet.of(queryCompletedEvent.getMetadata().getQueryId()));
    // Sum of row count processed by all leaf stages is equal to the number of rows in the table
    long actualCompletedPositions = splitCompletedEvents.stream().filter(// filter out the root stage
    e -> !e.getStageExecutionId().endsWith(".0.0")).mapToLong(e -> e.getStatistics().getCompletedPositions()).sum();
    MaterializedResult result = runQueryAndWaitForEvents("SELECT count(*) FROM lineitem", expectedEvents);
    long expectedCompletedPositions = (long) result.getMaterializedRows().get(0).getField(0);
    assertEquals(actualCompletedPositions, expectedCompletedPositions);
    assertEquals(queryCompletedEvent.getStatistics().getTotalRows(), expectedCompletedPositions);
}
Also used : Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) TestingEventListenerPlugin(com.facebook.presto.execution.TestEventListenerPlugin.TestingEventListenerPlugin) Assert.assertFalse(org.testng.Assert.assertFalse) Collectors.toSet(java.util.stream.Collectors.toSet) AfterClass(org.testng.annotations.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) TestQueues.createResourceGroupId(com.facebook.presto.execution.TestQueues.createResourceGroupId) Session(com.facebook.presto.Session) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) ResourceGroupManagerPlugin(com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin) QueryId(com.facebook.presto.spi.QueryId) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 4 with SplitCompletedEvent

use of com.facebook.presto.spi.eventlistener.SplitCompletedEvent in project presto by prestodb.

the class TestEventListener method testConstantQuery.

@Test
public void testConstantQuery() throws Exception {
    // QueryCreated: 1, QueryCompleted: 1, Splits: 1
    runQueryAndWaitForEvents("SELECT 1", 3);
    QueryCreatedEvent queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    assertEquals(queryCreatedEvent.getContext().getServerVersion(), "testversion");
    assertEquals(queryCreatedEvent.getContext().getServerAddress(), "127.0.0.1");
    assertEquals(queryCreatedEvent.getContext().getEnvironment(), "testing");
    assertEquals(queryCreatedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
    assertEquals(queryCreatedEvent.getMetadata().getQuery(), "SELECT 1");
    assertFalse(queryCreatedEvent.getMetadata().getPreparedQuery().isPresent());
    QueryCompletedEvent queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    assertTrue(queryCompletedEvent.getContext().getResourceGroupId().isPresent());
    assertEquals(queryCompletedEvent.getContext().getResourceGroupId().get(), createResourceGroupId("global", "user-user"));
    assertEquals(queryCompletedEvent.getStatistics().getTotalRows(), 0L);
    assertEquals(queryCompletedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
    assertEquals(queryCreatedEvent.getMetadata().getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
    assertFalse(queryCompletedEvent.getMetadata().getPreparedQuery().isPresent());
    List<SplitCompletedEvent> splitCompletedEvents = generatedEvents.getSplitCompletedEvents();
    assertEquals(splitCompletedEvents.get(0).getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
    assertEquals(splitCompletedEvents.get(0).getStatistics().getCompletedPositions(), 1);
}
Also used : SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) Test(org.testng.annotations.Test)

Aggregations

SplitCompletedEvent (com.facebook.presto.spi.eventlistener.SplitCompletedEvent)4 QueryCompletedEvent (com.facebook.presto.spi.eventlistener.QueryCompletedEvent)2 QueryCreatedEvent (com.facebook.presto.spi.eventlistener.QueryCreatedEvent)2 SplitFailureInfo (com.facebook.presto.spi.eventlistener.SplitFailureInfo)2 SplitStatistics (com.facebook.presto.spi.eventlistener.SplitStatistics)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Duration (java.time.Duration)2 Test (org.testng.annotations.Test)2 Session (com.facebook.presto.Session)1 TestingEventListenerPlugin (com.facebook.presto.execution.TestEventListenerPlugin.TestingEventListenerPlugin)1 TestQueues.createResourceGroupId (com.facebook.presto.execution.TestQueues.createResourceGroupId)1 ResourceGroupManagerPlugin (com.facebook.presto.resourceGroups.ResourceGroupManagerPlugin)1 QueryId (com.facebook.presto.spi.QueryId)1 MaterializedResult (com.facebook.presto.testing.MaterializedResult)1 TestingSession.testSessionBuilder (com.facebook.presto.testing.TestingSession.testSessionBuilder)1 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)1 TpchPlugin (com.facebook.presto.tpch.TpchPlugin)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1