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

 ##########
 File path: 
oap-server/server-storage-plugin/storage-influxdb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/influxdb/query/LogQuery.java
 ##########
 @@ -0,0 +1,154 @@
+/*
+ * 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.query;
+
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.Const;
+import 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord;
+import org.apache.skywalking.oap.server.core.query.entity.ContentType;
+import org.apache.skywalking.oap.server.core.query.entity.Log;
+import org.apache.skywalking.oap.server.core.query.entity.LogState;
+import org.apache.skywalking.oap.server.core.query.entity.Logs;
+import org.apache.skywalking.oap.server.core.query.entity.Pagination;
+import org.apache.skywalking.oap.server.core.storage.query.ILogQueryDAO;
+import org.apache.skywalking.oap.server.storage.plugin.influxdb.InfluxClient;
+import org.apache.skywalking.oap.server.storage.plugin.influxdb.base.RecordDAO;
+import org.elasticsearch.common.Strings;
+import org.influxdb.dto.Query;
+import org.influxdb.dto.QueryResult;
+import org.influxdb.querybuilder.SelectQueryImpl;
+import org.influxdb.querybuilder.WhereQueryImpl;
+import org.influxdb.querybuilder.clauses.ConjunctionClause;
+
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.CONTENT;
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.CONTENT_TYPE;
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.ENDPOINT_ID;
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.IS_ERROR;
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.SERVICE_ID;
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.SERVICE_INSTANCE_ID;
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.STATUS_CODE;
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.TIMESTAMP;
+import static 
org.apache.skywalking.oap.server.core.analysis.manual.log.AbstractLogRecord.TRACE_ID;
+import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
+import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.gte;
+import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.lte;
+import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.select;
+
+@Slf4j
+public class LogQuery implements ILogQueryDAO {
+    private final InfluxClient client;
+
+    public LogQuery(InfluxClient client) {
+        this.client = client;
+    }
+
+    @Override
+    public Logs queryLogs(String metricName, int serviceId, int 
serviceInstanceId, int endpointId, String traceId,
+                          LogState state, String stateCode, Pagination paging, 
int from, int limit,
+                          long startTB, long endTB) throws IOException {
+        WhereQueryImpl<SelectQueryImpl> recallQuery = 
select().regex("*::field")
+            .from(client.getDatabase(), metricName)
+            .where();
+        if (serviceId != Const.NONE) {
+            recallQuery.and(eq(RecordDAO.TAG_SERVICE_ID, 
String.valueOf(serviceId)));
+        }
+        if (serviceInstanceId != Const.NONE) {
+            recallQuery.and(eq(SERVICE_INSTANCE_ID, serviceInstanceId));
+        }
+        if (endpointId != Const.NONE) {
+            recallQuery.and(eq(ENDPOINT_ID, endpointId));
+        }
+        if (!Strings.isNullOrEmpty(traceId)) {
+            recallQuery.and(eq(TRACE_ID, traceId));
+        }
+        switch (state) {
+            case ERROR: {
+                recallQuery.and(eq(IS_ERROR, true));
+                break;
+            }
+            case SUCCESS: {
+                recallQuery.and(eq(IS_ERROR, false));
+                break;
+            }
+        }
+        if (!Strings.isNullOrEmpty(stateCode)) {
+            recallQuery.and(eq(STATUS_CODE, stateCode));
+        }
+        recallQuery.and(gte(AbstractLogRecord.TIME_BUCKET, startTB))
+                   .and(lte(AbstractLogRecord.TIME_BUCKET, endTB));
+
+        if (from > Const.NONE) {
+            limit += from;
 
 Review comment:
   why do you need this? seems the `limit` doesn't include the `offset`

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