You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/06/23 04:23:49 UTC

[GitHub] [inlong] luchunliang opened a new pull request, #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

luchunliang opened a new pull request, #4747:
URL: https://github.com/apache/inlong/pull/4747

   ### Prepare a Pull Request
   - Title : [INLONG-4741][Audit] AuditStore support ClickHouse sink
   - Fixes #4741 
   
   ### Motivation
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve?*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   *(Please pick either of the following options)*
   
   - [ ] This change is a trivial rework/code cleanup without any test coverage.
   
   - [ ] This change is already covered by existing tests, such as:
     *(please describe tests)*
   
   - [ ] This change added tests and can be verified as follows:
   
     *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a follow-up issue for adding the documentation
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] luchunliang commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
luchunliang commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r909424953


##########
inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/ClickHouseService.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.inlong.audit.service;
+
+import org.apache.inlong.audit.config.ClickHouseConfig;
+import org.apache.inlong.audit.db.entities.ClickHouseDataPo;
+import org.apache.inlong.audit.protocol.AuditData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * ClickHouseService
+ */
+public class ClickHouseService implements InsertData, AutoCloseable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ClickHouseService.class);
+    public static final String INSERT_SQL = "insert into audit_data (ip, docker_id, thread_id,\r\n"
+            + "      sdk_ts, packet_id, log_ts,\r\n"
+            + "      inlong_group_id, inlong_stream_id, audit_id,\r\n"
+            + "      count, size, delay, \r\n"
+            + "      update_time)\r\n"
+            + "    values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
+
+    private ClickHouseConfig chConfig;
+
+    private ScheduledExecutorService timerService = Executors.newScheduledThreadPool(1);

Review Comment:
   Change to newSingleThreadScheduledExecutor



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] luchunliang commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
luchunliang commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r905672164


##########
inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/ClickHouseService.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.inlong.audit.service;
+
+import org.apache.inlong.audit.config.ClickHouseConfig;
+import org.apache.inlong.audit.db.entities.ClickHouseDataPo;
+import org.apache.inlong.audit.protocol.AuditData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * ClickHouseService
+ */
+public class ClickHouseService implements InsertData, AutoCloseable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ClickHouseService.class);
+    public static final String INSERT_SQL = "insert into audit_data (ip, docker_id, thread_id,\r\n"
+            + "      sdk_ts, packet_id, log_ts,\r\n"
+            + "      inlong_group_id, inlong_stream_id, audit_id,\r\n"
+            + "      count, size, delay, \r\n"
+            + "      update_time)\r\n"
+            + "    values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
+
+    private ClickHouseConfig chConfig;
+
+    private ScheduledExecutorService timerService = Executors.newScheduledThreadPool(1);
+    private LinkedBlockingQueue<ClickHouseDataPo> batchQueue;
+    private AtomicBoolean needBatchOutput = new AtomicBoolean(false);
+    private AtomicInteger batchCounter = new AtomicInteger(0);
+
+    private Connection conn;
+
+    /**
+     * Constructor
+     * @param chConfig

Review Comment:
   [add method parameter description.](https://github.com/apache/inlong/pull/4747/commits/14e8f2b599452ec0b53dd4285975993eee366331)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] vernedeng commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
vernedeng commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r909383105


##########
inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/AuditMsgConsumerServer.java:
##########
@@ -59,12 +66,24 @@ public void afterPropertiesSet() {
         if (storeConfig.isElasticsearchStore()) {
             esService.startTimerRoutine();
         }
+        mqConsume.start();
+    }
 
-        if (mqConsume != null) {
-            mqConsume.start();
-        } else {
-            LOG.error("fail to auditMsgConsumerServer");
+    /**
+     * getInsertServiceList
+     * @return
+     */
+    private List<InsertData> getInsertServiceList() {
+        List<InsertData> insertServiceList = new ArrayList<>();
+        if (storeConfig.isMysqlStore()) {

Review Comment:
   may storeConfig matches multi store types? If not, **_swtich case_** may be a better format



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] luchunliang commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
luchunliang commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r909134514


##########
inlong-audit/conf/application.properties:
##########
@@ -77,3 +77,12 @@ elasticsearch.bulkInterval=10
 elasticsearch.bulkThreshold=5000
 elasticsearch.auditIdSet=1,2
 
+# clickhouse config
+clickhouse.driver=ru.yandex.clickhouse.ClickHouseDriver
+clickhouse.url=jdbc:clickhouse://9.135.145.171:8123/default

Review Comment:
   change the IP to 127.0.0.1



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] dockerzhang merged pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
dockerzhang merged PR #4747:
URL: https://github.com/apache/inlong/pull/4747


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] vernedeng commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
vernedeng commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r909386379


##########
inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/ClickHouseService.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.inlong.audit.service;
+
+import org.apache.inlong.audit.config.ClickHouseConfig;
+import org.apache.inlong.audit.db.entities.ClickHouseDataPo;
+import org.apache.inlong.audit.protocol.AuditData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * ClickHouseService
+ */
+public class ClickHouseService implements InsertData, AutoCloseable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ClickHouseService.class);
+    public static final String INSERT_SQL = "insert into audit_data (ip, docker_id, thread_id,\r\n"
+            + "      sdk_ts, packet_id, log_ts,\r\n"
+            + "      inlong_group_id, inlong_stream_id, audit_id,\r\n"
+            + "      count, size, delay, \r\n"
+            + "      update_time)\r\n"
+            + "    values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
+
+    private ClickHouseConfig chConfig;
+
+    private ScheduledExecutorService timerService = Executors.newScheduledThreadPool(1);

Review Comment:
   magic number,  use Executors.newSingleThreadScheduledExecutor() can fix it



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] dockerzhang commented on pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
dockerzhang commented on PR #4747:
URL: https://github.com/apache/inlong/pull/4747#issuecomment-1166931137

   @luchunliang thanks for completing this feature, there are two more things you need to do with PR.
   1, please add a configuration guide in the [audit doc](https://inlong.apache.org/docs/next/modules/audit/quick_start).
   2, add a license for the new `ru.yandex.clickhouse` dependency.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] healchow commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
healchow commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r904816744


##########
inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/ClickHouseService.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.inlong.audit.service;
+
+import org.apache.inlong.audit.config.ClickHouseConfig;
+import org.apache.inlong.audit.db.entities.ClickHouseDataPo;
+import org.apache.inlong.audit.protocol.AuditData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * ClickHouseService
+ */
+public class ClickHouseService implements InsertData, AutoCloseable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ClickHouseService.class);
+    public static final String INSERT_SQL = "insert into audit_data (ip, docker_id, thread_id,\r\n"
+            + "      sdk_ts, packet_id, log_ts,\r\n"
+            + "      inlong_group_id, inlong_stream_id, audit_id,\r\n"
+            + "      count, size, delay, \r\n"
+            + "      update_time)\r\n"
+            + "    values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
+
+    private ClickHouseConfig chConfig;
+
+    private ScheduledExecutorService timerService = Executors.newScheduledThreadPool(1);
+    private LinkedBlockingQueue<ClickHouseDataPo> batchQueue;
+    private AtomicBoolean needBatchOutput = new AtomicBoolean(false);
+    private AtomicInteger batchCounter = new AtomicInteger(0);
+
+    private Connection conn;
+
+    /**
+     * Constructor
+     * @param chConfig

Review Comment:
   It is suggested to add some description for param, return and throw in Java docs.
   Otherwise, IDEA or other IDE will be warned.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] gosonzhang commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
gosonzhang commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r907120915


##########
inlong-audit/audit-store/pom.xml:
##########
@@ -156,6 +156,10 @@
             <groupId>org.elasticsearch</groupId>
             <artifactId>elasticsearch</artifactId>
         </dependency>
+        <dependency>

Review Comment:
   Need to simultaneously increase the license and notice of binary dependencies



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] dockerzhang commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
dockerzhang commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r907010154


##########
inlong-audit/conf/application.properties:
##########
@@ -77,3 +77,12 @@ elasticsearch.bulkInterval=10
 elasticsearch.bulkThreshold=5000
 elasticsearch.auditIdSet=1,2
 
+# clickhouse config
+clickhouse.driver=ru.yandex.clickhouse.ClickHouseDriver
+clickhouse.url=jdbc:clickhouse://9.135.145.171:8123/default

Review Comment:
   remove the specific IP.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] luchunliang commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
luchunliang commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r909134384


##########
inlong-audit/audit-store/pom.xml:
##########
@@ -156,6 +156,10 @@
             <groupId>org.elasticsearch</groupId>
             <artifactId>elasticsearch</artifactId>
         </dependency>
+        <dependency>

Review Comment:
   Add license to licenses directory.
   ru.yandex.clickhouse:clickhouse-jdbc:0.3.1 - clickhouse-jdbc (https://github.com/ClickHouse/clickhouse-jdbc/tree/master/clickhouse-jdbc), (The Apache Software License, Version 2.0)
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] luchunliang commented on a diff in pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
luchunliang commented on code in PR #4747:
URL: https://github.com/apache/inlong/pull/4747#discussion_r909415048


##########
inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/AuditMsgConsumerServer.java:
##########
@@ -59,12 +66,24 @@ public void afterPropertiesSet() {
         if (storeConfig.isElasticsearchStore()) {
             esService.startTimerRoutine();
         }
+        mqConsume.start();
+    }
 
-        if (mqConsume != null) {
-            mqConsume.start();
-        } else {
-            LOG.error("fail to auditMsgConsumerServer");
+    /**
+     * getInsertServiceList
+     * @return
+     */
+    private List<InsertData> getInsertServiceList() {
+        List<InsertData> insertServiceList = new ArrayList<>();
+        if (storeConfig.isMysqlStore()) {

Review Comment:
   Audit data will store to multi cluster.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] dockerzhang commented on pull request #4747: [INLONG-4741][Audit] AuditStore support ClickHouse sink

Posted by GitBox <gi...@apache.org>.
dockerzhang commented on PR #4747:
URL: https://github.com/apache/inlong/pull/4747#issuecomment-1170664275

   please remove `LICENSE-clickhouse-jdbc.txt` file.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org