You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/10/24 11:42:00 UTC

[GitHub] [incubator-seatunnel] 531651225 opened a new pull request, #3174: [Feature][Connector-V2] influxdb sink connector

531651225 opened a new pull request, #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174

   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   refer to https://github.com/apache/incubator-seatunnel/issues/3018
   add Influxdb sink connector
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [x] Code changed are covered with tests, or it does not need tests for reason:
   * [x] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [x] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] EricJoy2048 closed pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
EricJoy2048 closed pull request #3174: [Feature][Connector-V2] influxdb sink connector
URL: https://github.com/apache/incubator-seatunnel/pull/3174


-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] 531651225 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
531651225 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1006406127


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-influxdb-e2e/src/test/java/org/apache/seatunnel/e2e/connector/influxdb/InfluxdbIT.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.seatunnel.e2e.connector.influxdb;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.InfluxDBConfig;
+import org.apache.seatunnel.e2e.common.TestResource;
+import org.apache.seatunnel.e2e.common.TestSuiteBase;
+import org.apache.seatunnel.e2e.common.container.TestContainer;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+import org.influxdb.dto.Query;
+import org.influxdb.dto.QueryResult;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.shaded.org.apache.commons.io.IOUtils;
+import org.testcontainers.utility.DockerImageName;
+import org.testcontainers.utility.DockerLoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import scala.Tuple2;
+
+@Slf4j
+public class InfluxdbIT extends TestSuiteBase implements TestResource {
+    private static final String IMAGE = "influxdb:1.8";
+    private static final String HOST = "influxdb-host";
+    private static final int PORT = 8086;
+    private static final String INFLUXDB_DATABASE = "test";
+    private static final String INFLUXDB_SOURCE_MEASUREMENT = "source";
+    private static final String INFLUXDB_SINK_MEASUREMENT = "sink";
+
+
+    private static final Tuple2<SeaTunnelRowType, List<SeaTunnelRow>> TEST_DATASET = generateTestDataSet();
+
+    private GenericContainer<?> influxdbContainer;
+    private String influxDBConnectUrl;
+
+    private InfluxDB influxDB;
+
+    @BeforeAll
+    @Override
+    public void startUp() throws Exception {
+        this.influxdbContainer = new GenericContainer<>(DockerImageName.parse(IMAGE))
+            .withNetwork(NETWORK)
+            .withNetworkAliases(HOST)
+            .withExposedPorts(PORT)
+            .withLogConsumer(new Slf4jLogConsumer(DockerLoggerFactory.getLogger(IMAGE)))
+            .waitingFor(new HostPortWaitStrategy()
+                .withStartupTimeout(Duration.ofMinutes(2)));
+        Startables.deepStart(Stream.of(influxdbContainer)).join();
+        influxDBConnectUrl = String.format("http://%s:%s", influxdbContainer.getHost(), influxdbContainer.getFirstMappedPort());
+        log.info("Influxdb container started");
+        this.initializeInfluxDBClient();
+        this.initSourceData();
+    }
+
+    private void initSourceData() {
+        influxDB.createDatabase(INFLUXDB_DATABASE);
+        BatchPoints batchPoints = BatchPoints
+                .database(INFLUXDB_DATABASE)
+                .build();
+        List<SeaTunnelRow> rows = TEST_DATASET._2();
+        SeaTunnelRowType rowType = TEST_DATASET._1();
+
+        for (int i = 0; i < rows.size(); i++) {
+            SeaTunnelRow row = rows.get(i);
+            Point point = Point.measurement(INFLUXDB_SOURCE_MEASUREMENT)
+                    .time((Long) row.getField(0), TimeUnit.NANOSECONDS)
+                    .tag(rowType.getFieldName(1), (String) row.getField(1))
+                    .addField(rowType.getFieldName(2), (String) row.getField(2))
+                    .addField(rowType.getFieldName(3), (Double) row.getField(3))
+                    .addField(rowType.getFieldName(4), (Long) row.getField(4))
+                    .addField(rowType.getFieldName(5), (Float) row.getField(5))
+                    .addField(rowType.getFieldName(6), (Integer) row.getField(6))
+                    .addField(rowType.getFieldName(7), (Short) row.getField(7))
+                    .addField(rowType.getFieldName(8), (Boolean) row.getField(8))
+                    .build();
+            batchPoints.point(point);
+        }
+        influxDB.write(batchPoints);
+    }
+
+    private static Tuple2<SeaTunnelRowType, List<SeaTunnelRow>> generateTestDataSet() {
+        SeaTunnelRowType rowType = new SeaTunnelRowType(
+            new String[]{
+                "time",
+                "label",
+                "c_string",
+                "c_double",
+                "c_bigint",
+                "c_float",
+                "c_int",
+                "c_smallint",
+                "c_boolean"
+            },
+            new SeaTunnelDataType[]{
+                BasicType.LONG_TYPE,
+                BasicType.STRING_TYPE,
+                BasicType.STRING_TYPE,
+                BasicType.DOUBLE_TYPE,
+                BasicType.LONG_TYPE,
+                BasicType.FLOAT_TYPE,
+                BasicType.INT_TYPE,
+                BasicType.SHORT_TYPE,
+                BasicType.BOOLEAN_TYPE
+            }
+        );
+
+        List<SeaTunnelRow> rows = new ArrayList<>();
+        for (int i = 0; i < 100; i++) {
+            SeaTunnelRow row = new SeaTunnelRow(
+                new Object[]{
+                    new Date().getTime(),
+                    String.format("label_%s", i),
+                    String.format("f1_%s", i),
+                    Double.parseDouble("1.1"),
+                    Long.parseLong("1"),
+                    Float.parseFloat("1.1"),
+                    Integer.valueOf(i),
+                    Short.parseShort("1"),
+                    i % 2 == 0 ? Boolean.TRUE : Boolean.FALSE
+                });
+            rows.add(row);
+        }
+        return Tuple2.apply(rowType, rows);
+    }
+
+    @AfterAll
+    @Override
+    public void tearDown() throws Exception {
+        influxDB.close();
+        influxdbContainer.stop();
+    }
+
+    @TestTemplate
+    public void testInfluxdb(TestContainer container) throws IOException, InterruptedException {
+        Container.ExecResult execResult = container.executeJob("/influxdb-to-influxdb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+        String sourceSql = String.format("select * from %s order by time", INFLUXDB_SOURCE_MEASUREMENT);
+        String sinkSql = String.format("select * from %s order by time", INFLUXDB_SINK_MEASUREMENT);
+        QueryResult sourceQueryResult = influxDB.query(new Query(sourceSql, INFLUXDB_DATABASE));
+        QueryResult sinkQueryResult = influxDB.query(new Query(sinkSql, INFLUXDB_DATABASE));
+        //assert data count
+        Assertions.assertEquals(sourceQueryResult.getResults().size(), sinkQueryResult.getResults().size());
+        //assert data values
+        List<List<Object>> sourceValues= sourceQueryResult.getResults().get(0).getSeries().get(0).getValues();
+        List<List<Object>> sinkValues = sourceQueryResult.getResults().get(0).getSeries().get(0).getValues();

Review Comment:
   > 
   
   thinks,i have fixed . PTAL



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
hailin0 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1003247375


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-influxdb-e2e/src/test/java/org/apache/seatunnel/e2e/connector/influxdb/InfluxdbIT.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.seatunnel.e2e.connector.influxdb;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.InfluxDBConfig;
+import org.apache.seatunnel.e2e.common.TestResource;
+import org.apache.seatunnel.e2e.common.TestSuiteBase;
+import org.apache.seatunnel.e2e.common.container.TestContainer;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+import org.influxdb.dto.Query;
+import org.influxdb.dto.QueryResult;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.shaded.org.apache.commons.io.IOUtils;
+import org.testcontainers.utility.DockerImageName;
+import org.testcontainers.utility.DockerLoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import scala.Tuple2;
+
+@Slf4j
+public class InfluxdbIT extends TestSuiteBase implements TestResource {
+    private static final String IMAGE = "influxdb:1.8";
+    private static final String HOST = "influxdb-host";
+    private static final int PORT = 8086;
+    private static final String INFLUXDB_DATABASE = "test";
+    private static final String INFLUXDB_SOURCE_MEASUREMENT = "source";
+    private static final String INFLUXDB_SINK_MEASUREMENT = "sink";
+
+
+    private static final Tuple2<SeaTunnelRowType, List<SeaTunnelRow>> TEST_DATASET = generateTestDataSet();
+
+    private GenericContainer<?> influxdbContainer;
+    private String influxDBConnectUrl;
+
+    private InfluxDB influxDB;
+
+    @BeforeAll
+    @Override
+    public void startUp() throws Exception {
+        this.influxdbContainer = new GenericContainer<>(DockerImageName.parse(IMAGE))
+            .withNetwork(NETWORK)
+            .withNetworkAliases(HOST)
+            .withExposedPorts(PORT)
+            .withLogConsumer(new Slf4jLogConsumer(DockerLoggerFactory.getLogger(IMAGE)))
+            .waitingFor(new HostPortWaitStrategy()
+                .withStartupTimeout(Duration.ofMinutes(2)));
+        Startables.deepStart(Stream.of(influxdbContainer)).join();
+        influxDBConnectUrl = String.format("http://%s:%s", influxdbContainer.getHost(), influxdbContainer.getFirstMappedPort());
+        log.info("Influxdb container started");
+        this.initializeInfluxDBClient();
+        this.initSourceData();
+    }
+
+    private void initSourceData() {
+        influxDB.createDatabase(INFLUXDB_DATABASE);
+        BatchPoints batchPoints = BatchPoints
+                .database(INFLUXDB_DATABASE)
+                .build();
+        List<SeaTunnelRow> rows = TEST_DATASET._2();
+        SeaTunnelRowType rowType = TEST_DATASET._1();
+
+        for (int i = 0; i < rows.size(); i++) {
+            SeaTunnelRow row = rows.get(i);
+            Point point = Point.measurement(INFLUXDB_SOURCE_MEASUREMENT)
+                    .time((Long) row.getField(0), TimeUnit.NANOSECONDS)
+                    .tag(rowType.getFieldName(1), (String) row.getField(1))
+                    .addField(rowType.getFieldName(2), (String) row.getField(2))
+                    .addField(rowType.getFieldName(3), (Double) row.getField(3))
+                    .addField(rowType.getFieldName(4), (Long) row.getField(4))
+                    .addField(rowType.getFieldName(5), (Float) row.getField(5))
+                    .addField(rowType.getFieldName(6), (Integer) row.getField(6))
+                    .addField(rowType.getFieldName(7), (Short) row.getField(7))
+                    .addField(rowType.getFieldName(8), (Boolean) row.getField(8))
+                    .build();
+            batchPoints.point(point);
+        }
+        influxDB.write(batchPoints);
+    }
+
+    private static Tuple2<SeaTunnelRowType, List<SeaTunnelRow>> generateTestDataSet() {
+        SeaTunnelRowType rowType = new SeaTunnelRowType(
+            new String[]{
+                "time",
+                "label",
+                "c_string",
+                "c_double",
+                "c_bigint",
+                "c_float",
+                "c_int",
+                "c_smallint",
+                "c_boolean"
+            },
+            new SeaTunnelDataType[]{
+                BasicType.LONG_TYPE,
+                BasicType.STRING_TYPE,
+                BasicType.STRING_TYPE,
+                BasicType.DOUBLE_TYPE,
+                BasicType.LONG_TYPE,
+                BasicType.FLOAT_TYPE,
+                BasicType.INT_TYPE,
+                BasicType.SHORT_TYPE,
+                BasicType.BOOLEAN_TYPE
+            }
+        );
+
+        List<SeaTunnelRow> rows = new ArrayList<>();
+        for (int i = 0; i < 100; i++) {
+            SeaTunnelRow row = new SeaTunnelRow(
+                new Object[]{
+                    new Date().getTime(),
+                    String.format("label_%s", i),
+                    String.format("f1_%s", i),
+                    Double.parseDouble("1.1"),
+                    Long.parseLong("1"),
+                    Float.parseFloat("1.1"),
+                    Integer.valueOf(i),
+                    Short.parseShort("1"),
+                    i % 2 == 0 ? Boolean.TRUE : Boolean.FALSE
+                });
+            rows.add(row);
+        }
+        return Tuple2.apply(rowType, rows);
+    }
+
+    @AfterAll
+    @Override
+    public void tearDown() throws Exception {
+        influxDB.close();
+        influxdbContainer.stop();
+    }
+
+    @TestTemplate
+    public void testInfluxdb(TestContainer container) throws IOException, InterruptedException {
+        Container.ExecResult execResult = container.executeJob("/influxdb-to-influxdb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+        String sourceSql = String.format("select * from %s order by time", INFLUXDB_SOURCE_MEASUREMENT);
+        String sinkSql = String.format("select * from %s order by time", INFLUXDB_SINK_MEASUREMENT);
+        QueryResult sourceQueryResult = influxDB.query(new Query(sourceSql, INFLUXDB_DATABASE));
+        QueryResult sinkQueryResult = influxDB.query(new Query(sinkSql, INFLUXDB_DATABASE));
+        //assert data count
+        Assertions.assertEquals(sourceQueryResult.getResults().size(), sinkQueryResult.getResults().size());
+        //assert data values
+        List<List<Object>> sourceValues= sourceQueryResult.getResults().get(0).getSeries().get(0).getValues();
+        List<List<Object>> sinkValues = sourceQueryResult.getResults().get(0).getSeries().get(0).getValues();

Review Comment:
   ```suggestion
           List<List<Object>> sinkValues = sinkQueryResult.getResults().get(0).getSeries().get(0).getValues();
   ```



##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-influxdb-e2e/pom.xml:
##########
@@ -0,0 +1,27 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

Review Comment:
   ```suggestion
   <?xml version="1.0" encoding="UTF-8"?>
   <!--
       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.
   -->
   <project xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   ```



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
hailin0 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1013927691


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-influxdb-e2e/src/test/resources/log4j.properties:
##########
@@ -0,0 +1,22 @@
+#

Review Comment:
   Remove this file.
   
   This is the common configuration of e2e
   https://github.com/apache/incubator-seatunnel/blob/dev/seatunnel-e2e/seatunnel-e2e-common/src/test/resources/log4j2.properties



##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-influxdb-e2e/src/test/java/org/apache/seatunnel/e2e/connector/influxdb/InfluxdbIT.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.seatunnel.e2e.connector.influxdb;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.InfluxDBConfig;
+import org.apache.seatunnel.e2e.common.TestResource;
+import org.apache.seatunnel.e2e.common.TestSuiteBase;
+import org.apache.seatunnel.e2e.common.container.TestContainer;
+
+import lombok.extern.slf4j.Slf4j;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+import org.influxdb.dto.Query;
+import org.influxdb.dto.QueryResult;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+import org.testcontainers.utility.DockerLoggerFactory;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import scala.Tuple2;
+
+@Slf4j
+public class InfluxdbIT extends TestSuiteBase implements TestResource {
+    private static final String IMAGE = "influxdb:1.8";
+    private static final String HOST = "influxdb-host";
+    private static final int PORT = 8086;
+    private static final String INFLUXDB_DATABASE = "test";
+    private static final String INFLUXDB_SOURCE_MEASUREMENT = "source";
+    private static final String INFLUXDB_SINK_MEASUREMENT = "sink";
+
+
+    private static final Tuple2<SeaTunnelRowType, List<SeaTunnelRow>> TEST_DATASET = generateTestDataSet();
+
+    private GenericContainer<?> influxdbContainer;
+    private String influxDBConnectUrl;
+
+    private InfluxDB influxDB;
+
+    @BeforeAll
+    @Override
+    public void startUp() throws Exception {
+        this.influxdbContainer = new GenericContainer<>(DockerImageName.parse(IMAGE))
+            .withNetwork(NETWORK)
+            .withNetworkAliases(HOST)
+            .withExposedPorts(PORT)
+            .withLogConsumer(new Slf4jLogConsumer(DockerLoggerFactory.getLogger(IMAGE)))
+            .waitingFor(new HostPortWaitStrategy()
+                .withStartupTimeout(Duration.ofMinutes(2)));
+        Startables.deepStart(Stream.of(influxdbContainer)).join();
+        influxDBConnectUrl = String.format("http://%s:%s", influxdbContainer.getHost(), influxdbContainer.getFirstMappedPort());
+        log.info("Influxdb container started");
+        this.initializeInfluxDBClient();
+        this.initSourceData();
+    }
+
+    private void initSourceData() {
+        influxDB.createDatabase(INFLUXDB_DATABASE);
+        BatchPoints batchPoints = BatchPoints
+                .database(INFLUXDB_DATABASE)
+                .build();
+        List<SeaTunnelRow> rows = TEST_DATASET._2();
+        SeaTunnelRowType rowType = TEST_DATASET._1();
+
+        for (int i = 0; i < rows.size(); i++) {
+            SeaTunnelRow row = rows.get(i);
+            Point point = Point.measurement(INFLUXDB_SOURCE_MEASUREMENT)
+                    .time((Long) row.getField(0), TimeUnit.NANOSECONDS)
+                    .tag(rowType.getFieldName(1), (String) row.getField(1))
+                    .addField(rowType.getFieldName(2), (String) row.getField(2))
+                    .addField(rowType.getFieldName(3), (Double) row.getField(3))
+                    .addField(rowType.getFieldName(4), (Long) row.getField(4))
+                    .addField(rowType.getFieldName(5), (Float) row.getField(5))
+                    .addField(rowType.getFieldName(6), (Integer) row.getField(6))
+                    .addField(rowType.getFieldName(7), (Short) row.getField(7))
+                    .addField(rowType.getFieldName(8), (Boolean) row.getField(8))
+                    .build();
+            batchPoints.point(point);
+        }
+        influxDB.write(batchPoints);
+    }
+
+    private static Tuple2<SeaTunnelRowType, List<SeaTunnelRow>> generateTestDataSet() {
+        SeaTunnelRowType rowType = new SeaTunnelRowType(
+            new String[]{
+                "time",
+                "label",
+                "c_string",
+                "c_double",
+                "c_bigint",
+                "c_float",
+                "c_int",
+                "c_smallint",
+                "c_boolean"
+            },
+            new SeaTunnelDataType[]{
+                BasicType.LONG_TYPE,
+                BasicType.STRING_TYPE,
+                BasicType.STRING_TYPE,
+                BasicType.DOUBLE_TYPE,
+                BasicType.LONG_TYPE,
+                BasicType.FLOAT_TYPE,
+                BasicType.INT_TYPE,
+                BasicType.SHORT_TYPE,
+                BasicType.BOOLEAN_TYPE
+            }
+        );
+
+        List<SeaTunnelRow> rows = new ArrayList<>();
+        for (int i = 0; i < 100; i++) {
+            SeaTunnelRow row = new SeaTunnelRow(
+                new Object[]{
+                    new Date().getTime(),
+                    String.format("label_%s", i),
+                    String.format("f1_%s", i),
+                    Double.parseDouble("1.1"),
+                    Long.parseLong("1"),
+                    Float.parseFloat("1.1"),
+                    Integer.valueOf(i),
+                    Short.parseShort("1"),
+                    i % 2 == 0 ? Boolean.TRUE : Boolean.FALSE
+                });
+            rows.add(row);
+        }
+        return Tuple2.apply(rowType, rows);
+    }
+
+    @AfterAll
+    @Override
+    public void tearDown() throws Exception {
+        influxDB.close();
+        influxdbContainer.stop();
+    }
+
+    @TestTemplate
+    public void testInfluxdb(TestContainer container) throws IOException, InterruptedException {
+        Container.ExecResult execResult = container.executeJob("/influxdb-to-influxdb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+        String sourceSql = String.format("select * from %s order by time", INFLUXDB_SOURCE_MEASUREMENT);
+        String sinkSql = String.format("select * from %s order by time", INFLUXDB_SINK_MEASUREMENT);
+        QueryResult sourceQueryResult = influxDB.query(new Query(sourceSql, INFLUXDB_DATABASE));
+        QueryResult sinkQueryResult = influxDB.query(new Query(sinkSql, INFLUXDB_DATABASE));
+        //assert data count
+        Assertions.assertEquals(sourceQueryResult.getResults().size(), sinkQueryResult.getResults().size());
+        //assert data values
+        List<List<Object>> sourceValues = sourceQueryResult.getResults().get(0).getSeries().get(0).getValues();
+        List<List<Object>> sinkValues = sinkQueryResult.getResults().get(0).getSeries().get(0).getValues();
+        for (Object sourceVal : sourceValues.get(0)) {
+            for (Object sinkVal : sinkValues.get(0)) {
+                if (!Objects.deepEquals(sourceVal, sinkVal)) {
+                    Assertions.assertEquals(sourceVal, sourceVal);

Review Comment:
   ```suggestion
                       Assertions.assertEquals(sourceVal, sinkVal);
   ```



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] 531651225 commented on pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
531651225 commented on PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#issuecomment-1305045573

   > Please add this connector to `seatunnel-dist/pom.xml`
   thinks,i have added in influxdb source connector,  PTAL @EricJoy2048 
   <img width="1331" alt="图片" src="https://user-images.githubusercontent.com/33744252/200223032-12fd078c-039e-474e-975a-41faf6993379.png">
   


-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] 531651225 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
531651225 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1006356716


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-influxdb-e2e/pom.xml:
##########
@@ -0,0 +1,27 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

Review Comment:
   > 
   
   thinks,i have fixed in new commit



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] ic4y commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
ic4y commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1016234449


##########
seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkWriter.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.influxdb.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.SinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.DefaultSerializer;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.Serializer;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+public class InfluxDBSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final Serializer serializer;
+    private InfluxDB influxDB;
+    private SinkConfig sinkConfig;
+    private final List<Point> batchList;
+    private ScheduledExecutorService scheduler;
+    private ScheduledFuture<?> scheduledFuture;
+    private volatile Exception flushException;
+    private final Integer batchIntervalMs;
+
+    public InfluxDBSinkWriter(Config pluginConfig,
+                              SeaTunnelRowType seaTunnelRowType) throws ConnectException {
+        this.sinkConfig = SinkConfig.loadConfig(pluginConfig);
+        this.batchIntervalMs = sinkConfig.getBatchIntervalMs();
+        this.serializer = new DefaultSerializer(
+                seaTunnelRowType, sinkConfig.getPrecision().getTimeUnit(), sinkConfig.getKeyTags(), sinkConfig.getKeyTime(), sinkConfig.getMeasurement());
+        this.batchList = new ArrayList<>();
+
+        if (batchIntervalMs != null) {
+            scheduler = Executors.newSingleThreadScheduledExecutor(
+                    new ThreadFactoryBuilder().setNameFormat("influxDB-sink-output-%s").build());
+            scheduledFuture = scheduler.scheduleAtFixedRate(
+                () -> {
+                    try {
+                        flush();
+                    } catch (IOException e) {
+                        flushException = e;
+                    }
+                },
+                batchIntervalMs,
+                batchIntervalMs,
+                TimeUnit.MILLISECONDS);
+        }
+
+        connect();
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) throws IOException {
+        Point record = serializer.serialize(element);
+        write(record);
+    }
+
+    @SneakyThrows
+    @Override
+    public Optional<Void> prepareCommit() {
+        // Flush to storage before snapshot state is performed
+        flush();
+        return super.prepareCommit();
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (scheduledFuture != null) {
+            scheduledFuture.cancel(false);
+            scheduler.shutdown();
+        }
+
+        flush();
+
+        if (influxDB != null) {
+            influxDB.close();
+            influxDB = null;
+        }
+    }
+
+    public synchronized void write(Point record) throws IOException {

Review Comment:
   There is no need to add synchronized, the writer is a single-threaded operation



##########
seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkWriter.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.influxdb.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.SinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.DefaultSerializer;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.Serializer;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+public class InfluxDBSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final Serializer serializer;
+    private InfluxDB influxDB;
+    private SinkConfig sinkConfig;
+    private final List<Point> batchList;
+    private ScheduledExecutorService scheduler;
+    private ScheduledFuture<?> scheduledFuture;
+    private volatile Exception flushException;
+    private final Integer batchIntervalMs;
+
+    public InfluxDBSinkWriter(Config pluginConfig,
+                              SeaTunnelRowType seaTunnelRowType) throws ConnectException {
+        this.sinkConfig = SinkConfig.loadConfig(pluginConfig);
+        this.batchIntervalMs = sinkConfig.getBatchIntervalMs();
+        this.serializer = new DefaultSerializer(
+                seaTunnelRowType, sinkConfig.getPrecision().getTimeUnit(), sinkConfig.getKeyTags(), sinkConfig.getKeyTime(), sinkConfig.getMeasurement());
+        this.batchList = new ArrayList<>();
+
+        if (batchIntervalMs != null) {
+            scheduler = Executors.newSingleThreadScheduledExecutor(
+                    new ThreadFactoryBuilder().setNameFormat("influxDB-sink-output-%s").build());
+            scheduledFuture = scheduler.scheduleAtFixedRate(
+                () -> {
+                    try {
+                        flush();
+                    } catch (IOException e) {
+                        flushException = e;
+                    }
+                },
+                batchIntervalMs,
+                batchIntervalMs,
+                TimeUnit.MILLISECONDS);
+        }
+
+        connect();
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) throws IOException {
+        Point record = serializer.serialize(element);
+        write(record);
+    }
+
+    @SneakyThrows
+    @Override
+    public Optional<Void> prepareCommit() {
+        // Flush to storage before snapshot state is performed
+        flush();
+        return super.prepareCommit();
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (scheduledFuture != null) {
+            scheduledFuture.cancel(false);
+            scheduler.shutdown();
+        }
+
+        flush();
+
+        if (influxDB != null) {
+            influxDB.close();
+            influxDB = null;
+        }
+    }
+
+    public synchronized void write(Point record) throws IOException {
+        checkFlushException();
+
+        batchList.add(record);
+        if (sinkConfig.getBatchSize() > 0
+                && batchList.size() >= sinkConfig.getBatchSize()) {
+            flush();
+        }
+    }
+
+    public synchronized void flush() throws IOException {

Review Comment:
   Ditto



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] 531651225 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
531651225 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1016072129


##########
seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkWriter.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.influxdb.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.SinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.DefaultSerializer;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.Serializer;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+public class InfluxDBSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final Serializer serializer;
+    private InfluxDB influxDB;
+    private SinkConfig sinkConfig;
+    private final List<Point> batchList;
+
+    private ScheduledExecutorService scheduler;
+    private ScheduledFuture<?> scheduledFuture;
+    private volatile boolean initialize;
+    private volatile Exception flushException;
+    private final Integer batchIntervalMs;
+
+    public InfluxDBSinkWriter(Config pluginConfig,
+                              SeaTunnelRowType seaTunnelRowType) throws ConnectException {
+        this.sinkConfig = SinkConfig.loadConfig(pluginConfig);
+        this.batchIntervalMs = sinkConfig.getBatchIntervalMs();
+        this.serializer = new DefaultSerializer(
+                seaTunnelRowType, sinkConfig.getPrecision().getTimeUnit(), sinkConfig.getKeyTags(), sinkConfig.getKeyTime(), sinkConfig.getMeasurement());
+        this.batchList = new ArrayList<>();
+
+        connect();
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) throws IOException {
+        Point record = serializer.serialize(element);
+        write(record);
+    }
+
+    @SneakyThrows
+    @Override
+    public Optional<Void> prepareCommit() {
+        // Flush to storage before snapshot state is performed
+        flush();
+        return super.prepareCommit();
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (scheduledFuture != null) {
+            scheduledFuture.cancel(false);
+            scheduler.shutdown();
+        }
+
+        flush();
+
+        if (influxDB != null) {
+            influxDB.close();
+            influxDB = null;
+        }
+    }
+
+    private void tryInit() throws IOException {
+        if (initialize) {
+            return;
+        }
+        initialize = true;
+        connect();
+        if (batchIntervalMs != null) {
+            scheduler = Executors.newSingleThreadScheduledExecutor(
+                    new ThreadFactoryBuilder().setNameFormat("influxDB-sink-output-%s").build());
+            scheduledFuture = scheduler.scheduleAtFixedRate(
+                () -> {
+                    try {
+                        flush();
+                    } catch (IOException e) {
+                        flushException = e;
+                    }
+                },
+                    batchIntervalMs,
+                    batchIntervalMs,
+                    TimeUnit.MILLISECONDS);
+        }
+    }
+
+    public synchronized void write(Point record) throws IOException {
+        tryInit();

Review Comment:
   > Why not build the scheduler thread in the constructor of InfluxDBSinkWriter
   
   thinks,i have fixed it. PTAL @ic4y 



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] 531651225 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
531651225 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1013567315


##########
docs/en/connector-v2/sink/InfluxDB.md:
##########
@@ -0,0 +1,98 @@
+# InfluxDB
+
+> InfluxDB sink connector
+
+## Description
+
+Write data to InfluxDB.
+
+## Key features
+
+- [ ] [exactly-once](../../concept/connector-v2-features.md)
+- [ ] [schema projection](../../concept/connector-v2-features.md)
+
+## Options
+
+| name                        | type     | required | default value                 |
+|-----------------------------|----------|----------|-------------------------------|
+| url                         | string   | yes      | -                             |
+| database                    | string   | yes      |                               |
+| measurement                 | string   | yes      |                               |
+| username                    | string   | no       | -                             |
+| password                    | string   | no       | -                             |
+| key_time                    | string   | yes      | processing time               |
+| key_tags                    | array    | no       | exclude `field` & `key_time`  |
+| batch_size                  | int      | no       | 1024                          |
+| batch_interval_ms           | int      | no       | -                             |
+| max_retries                 | int      | no       | -                             |
+| retry_backoff_multiplier_ms | int      | no       | -                             |
+| connect_timeout_ms          | long     | no       | 15000                         |
+
+### url
+the url to connect to influxDB e.g.
+``` 
+http://influxdb-host:8086
+```
+
+### database [string]
+
+The name of `influxDB` database
+
+### measurement [string]
+
+The name of `influxDB` measurement
+
+### username [string]
+
+`influxDB` user username
+
+### password [string]
+
+`influxDB` user password
+
+### key_time [string]
+
+Specify field-name of the `influxDB` measurement timestamp in SeaTunnelRow. If not specified, use processing-time as timestamp
+
+### key_tags [array]
+
+Specify field-name of the `influxDB` measurement tags in SeaTunnelRow.
+If not specified, include all fields with `influxDB` measurement field
+
+### batch_size [int]
+
+For batch writing, when the number of buffers reaches the number of `batch_size` or the time reaches `batch_interval_ms`, the data will be flushed into the influxDB
+
+### batch_interval_ms [int]
+
+For batch writing, when the number of buffers reaches the number of `batch_size` or the time reaches `batch_interval_ms`, the data will be flushed into the influxDB
+
+### max_retries [int]
+
+The number of retries to flush failed
+
+### retry_backoff_multiplier_ms [int]
+
+Using as a multiplier for generating the next delay for backoff
+
+### max_retry_backoff_ms [int]
+
+The amount of time to wait before attempting to retry a request to `influxDB`
+
+### connect_timeout_ms [long]
+the timeout for connecting to InfluxDB, in milliseconds 
+
+## Examples
+```hocon
+sink {
+    InfluxDB {
+        url = "http://influxdb-host:8086"
+        database = "test"
+        measurement = "sink"
+        key_time = "time"
+        key_tags = ["label"]
+        batch_size = 1
+    }
+}
+
+```

Review Comment:
   > Please add `changed log` reference https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/connector-v2/source/SftpFile.md
   thinks,i have fixed . PTAL
   



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] 531651225 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
531651225 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1016264010


##########
seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkWriter.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.influxdb.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.SinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.DefaultSerializer;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.Serializer;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+public class InfluxDBSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final Serializer serializer;
+    private InfluxDB influxDB;
+    private SinkConfig sinkConfig;
+    private final List<Point> batchList;
+    private ScheduledExecutorService scheduler;
+    private ScheduledFuture<?> scheduledFuture;
+    private volatile Exception flushException;
+    private final Integer batchIntervalMs;
+
+    public InfluxDBSinkWriter(Config pluginConfig,
+                              SeaTunnelRowType seaTunnelRowType) throws ConnectException {
+        this.sinkConfig = SinkConfig.loadConfig(pluginConfig);
+        this.batchIntervalMs = sinkConfig.getBatchIntervalMs();
+        this.serializer = new DefaultSerializer(
+                seaTunnelRowType, sinkConfig.getPrecision().getTimeUnit(), sinkConfig.getKeyTags(), sinkConfig.getKeyTime(), sinkConfig.getMeasurement());
+        this.batchList = new ArrayList<>();
+
+        if (batchIntervalMs != null) {
+            scheduler = Executors.newSingleThreadScheduledExecutor(
+                    new ThreadFactoryBuilder().setNameFormat("influxDB-sink-output-%s").build());
+            scheduledFuture = scheduler.scheduleAtFixedRate(
+                () -> {
+                    try {
+                        flush();
+                    } catch (IOException e) {
+                        flushException = e;
+                    }
+                },
+                batchIntervalMs,
+                batchIntervalMs,
+                TimeUnit.MILLISECONDS);
+        }
+
+        connect();
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) throws IOException {
+        Point record = serializer.serialize(element);
+        write(record);
+    }
+
+    @SneakyThrows
+    @Override
+    public Optional<Void> prepareCommit() {
+        // Flush to storage before snapshot state is performed
+        flush();
+        return super.prepareCommit();
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (scheduledFuture != null) {
+            scheduledFuture.cancel(false);
+            scheduler.shutdown();
+        }
+
+        flush();
+
+        if (influxDB != null) {
+            influxDB.close();
+            influxDB = null;
+        }
+    }
+
+    public synchronized void write(Point record) throws IOException {

Review Comment:
   > There is no need to add synchronized, the writer is a single-threaded operation
   
   thinks,i have fixed it in new commit. PTAL



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] EricJoy2048 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
EricJoy2048 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1009206447


##########
docs/en/connector-v2/sink/InfluxDB.md:
##########
@@ -0,0 +1,98 @@
+# InfluxDB
+
+> InfluxDB sink connector
+
+## Description
+
+Write data to InfluxDB.
+
+## Key features
+
+- [ ] [exactly-once](../../concept/connector-v2-features.md)
+- [ ] [schema projection](../../concept/connector-v2-features.md)
+
+## Options
+
+| name                        | type     | required | default value                 |
+|-----------------------------|----------|----------|-------------------------------|
+| url                         | string   | yes      | -                             |
+| database                    | string   | yes      |                               |
+| measurement                 | string   | yes      |                               |
+| username                    | string   | no       | -                             |
+| password                    | string   | no       | -                             |
+| key_time                    | string   | yes      | processing time               |
+| key_tags                    | array    | no       | exclude `field` & `key_time`  |
+| batch_size                  | int      | no       | 1024                          |
+| batch_interval_ms           | int      | no       | -                             |
+| max_retries                 | int      | no       | -                             |
+| retry_backoff_multiplier_ms | int      | no       | -                             |
+| connect_timeout_ms          | long     | no       | 15000                         |
+
+### url
+the url to connect to influxDB e.g.
+``` 
+http://influxdb-host:8086
+```
+
+### database [string]
+
+The name of `influxDB` database
+
+### measurement [string]
+
+The name of `influxDB` measurement
+
+### username [string]
+
+`influxDB` user username
+
+### password [string]
+
+`influxDB` user password
+
+### key_time [string]
+
+Specify field-name of the `influxDB` measurement timestamp in SeaTunnelRow. If not specified, use processing-time as timestamp
+
+### key_tags [array]
+
+Specify field-name of the `influxDB` measurement tags in SeaTunnelRow.
+If not specified, include all fields with `influxDB` measurement field
+
+### batch_size [int]
+
+For batch writing, when the number of buffers reaches the number of `batch_size` or the time reaches `batch_interval_ms`, the data will be flushed into the influxDB
+
+### batch_interval_ms [int]
+
+For batch writing, when the number of buffers reaches the number of `batch_size` or the time reaches `batch_interval_ms`, the data will be flushed into the influxDB
+
+### max_retries [int]
+
+The number of retries to flush failed
+
+### retry_backoff_multiplier_ms [int]
+
+Using as a multiplier for generating the next delay for backoff
+
+### max_retry_backoff_ms [int]
+
+The amount of time to wait before attempting to retry a request to `influxDB`
+
+### connect_timeout_ms [long]
+the timeout for connecting to InfluxDB, in milliseconds 
+
+## Examples
+```hocon
+sink {
+    InfluxDB {
+        url = "http://influxdb-host:8086"
+        database = "test"
+        measurement = "sink"
+        key_time = "time"
+        key_tags = ["label"]
+        batch_size = 1
+    }
+}
+
+```

Review Comment:
   Please add `changed log` reference https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/connector-v2/source/SftpFile.md



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] 531651225 commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
531651225 commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1015008026


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-influxdb-e2e/src/test/java/org/apache/seatunnel/e2e/connector/influxdb/InfluxdbIT.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.seatunnel.e2e.connector.influxdb;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.InfluxDBConfig;
+import org.apache.seatunnel.e2e.common.TestResource;
+import org.apache.seatunnel.e2e.common.TestSuiteBase;
+import org.apache.seatunnel.e2e.common.container.TestContainer;
+
+import lombok.extern.slf4j.Slf4j;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+import org.influxdb.dto.Query;
+import org.influxdb.dto.QueryResult;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+import org.testcontainers.utility.DockerLoggerFactory;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import scala.Tuple2;
+
+@Slf4j
+public class InfluxdbIT extends TestSuiteBase implements TestResource {
+    private static final String IMAGE = "influxdb:1.8";
+    private static final String HOST = "influxdb-host";
+    private static final int PORT = 8086;
+    private static final String INFLUXDB_DATABASE = "test";
+    private static final String INFLUXDB_SOURCE_MEASUREMENT = "source";
+    private static final String INFLUXDB_SINK_MEASUREMENT = "sink";
+
+
+    private static final Tuple2<SeaTunnelRowType, List<SeaTunnelRow>> TEST_DATASET = generateTestDataSet();
+
+    private GenericContainer<?> influxdbContainer;
+    private String influxDBConnectUrl;
+
+    private InfluxDB influxDB;
+
+    @BeforeAll
+    @Override
+    public void startUp() throws Exception {
+        this.influxdbContainer = new GenericContainer<>(DockerImageName.parse(IMAGE))
+            .withNetwork(NETWORK)
+            .withNetworkAliases(HOST)
+            .withExposedPorts(PORT)
+            .withLogConsumer(new Slf4jLogConsumer(DockerLoggerFactory.getLogger(IMAGE)))
+            .waitingFor(new HostPortWaitStrategy()
+                .withStartupTimeout(Duration.ofMinutes(2)));
+        Startables.deepStart(Stream.of(influxdbContainer)).join();
+        influxDBConnectUrl = String.format("http://%s:%s", influxdbContainer.getHost(), influxdbContainer.getFirstMappedPort());
+        log.info("Influxdb container started");
+        this.initializeInfluxDBClient();
+        this.initSourceData();
+    }
+
+    private void initSourceData() {
+        influxDB.createDatabase(INFLUXDB_DATABASE);
+        BatchPoints batchPoints = BatchPoints
+                .database(INFLUXDB_DATABASE)
+                .build();
+        List<SeaTunnelRow> rows = TEST_DATASET._2();
+        SeaTunnelRowType rowType = TEST_DATASET._1();
+
+        for (int i = 0; i < rows.size(); i++) {
+            SeaTunnelRow row = rows.get(i);
+            Point point = Point.measurement(INFLUXDB_SOURCE_MEASUREMENT)
+                    .time((Long) row.getField(0), TimeUnit.NANOSECONDS)
+                    .tag(rowType.getFieldName(1), (String) row.getField(1))
+                    .addField(rowType.getFieldName(2), (String) row.getField(2))
+                    .addField(rowType.getFieldName(3), (Double) row.getField(3))
+                    .addField(rowType.getFieldName(4), (Long) row.getField(4))
+                    .addField(rowType.getFieldName(5), (Float) row.getField(5))
+                    .addField(rowType.getFieldName(6), (Integer) row.getField(6))
+                    .addField(rowType.getFieldName(7), (Short) row.getField(7))
+                    .addField(rowType.getFieldName(8), (Boolean) row.getField(8))
+                    .build();
+            batchPoints.point(point);
+        }
+        influxDB.write(batchPoints);
+    }
+
+    private static Tuple2<SeaTunnelRowType, List<SeaTunnelRow>> generateTestDataSet() {
+        SeaTunnelRowType rowType = new SeaTunnelRowType(
+            new String[]{
+                "time",
+                "label",
+                "c_string",
+                "c_double",
+                "c_bigint",
+                "c_float",
+                "c_int",
+                "c_smallint",
+                "c_boolean"
+            },
+            new SeaTunnelDataType[]{
+                BasicType.LONG_TYPE,
+                BasicType.STRING_TYPE,
+                BasicType.STRING_TYPE,
+                BasicType.DOUBLE_TYPE,
+                BasicType.LONG_TYPE,
+                BasicType.FLOAT_TYPE,
+                BasicType.INT_TYPE,
+                BasicType.SHORT_TYPE,
+                BasicType.BOOLEAN_TYPE
+            }
+        );
+
+        List<SeaTunnelRow> rows = new ArrayList<>();
+        for (int i = 0; i < 100; i++) {
+            SeaTunnelRow row = new SeaTunnelRow(
+                new Object[]{
+                    new Date().getTime(),
+                    String.format("label_%s", i),
+                    String.format("f1_%s", i),
+                    Double.parseDouble("1.1"),
+                    Long.parseLong("1"),
+                    Float.parseFloat("1.1"),
+                    Integer.valueOf(i),
+                    Short.parseShort("1"),
+                    i % 2 == 0 ? Boolean.TRUE : Boolean.FALSE
+                });
+            rows.add(row);
+        }
+        return Tuple2.apply(rowType, rows);
+    }
+
+    @AfterAll
+    @Override
+    public void tearDown() throws Exception {
+        influxDB.close();
+        influxdbContainer.stop();
+    }
+
+    @TestTemplate
+    public void testInfluxdb(TestContainer container) throws IOException, InterruptedException {
+        Container.ExecResult execResult = container.executeJob("/influxdb-to-influxdb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+        String sourceSql = String.format("select * from %s order by time", INFLUXDB_SOURCE_MEASUREMENT);
+        String sinkSql = String.format("select * from %s order by time", INFLUXDB_SINK_MEASUREMENT);
+        QueryResult sourceQueryResult = influxDB.query(new Query(sourceSql, INFLUXDB_DATABASE));
+        QueryResult sinkQueryResult = influxDB.query(new Query(sinkSql, INFLUXDB_DATABASE));
+        //assert data count
+        Assertions.assertEquals(sourceQueryResult.getResults().size(), sinkQueryResult.getResults().size());
+        //assert data values
+        List<List<Object>> sourceValues = sourceQueryResult.getResults().get(0).getSeries().get(0).getValues();
+        List<List<Object>> sinkValues = sinkQueryResult.getResults().get(0).getSeries().get(0).getValues();
+        for (Object sourceVal : sourceValues.get(0)) {
+            for (Object sinkVal : sinkValues.get(0)) {
+                if (!Objects.deepEquals(sourceVal, sinkVal)) {
+                    Assertions.assertEquals(sourceVal, sourceVal);

Review Comment:
   > 
   
   thinks,i have fixed . PTAL



##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-influxdb-e2e/src/test/resources/log4j.properties:
##########
@@ -0,0 +1,22 @@
+#

Review Comment:
   > Remove this file.
   > 
   > This is the common configuration of e2e https://github.com/apache/incubator-seatunnel/blob/dev/seatunnel-e2e/seatunnel-e2e-common/src/test/resources/log4j2.properties
   
   thinks,i have fixed . PTAL



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] ic4y commented on a diff in pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
ic4y commented on code in PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174#discussion_r1015310809


##########
seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkWriter.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.influxdb.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.client.InfluxDBClient;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.SinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.DefaultSerializer;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.serialize.Serializer;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+public class InfluxDBSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final Serializer serializer;
+    private InfluxDB influxDB;
+    private SinkConfig sinkConfig;
+    private final List<Point> batchList;
+
+    private ScheduledExecutorService scheduler;
+    private ScheduledFuture<?> scheduledFuture;
+    private volatile boolean initialize;
+    private volatile Exception flushException;
+    private final Integer batchIntervalMs;
+
+    public InfluxDBSinkWriter(Config pluginConfig,
+                              SeaTunnelRowType seaTunnelRowType) throws ConnectException {
+        this.sinkConfig = SinkConfig.loadConfig(pluginConfig);
+        this.batchIntervalMs = sinkConfig.getBatchIntervalMs();
+        this.serializer = new DefaultSerializer(
+                seaTunnelRowType, sinkConfig.getPrecision().getTimeUnit(), sinkConfig.getKeyTags(), sinkConfig.getKeyTime(), sinkConfig.getMeasurement());
+        this.batchList = new ArrayList<>();
+
+        connect();
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) throws IOException {
+        Point record = serializer.serialize(element);
+        write(record);
+    }
+
+    @SneakyThrows
+    @Override
+    public Optional<Void> prepareCommit() {
+        // Flush to storage before snapshot state is performed
+        flush();
+        return super.prepareCommit();
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (scheduledFuture != null) {
+            scheduledFuture.cancel(false);
+            scheduler.shutdown();
+        }
+
+        flush();
+
+        if (influxDB != null) {
+            influxDB.close();
+            influxDB = null;
+        }
+    }
+
+    private void tryInit() throws IOException {
+        if (initialize) {
+            return;
+        }
+        initialize = true;
+        connect();
+        if (batchIntervalMs != null) {
+            scheduler = Executors.newSingleThreadScheduledExecutor(
+                    new ThreadFactoryBuilder().setNameFormat("influxDB-sink-output-%s").build());
+            scheduledFuture = scheduler.scheduleAtFixedRate(
+                () -> {
+                    try {
+                        flush();
+                    } catch (IOException e) {
+                        flushException = e;
+                    }
+                },
+                    batchIntervalMs,
+                    batchIntervalMs,
+                    TimeUnit.MILLISECONDS);
+        }
+    }
+
+    public synchronized void write(Point record) throws IOException {
+        tryInit();

Review Comment:
   Why not build the scheduler thread in the constructor of InfluxDBSinkWriter



-- 
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@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] ic4y merged pull request #3174: [Feature][Connector-V2] influxdb sink connector

Posted by GitBox <gi...@apache.org>.
ic4y merged PR #3174:
URL: https://github.com/apache/incubator-seatunnel/pull/3174


-- 
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@seatunnel.apache.org

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