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/07/13 04:08:42 UTC

[GitHub] [skywalking] mrproliu commented on a diff in pull request #9337: Support eBPF Network Profiling

mrproliu commented on code in PR #9337:
URL: https://github.com/apache/skywalking/pull/9337#discussion_r919629053


##########
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/ProcessTopologyBuilder.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.core.query;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.core.analysis.IDManager;
+import org.apache.skywalking.oap.server.core.analysis.manual.process.ProcessDetectType;
+import org.apache.skywalking.oap.server.core.analysis.manual.process.ProcessTraffic;
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import org.apache.skywalking.oap.server.core.query.type.Call;
+import org.apache.skywalking.oap.server.core.query.type.ProcessNode;
+import org.apache.skywalking.oap.server.core.query.type.ProcessTopology;
+import org.apache.skywalking.oap.server.core.source.DetectPoint;
+import org.apache.skywalking.oap.server.core.storage.IMetricsDAO;
+import org.apache.skywalking.oap.server.core.storage.StorageDAO;
+import org.apache.skywalking.oap.server.core.storage.StorageModule;
+import org.apache.skywalking.oap.server.core.storage.model.Model;
+import org.apache.skywalking.oap.server.core.storage.model.StorageModels;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+@Slf4j
+public class ProcessTopologyBuilder {
+    private final IMetricsDAO metricsDAO;
+    private Model processTrafficModel;
+
+    public ProcessTopologyBuilder(ModuleManager moduleManager, StorageModels storageModels) {
+        final StorageDAO storageDAO = moduleManager.find(StorageModule.NAME).provider().getService(StorageDAO.class);
+        this.metricsDAO = storageDAO.newMetricsDao(new ProcessTraffic.Builder());
+        for (Model model : storageModels.allModels()) {
+            if (Objects.equals(model.getName(), ProcessTraffic.INDEX_NAME)) {
+                this.processTrafficModel = model;
+                break;
+            }
+        }
+        if (this.processTrafficModel == null) {
+            throw new IllegalStateException("could not found the process traffic model");
+        }
+    }
+
+    ProcessTopology build(List<Call.CallDetail> clientCalls,
+                          List<Call.CallDetail> serverCalls) throws IOException {
+        List<Call> calls = new LinkedList<>();
+        HashMap<String, Call> callMap = new HashMap<>();
+
+        final Set<String> sourceProcessIdList = Stream.concat(clientCalls.stream(), serverCalls.stream())
+            .map(Call.CallDetail::getSource).collect(Collectors.toSet());
+        final Set<String> destProcessIdList = Stream.concat(clientCalls.stream(), serverCalls.stream())
+            .map(Call.CallDetail::getTarget).collect(Collectors.toSet());
+        sourceProcessIdList.addAll(destProcessIdList);
+
+        // query all traffic data
+        final Map<String, ProcessNode> nodes = this.metricsDAO.multiGet(this.processTrafficModel, Stream.concat(sourceProcessIdList.stream(), destProcessIdList.stream())
+                .distinct().map(processId -> {
+                    final ProcessTraffic p = new ProcessTraffic();
+                    p.setProcessId(processId);
+                    return p;
+                }).collect(Collectors.toList())).stream()
+            .map(t -> (ProcessTraffic) t)
+            .collect(Collectors.toMap(Metrics::id, this::buildNode));
+
+        // adding client side call
+        for (Call.CallDetail clientCall : clientCalls) {
+            if (!callMap.containsKey(clientCall.getId())) {
+                Call call = new Call();
+
+                callMap.put(clientCall.getId(), call);
+                call.setSource(clientCall.getSource());
+                call.setTarget(clientCall.getTarget());
+                call.setId(clientCall.getId());
+                call.addDetectPoint(DetectPoint.CLIENT);
+                calls.add(call);
+            }
+        }
+
+        // adding server side call
+        for (Call.CallDetail serverCall : serverCalls) {
+            if (!callMap.containsKey(serverCall.getId())) {
+                Call call = new Call();
+
+                callMap.put(serverCall.getId(), call);
+                call.setSource(serverCall.getSource());
+                call.setTarget(serverCall.getTarget());
+                call.setId(serverCall.getId());
+                call.addDetectPoint(DetectPoint.SERVER);
+                calls.add(call);
+            } else {
+                Call call = callMap.get(serverCall.getId());
+                call.addDetectPoint(DetectPoint.SERVER);
+            }
+        }
+
+        ProcessTopology topology = new ProcessTopology();
+        topology.getCalls().addAll(calls);

Review Comment:
   @sonatype-lift ignore



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