diff --git a/core/trino-main/src/main/java/io/trino/eventlistener/EventListenerContextInstance.java b/core/trino-main/src/main/java/io/trino/eventlistener/EventListenerContextInstance.java new file mode 100644 index 000000000000..86eaeab141d8 --- /dev/null +++ b/core/trino-main/src/main/java/io/trino/eventlistener/EventListenerContextInstance.java @@ -0,0 +1,53 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.eventlistener; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; +import io.trino.spi.eventlistener.EventListenerFactory; + +import static java.util.Objects.requireNonNull; + +public class EventListenerContextInstance + implements EventListenerFactory.EventListenerContext +{ + private final OpenTelemetry openTelemetry; + private final Tracer tracer; + private final String version; + + public EventListenerContextInstance(String version, OpenTelemetry openTelemetry, Tracer tracer) + { + this.version = requireNonNull(version, "version is null"); + this.openTelemetry = requireNonNull(openTelemetry, "openTelemetry is null"); + this.tracer = requireNonNull(tracer, "tracer is null"); + } + + @Override + public String getVersion() + { + return version; + } + + @Override + public OpenTelemetry getOpenTelemetry() + { + return openTelemetry; + } + + @Override + public Tracer getTracer() + { + return tracer; + } +} diff --git a/core/trino-main/src/main/java/io/trino/eventlistener/EventListenerManager.java b/core/trino-main/src/main/java/io/trino/eventlistener/EventListenerManager.java index 2be3158a20b9..8aff62eac46a 100644 --- a/core/trino-main/src/main/java/io/trino/eventlistener/EventListenerManager.java +++ b/core/trino-main/src/main/java/io/trino/eventlistener/EventListenerManager.java @@ -19,6 +19,9 @@ import io.airlift.configuration.secrets.SecretsResolver; import io.airlift.log.Logger; import io.airlift.stats.TimeStat; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; +import io.trino.client.NodeVersion; import io.trino.spi.classloader.ThreadContextClassLoader; import io.trino.spi.eventlistener.EventListener; import io.trino.spi.eventlistener.EventListenerFactory; @@ -67,12 +70,14 @@ public class EventListenerManager private final TimeStat queryCompletedTime = new TimeStat(MILLISECONDS); private final TimeStat splitCompletedTime = new TimeStat(MILLISECONDS); private final SecretsResolver secretsResolver; + private final EventListenerContextInstance context; @Inject - public EventListenerManager(EventListenerConfig config, SecretsResolver secretsResolver) + public EventListenerManager(EventListenerConfig config, SecretsResolver secretsResolver, OpenTelemetry openTelemetry, Tracer tracer, NodeVersion version) { this.configFiles = ImmutableList.copyOf(config.getEventListenerFiles()); this.secretsResolver = requireNonNull(secretsResolver, "secretsResolver is null"); + this.context = new EventListenerContextInstance(version.toString(), openTelemetry, tracer); } public void addEventListenerFactory(EventListenerFactory eventListenerFactory) @@ -129,7 +134,7 @@ private EventListener createEventListener(File configFile) EventListener eventListener; try (ThreadContextClassLoader _ = new ThreadContextClassLoader(factory.getClass().getClassLoader())) { - eventListener = factory.create(secretsResolver.getResolvedConfiguration(properties)); + eventListener = factory.create(secretsResolver.getResolvedConfiguration(properties), context); } log.info("-- Loaded event listener %s --", configFile); diff --git a/core/trino-main/src/main/java/io/trino/testing/PlanTester.java b/core/trino-main/src/main/java/io/trino/testing/PlanTester.java index 2f210edb303a..bfce4411861b 100644 --- a/core/trino-main/src/main/java/io/trino/testing/PlanTester.java +++ b/core/trino-main/src/main/java/io/trino/testing/PlanTester.java @@ -372,7 +372,7 @@ private PlanTester(Session defaultSession, int nodeCountForStats) this.joinCompiler = new JoinCompiler(typeOperators); this.hashStrategyCompiler = new FlatHashStrategyCompiler(typeOperators); PageIndexerFactory pageIndexerFactory = new GroupByHashPageIndexerFactory(hashStrategyCompiler); - EventListenerManager eventListenerManager = new EventListenerManager(new EventListenerConfig(), secretsResolver); + EventListenerManager eventListenerManager = new EventListenerManager(new EventListenerConfig(), secretsResolver, noop(), tracer, nodeManager.getCurrentNode().getNodeVersion()); this.accessControl = new TestingAccessControlManager(transactionManager, eventListenerManager, secretsResolver); accessControl.loadSystemAccessControl(AllowAllSystemAccessControl.NAME, ImmutableMap.of()); diff --git a/core/trino-main/src/main/java/io/trino/testing/TestingEventListenerContext.java b/core/trino-main/src/main/java/io/trino/testing/TestingEventListenerContext.java new file mode 100644 index 000000000000..0bd8c56ba392 --- /dev/null +++ b/core/trino-main/src/main/java/io/trino/testing/TestingEventListenerContext.java @@ -0,0 +1,41 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.testing; + +import io.airlift.tracing.Tracing; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; +import io.trino.spi.eventlistener.EventListenerFactory; + +public class TestingEventListenerContext + implements EventListenerFactory.EventListenerContext +{ + @Override + public String getVersion() + { + return "test-version"; + } + + @Override + public OpenTelemetry getOpenTelemetry() + { + return OpenTelemetry.noop(); + } + + @Override + public Tracer getTracer() + { + return Tracing.noopTracer(); + } +} diff --git a/core/trino-main/src/main/java/io/trino/testing/TestingEventListenerManager.java b/core/trino-main/src/main/java/io/trino/testing/TestingEventListenerManager.java index 17c0f0da14a1..3c26f03ac9d2 100644 --- a/core/trino-main/src/main/java/io/trino/testing/TestingEventListenerManager.java +++ b/core/trino-main/src/main/java/io/trino/testing/TestingEventListenerManager.java @@ -18,6 +18,9 @@ import com.google.common.collect.ImmutableMap; import com.google.inject.Inject; import io.airlift.configuration.secrets.SecretsResolver; +import io.airlift.tracing.Tracing; +import io.opentelemetry.api.OpenTelemetry; +import io.trino.client.NodeVersion; import io.trino.eventlistener.EventListenerConfig; import io.trino.eventlistener.EventListenerManager; import io.trino.spi.eventlistener.EventListener; @@ -43,13 +46,13 @@ public static TestingEventListenerManager emptyEventListenerManager() @Inject public TestingEventListenerManager(EventListenerConfig config, SecretsResolver secretsResolver) { - super(config, secretsResolver); + super(config, secretsResolver, OpenTelemetry.noop(), Tracing.noopTracer(), new NodeVersion("test-version")); } @Override public void addEventListenerFactory(EventListenerFactory eventListenerFactory) { - configuredEventListeners.add(eventListenerFactory.create(ImmutableMap.of())); + configuredEventListeners.add(eventListenerFactory.create(ImmutableMap.of(), new TestingEventListenerContext())); } @Override diff --git a/core/trino-main/src/test/java/io/trino/dispatcher/TestLocalDispatchQuery.java b/core/trino-main/src/test/java/io/trino/dispatcher/TestLocalDispatchQuery.java index 2f156e636c63..1a3f052a4b55 100644 --- a/core/trino-main/src/test/java/io/trino/dispatcher/TestLocalDispatchQuery.java +++ b/core/trino-main/src/test/java/io/trino/dispatcher/TestLocalDispatchQuery.java @@ -22,7 +22,6 @@ import io.airlift.json.JsonCodec; import io.airlift.node.NodeInfo; import io.airlift.units.Duration; -import io.opentelemetry.api.OpenTelemetry; import io.trino.Session; import io.trino.client.NodeVersion; import io.trino.connector.ConnectorCatalogServiceProvider; @@ -76,6 +75,8 @@ import static com.google.common.util.concurrent.Futures.immediateVoidFuture; import static io.airlift.concurrent.Threads.daemonThreadsNamed; +import static io.airlift.tracing.Tracing.noopTracer; +import static io.opentelemetry.api.OpenTelemetry.noop; import static io.trino.SessionTestUtils.TEST_SESSION; import static io.trino.execution.querystats.PlanOptimizersStatsCollector.createPlanOptimizersStatsCollector; import static io.trino.metadata.TestMetadataManager.createTestMetadataManager; @@ -102,7 +103,7 @@ public void testSubmittedForDispatchedQuery() transactionManager, emptyEventListenerManager(), new AccessControlConfig(), - OpenTelemetry.noop(), + noop(), new SecretsResolver(ImmutableMap.of()), DefaultSystemAccessControl.NAME); accessControl.setSystemAccessControls(List.of(AllowAllSystemAccessControl.INSTANCE)); @@ -128,7 +129,7 @@ public void testSubmittedForDispatchedQuery() JsonCodec.jsonCodec(OperatorStats.class), JsonCodec.jsonCodec(ExecutionFailureInfo.class), JsonCodec.jsonCodec(StatsAndCosts.class), - new EventListenerManager(new EventListenerConfig(), new SecretsResolver(ImmutableMap.of())), + new EventListenerManager(new EventListenerConfig(), new SecretsResolver(ImmutableMap.of()), noop(), noopTracer(), new NodeVersion("test")), new NodeInfo("node"), new NodeVersion("version"), new SessionPropertyManager(), diff --git a/core/trino-main/src/test/java/io/trino/eventlistener/TestEventListenerManager.java b/core/trino-main/src/test/java/io/trino/eventlistener/TestEventListenerManager.java index c330ff4d17f6..45cfb5bc7b17 100644 --- a/core/trino-main/src/test/java/io/trino/eventlistener/TestEventListenerManager.java +++ b/core/trino-main/src/test/java/io/trino/eventlistener/TestEventListenerManager.java @@ -15,12 +15,15 @@ import com.google.common.collect.ImmutableMap; import io.airlift.configuration.secrets.SecretsResolver; +import io.trino.client.NodeVersion; import io.trino.spi.eventlistener.EventListener; import io.trino.spi.eventlistener.QueryCompletedEvent; import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicBoolean; +import static io.airlift.tracing.Tracing.noopTracer; +import static io.opentelemetry.api.OpenTelemetry.noop; import static org.assertj.core.api.Assertions.assertThat; class TestEventListenerManager @@ -28,7 +31,7 @@ class TestEventListenerManager @Test public void testShutdownIsForwardedToListeners() { - EventListenerManager eventListenerManager = new EventListenerManager(new EventListenerConfig(), new SecretsResolver(ImmutableMap.of())); + EventListenerManager eventListenerManager = new EventListenerManager(new EventListenerConfig(), new SecretsResolver(ImmutableMap.of()), noop(), noopTracer(), new NodeVersion("test-version")); AtomicBoolean wasCalled = new AtomicBoolean(false); EventListener listener = new EventListener() { diff --git a/core/trino-main/src/test/java/io/trino/execution/TaskTestUtils.java b/core/trino-main/src/test/java/io/trino/execution/TaskTestUtils.java index 50cfa5a24231..d3568e4d5432 100644 --- a/core/trino-main/src/test/java/io/trino/execution/TaskTestUtils.java +++ b/core/trino-main/src/test/java/io/trino/execution/TaskTestUtils.java @@ -18,8 +18,6 @@ import com.google.common.collect.ImmutableSet; import io.airlift.configuration.secrets.SecretsResolver; import io.airlift.json.ObjectMapperProvider; -import io.airlift.tracing.Tracing; -import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Span; import io.trino.client.NodeVersion; import io.trino.connector.CatalogServiceProvider; @@ -73,6 +71,8 @@ import java.util.Optional; import java.util.Set; +import static io.airlift.tracing.Tracing.noopTracer; +import static io.opentelemetry.api.OpenTelemetry.noop; import static io.trino.SessionTestUtils.TEST_SESSION; import static io.trino.spi.type.BigintType.BIGINT; import static io.trino.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION; @@ -195,7 +195,7 @@ public static LocalExecutionPlanner createTestingPlanner() blockTypeOperators, PLANNER_CONTEXT.getTypeOperators(), new TableExecuteContextManager(), - new ExchangeManagerRegistry(OpenTelemetry.noop(), Tracing.noopTracer(), new SecretsResolver(ImmutableMap.of())), + new ExchangeManagerRegistry(noop(), noopTracer(), new SecretsResolver(ImmutableMap.of())), new NodeVersion("test"), new CompilerConfig()); } @@ -208,7 +208,7 @@ public static TaskInfo updateTask(SqlTask sqlTask, List splitAs public static SplitMonitor createTestSplitMonitor() { return new SplitMonitor( - new EventListenerManager(new EventListenerConfig(), new SecretsResolver(ImmutableMap.of())), + new EventListenerManager(new EventListenerConfig(), new SecretsResolver(ImmutableMap.of()), noop(), noopTracer(), new NodeVersion("test")), new ObjectMapperProvider().get()); } } diff --git a/core/trino-spi/pom.xml b/core/trino-spi/pom.xml index dcf155f04eb7..49bd12750f92 100644 --- a/core/trino-spi/pom.xml +++ b/core/trino-spi/pom.xml @@ -237,6 +237,13 @@ method io.trino.spi.security.SystemAccessControl io.trino.spi.security.SystemAccessControlFactory::create(java.util.Map<java.lang.String, java.lang.String>, io.trino.spi.security.SystemAccessControlFactory.SystemAccessControlContext) Old variant was removed and this becomes the new non-default one + + true + java.method.numberOfParametersChanged + method io.trino.spi.eventlistener.EventListener io.trino.spi.eventlistener.EventListenerFactory::create(java.util.Map<java.lang.String, java.lang.String>) + method io.trino.spi.eventlistener.EventListener io.trino.spi.eventlistener.EventListenerFactory::create(java.util.Map<java.lang.String, java.lang.String>, io.trino.spi.eventlistener.EventListenerFactory.EventListenerContext) + Added EventListenerContext + diff --git a/core/trino-spi/src/main/java/io/trino/spi/eventlistener/EventListenerFactory.java b/core/trino-spi/src/main/java/io/trino/spi/eventlistener/EventListenerFactory.java index fd4c4daa9b03..b873768d4627 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/eventlistener/EventListenerFactory.java +++ b/core/trino-spi/src/main/java/io/trino/spi/eventlistener/EventListenerFactory.java @@ -13,11 +13,23 @@ */ package io.trino.spi.eventlistener; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; + import java.util.Map; public interface EventListenerFactory { String getName(); - EventListener create(Map config); + EventListener create(Map config, EventListenerContext context); + + interface EventListenerContext + { + String getVersion(); + + OpenTelemetry getOpenTelemetry(); + + Tracer getTracer(); + } } diff --git a/lib/trino-plugin-toolkit/src/test/java/io/trino/plugin/base/evenlistener/TestingEventListenerContext.java b/lib/trino-plugin-toolkit/src/test/java/io/trino/plugin/base/evenlistener/TestingEventListenerContext.java new file mode 100644 index 000000000000..a12c34787bca --- /dev/null +++ b/lib/trino-plugin-toolkit/src/test/java/io/trino/plugin/base/evenlistener/TestingEventListenerContext.java @@ -0,0 +1,54 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.plugin.base.evenlistener; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; +import io.trino.spi.eventlistener.EventListenerFactory; + +import static java.util.Objects.requireNonNull; + +public class TestingEventListenerContext + implements EventListenerFactory.EventListenerContext +{ + private final String trinoVersion; + + public TestingEventListenerContext() + { + this("trino-version"); + } + + public TestingEventListenerContext(String version) + { + this.trinoVersion = requireNonNull(version, "version is null"); + } + + @Override + public String getVersion() + { + return this.trinoVersion; + } + + @Override + public OpenTelemetry getOpenTelemetry() + { + return OpenTelemetry.noop(); + } + + @Override + public Tracer getTracer() + { + return OpenTelemetry.noop().getTracer("TEST_TRACER"); + } +} diff --git a/plugin/trino-http-event-listener/pom.xml b/plugin/trino-http-event-listener/pom.xml index debd159a12be..986ced7f6fdc 100644 --- a/plugin/trino-http-event-listener/pom.xml +++ b/plugin/trino-http-event-listener/pom.xml @@ -149,6 +149,13 @@ test + + io.trino + trino-plugin-toolkit + test-jar + test + + io.trino trino-testing-services diff --git a/plugin/trino-http-event-listener/src/main/java/io/trino/plugin/httpquery/HttpEventListenerFactory.java b/plugin/trino-http-event-listener/src/main/java/io/trino/plugin/httpquery/HttpEventListenerFactory.java index ddc6a6675a09..393b2bc6c694 100644 --- a/plugin/trino-http-event-listener/src/main/java/io/trino/plugin/httpquery/HttpEventListenerFactory.java +++ b/plugin/trino-http-event-listener/src/main/java/io/trino/plugin/httpquery/HttpEventListenerFactory.java @@ -38,7 +38,7 @@ public String getName() } @Override - public EventListener create(Map config) + public EventListener create(Map config, EventListenerContext context) { Bootstrap app = new Bootstrap( new JsonModule(), 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 607d7413cc45..0e1e86e7ce38 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 @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableMap; import io.airlift.json.JsonCodec; import io.trino.operator.RetryPolicy; +import io.trino.plugin.base.evenlistener.TestingEventListenerContext; import io.trino.spi.eventlistener.EventListener; import io.trino.spi.eventlistener.EventListenerFactory; import io.trino.spi.eventlistener.QueryCompletedEvent; @@ -520,6 +521,6 @@ private EventListener createEventListener(Map config) return factory.create(ImmutableMap.builder() .putAll(config) .put("bootstrap.quiet", "true") - .buildOrThrow()); + .buildOrThrow(), new TestingEventListenerContext()); } } diff --git a/plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListenerPlugin.java b/plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListenerPlugin.java index a0877c6414e9..c4ec3a3c889b 100644 --- a/plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListenerPlugin.java +++ b/plugin/trino-http-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpEventListenerPlugin.java @@ -14,6 +14,7 @@ package io.trino.plugin.httpquery; import com.google.common.collect.ImmutableMap; +import io.trino.plugin.base.evenlistener.TestingEventListenerContext; import io.trino.spi.eventlistener.EventListenerFactory; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ void testCreateEventListener() ImmutableMap.builder() .put("http-event-listener.connect-ingest-uri", "http://localhost:8080") .put("bootstrap.quiet", "true") - .buildOrThrow()) + .buildOrThrow(), new TestingEventListenerContext()) .shutdown(); } } diff --git a/plugin/trino-http-server-event-listener/pom.xml b/plugin/trino-http-server-event-listener/pom.xml index 0542afde24e4..5fc3997f1ef7 100644 --- a/plugin/trino-http-server-event-listener/pom.xml +++ b/plugin/trino-http-server-event-listener/pom.xml @@ -58,11 +58,6 @@ node - - io.airlift - tracing - - io.airlift units @@ -148,6 +143,13 @@ test + + io.trino + trino-plugin-toolkit + test-jar + test + + io.trino trino-testing-services diff --git a/plugin/trino-http-server-event-listener/src/main/java/io/trino/plugin/httpquery/HttpServerEventListenerFactory.java b/plugin/trino-http-server-event-listener/src/main/java/io/trino/plugin/httpquery/HttpServerEventListenerFactory.java index 3e5e747d50df..20766d571279 100644 --- a/plugin/trino-http-server-event-listener/src/main/java/io/trino/plugin/httpquery/HttpServerEventListenerFactory.java +++ b/plugin/trino-http-server-event-listener/src/main/java/io/trino/plugin/httpquery/HttpServerEventListenerFactory.java @@ -22,14 +22,14 @@ import io.airlift.jaxrs.JaxrsModule; import io.airlift.json.JsonModule; import io.airlift.node.NodeInfo; -import io.airlift.tracing.TracingModule; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; import io.trino.spi.eventlistener.EventListener; import io.trino.spi.eventlistener.EventListenerFactory; import io.trino.spi.eventlistener.QueryCompletedEvent; import java.util.Map; -import static com.google.common.base.MoreObjects.firstNonNull; import static io.airlift.configuration.ConfigBinder.configBinder; import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder; import static io.airlift.json.JsonCodecBinder.jsonCodecBinder; @@ -44,22 +44,21 @@ public String getName() } @Override - public EventListener create(Map config) + public EventListener create(Map config, EventListenerContext context) { - return createInternal(config, false); + return createInternal(config, context, false); } @VisibleForTesting - HttpServerEventListener createInternal(Map config, boolean testing) + HttpServerEventListener createInternal(Map config, EventListenerContext context, boolean testing) { Bootstrap app = new Bootstrap( new JsonModule(), new JaxrsModule(), - new TracingModule( - "http-event-listener", - firstNonNull(getClass().getPackage().getImplementationVersion(), "unknown")), testing ? new TestingHttpServerModule() : new HttpServerModule(), binder -> { + binder.bind(Tracer.class).toInstance(context.getTracer()); + binder.bind(OpenTelemetry.class).toInstance(context.getOpenTelemetry()); jsonCodecBinder(binder).bindJsonCodec(QueryCompletedEvent.class); configBinder(binder).bindConfig(HttpServerEventListenerConfig.class); binder.bind(HttpServerEventListener.class).in(Scopes.SINGLETON); 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 bc491a8c0699..bf7931a72b2b 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 @@ -20,6 +20,7 @@ import io.airlift.http.client.jetty.JettyHttpClient; import io.airlift.json.JsonCodec; import io.trino.operator.RetryPolicy; +import io.trino.plugin.base.evenlistener.TestingEventListenerContext; import io.trino.spi.eventlistener.QueryCompletedEvent; import io.trino.spi.eventlistener.QueryContext; import io.trino.spi.eventlistener.QueryIOMetadata; @@ -271,6 +272,7 @@ private HttpServerEventListener createEventListener() ImmutableMap.builder() .put("bootstrap.quiet", "true") .buildOrThrow(), + new TestingEventListenerContext(), true); } } diff --git a/plugin/trino-http-server-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpServerListenerPlugin.java b/plugin/trino-http-server-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpServerListenerPlugin.java index 00656c1d9d04..f10d96692f7e 100644 --- a/plugin/trino-http-server-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpServerListenerPlugin.java +++ b/plugin/trino-http-server-event-listener/src/test/java/io/trino/plugin/httpquery/TestHttpServerListenerPlugin.java @@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableMap; import io.trino.spi.eventlistener.EventListener; import io.trino.spi.eventlistener.EventListenerFactory; +import io.trino.testing.TestingEventListenerContext; import org.junit.jupiter.api.Test; import static com.google.common.collect.Iterables.getOnlyElement; @@ -27,10 +28,7 @@ void testCreateEventListener() { HttpServerEventListenerPlugin plugin = new HttpServerEventListenerPlugin(); EventListenerFactory factory = getOnlyElement(plugin.getEventListenerFactories()); - EventListener eventListener = factory.create( - ImmutableMap.of( - "http-server.http.port", "0")); - + EventListener eventListener = factory.create(ImmutableMap.of("http-server.http.port", "0"), new TestingEventListenerContext()); eventListener.shutdown(); } } diff --git a/plugin/trino-kafka-event-listener/pom.xml b/plugin/trino-kafka-event-listener/pom.xml index 08554bfd9d2c..2f142b24f597 100644 --- a/plugin/trino-kafka-event-listener/pom.xml +++ b/plugin/trino-kafka-event-listener/pom.xml @@ -156,6 +156,13 @@ test + + io.trino + trino-plugin-toolkit + test-jar + test + + io.trino trino-testing diff --git a/plugin/trino-kafka-event-listener/src/main/java/io/trino/plugin/eventlistener/kafka/KafkaEventListenerFactory.java b/plugin/trino-kafka-event-listener/src/main/java/io/trino/plugin/eventlistener/kafka/KafkaEventListenerFactory.java index 4ca141c37ebb..d57215cf5627 100644 --- a/plugin/trino-kafka-event-listener/src/main/java/io/trino/plugin/eventlistener/kafka/KafkaEventListenerFactory.java +++ b/plugin/trino-kafka-event-listener/src/main/java/io/trino/plugin/eventlistener/kafka/KafkaEventListenerFactory.java @@ -37,7 +37,7 @@ public String getName() } @Override - public EventListener create(Map config) + public EventListener create(Map config, EventListenerContext context) { Bootstrap app = new Bootstrap( new MBeanModule(), diff --git a/plugin/trino-kafka-event-listener/src/test/java/io/trino/plugin/eventlistener/kafka/TestKafkaEventListenerPlugin.java b/plugin/trino-kafka-event-listener/src/test/java/io/trino/plugin/eventlistener/kafka/TestKafkaEventListenerPlugin.java index 7ce3f7f6ce03..af7060496370 100644 --- a/plugin/trino-kafka-event-listener/src/test/java/io/trino/plugin/eventlistener/kafka/TestKafkaEventListenerPlugin.java +++ b/plugin/trino-kafka-event-listener/src/test/java/io/trino/plugin/eventlistener/kafka/TestKafkaEventListenerPlugin.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import io.trino.plugin.base.evenlistener.TestingEventListenerContext; import io.trino.spi.eventlistener.EventListener; import io.trino.spi.eventlistener.EventListenerFactory; import io.trino.testing.kafka.TestingKafka; @@ -84,7 +85,8 @@ void testEventListenerEndToEnd() .put("kafka-event-listener.request-timeout", "30s") .put("kafka-event-listener.excluded-fields", "ioMetadata") .put("kafka.security-protocol", "plaintext") - .buildOrThrow()); + .buildOrThrow(), + new TestingEventListenerContext()); try { // produce and consume a test created event diff --git a/plugin/trino-mysql-event-listener/pom.xml b/plugin/trino-mysql-event-listener/pom.xml index bc446c50d3fb..5f1310559bce 100644 --- a/plugin/trino-mysql-event-listener/pom.xml +++ b/plugin/trino-mysql-event-listener/pom.xml @@ -115,6 +115,13 @@ test + + io.trino + trino-plugin-toolkit + test-jar + test + + org.assertj assertj-core diff --git a/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListenerFactory.java b/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListenerFactory.java index e2685a224bd3..209408a56d2e 100644 --- a/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListenerFactory.java +++ b/plugin/trino-mysql-event-listener/src/main/java/io/trino/plugin/eventlistener/mysql/MysqlEventListenerFactory.java @@ -51,7 +51,7 @@ public String getName() } @Override - public EventListener create(Map config) + public EventListener create(Map config, EventListenerContext context) { Bootstrap app = new Bootstrap( new JsonModule(), 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 341067381ff1..34187254ec68 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 @@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; import io.airlift.json.JsonCodecFactory; +import io.trino.plugin.base.evenlistener.TestingEventListenerContext; import io.trino.spi.TrinoWarning; import io.trino.spi.connector.CatalogHandle.CatalogVersion; import io.trino.spi.connector.StandardWarningCode; @@ -349,7 +350,7 @@ void setup() mysqlContainer.start(); mysqlContainerUrl = getJdbcUrl(mysqlContainer); eventListener = new MysqlEventListenerFactory() - .create(Map.of("mysql-event-listener.db.url", mysqlContainerUrl)); + .create(Map.of("mysql-event-listener.db.url", mysqlContainerUrl), new TestingEventListenerContext()); jsonCodecFactory = new JsonCodecFactory(); } diff --git a/plugin/trino-openlineage/pom.xml b/plugin/trino-openlineage/pom.xml index daf626081f13..f6879be23037 100644 --- a/plugin/trino-openlineage/pom.xml +++ b/plugin/trino-openlineage/pom.xml @@ -151,6 +151,13 @@ test + + io.trino + trino-plugin-toolkit + test-jar + test + + io.trino trino-testing diff --git a/plugin/trino-openlineage/src/main/java/io/trino/plugin/openlineage/OpenLineageListenerFactory.java b/plugin/trino-openlineage/src/main/java/io/trino/plugin/openlineage/OpenLineageListenerFactory.java index ff8ee0386897..7662ab0e6247 100644 --- a/plugin/trino-openlineage/src/main/java/io/trino/plugin/openlineage/OpenLineageListenerFactory.java +++ b/plugin/trino-openlineage/src/main/java/io/trino/plugin/openlineage/OpenLineageListenerFactory.java @@ -30,7 +30,7 @@ public String getName() } @Override - public EventListener create(Map config) + public EventListener create(Map config, EventListenerContext context) { Bootstrap app = new Bootstrap(new OpenLineageListenerModule()); Injector injector = app diff --git a/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/OpenLineageListenerQueryRunner.java b/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/OpenLineageListenerQueryRunner.java index 3003b539ccd6..a6be86c4d719 100644 --- a/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/OpenLineageListenerQueryRunner.java +++ b/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/OpenLineageListenerQueryRunner.java @@ -15,6 +15,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.airlift.log.Logger; +import io.trino.plugin.base.evenlistener.TestingEventListenerContext; import io.trino.plugin.memory.MemoryPlugin; import io.trino.plugin.tpch.TpchPlugin; import io.trino.testing.DistributedQueryRunner; @@ -62,7 +63,7 @@ public Builder addListenerProperty(String key, String value) public DistributedQueryRunner build() throws Exception { - super.setEventListener(new OpenLineageListenerFactory().create(listenerProperties)); + super.setEventListener(new OpenLineageListenerFactory().create(listenerProperties, new TestingEventListenerContext())); DistributedQueryRunner queryRunner = super.build(); try { // catalog used for output data diff --git a/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TestOpenLineageListener.java b/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TestOpenLineageListener.java index 3314c5a4a470..f8c54d78be12 100644 --- a/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TestOpenLineageListener.java +++ b/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TestOpenLineageListener.java @@ -17,6 +17,7 @@ import io.openlineage.client.OpenLineage.Job; import io.openlineage.client.OpenLineage.Run; import io.openlineage.client.OpenLineage.RunEvent; +import io.trino.plugin.base.evenlistener.TestingEventListenerContext; import io.trino.spi.eventlistener.EventListener; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -94,6 +95,6 @@ void testGetStartEvent() private static EventListener createEventListener(Map config) { - return new OpenLineageListenerFactory().create(ImmutableMap.copyOf(config)); + return new OpenLineageListenerFactory().create(ImmutableMap.copyOf(config), new TestingEventListenerContext()); } } diff --git a/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TestOpenLineagePlugin.java b/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TestOpenLineagePlugin.java index c06d61e706bf..4fd48f8432b1 100644 --- a/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TestOpenLineagePlugin.java +++ b/plugin/trino-openlineage/src/test/java/io/trino/plugin/openlineage/TestOpenLineagePlugin.java @@ -14,6 +14,7 @@ package io.trino.plugin.openlineage; import com.google.common.collect.ImmutableMap; +import io.trino.plugin.base.evenlistener.TestingEventListenerContext; import io.trino.spi.eventlistener.EventListenerFactory; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ void testCreateEventListener() ImmutableMap.builder() .put("openlineage-event-listener.trino.uri", "http://localhost:8080") .put("bootstrap.quiet", "true") - .buildOrThrow()) + .buildOrThrow(), new TestingEventListenerContext()) .shutdown(); } } diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerPlugin.java b/testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerPlugin.java index 7a27b4d04604..2e3b7eaf5de1 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerPlugin.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestEventListenerPlugin.java @@ -58,7 +58,7 @@ public String getName() } @Override - public EventListener create(Map config) + public EventListener create(Map config, EventListenerContext context) { return new TestingEventListener(eventsCollector); }