You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2020/02/19 05:05:02 UTC

[GitHub] [skywalking] aderm commented on a change in pull request #4239: Provide influxdb as a new storage plugin

aderm commented on a change in pull request #4239: Provide influxdb as a new storage plugin
URL: https://github.com/apache/skywalking/pull/4239#discussion_r381078944
 
 

 ##########
 File path: oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/InfluxClient.java
 ##########
 @@ -0,0 +1,191 @@
+/*
+ * 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.skywalking.oap.server.storage.plugin.influxdb;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.OkHttpClient;
+import org.apache.skywalking.oap.server.core.analysis.Downsampling;
+import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
+import org.apache.skywalking.oap.server.library.client.Client;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.influxdb.InfluxDB;
+import org.influxdb.InfluxDBFactory;
+import org.influxdb.dto.BatchPoints;
+import org.influxdb.dto.Point;
+import org.influxdb.dto.Query;
+import org.influxdb.dto.QueryResult;
+import org.influxdb.querybuilder.time.TimeInterval;
+
+import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.ti;
+
+/**
+ * InfluxDB connection maintainer, provides base data write/query API.
+ */
+@Slf4j
+public class InfluxClient implements Client {
+    private InfluxStorageConfig config;
+    private InfluxDB influx;
+
+    /**
+     * A constant, the name of time field in Time-series database.
+     */
+    public static final String TIME = "time";
+    /**
+     * A constant, the name of tag of time_bucket.
+     */
+    public static final String TAG_TIME_BUCKET = "_time_bucket";
+
+    private final String database;
+
+    public InfluxClient(InfluxStorageConfig config) {
+        this.config = config;
+        this.database = config.getDatabase();
+    }
+
+    public final String getDatabase() {
+        return database;
+    }
+
+    @Override
+    public void connect() {
+        influx = InfluxDBFactory.connect(config.getUrl(), config.getUser(), config.getPassword(),
+                                         new OkHttpClient.Builder().readTimeout(3, TimeUnit.MINUTES)
+                                                                   .writeTimeout(3, TimeUnit.MINUTES),
+                                         InfluxDB.ResponseFormat.MSGPACK
+        );
+        influx.query(new Query("CREATE DATABASE " + database));
+
+        influx.enableBatch(config.getActions(), config.getDuration(), TimeUnit.MILLISECONDS);
+        influx.setDatabase(database);
+    }
+
+    /**
+     * To get a connection of InfluxDB.
+     *
+     * @return InfluxDB's connection
+     */
+    private InfluxDB getInflux() {
+        return influx;
 
 Review comment:
   recommend add a null value to judge here,subsequence queries are based on the available influx

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services