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

 ##########
 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,194 @@
+/*
+ * 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.lang.invoke.MethodHandles;
+import java.util.List;
+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.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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.ti;
+
+/**
+ *
+ */
+public class InfluxClient implements Client {
+    private static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+    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.
+     */
+    public static final String TAG_ENTITY_ID = "entity_id";
+
+    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(), InfluxDB.ResponseFormat.MSGPACK);
+        influx.query(new Query("CREATE DATABASE " + database));
+
+        influx.setDatabase(database);
+        influx.enableBatch();
+    }
+
+    /**
+     * To get a connection of InfluxDB
+     *
+     * @return InfluxDB's connection
+     */
+    public InfluxDB getInflux() {
+        return influx;
+    }
+
+    /**
+     * Request with a {@link Query} to InfluxDB and return a set of {@link 
QueryResult.Result}s.
+     *
+     * @param query
+     * @return a set of Result.
+     * @throws IOException
+     */
+    public List<QueryResult.Result> query(Query query) throws IOException {
+        if (logger.isDebugEnabled()) {
+            logger.debug("SQL Statement: {}", query.getCommand());
+        }
+
+        try {
+            QueryResult result = getInflux().query(query);
+            if (result.hasError()) {
+                throw new IOException(result.getError());
+            }
+            return result.getResults();
+        } catch (Exception e) {
+            throw new IOException(e.getMessage() + System.lineSeparator() + 
"SQL Statement: " + query.getCommand(), e);
+        }
+    }
+
+    /**
+     * Request with one statement to InfluxDB and return a set of {@link 
QueryResult.Series}s.
+     *
+     * @param query
+     * @return a set of Series
+     * @throws IOException
+     */
+    public List<QueryResult.Series> queryForSeries(Query query) throws 
IOException {
+        return query(query).get(0).getSeries();
 
 Review comment:
   Yes.
   In `ITraceQueryDAO#queryBasicTraces(...)`, we have 2 statements in a 
request. The one gets the number of traces, and another recalls all trace data.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to