Search in sources :

Example 1 with QueryMetadata

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

the class QueryMonitor method queryCompletedEvent.

public void queryCompletedEvent(QueryInfo queryInfo) {
    try {
        Optional<QueryFailureInfo> queryFailureInfo = Optional.empty();
        if (queryInfo.getFailureInfo() != null) {
            FailureInfo failureInfo = queryInfo.getFailureInfo();
            Optional<TaskInfo> failedTask = queryInfo.getOutputStage().flatMap(QueryMonitor::findFailedTask);
            queryFailureInfo = Optional.of(new QueryFailureInfo(queryInfo.getErrorCode(), Optional.ofNullable(failureInfo.getType()), Optional.ofNullable(failureInfo.getMessage()), failedTask.map(task -> task.getTaskStatus().getTaskId().toString()), failedTask.map(task -> task.getTaskStatus().getSelf().getHost()), objectMapper.writeValueAsString(queryInfo.getFailureInfo())));
        }
        ImmutableList.Builder<QueryInputMetadata> inputs = ImmutableList.builder();
        for (Input input : queryInfo.getInputs()) {
            inputs.add(new QueryInputMetadata(input.getConnectorId().getCatalogName(), input.getSchema(), input.getTable(), input.getColumns().stream().map(Column::toString).collect(Collectors.toList()), input.getConnectorInfo()));
        }
        QueryStats queryStats = queryInfo.getQueryStats();
        Optional<QueryOutputMetadata> output = Optional.empty();
        if (queryInfo.getOutput().isPresent()) {
            Optional<TableFinishInfo> tableFinishInfo = queryStats.getOperatorSummaries().stream().map(OperatorStats::getInfo).filter(TableFinishInfo.class::isInstance).map(TableFinishInfo.class::cast).findFirst();
            output = Optional.of(new QueryOutputMetadata(queryInfo.getOutput().get().getConnectorId().getCatalogName(), queryInfo.getOutput().get().getSchema(), queryInfo.getOutput().get().getTable(), tableFinishInfo.map(TableFinishInfo::getConnectorOutputMetadata), tableFinishInfo.map(TableFinishInfo::isJsonLengthLimitExceeded)));
        }
        eventListenerManager.queryCompleted(new QueryCompletedEvent(new QueryMetadata(queryInfo.getQueryId().toString(), queryInfo.getSession().getTransactionId().map(TransactionId::toString), queryInfo.getQuery(), queryInfo.getState().toString(), queryInfo.getSelf(), queryInfo.getOutputStage().flatMap(stage -> stageInfoCodec.toJsonWithLengthLimit(stage, toIntExact(config.getMaxOutputStageJsonSize().toBytes())))), new QueryStatistics(ofMillis(queryStats.getTotalCpuTime().toMillis()), ofMillis(queryStats.getTotalScheduledTime().toMillis()), ofMillis(queryStats.getQueuedTime().toMillis()), Optional.ofNullable(queryStats.getAnalysisTime()).map(duration -> ofMillis(duration.toMillis())), Optional.ofNullable(queryStats.getDistributedPlanningTime()).map(duration -> ofMillis(duration.toMillis())), queryStats.getPeakMemoryReservation().toBytes(), queryStats.getRawInputDataSize().toBytes(), queryStats.getRawInputPositions(), queryStats.getCompletedDrivers(), queryInfo.isCompleteInfo(), objectMapper.writeValueAsString(queryInfo.getQueryStats().getOperatorSummaries())), new QueryContext(queryInfo.getSession().getUser(), queryInfo.getSession().getPrincipal(), queryInfo.getSession().getRemoteUserAddress(), queryInfo.getSession().getUserAgent(), queryInfo.getSession().getClientInfo(), queryInfo.getSession().getSource(), queryInfo.getSession().getCatalog(), queryInfo.getSession().getSchema(), mergeSessionAndCatalogProperties(queryInfo), serverAddress, serverVersion, environment), new QueryIOMetadata(inputs.build(), output), queryFailureInfo, ofEpochMilli(queryStats.getCreateTime().getMillis()), ofEpochMilli(queryStats.getExecutionStartTime().getMillis()), ofEpochMilli(queryStats.getEndTime().getMillis())));
        logQueryTimeline(queryInfo);
    } catch (JsonProcessingException e) {
        throw Throwables.propagate(e);
    }
}
Also used : TaskStats(com.facebook.presto.operator.TaskStats) QueryContext(com.facebook.presto.spi.eventlistener.QueryContext) NodeInfo(io.airlift.node.NodeInfo) TaskState(com.facebook.presto.execution.TaskState) NodeVersion(com.facebook.presto.client.NodeVersion) TableFinishInfo(com.facebook.presto.operator.TableFinishInfo) EventListenerManager(com.facebook.presto.eventlistener.EventListenerManager) QueryStatistics(com.facebook.presto.spi.eventlistener.QueryStatistics) OperatorStats(com.facebook.presto.operator.OperatorStats) StageInfo(com.facebook.presto.execution.StageInfo) Instant.ofEpochMilli(java.time.Instant.ofEpochMilli) Duration(java.time.Duration) Map(java.util.Map) QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) TransactionId(com.facebook.presto.transaction.TransactionId) SplitStatistics(com.facebook.presto.spi.eventlistener.SplitStatistics) Column(com.facebook.presto.execution.Column) ImmutableMap(com.google.common.collect.ImmutableMap) SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) Collectors(java.util.stream.Collectors) List(java.util.List) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) Input(com.facebook.presto.execution.Input) QueryInfo(com.facebook.presto.execution.QueryInfo) Optional(java.util.Optional) Math.max(java.lang.Math.max) ConnectorId(com.facebook.presto.connector.ConnectorId) Duration.ofMillis(java.time.Duration.ofMillis) QueryFailureInfo(com.facebook.presto.spi.eventlistener.QueryFailureInfo) JsonCodec(io.airlift.json.JsonCodec) DriverStats(com.facebook.presto.operator.DriverStats) QueryIOMetadata(com.facebook.presto.spi.eventlistener.QueryIOMetadata) Logger(io.airlift.log.Logger) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) FailureInfo(com.facebook.presto.client.FailureInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) Math.toIntExact(java.lang.Math.toIntExact) Nullable(javax.annotation.Nullable) QueryOutputMetadata(com.facebook.presto.spi.eventlistener.QueryOutputMetadata) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) Throwables(com.google.common.base.Throwables) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) QueryInputMetadata(com.facebook.presto.spi.eventlistener.QueryInputMetadata) QueryStats(com.facebook.presto.execution.QueryStats) SplitFailureInfo(com.facebook.presto.spi.eventlistener.SplitFailureInfo) TaskId(com.facebook.presto.execution.TaskId) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) TaskInfo(com.facebook.presto.execution.TaskInfo) TableFinishInfo(com.facebook.presto.operator.TableFinishInfo) QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) ImmutableList(com.google.common.collect.ImmutableList) QueryOutputMetadata(com.facebook.presto.spi.eventlistener.QueryOutputMetadata) QueryContext(com.facebook.presto.spi.eventlistener.QueryContext) QueryInputMetadata(com.facebook.presto.spi.eventlistener.QueryInputMetadata) QueryFailureInfo(com.facebook.presto.spi.eventlistener.QueryFailureInfo) TaskInfo(com.facebook.presto.execution.TaskInfo) Input(com.facebook.presto.execution.Input) QueryStats(com.facebook.presto.execution.QueryStats) QueryStatistics(com.facebook.presto.spi.eventlistener.QueryStatistics) QueryFailureInfo(com.facebook.presto.spi.eventlistener.QueryFailureInfo) FailureInfo(com.facebook.presto.client.FailureInfo) SplitFailureInfo(com.facebook.presto.spi.eventlistener.SplitFailureInfo) QueryIOMetadata(com.facebook.presto.spi.eventlistener.QueryIOMetadata) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with QueryMetadata

use of com.facebook.presto.spi.eventlistener.QueryMetadata in project presto-audit by yahoojapan.

the class TestHelper method createNormalEvent.

public QueryCompletedEvent createNormalEvent() {
    setUp();
    QueryMetadata metadata = new QueryMetadata("20170606_044544_00024_nfhe3", Optional.of("4c52973c-14c6-4534-837f-238e21d9b061"), "select * from airdelays_s3_csv WHERE kw = 'presto-kw-example' limit 5", "FINISHED", uri, Optional.empty(), Optional.empty());
    return new QueryCompletedEvent(metadata, statistics, context, ioMetadata, Optional.empty(), createTime, executionStartTime, endTime);
}
Also used : QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent)

Example 3 with QueryMetadata

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

the class TestEventListenerWithExchangeMaterialization method testRuntimeOptimizedStagesCorrectness.

@Test
public void testRuntimeOptimizedStagesCorrectness() throws Exception {
    // We expect one runtime optimized stage: 1.
    int expectedEvents = 2;
    QueryId queryId = runQueryAndWaitForEvents("SELECT phone, regionkey FROM nation INNER JOIN supplier ON supplier.nationkey=nation.nationkey", expectedEvents);
    QueryCreatedEvent queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    QueryCompletedEvent queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    QueryMetadata queryMetadata = queryCompletedEvent.getMetadata();
    Optional<List<StageId>> runtimeOptimizedStages = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getRuntimeOptimizedStages();
    assertEquals(queryMetadata.getQueryId(), queryId.toString());
    assertEquals(queryMetadata.getRuntimeOptimizedStages().size(), 1);
    assertEquals(queryMetadata.getRuntimeOptimizedStages().get(0), "1");
    assertTrue(runtimeOptimizedStages.isPresent());
    assertEquals(runtimeOptimizedStages.get().size(), 1);
    assertEquals(queryMetadata.getRuntimeOptimizedStages(), runtimeOptimizedStages.get().stream().map(stageId -> String.valueOf(stageId.getId())).collect(toImmutableList()));
    // Now, the following query should not trigger runtime optimizations, so should have empty list of runtime optimized stages.
    runQueryAndWaitForEvents("SELECT phone, regionkey FROM supplier INNER JOIN nation ON supplier.nationkey=nation.nationkey", expectedEvents);
    queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    runtimeOptimizedStages = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getRuntimeOptimizedStages();
    assertTrue(queryCompletedEvent.getMetadata().getRuntimeOptimizedStages().isEmpty());
    assertFalse(runtimeOptimizedStages.isPresent());
    // Now, the following query should have two optimized joins in a single stage (both on the same nationkey), therefore expect only one optimized stage: 1.
    runQueryAndWaitForEvents("SELECT supplier.phone, regionkey, custkey FROM nation INNER JOIN supplier ON supplier.nationkey=nation.nationkey INNER JOIN customer ON nation.nationkey=customer.nationkey", expectedEvents);
    queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    queryMetadata = queryCompletedEvent.getMetadata();
    runtimeOptimizedStages = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getRuntimeOptimizedStages();
    assertEquals(queryMetadata.getRuntimeOptimizedStages().size(), 1);
    assertEquals(queryMetadata.getRuntimeOptimizedStages().get(0), "1");
    assertTrue(runtimeOptimizedStages.isPresent());
    assertEquals(runtimeOptimizedStages.get().size(), 1);
    assertEquals(queryMetadata.getRuntimeOptimizedStages(), runtimeOptimizedStages.get().stream().map(stageId -> String.valueOf(stageId.getId())).collect(toImmutableList()));
    // Now, the following query should have two runtime optimized stages: 1 and 4, corresponding to the two join operations (on regionkey and nationkey respectively).
    runQueryAndWaitForEvents("WITH natreg AS (SELECT nation.regionkey, nationkey, region.name FROM region INNER JOIN nation ON nation.regionkey=region.regionkey) SELECT phone, regionkey FROM natreg INNER JOIN supplier ON supplier.nationkey=natreg.nationkey", expectedEvents);
    queryCreatedEvent = getOnlyElement(generatedEvents.getQueryCreatedEvents());
    queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents());
    queryMetadata = queryCompletedEvent.getMetadata();
    runtimeOptimizedStages = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(new QueryId(queryCreatedEvent.getMetadata().getQueryId())).getRuntimeOptimizedStages();
    assertEquals(queryMetadata.getRuntimeOptimizedStages().size(), 2);
    assertEquals(ImmutableSet.copyOf(queryMetadata.getRuntimeOptimizedStages()), ImmutableSet.of("1", "4"));
    assertTrue(runtimeOptimizedStages.isPresent());
    assertEquals(runtimeOptimizedStages.get().size(), 2);
    assertEquals(queryMetadata.getRuntimeOptimizedStages(), runtimeOptimizedStages.get().stream().map(stageId -> String.valueOf(stageId.getId())).collect(toImmutableList()));
}
Also used : QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) QueryId(com.facebook.presto.spi.QueryId) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 4 with QueryMetadata

use of com.facebook.presto.spi.eventlistener.QueryMetadata in project presto-audit by yahoojapan.

the class TestHelper method createQueryWithSource.

public QueryCompletedEvent createQueryWithSource(Optional<String> source) {
    setUp();
    QueryMetadata metadata = new QueryMetadata("20170606_044544_00024_nfhe3", Optional.of("4c52973c-14c6-4534-837f-238e21d9b061"), "select * from airdelays_s3_csv WHERE kw = 'presto-kw-example' limit 5", "FINISHED", uri, Optional.empty(), Optional.empty());
    QueryContext context = new QueryContext("test-user", Optional.of("principal"), Optional.of("example.com"), Optional.of("StatementClient 0.167"), Optional.of("clientInfo"), new HashSet<>(), source, Optional.of("catalog"), Optional.of("schema"), Optional.of(""), new HashMap<>(), "127.0.0.1", "0.175", "environment");
    return new QueryCompletedEvent(metadata, statistics, context, ioMetadata, Optional.empty(), createTime, executionStartTime, endTime);
}
Also used : QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) QueryContext(com.facebook.presto.spi.eventlistener.QueryContext)

Example 5 with QueryMetadata

use of com.facebook.presto.spi.eventlistener.QueryMetadata in project presto-audit by yahoojapan.

the class TestHelper method createFailureEvent.

public QueryCompletedEvent createFailureEvent() {
    setUp();
    QueryMetadata metadata = new QueryMetadata("20170606_044544_00024_nfhe3", Optional.of("4c52973c-14c6-4534-837f-238e21d9b061"), "select 2a", "FAILED", uri, Optional.empty(), Optional.empty());
    ErrorCode errorCode = new ErrorCode(1, "SYNTAX_ERROR", ErrorType.USER_ERROR);
    QueryFailureInfo failureInfo = new QueryFailureInfo(errorCode, Optional.of("com.facebook.presto.sql.parser.ParsingException"), Optional.of("line 1:15: mismatched input '0' expecting ')'"), Optional.empty(), Optional.empty(), "{json-error}");
    return new QueryCompletedEvent(metadata, statistics, context, ioMetadata, Optional.of(failureInfo), createTime, executionStartTime, endTime);
}
Also used : QueryFailureInfo(com.facebook.presto.spi.eventlistener.QueryFailureInfo) QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) ErrorCode(com.facebook.presto.spi.ErrorCode)

Aggregations

QueryCompletedEvent (com.facebook.presto.spi.eventlistener.QueryCompletedEvent)6 QueryMetadata (com.facebook.presto.spi.eventlistener.QueryMetadata)6 QueryContext (com.facebook.presto.spi.eventlistener.QueryContext)2 QueryCreatedEvent (com.facebook.presto.spi.eventlistener.QueryCreatedEvent)2 QueryFailureInfo (com.facebook.presto.spi.eventlistener.QueryFailureInfo)2 QueryIOMetadata (com.facebook.presto.spi.eventlistener.QueryIOMetadata)2 QueryStatistics (com.facebook.presto.spi.eventlistener.QueryStatistics)2 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 FailureInfo (com.facebook.presto.client.FailureInfo)1 NodeVersion (com.facebook.presto.client.NodeVersion)1 RuntimeStats (com.facebook.presto.common.RuntimeStats)1 ConnectorId (com.facebook.presto.connector.ConnectorId)1 EventListenerManager (com.facebook.presto.eventlistener.EventListenerManager)1 Column (com.facebook.presto.execution.Column)1 Input (com.facebook.presto.execution.Input)1 QueryInfo (com.facebook.presto.execution.QueryInfo)1 QueryStats (com.facebook.presto.execution.QueryStats)1 StageInfo (com.facebook.presto.execution.StageInfo)1 TaskId (com.facebook.presto.execution.TaskId)1