suneet-s commented on a change in pull request #9919:
URL: https://github.com/apache/druid/pull/9919#discussion_r430571970
##########
File path:
extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnector.java
##########
@@ -143,6 +144,7 @@ public MySQLConnector(
datasource.setConnectionInitSqls(ImmutableList.of("SET
sql_mode='ANSI_QUOTES'"));
this.dbi = new DBI(datasource);
+ this.dbi.setSQLLog(new SQLProfileLogger());
Review comment:
don't use `new` inside a constructor. This makes it difficult to test.
Guice inject the logger instead. Should the logger be a singleton?
##########
File path: server/src/main/java/org/apache/druid/metadata/SQLProfileLogger.java
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.druid.metadata;
+
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.tweak.SQLLog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * record the execution time of SQL to log file
+ */
+public class SQLProfileLogger implements SQLLog
+{
+ static Logger logger = LoggerFactory.getLogger(SQLProfileLogger.class);
+
+ @Override
+ public void logBeginTransaction(Handle h)
+ {
+ }
+
+ @Override
+ public void logCommitTransaction(long time, Handle h)
+ {
+ }
+
+ @Override
+ public void logRollbackTransaction(long time, Handle h)
+ {
+ }
+
+ @Override
+ public void logObtainHandle(long time, Handle h)
+ {
+ }
+
+ @Override
+ public void logReleaseHandle(Handle h)
+ {
+ }
+
+ @Override
+ public void logSQL(long time, String sql)
+ {
+ logger.info("statement:[{}] took {} millis", sql, time);
+ }
+
+ @Override
+ public void logPreparedBatch(long time, String sql, int count)
+ {
+ }
+
+ @Override
+ public BatchLogger logBatch()
+ {
+ return new BatchLogger()
+ {
+ private StringBuilder builder = new StringBuilder("batch:[");
+ private boolean added = false;
+
+ @Override
+ public void add(String sql)
+ {
+ added = true;
Review comment:
This should be protected by an `isEnabled` check - otherwise we'll be
building the StringBuilder only to throw it away
##########
File path: server/src/main/java/org/apache/druid/metadata/SQLProfileLogger.java
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.druid.metadata;
+
+import org.skife.jdbi.v2.Handle;
+import org.skife.jdbi.v2.tweak.SQLLog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * record the execution time of SQL to log file
+ */
+public class SQLProfileLogger implements SQLLog
+{
+ static Logger logger = LoggerFactory.getLogger(SQLProfileLogger.class);
+
+ @Override
+ public void logBeginTransaction(Handle h)
+ {
+ }
+
+ @Override
+ public void logCommitTransaction(long time, Handle h)
+ {
+ }
+
+ @Override
+ public void logRollbackTransaction(long time, Handle h)
+ {
+ }
+
+ @Override
+ public void logObtainHandle(long time, Handle h)
+ {
+ }
+
+ @Override
+ public void logReleaseHandle(Handle h)
+ {
+ }
+
+ @Override
+ public void logSQL(long time, String sql)
+ {
+ logger.info("statement:[{}] took {} millis", sql, time);
Review comment:
Why is info the correct level? These log lines are not needed to
indicate regular operation of Druid
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]