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 2022/11/22 10:05:51 UTC

[GitHub] [skywalking] wankai123 opened a new pull request, #10004: [Feature] Zipkin module support BanyanDB storage.

wankai123 opened a new pull request, #10004:
URL: https://github.com/apache/skywalking/pull/10004

   * Zipkin traces query API, sort the result set by start time by default.
   
   - [ ] If this is non-trivial feature, paste the links/URLs to the design doc.
   - [X] Update the documentation to include this new feature.
   - [X] Tests(including UT, IT, E2E) are added to verify the new feature.
   - [ ] If it's UI related, attach the screenshots below.
   
   - [X] If this pull request closes/resolves/fixes an existing issue, replace the issue number. Closes #9183 .
   - [X] Update the [`CHANGES` log](https://github.com/apache/skywalking/blob/master/docs/en/changes/changes.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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking] wu-sheng commented on a diff in pull request #10004: [Feature] Zipkin module support BanyanDB storage.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #10004:
URL: https://github.com/apache/skywalking/pull/10004#discussion_r1029926185


##########
oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBZipkinQueryDAO.java:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.banyandb;
+
+import com.google.common.collect.ImmutableSet;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.skywalking.banyandb.v1.client.AbstractCriteria;
+import org.apache.skywalking.banyandb.v1.client.AbstractQuery;
+import org.apache.skywalking.banyandb.v1.client.DataPoint;
+import org.apache.skywalking.banyandb.v1.client.MeasureQuery;
+import org.apache.skywalking.banyandb.v1.client.MeasureQueryResponse;
+import org.apache.skywalking.banyandb.v1.client.RowEntity;
+import org.apache.skywalking.banyandb.v1.client.StreamQuery;
+import org.apache.skywalking.banyandb.v1.client.StreamQueryResponse;
+import org.apache.skywalking.banyandb.v1.client.TimestampRange;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.storage.query.IZipkinQueryDAO;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceRelationTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceSpanTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinSpanRecord;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.apache.skywalking.oap.server.library.util.StringUtil;
+import org.apache.skywalking.oap.server.storage.plugin.banyandb.stream.AbstractBanyanDBDAO;
+import zipkin2.Span;
+import zipkin2.storage.QueryRequest;
+
+public class BanyanDBZipkinQueryDAO extends AbstractBanyanDBDAO implements IZipkinQueryDAO {
+    private final static int QUERY_MAX_SIZE = Integer.MAX_VALUE;
+    private static final Set<String> SERVICE_TRAFFIC_TAGS = ImmutableSet.of(ZipkinServiceTraffic.SERVICE_NAME);
+    private static final Set<String> REMOTE_SERVICE_TRAFFIC_TAGS = ImmutableSet.of(
+        ZipkinServiceRelationTraffic.REMOTE_SERVICE_NAME);
+    private static final Set<String> SPAN_TRAFFIC_TAGS = ImmutableSet.of(ZipkinServiceSpanTraffic.SPAN_NAME);
+    private static final Set<String> TRACE_ID = ImmutableSet.of(ZipkinSpanRecord.TRACE_ID);
+    private static final Set<String> TRACE_TAGS = ImmutableSet.of(
+        ZipkinSpanRecord.TRACE_ID,
+        ZipkinSpanRecord.SPAN_ID,
+        ZipkinSpanRecord.PARENT_ID,
+        ZipkinSpanRecord.KIND,
+        ZipkinSpanRecord.TIMESTAMP,
+        ZipkinSpanRecord.TIMESTAMP_MILLIS,
+        ZipkinSpanRecord.DURATION,
+        ZipkinSpanRecord.NAME,
+        ZipkinSpanRecord.DEBUG,
+        ZipkinSpanRecord.SHARED,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_SERVICE_NAME,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_IPV4,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_IPV6,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_PORT,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_SERVICE_NAME,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_IPV4,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_IPV6,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_PORT,
+        ZipkinSpanRecord.TAGS,
+        ZipkinSpanRecord.ANNOTATIONS
+    );
+
+    public BanyanDBZipkinQueryDAO(BanyanDBStorageClient client) {
+        super(client);
+    }
+
+    @Override
+    public List<String> getServiceNames() throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceTraffic.INDEX_NAME,
+                  SERVICE_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> services = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            services.add(dataPoint.getTagValue(ZipkinServiceTraffic.SERVICE_NAME));
+        }
+        return services;
+    }
+
+    @Override
+    public List<String> getRemoteServiceNames(final String serviceName) throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceRelationTraffic.INDEX_NAME,
+                  REMOTE_SERVICE_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        if (StringUtil.isNotEmpty(serviceName)) {
+                            query.and(eq(ZipkinServiceRelationTraffic.SERVICE_NAME, serviceName));
+                        }
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> remoteServices = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            remoteServices.add(dataPoint.getTagValue(ZipkinServiceRelationTraffic.REMOTE_SERVICE_NAME));
+        }
+        return remoteServices;
+    }
+
+    @Override
+    public List<String> getSpanNames(final String serviceName) throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceSpanTraffic.INDEX_NAME,
+                  SPAN_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        if (StringUtil.isNotEmpty(serviceName)) {
+                            query.and(eq(ZipkinServiceSpanTraffic.SERVICE_NAME, serviceName));
+                        }
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> spanNames = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            spanNames.add(dataPoint.getTagValue(ZipkinServiceSpanTraffic.SPAN_NAME));
+        }
+        return spanNames;
+    }
+
+    @Override
+    public List<Span> getTrace(final String traceId) throws IOException {
+        StreamQueryResponse resp =
+            query(ZipkinSpanRecord.INDEX_NAME, TRACE_TAGS,
+                  new QueryBuilder<StreamQuery>() {
+
+                      @Override
+                      protected void apply(StreamQuery query) {
+                          query.and(eq(ZipkinSpanRecord.TRACE_ID, traceId));
+                          query.setLimit(QUERY_MAX_SIZE);
+                      }
+                  }
+            );
+
+        List<Span> trace = new ArrayList<>(resp.getElements().size());
+
+        for (final RowEntity rowEntity : resp.getElements()) {
+            ZipkinSpanRecord spanRecord = new ZipkinSpanRecord.Builder().storage2Entity(
+                new BanyanDBConverter.StorageToStream(ZipkinSpanRecord.INDEX_NAME, rowEntity));
+            trace.add(ZipkinSpanRecord.buildSpanFromRecord(spanRecord));
+        }
+
+        return trace;
+    }
+
+    @Override
+    public List<List<Span>> getTraces(final QueryRequest request, Duration duration) throws IOException {
+        final int tracesLimit = request.limit();
+        int scrollLimit = 1000;
+        int scrollFrom = 0;
+        Set<String> traceIds = new HashSet<>();
+        while (traceIds.size() < tracesLimit) {
+            Set<String> resp = getTraceIds(request, duration, scrollFrom, scrollLimit);

Review Comment:
   Time range is user condition, not ours. Unless we use some kind of order by and rolling according to last read record. But is the timestamp accurate enough?
    Is it millisecond? Or it is just second but formated in millisecond format? @wankai123 



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking] wu-sheng commented on a diff in pull request #10004: [Feature] Zipkin module support BanyanDB storage.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #10004:
URL: https://github.com/apache/skywalking/pull/10004#discussion_r1029244547


##########
oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBZipkinQueryDAO.java:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.banyandb;
+
+import com.google.common.collect.ImmutableSet;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.skywalking.banyandb.v1.client.AbstractCriteria;
+import org.apache.skywalking.banyandb.v1.client.AbstractQuery;
+import org.apache.skywalking.banyandb.v1.client.DataPoint;
+import org.apache.skywalking.banyandb.v1.client.MeasureQuery;
+import org.apache.skywalking.banyandb.v1.client.MeasureQueryResponse;
+import org.apache.skywalking.banyandb.v1.client.RowEntity;
+import org.apache.skywalking.banyandb.v1.client.StreamQuery;
+import org.apache.skywalking.banyandb.v1.client.StreamQueryResponse;
+import org.apache.skywalking.banyandb.v1.client.TimestampRange;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.storage.query.IZipkinQueryDAO;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceRelationTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceSpanTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinSpanRecord;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.apache.skywalking.oap.server.library.util.StringUtil;
+import org.apache.skywalking.oap.server.storage.plugin.banyandb.stream.AbstractBanyanDBDAO;
+import zipkin2.Span;
+import zipkin2.storage.QueryRequest;
+
+public class BanyanDBZipkinQueryDAO extends AbstractBanyanDBDAO implements IZipkinQueryDAO {
+    private final static int QUERY_MAX_SIZE = Integer.MAX_VALUE;
+    private static final Set<String> SERVICE_TRAFFIC_TAGS = ImmutableSet.of(ZipkinServiceTraffic.SERVICE_NAME);
+    private static final Set<String> REMOTE_SERVICE_TRAFFIC_TAGS = ImmutableSet.of(
+        ZipkinServiceRelationTraffic.REMOTE_SERVICE_NAME);
+    private static final Set<String> SPAN_TRAFFIC_TAGS = ImmutableSet.of(ZipkinServiceSpanTraffic.SPAN_NAME);
+    private static final Set<String> TRACE_ID = ImmutableSet.of(ZipkinSpanRecord.TRACE_ID);
+    private static final Set<String> TRACE_TAGS = ImmutableSet.of(
+        ZipkinSpanRecord.TRACE_ID,
+        ZipkinSpanRecord.SPAN_ID,
+        ZipkinSpanRecord.PARENT_ID,
+        ZipkinSpanRecord.KIND,
+        ZipkinSpanRecord.TIMESTAMP,
+        ZipkinSpanRecord.TIMESTAMP_MILLIS,
+        ZipkinSpanRecord.DURATION,
+        ZipkinSpanRecord.NAME,
+        ZipkinSpanRecord.DEBUG,
+        ZipkinSpanRecord.SHARED,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_SERVICE_NAME,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_IPV4,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_IPV6,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_PORT,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_SERVICE_NAME,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_IPV4,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_IPV6,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_PORT,
+        ZipkinSpanRecord.TAGS,
+        ZipkinSpanRecord.ANNOTATIONS
+    );
+
+    public BanyanDBZipkinQueryDAO(BanyanDBStorageClient client) {
+        super(client);
+    }
+
+    @Override
+    public List<String> getServiceNames() throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceTraffic.INDEX_NAME,
+                  SERVICE_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> services = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            services.add(dataPoint.getTagValue(ZipkinServiceTraffic.SERVICE_NAME));
+        }
+        return services;
+    }
+
+    @Override
+    public List<String> getRemoteServiceNames(final String serviceName) throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceRelationTraffic.INDEX_NAME,
+                  REMOTE_SERVICE_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        if (StringUtil.isNotEmpty(serviceName)) {
+                            query.and(eq(ZipkinServiceRelationTraffic.SERVICE_NAME, serviceName));
+                        }
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> remoteServices = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            remoteServices.add(dataPoint.getTagValue(ZipkinServiceRelationTraffic.REMOTE_SERVICE_NAME));
+        }
+        return remoteServices;
+    }
+
+    @Override
+    public List<String> getSpanNames(final String serviceName) throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceSpanTraffic.INDEX_NAME,
+                  SPAN_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        if (StringUtil.isNotEmpty(serviceName)) {
+                            query.and(eq(ZipkinServiceSpanTraffic.SERVICE_NAME, serviceName));
+                        }
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> spanNames = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            spanNames.add(dataPoint.getTagValue(ZipkinServiceSpanTraffic.SPAN_NAME));
+        }
+        return spanNames;
+    }
+
+    @Override
+    public List<Span> getTrace(final String traceId) throws IOException {
+        StreamQueryResponse resp =
+            query(ZipkinSpanRecord.INDEX_NAME, TRACE_TAGS,
+                  new QueryBuilder<StreamQuery>() {
+
+                      @Override
+                      protected void apply(StreamQuery query) {
+                          query.and(eq(ZipkinSpanRecord.TRACE_ID, traceId));
+                          query.setLimit(QUERY_MAX_SIZE);
+                      }
+                  }
+            );
+
+        List<Span> trace = new ArrayList<>(resp.getElements().size());
+
+        for (final RowEntity rowEntity : resp.getElements()) {
+            ZipkinSpanRecord spanRecord = new ZipkinSpanRecord.Builder().storage2Entity(
+                new BanyanDBConverter.StorageToStream(ZipkinSpanRecord.INDEX_NAME, rowEntity));
+            trace.add(ZipkinSpanRecord.buildSpanFromRecord(spanRecord));
+        }
+
+        return trace;
+    }
+
+    @Override
+    public List<List<Span>> getTraces(final QueryRequest request, Duration duration) throws IOException {
+        final int tracesLimit = request.limit();
+        int scrollLimit = 1000;
+        int scrollFrom = 0;
+        Set<String> traceIds = new HashSet<>();
+        while (traceIds.size() < tracesLimit) {
+            Set<String> resp = getTraceIds(request, duration, scrollFrom, scrollLimit);

Review Comment:
   @hanahmily @lujiajing1126 Please confirm this is good enough. 
   
   Zipkin provides trace IDs query to the Span table, and also requires distinct trace IDs according to the `limit` condition. It is using `aggregation` or `distinct .. group by` in other storage options, but BanyanDB doesn't provide this.
   So, we have to do a rolling query, but as BanyanDB can't provide a rolling query(no rolling ID concept), we have to use `from... to...`



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking] wu-sheng merged pull request #10004: [Feature] Zipkin module support BanyanDB storage.

Posted by GitBox <gi...@apache.org>.
wu-sheng merged PR #10004:
URL: https://github.com/apache/skywalking/pull/10004


-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking] wankai123 commented on a diff in pull request #10004: [Feature] Zipkin module support BanyanDB storage.

Posted by GitBox <gi...@apache.org>.
wankai123 commented on code in PR #10004:
URL: https://github.com/apache/skywalking/pull/10004#discussion_r1029939792


##########
oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBZipkinQueryDAO.java:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.banyandb;
+
+import com.google.common.collect.ImmutableSet;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.skywalking.banyandb.v1.client.AbstractCriteria;
+import org.apache.skywalking.banyandb.v1.client.AbstractQuery;
+import org.apache.skywalking.banyandb.v1.client.DataPoint;
+import org.apache.skywalking.banyandb.v1.client.MeasureQuery;
+import org.apache.skywalking.banyandb.v1.client.MeasureQueryResponse;
+import org.apache.skywalking.banyandb.v1.client.RowEntity;
+import org.apache.skywalking.banyandb.v1.client.StreamQuery;
+import org.apache.skywalking.banyandb.v1.client.StreamQueryResponse;
+import org.apache.skywalking.banyandb.v1.client.TimestampRange;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.storage.query.IZipkinQueryDAO;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceRelationTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceSpanTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinSpanRecord;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.apache.skywalking.oap.server.library.util.StringUtil;
+import org.apache.skywalking.oap.server.storage.plugin.banyandb.stream.AbstractBanyanDBDAO;
+import zipkin2.Span;
+import zipkin2.storage.QueryRequest;
+
+public class BanyanDBZipkinQueryDAO extends AbstractBanyanDBDAO implements IZipkinQueryDAO {
+    private final static int QUERY_MAX_SIZE = Integer.MAX_VALUE;
+    private static final Set<String> SERVICE_TRAFFIC_TAGS = ImmutableSet.of(ZipkinServiceTraffic.SERVICE_NAME);
+    private static final Set<String> REMOTE_SERVICE_TRAFFIC_TAGS = ImmutableSet.of(
+        ZipkinServiceRelationTraffic.REMOTE_SERVICE_NAME);
+    private static final Set<String> SPAN_TRAFFIC_TAGS = ImmutableSet.of(ZipkinServiceSpanTraffic.SPAN_NAME);
+    private static final Set<String> TRACE_ID = ImmutableSet.of(ZipkinSpanRecord.TRACE_ID);
+    private static final Set<String> TRACE_TAGS = ImmutableSet.of(
+        ZipkinSpanRecord.TRACE_ID,
+        ZipkinSpanRecord.SPAN_ID,
+        ZipkinSpanRecord.PARENT_ID,
+        ZipkinSpanRecord.KIND,
+        ZipkinSpanRecord.TIMESTAMP,
+        ZipkinSpanRecord.TIMESTAMP_MILLIS,
+        ZipkinSpanRecord.DURATION,
+        ZipkinSpanRecord.NAME,
+        ZipkinSpanRecord.DEBUG,
+        ZipkinSpanRecord.SHARED,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_SERVICE_NAME,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_IPV4,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_IPV6,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_PORT,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_SERVICE_NAME,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_IPV4,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_IPV6,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_PORT,
+        ZipkinSpanRecord.TAGS,
+        ZipkinSpanRecord.ANNOTATIONS
+    );
+
+    public BanyanDBZipkinQueryDAO(BanyanDBStorageClient client) {
+        super(client);
+    }
+
+    @Override
+    public List<String> getServiceNames() throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceTraffic.INDEX_NAME,
+                  SERVICE_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> services = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            services.add(dataPoint.getTagValue(ZipkinServiceTraffic.SERVICE_NAME));
+        }
+        return services;
+    }
+
+    @Override
+    public List<String> getRemoteServiceNames(final String serviceName) throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceRelationTraffic.INDEX_NAME,
+                  REMOTE_SERVICE_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        if (StringUtil.isNotEmpty(serviceName)) {
+                            query.and(eq(ZipkinServiceRelationTraffic.SERVICE_NAME, serviceName));
+                        }
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> remoteServices = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            remoteServices.add(dataPoint.getTagValue(ZipkinServiceRelationTraffic.REMOTE_SERVICE_NAME));
+        }
+        return remoteServices;
+    }
+
+    @Override
+    public List<String> getSpanNames(final String serviceName) throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceSpanTraffic.INDEX_NAME,
+                  SPAN_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        if (StringUtil.isNotEmpty(serviceName)) {
+                            query.and(eq(ZipkinServiceSpanTraffic.SERVICE_NAME, serviceName));
+                        }
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> spanNames = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            spanNames.add(dataPoint.getTagValue(ZipkinServiceSpanTraffic.SPAN_NAME));
+        }
+        return spanNames;
+    }
+
+    @Override
+    public List<Span> getTrace(final String traceId) throws IOException {
+        StreamQueryResponse resp =
+            query(ZipkinSpanRecord.INDEX_NAME, TRACE_TAGS,
+                  new QueryBuilder<StreamQuery>() {
+
+                      @Override
+                      protected void apply(StreamQuery query) {
+                          query.and(eq(ZipkinSpanRecord.TRACE_ID, traceId));
+                          query.setLimit(QUERY_MAX_SIZE);
+                      }
+                  }
+            );
+
+        List<Span> trace = new ArrayList<>(resp.getElements().size());
+
+        for (final RowEntity rowEntity : resp.getElements()) {
+            ZipkinSpanRecord spanRecord = new ZipkinSpanRecord.Builder().storage2Entity(
+                new BanyanDBConverter.StorageToStream(ZipkinSpanRecord.INDEX_NAME, rowEntity));
+            trace.add(ZipkinSpanRecord.buildSpanFromRecord(spanRecord));
+        }
+
+        return trace;
+    }
+
+    @Override
+    public List<List<Span>> getTraces(final QueryRequest request, Duration duration) throws IOException {
+        final int tracesLimit = request.limit();
+        int scrollLimit = 1000;
+        int scrollFrom = 0;
+        Set<String> traceIds = new HashSet<>();
+        while (traceIds.size() < tracesLimit) {
+            Set<String> resp = getTraceIds(request, duration, scrollFrom, scrollLimit);

Review Comment:
   The milliseconds in the span and storage are formatted from nanoseconds.
   The milliseconds in the query condition are formatted from seconds, as a user can not select a milliseconds time.



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking] lujiajing1126 commented on a diff in pull request #10004: [Feature] Zipkin module support BanyanDB storage.

Posted by GitBox <gi...@apache.org>.
lujiajing1126 commented on code in PR #10004:
URL: https://github.com/apache/skywalking/pull/10004#discussion_r1029499338


##########
oap-server-bom/pom.xml:
##########
@@ -73,7 +73,7 @@
         <awaitility.version>3.0.0</awaitility.version>
         <httpcore.version>4.4.13</httpcore.version>
         <commons-compress.version>1.21</commons-compress.version>
-        <banyandb-java-client.version>0.2.0</banyandb-java-client.version>
+        <banyandb-java-client.version>0.3.0-SNAPSHOT</banyandb-java-client.version>

Review Comment:
   Sure. We could cherry-pick the last commit and release a patch version.



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking] lujiajing1126 commented on a diff in pull request #10004: [Feature] Zipkin module support BanyanDB storage.

Posted by GitBox <gi...@apache.org>.
lujiajing1126 commented on code in PR #10004:
URL: https://github.com/apache/skywalking/pull/10004#discussion_r1029510526


##########
oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBZipkinQueryDAO.java:
##########
@@ -0,0 +1,297 @@
+/*
+ * 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.banyandb;
+
+import com.google.common.collect.ImmutableSet;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.skywalking.banyandb.v1.client.AbstractCriteria;
+import org.apache.skywalking.banyandb.v1.client.AbstractQuery;
+import org.apache.skywalking.banyandb.v1.client.DataPoint;
+import org.apache.skywalking.banyandb.v1.client.MeasureQuery;
+import org.apache.skywalking.banyandb.v1.client.MeasureQueryResponse;
+import org.apache.skywalking.banyandb.v1.client.RowEntity;
+import org.apache.skywalking.banyandb.v1.client.StreamQuery;
+import org.apache.skywalking.banyandb.v1.client.StreamQueryResponse;
+import org.apache.skywalking.banyandb.v1.client.TimestampRange;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.storage.query.IZipkinQueryDAO;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceRelationTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceSpanTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinServiceTraffic;
+import org.apache.skywalking.oap.server.core.zipkin.ZipkinSpanRecord;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.apache.skywalking.oap.server.library.util.StringUtil;
+import org.apache.skywalking.oap.server.storage.plugin.banyandb.stream.AbstractBanyanDBDAO;
+import zipkin2.Span;
+import zipkin2.storage.QueryRequest;
+
+public class BanyanDBZipkinQueryDAO extends AbstractBanyanDBDAO implements IZipkinQueryDAO {
+    private final static int QUERY_MAX_SIZE = Integer.MAX_VALUE;
+    private static final Set<String> SERVICE_TRAFFIC_TAGS = ImmutableSet.of(ZipkinServiceTraffic.SERVICE_NAME);
+    private static final Set<String> REMOTE_SERVICE_TRAFFIC_TAGS = ImmutableSet.of(
+        ZipkinServiceRelationTraffic.REMOTE_SERVICE_NAME);
+    private static final Set<String> SPAN_TRAFFIC_TAGS = ImmutableSet.of(ZipkinServiceSpanTraffic.SPAN_NAME);
+    private static final Set<String> TRACE_ID = ImmutableSet.of(ZipkinSpanRecord.TRACE_ID);
+    private static final Set<String> TRACE_TAGS = ImmutableSet.of(
+        ZipkinSpanRecord.TRACE_ID,
+        ZipkinSpanRecord.SPAN_ID,
+        ZipkinSpanRecord.PARENT_ID,
+        ZipkinSpanRecord.KIND,
+        ZipkinSpanRecord.TIMESTAMP,
+        ZipkinSpanRecord.TIMESTAMP_MILLIS,
+        ZipkinSpanRecord.DURATION,
+        ZipkinSpanRecord.NAME,
+        ZipkinSpanRecord.DEBUG,
+        ZipkinSpanRecord.SHARED,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_SERVICE_NAME,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_IPV4,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_IPV6,
+        ZipkinSpanRecord.LOCAL_ENDPOINT_PORT,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_SERVICE_NAME,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_IPV4,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_IPV6,
+        ZipkinSpanRecord.REMOTE_ENDPOINT_PORT,
+        ZipkinSpanRecord.TAGS,
+        ZipkinSpanRecord.ANNOTATIONS
+    );
+
+    public BanyanDBZipkinQueryDAO(BanyanDBStorageClient client) {
+        super(client);
+    }
+
+    @Override
+    public List<String> getServiceNames() throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceTraffic.INDEX_NAME,
+                  SERVICE_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> services = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            services.add(dataPoint.getTagValue(ZipkinServiceTraffic.SERVICE_NAME));
+        }
+        return services;
+    }
+
+    @Override
+    public List<String> getRemoteServiceNames(final String serviceName) throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceRelationTraffic.INDEX_NAME,
+                  REMOTE_SERVICE_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        if (StringUtil.isNotEmpty(serviceName)) {
+                            query.and(eq(ZipkinServiceRelationTraffic.SERVICE_NAME, serviceName));
+                        }
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> remoteServices = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            remoteServices.add(dataPoint.getTagValue(ZipkinServiceRelationTraffic.REMOTE_SERVICE_NAME));
+        }
+        return remoteServices;
+    }
+
+    @Override
+    public List<String> getSpanNames(final String serviceName) throws IOException {
+        MeasureQueryResponse resp =
+            query(ZipkinServiceSpanTraffic.INDEX_NAME,
+                  SPAN_TRAFFIC_TAGS,
+                  Collections.emptySet(), new QueryBuilder<MeasureQuery>() {
+
+                    @Override
+                    protected void apply(MeasureQuery query) {
+                        if (StringUtil.isNotEmpty(serviceName)) {
+                            query.and(eq(ZipkinServiceSpanTraffic.SERVICE_NAME, serviceName));
+                        }
+                        query.setLimit(QUERY_MAX_SIZE);
+                    }
+                }
+            );
+        final List<String> spanNames = new ArrayList<>();
+        for (final DataPoint dataPoint : resp.getDataPoints()) {
+            spanNames.add(dataPoint.getTagValue(ZipkinServiceSpanTraffic.SPAN_NAME));
+        }
+        return spanNames;
+    }
+
+    @Override
+    public List<Span> getTrace(final String traceId) throws IOException {
+        StreamQueryResponse resp =
+            query(ZipkinSpanRecord.INDEX_NAME, TRACE_TAGS,
+                  new QueryBuilder<StreamQuery>() {
+
+                      @Override
+                      protected void apply(StreamQuery query) {
+                          query.and(eq(ZipkinSpanRecord.TRACE_ID, traceId));
+                          query.setLimit(QUERY_MAX_SIZE);
+                      }
+                  }
+            );
+
+        List<Span> trace = new ArrayList<>(resp.getElements().size());
+
+        for (final RowEntity rowEntity : resp.getElements()) {
+            ZipkinSpanRecord spanRecord = new ZipkinSpanRecord.Builder().storage2Entity(
+                new BanyanDBConverter.StorageToStream(ZipkinSpanRecord.INDEX_NAME, rowEntity));
+            trace.add(ZipkinSpanRecord.buildSpanFromRecord(spanRecord));
+        }
+
+        return trace;
+    }
+
+    @Override
+    public List<List<Span>> getTraces(final QueryRequest request, Duration duration) throws IOException {
+        final int tracesLimit = request.limit();
+        int scrollLimit = 1000;
+        int scrollFrom = 0;
+        Set<String> traceIds = new HashSet<>();
+        while (traceIds.size() < tracesLimit) {
+            Set<String> resp = getTraceIds(request, duration, scrollFrom, scrollLimit);

Review Comment:
   Shall we consider using an extra condition, e.g. `ZipkinSpanRecord.TIMESTAMP_MILLIS` instead of using `limit` and `offset`?
   WDYT @hanahmily 



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking] wu-sheng commented on a diff in pull request #10004: [Feature] Zipkin module support BanyanDB storage.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #10004:
URL: https://github.com/apache/skywalking/pull/10004#discussion_r1029236288


##########
oap-server-bom/pom.xml:
##########
@@ -73,7 +73,7 @@
         <awaitility.version>3.0.0</awaitility.version>
         <httpcore.version>4.4.13</httpcore.version>
         <commons-compress.version>1.21</commons-compress.version>
-        <banyandb-java-client.version>0.2.0</banyandb-java-client.version>
+        <banyandb-java-client.version>0.3.0-SNAPSHOT</banyandb-java-client.version>

Review Comment:
   @lujiajing1126 I think you are able to initialize the 0.2.1 release.



-- 
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: notifications-unsubscribe@skywalking.apache.org

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