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