Search in sources :

Example 1 with SplitStatistics

use of io.trino.spi.eventlistener.SplitStatistics in project trino by trinodb.

the class SplitMonitor method splitCompletedEvent.

private void splitCompletedEvent(TaskId taskId, DriverStats driverStats, @Nullable String failureType, @Nullable String failureMessage) {
    Duration queuedTime = ofMillis(driverStats.getQueuedTime().toMillis());
    Optional<Duration> queuedTimeIfSplitRan = Optional.empty();
    if (driverStats.getStartTime() != null) {
        queuedTimeIfSplitRan = Optional.of(queuedTime);
    }
    Duration elapsedTime = ofMillis(driverStats.getElapsedTime().toMillis());
    Optional<Duration> elapsedTimeIfSplitRan = Optional.empty();
    if (driverStats.getEndTime() != null) {
        elapsedTimeIfSplitRan = Optional.of(elapsedTime);
    }
    Optional<SplitFailureInfo> splitFailureMetadata = Optional.empty();
    if (failureType != null) {
        splitFailureMetadata = Optional.of(new SplitFailureInfo(failureType, failureMessage != null ? failureMessage : ""));
    }
    Optional<String> splitCatalog = driverStats.getOperatorStats().stream().map(OperatorStats::getInfo).filter(SplitOperatorInfo.class::isInstance).map(SplitOperatorInfo.class::cast).map(info -> info.getCatalogName().getCatalogName()).findFirst();
    try {
        eventListenerManager.splitCompleted(new SplitCompletedEvent(taskId.getQueryId().toString(), taskId.getStageId().toString(), taskId.toString(), splitCatalog, 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()), elapsedTime, queuedTime, ofMillis(driverStats.getRawInputReadTime().toMillis()), driverStats.getRawInputPositions(), driverStats.getRawInputDataSize().toBytes(), queuedTimeIfSplitRan, elapsedTimeIfSplitRan), splitFailureMetadata, objectMapper.writeValueAsString(driverStats)));
    } catch (JsonProcessingException e) {
        log.error(e, "Error processing split completion event for task %s", taskId);
    }
}
Also used : SplitCompletedEvent(io.trino.spi.eventlistener.SplitCompletedEvent) SplitFailureInfo(io.trino.spi.eventlistener.SplitFailureInfo) Logger(io.airlift.log.Logger) OperatorStats(io.trino.operator.OperatorStats) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DriverStats(io.trino.operator.DriverStats) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskId(io.trino.execution.TaskId) SplitStatistics(io.trino.spi.eventlistener.SplitStatistics) Inject(javax.inject.Inject) EventListenerManager(io.trino.eventlistener.EventListenerManager) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) SplitOperatorInfo(io.trino.operator.SplitOperatorInfo) Optional(java.util.Optional) Duration.ofMillis(java.time.Duration.ofMillis) Nullable(javax.annotation.Nullable) SplitCompletedEvent(io.trino.spi.eventlistener.SplitCompletedEvent) SplitStatistics(io.trino.spi.eventlistener.SplitStatistics) SplitFailureInfo(io.trino.spi.eventlistener.SplitFailureInfo) Duration(java.time.Duration) SplitOperatorInfo(io.trino.operator.SplitOperatorInfo) OperatorStats(io.trino.operator.OperatorStats) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Logger (io.airlift.log.Logger)1 EventListenerManager (io.trino.eventlistener.EventListenerManager)1 TaskId (io.trino.execution.TaskId)1 DriverStats (io.trino.operator.DriverStats)1 OperatorStats (io.trino.operator.OperatorStats)1 SplitOperatorInfo (io.trino.operator.SplitOperatorInfo)1 SplitCompletedEvent (io.trino.spi.eventlistener.SplitCompletedEvent)1 SplitFailureInfo (io.trino.spi.eventlistener.SplitFailureInfo)1 SplitStatistics (io.trino.spi.eventlistener.SplitStatistics)1 Duration (java.time.Duration)1 Duration.ofMillis (java.time.Duration.ofMillis)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1