diff --git a/quidem-it/src/main/java/org/apache/druid/quidem/ExposedAsBrokerQueryComponentSupplierWrapper.java b/quidem-it/src/main/java/org/apache/druid/quidem/ExposedAsBrokerQueryComponentSupplierWrapper.java index b1a8ea63796..097b7df95c2 100644 --- a/quidem-it/src/main/java/org/apache/druid/quidem/ExposedAsBrokerQueryComponentSupplierWrapper.java +++ b/quidem-it/src/main/java/org/apache/druid/quidem/ExposedAsBrokerQueryComponentSupplierWrapper.java @@ -77,7 +77,6 @@ import org.apache.druid.initialization.Log4jShutterDownerModule; import org.apache.druid.initialization.ServerInjectorBuilder; import org.apache.druid.initialization.TombstoneDataStorageModule; import org.apache.druid.java.util.common.io.Closer; -import org.apache.druid.java.util.emitter.service.ServiceEmitter; import org.apache.druid.metadata.storage.derby.DerbyMetadataStorageDruidModule; import org.apache.druid.query.QueryRunnerFactoryConglomerate; import org.apache.druid.query.QuerySegmentWalker; @@ -96,6 +95,7 @@ import org.apache.druid.server.SpecificSegmentsQuerySegmentWalker; import org.apache.druid.server.SubqueryGuardrailHelper; import org.apache.druid.server.SubqueryGuardrailHelperProvider; import org.apache.druid.server.coordination.ServerType; +import org.apache.druid.server.emitter.EmitterModule; import org.apache.druid.server.http.BrokerResource; import org.apache.druid.server.http.SelfDiscoveryResource; import org.apache.druid.server.initialization.AuthorizerMapperModule; @@ -104,7 +104,6 @@ import org.apache.druid.server.initialization.jetty.JettyServerInitializer; import org.apache.druid.server.initialization.jetty.JettyServerModule; import org.apache.druid.server.log.NoopRequestLogger; import org.apache.druid.server.log.RequestLogger; -import org.apache.druid.server.metrics.NoopServiceEmitter; import org.apache.druid.server.metrics.QueryCountStatsProvider; import org.apache.druid.server.metrics.SubqueryCountStatsProvider; import org.apache.druid.server.router.TieredBrokerConfig; @@ -226,7 +225,6 @@ public class ExposedAsBrokerQueryComponentSupplierWrapper implements QueryCompon bind(String.class) .annotatedWith(DruidSchemaName.class) .toInstance(CalciteTests.DRUID_SCHEMA_NAME); - bind(ServiceEmitter.class).to(NoopServiceEmitter.class); bind(QuerySchedulerProvider.class).in(LazySingleton.class); bind(CalciteRulesManager.class).toInstance(new CalciteRulesManager(ImmutableSet.of())); bind(CatalogResolver.class).toInstance(CatalogResolver.NULL_RESOLVER); @@ -282,7 +280,7 @@ public class ExposedAsBrokerQueryComponentSupplierWrapper implements QueryCompon ExtensionsModule.SecondaryModule.class, new DruidAuthModule(), TLSCertificateCheckerModule.class, - // EmitterModule.class, + EmitterModule.class, HttpClientModule.global(), HttpClientModule.escalatedGlobal(), new HttpClientModule("druid.broker.http", Client.class, true), diff --git a/quidem-it/src/main/java/org/apache/druid/quidem/QuidemCaptureResource.java b/quidem-it/src/main/java/org/apache/druid/quidem/QuidemCaptureResource.java index c50dbb219a4..d6bf48e8836 100644 --- a/quidem-it/src/main/java/org/apache/druid/quidem/QuidemCaptureResource.java +++ b/quidem-it/src/main/java/org/apache/druid/quidem/QuidemCaptureResource.java @@ -27,8 +27,8 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintStream; import java.net.URI; @Path("/quidem") @@ -62,7 +62,10 @@ public class QuidemCaptureResource public synchronized String start() throws IOException { stopIfRunning(); - recorder = new QuidemRecorder(quidemURI, new PrintStream("/tmp/new.iq")); + recorder = new QuidemRecorder( + quidemURI, + new FileOutputStream("/tmp/new.iq") + ); return recorder.toString(); } diff --git a/quidem-it/src/main/java/org/apache/druid/quidem/QuidemRecorder.java b/quidem-it/src/main/java/org/apache/druid/quidem/QuidemRecorder.java index 38898ca6685..ec75d6cef0b 100644 --- a/quidem-it/src/main/java/org/apache/druid/quidem/QuidemRecorder.java +++ b/quidem-it/src/main/java/org/apache/druid/quidem/QuidemRecorder.java @@ -21,16 +21,24 @@ package org.apache.druid.quidem; import org.apache.druid.sql.calcite.run.DruidHook; +import java.io.FileOutputStream; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.net.URI; +import java.nio.charset.StandardCharsets; public class QuidemRecorder implements AutoCloseable, DruidHook { private PrintStream printStream; - public QuidemRecorder(URI quidemURI, PrintStream printStream) + public QuidemRecorder(URI quidemURI, FileOutputStream fileOutputStream) { - this.printStream = printStream; + try { + this.printStream = new PrintStream(fileOutputStream, true, StandardCharsets.UTF_8.name()); + } + catch (UnsupportedEncodingException e) { + throw new RuntimeException(); + } printStream.println("#started"); printStream.println("!connect " + quidemURI.toString()); DruidHook.register(DruidHook.SQL, this); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/run/DruidHook.java b/sql/src/main/java/org/apache/druid/sql/calcite/run/DruidHook.java index b4c6572ecfe..077c803829f 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/run/DruidHook.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/run/DruidHook.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.Objects; @FunctionalInterface - public interface DruidHook { static class HookKey @@ -73,14 +72,14 @@ public interface DruidHook void invoke(HookKey key, T object); - static Map, List> GLOBAL = new HashMap<>(); + static Map, List>> GLOBAL = new HashMap<>(); - public static void register(HookKey label, DruidHook hook) + static void register(HookKey label, DruidHook hook) { GLOBAL.computeIfAbsent(label, k -> new ArrayList<>()).add(hook); } - public static void unregister(HookKey key, DruidHook hook) + static void unregister(HookKey key, DruidHook hook) { GLOBAL.get(key).remove(hook); } @@ -100,7 +99,7 @@ public interface DruidHook public static void dispatch(HookKey key, T object) { - List hooks = GLOBAL.get(key); + List> hooks = GLOBAL.get(key); if (hooks != null) { for (DruidHook hook : hooks) { hook.invoke(key, object);