From 36d1a33f229348938596cf7bebdacbe208675cca Mon Sep 17 00:00:00 2001 From: Karol Sobczak Date: Fri, 23 Aug 2024 11:45:49 +0200 Subject: [PATCH] Expose starting time to event listener --- .../src/main/java/io/trino/event/QueryMonitor.java | 2 ++ .../io/trino/spi/eventlistener/QueryStatistics.java | 11 +++++++++++ .../trino/plugin/httpquery/TestHttpEventListener.java | 1 + .../plugin/httpquery/TestHttpServerEventListener.java | 1 + .../trino/plugin/eventlistener/kafka/TestUtils.java | 1 + .../eventlistener/mysql/MysqlEventListener.java | 1 + .../io/trino/plugin/eventlistener/mysql/QueryDao.java | 3 +++ .../trino/plugin/eventlistener/mysql/QueryEntity.java | 8 ++++++++ .../eventlistener/mysql/TestMysqlEventListener.java | 3 +++ .../io/trino/plugin/openlineage/TrinoEventData.java | 1 + 10 files changed, 32 insertions(+) diff --git a/core/trino-main/src/main/java/io/trino/event/QueryMonitor.java b/core/trino-main/src/main/java/io/trino/event/QueryMonitor.java index 2efbf816c1ba79..a86bda27fe3195 100644 --- a/core/trino-main/src/main/java/io/trino/event/QueryMonitor.java +++ b/core/trino-main/src/main/java/io/trino/event/QueryMonitor.java @@ -209,6 +209,7 @@ public void queryImmediateFailureEvent(BasicQueryInfo queryInfo, ExecutionFailur Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), 0, 0, 0, @@ -317,6 +318,7 @@ private QueryStatistics createQueryStatistics(QueryInfo queryInfo) Optional.of(ofMillis(queryStats.getAnalysisTime().toMillis())), Optional.of(ofMillis(queryStats.getPlanningTime().toMillis())), Optional.of(ofMillis(queryStats.getPlanningCpuTime().toMillis())), + Optional.of(ofMillis(queryStats.getStartingTime().toMillis())), Optional.of(ofMillis(queryStats.getExecutionTime().toMillis())), Optional.of(ofMillis(queryStats.getInputBlockedTime().toMillis())), Optional.of(ofMillis(queryStats.getFailedInputBlockedTime().toMillis())), diff --git a/core/trino-spi/src/main/java/io/trino/spi/eventlistener/QueryStatistics.java b/core/trino-spi/src/main/java/io/trino/spi/eventlistener/QueryStatistics.java index 2ca79eed6f3c18..dc5f0c6e7bb6b7 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/eventlistener/QueryStatistics.java +++ b/core/trino-spi/src/main/java/io/trino/spi/eventlistener/QueryStatistics.java @@ -39,6 +39,7 @@ public class QueryStatistics private final Optional analysisTime; private final Optional planningTime; private final Optional planningCpuTime; + private final Optional startingTime; private final Optional executionTime; private final Optional inputBlockedTime; private final Optional failedInputBlockedTime; @@ -100,6 +101,7 @@ public QueryStatistics( Optional analysisTime, Optional planningTime, Optional planningCpuTime, + Optional startingTime, Optional executionTime, Optional inputBlockedTime, Optional failedInputBlockedTime, @@ -145,6 +147,7 @@ public QueryStatistics( analysisTime, planningTime, planningCpuTime, + startingTime, executionTime, inputBlockedTime, failedInputBlockedTime, @@ -191,6 +194,7 @@ public QueryStatistics( Optional analysisTime, Optional planningTime, Optional planningCpuTime, + Optional startingTime, Optional executionTime, Optional inputBlockedTime, Optional failedInputBlockedTime, @@ -235,6 +239,7 @@ public QueryStatistics( this.analysisTime = requireNonNull(analysisTime, "analysisTime is null"); this.planningTime = requireNonNull(planningTime, "planningTime is null"); this.planningCpuTime = requireNonNull(planningCpuTime, "planningCpuTime is null"); + this.startingTime = requireNonNull(startingTime, "startingTime is null"); this.executionTime = requireNonNull(executionTime, "executionTime is null"); this.inputBlockedTime = requireNonNull(inputBlockedTime, "inputBlockedTime is null"); this.failedInputBlockedTime = requireNonNull(failedInputBlockedTime, "failedInputBlockedTime is null"); @@ -330,6 +335,12 @@ public Optional getPlanningCpuTime() return planningCpuTime; } + @JsonProperty + public Optional getStartingTime() + { + return startingTime; + } + @JsonProperty public Optional getExecutionTime() { diff --git a/plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListener.java b/plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListener.java index e12c48e6c93b62..bf6fff2debcbcb 100644 --- a/plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListener.java +++ b/plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListener.java @@ -166,6 +166,7 @@ final class TestHttpEventListener Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), 0L, 0L, 0L, diff --git a/plugin/trino-http-server-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpServerEventListener.java b/plugin/trino-http-server-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpServerEventListener.java index ea66cf657820cc..225ca523ffdea3 100644 --- a/plugin/trino-http-server-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpServerEventListener.java +++ b/plugin/trino-http-server-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpServerEventListener.java @@ -136,6 +136,7 @@ final class TestHttpServerEventListener Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), 0L, 0L, 0L, diff --git a/plugin/trino-kafka-event-listener/src/test/java/io/trino/plugin/eventlistener/kafka/TestUtils.java b/plugin/trino-kafka-event-listener/src/test/java/io/trino/plugin/eventlistener/kafka/TestUtils.java index 7c1f56cb6bb894..fd9fd3372f82c5 100644 --- a/plugin/trino-kafka-event-listener/src/test/java/io/trino/plugin/eventlistener/kafka/TestUtils.java +++ b/plugin/trino-kafka-event-listener/src/test/java/io/trino/plugin/eventlistener/kafka/TestUtils.java @@ -131,6 +131,7 @@ private TestUtils() Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), 0L, 0L, 0L, diff --git a/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListener.java b/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListener.java index 0fff350fcac1f2..c68868985090c1 100644 --- a/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListener.java +++ b/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListener.java @@ -137,6 +137,7 @@ public void queryCompleted(QueryCompletedEvent event) stats.getAnalysisTime().map(Duration::toMillis).orElse(0L), stats.getPlanningTime().map(Duration::toMillis).orElse(0L), stats.getPlanningCpuTime().map(Duration::toMillis).orElse(0L), + stats.getStartingTime().map(Duration::toMillis).orElse(0L), stats.getExecutionTime().map(Duration::toMillis).orElse(0L), stats.getInputBlockedTime().map(Duration::toMillis).orElse(0L), stats.getFailedInputBlockedTime().map(Duration::toMillis).orElse(0L), diff --git a/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/QueryDao.java b/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/QueryDao.java index 79d4bf789a9bc6..278cfdaf3f75c3 100644 --- a/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/QueryDao.java +++ b/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/QueryDao.java @@ -63,6 +63,7 @@ public interface QueryDao " analysis_time_millis BIGINT NOT NULL,\n" + " planning_time_millis BIGINT NOT NULL,\n" + " planning_cpu_time_millis BIGINT NOT NULL,\n" + + " starting_time_millis BIGINT NOT NULL,\n" + " execution_time_millis BIGINT NOT NULL,\n" + " input_blocked_time_millis BIGINT NOT NULL,\n" + " failed_input_blocked_time_millis BIGINT NOT NULL,\n" + @@ -135,6 +136,7 @@ public interface QueryDao " analysis_time_millis,\n" + " planning_time_millis,\n" + " planning_cpu_time_millis,\n" + + " starting_time_millis,\n" + " execution_time_millis,\n" + " input_blocked_time_millis,\n" + " failed_input_blocked_time_millis,\n" + @@ -204,6 +206,7 @@ public interface QueryDao " :analysisTimeMillis,\n" + " :planningTimeMillis,\n" + " :planningCpuTimeMillis,\n" + + " :startingTimeMillis,\n" + " :executionTimeMillis,\n" + " :inputBlockedTimeMillis,\n" + " :failedInputBlockedTimeMillis,\n" + diff --git a/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/QueryEntity.java b/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/QueryEntity.java index 209a016c332967..3bd6fb7d2acf7b 100644 --- a/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/QueryEntity.java +++ b/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/QueryEntity.java @@ -74,6 +74,7 @@ public class QueryEntity private final long analysisTimeMillis; private final long planningTimeMillis; private final long planningCpuTimeMillis; + private final long startingTimeMillis; private final long executionTimeMillis; private final long inputBlockedTimeMillis; private final long failedInputBlockedTimeMillis; @@ -147,6 +148,7 @@ public QueryEntity( long analysisTimeMillis, long planningTimeMillis, long planningCpuTimeMillis, + long startingTimeMillis, long executionTimeMillis, long inputBlockedTimeMillis, long failedInputBlockedTimeMillis, @@ -215,6 +217,7 @@ public QueryEntity( this.analysisTimeMillis = analysisTimeMillis; this.planningTimeMillis = planningTimeMillis; this.planningCpuTimeMillis = planningCpuTimeMillis; + this.startingTimeMillis = startingTimeMillis; this.executionTimeMillis = executionTimeMillis; this.inputBlockedTimeMillis = inputBlockedTimeMillis; this.failedInputBlockedTimeMillis = failedInputBlockedTimeMillis; @@ -460,6 +463,11 @@ public long getPlanningCpuTimeMillis() return planningCpuTimeMillis; } + public long getStartingTimeMillis() + { + return startingTimeMillis; + } + public long getExecutionTimeMillis() { return executionTimeMillis; diff --git a/plugin/trino-mysql-event-listener/src/test/java/io/trino/plugin/eventlistener/mysql/TestMysqlEventListener.java b/plugin/trino-mysql-event-listener/src/test/java/io/trino/plugin/eventlistener/mysql/TestMysqlEventListener.java index da9eb686fc8331..fb8901be9ce5e1 100644 --- a/plugin/trino-mysql-event-listener/src/test/java/io/trino/plugin/eventlistener/mysql/TestMysqlEventListener.java +++ b/plugin/trino-mysql-event-listener/src/test/java/io/trino/plugin/eventlistener/mysql/TestMysqlEventListener.java @@ -95,6 +95,7 @@ final class TestMysqlEventListener Optional.of(ofMillis(108)), Optional.of(ofMillis(109)), Optional.of(ofMillis(1091)), + Optional.of(ofMillis(1092)), Optional.of(ofMillis(110)), Optional.of(ofMillis(111)), Optional.of(ofMillis(112)), @@ -260,6 +261,7 @@ final class TestMysqlEventListener Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), 115L, 116L, 117L, @@ -424,6 +426,7 @@ void testFull() assertThat(resultSet.getLong("analysis_time_millis")).isEqualTo(108); assertThat(resultSet.getLong("planning_time_millis")).isEqualTo(109); assertThat(resultSet.getLong("planning_cpu_time_millis")).isEqualTo(1091); + assertThat(resultSet.getLong("starting_time_millis")).isEqualTo(1092); assertThat(resultSet.getLong("execution_time_millis")).isEqualTo(110); assertThat(resultSet.getLong("input_blocked_time_millis")).isEqualTo(111); assertThat(resultSet.getLong("failed_input_blocked_time_millis")).isEqualTo(112); diff --git a/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TrinoEventData.java b/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TrinoEventData.java index f4d847a1c91829..3db745e63ca75b 100644 --- a/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TrinoEventData.java +++ b/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TrinoEventData.java @@ -109,6 +109,7 @@ private TrinoEventData() Optional.empty(), Optional.empty(), Optional.empty(), + Optional.empty(), 0L, 0L, 0L,