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


##########
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmMessage.java:
##########
@@ -35,6 +35,7 @@ public class AlarmMessage {
     private String name;
     private String message;
     private Long startTime;
+    private Long recoveryTime;

Review Comment:
   Is this related to this pprof feature?



##########
test/e2e-v2/cases/profiling/pprof/expected/progress.yml:
##########
@@ -0,0 +1,26 @@
+# 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.
+
+logs:
+  {{- contains .logs }}
+- id: {{ notEmpty .id}}
+  instanceid: {{ b64enc "go-service" }}.1_{{ b64enc "provider1" }}
+  instancename: {{ notEmpty .instancename}}
+  operationtype: {{ notEmpty .operationtype}}

Review Comment:
   Please verify the specific operation type and name. 



##########
oap-server/server-receiver-plugin/skywalking-pprof-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/pprof/provider/handler/PprofServiceHandler.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.receiver.pprof.provider.handler;
+
+import io.grpc.stub.StreamObserver;
+import lombok.extern.slf4j.Slf4j;
+import java.io.IOException;
+import 
org.apache.skywalking.oap.server.core.query.type.PprofTaskLogOperationType;
+import org.apache.skywalking.apm.network.pprof.v10.PprofData;
+import org.apache.skywalking.apm.network.pprof.v10.PprofTaskGrpc;
+import org.apache.skywalking.apm.network.pprof.v10.PprofCollectionResponse;
+import org.apache.skywalking.apm.network.pprof.v10.PprofMetaData;
+
+import org.apache.skywalking.apm.network.common.v3.Commands;
+import org.apache.skywalking.apm.network.pprof.v10.PprofTaskCommandQuery;
+
+import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.analysis.IDManager;
+import org.apache.skywalking.oap.server.core.command.CommandService;
+import java.util.Objects;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+import org.apache.skywalking.oap.server.core.query.type.PprofTask;
+import org.apache.skywalking.oap.server.core.source.SourceReceiver;
+import 
org.apache.skywalking.oap.server.core.storage.profiling.pprof.IPprofTaskQueryDAO;
+import org.apache.skywalking.oap.server.core.storage.StorageModule;
+import org.apache.skywalking.oap.server.core.cache.PprofTaskCache;
+import 
org.apache.skywalking.oap.server.core.profiling.pprof.storage.PprofTaskLogRecord;
+import 
org.apache.skywalking.oap.server.core.analysis.worker.RecordStreamProcessor;
+import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
+import java.util.concurrent.TimeUnit;
+
+//import org.apache.skywalking.oap.server.core.storage.StorageModule;
+//import 
org.apache.skywalking.oap.server.core.storage.profiling.pprof.IPprofTaskQueryDAO;
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
+import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
+import 
org.apache.skywalking.oap.server.network.trace.component.command.PprofTaskCommand;
+import 
org.apache.skywalking.oap.server.receiver.pprof.provider.handler.stream.PprofByteBufCollectionObserver;
+import 
org.apache.skywalking.oap.server.receiver.pprof.provider.handler.stream.PprofCollectionMetaData;
+import 
org.apache.skywalking.oap.server.receiver.pprof.provider.handler.stream.PprofFileCollectionObserver;
+
+@Slf4j
+public class PprofServiceHandler extends PprofTaskGrpc.PprofTaskImplBase 
implements GRPCHandler {
+
+    private final IPprofTaskQueryDAO taskDAO;
+    private final SourceReceiver sourceReceiver;
+    private final CommandService commandService;
+    private final PprofTaskCache taskCache;
+    private final int pprofMaxSize;
+    private final boolean memoryParserEnabled;
+
+    public PprofServiceHandler(ModuleManager moduleManager, int pprofMaxSize, 
boolean memoryParserEnabled) {
+        this.taskDAO = 
moduleManager.find(StorageModule.NAME).provider().getService(IPprofTaskQueryDAO.class);
+        this.commandService = 
moduleManager.find(CoreModule.NAME).provider().getService(CommandService.class);
+        this.sourceReceiver = 
moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
+        this.taskCache = 
moduleManager.find(CoreModule.NAME).provider().getService(PprofTaskCache.class);
+        this.pprofMaxSize = pprofMaxSize;
+        this.memoryParserEnabled = memoryParserEnabled;
+    }
+    
+    @Override
+    public StreamObserver<PprofData> 
collect(StreamObserver<PprofCollectionResponse> responseObserver) {
+        return memoryParserEnabled ?
+                new PprofByteBufCollectionObserver(taskDAO, responseObserver, 
sourceReceiver, pprofMaxSize)
+                : new PprofFileCollectionObserver(taskDAO, responseObserver, 
sourceReceiver, pprofMaxSize);
+    }
+
+    @Override
+    public void getPprofTaskCommands(PprofTaskCommandQuery request, 
StreamObserver<Commands> responseObserver) {
+        String serviceId = IDManager.ServiceID.buildId(request.getService(), 
true);
+        String serviceInstanceId = 
IDManager.ServiceInstanceID.buildId(serviceId, request.getServiceInstance());
+        PprofTask task = taskCache.getPprofTask(serviceId);

Review Comment:
   Since you have 
https://github.com/apache/skywalking-data-collect-protocol/blob/master/pprof/Pprof.proto#L76
 parameter, please use this to query the newer tasks. 



##########
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/pom.xml:
##########
@@ -48,11 +48,57 @@
             <groupId>org.postgresql</groupId>
             <artifactId>postgresql</artifactId>
         </dependency>
+        <dependency>

Review Comment:
   Please rmeove the mysql dependency in this file. 



##########
oap-server/server-receiver-plugin/skywalking-pprof-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/pprof/provider/handler/stream/PprofByteBufCollectionObserver.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.receiver.pprof.provider.handler.stream;
+
+import io.grpc.Status;
+import io.grpc.stub.StreamObserver;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.library.pprof.parser.PprofParser;
+import org.apache.skywalking.oap.server.library.pprof.type.FrameTree;
+import org.apache.skywalking.apm.network.pprof.v10.PprofData;
+import org.apache.skywalking.oap.server.core.query.type.PprofTask;
+import org.apache.skywalking.apm.network.pprof.v10.PprofCollectionResponse;
+import org.apache.skywalking.apm.network.pprof.v10.PprofProfilingStatus;
+import org.apache.skywalking.oap.server.core.source.PprofProfilingData;
+import org.apache.skywalking.oap.server.core.source.SourceReceiver;
+import 
org.apache.skywalking.oap.server.core.storage.profiling.pprof.IPprofTaskQueryDAO;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import org.apache.skywalking.oap.server.core.query.type.PprofEventType;
+import 
org.apache.skywalking.oap.server.core.query.type.PprofTaskLogOperationType;
+import static 
org.apache.skywalking.oap.server.receiver.pprof.provider.handler.PprofServiceHandler.parseMetaData;
+import static 
org.apache.skywalking.oap.server.receiver.pprof.provider.handler.PprofServiceHandler.recordPprofTaskLog;
+
+@Slf4j
+public class PprofByteBufCollectionObserver implements 
StreamObserver<PprofData> {
+    private final IPprofTaskQueryDAO taskDAO;
+    private final StreamObserver<PprofCollectionResponse> responseObserver;
+    private final SourceReceiver sourceReceiver;
+    private final int pprofMaxSize;
+    private PprofCollectionMetaData taskMetaData;
+    private ByteBuffer buf;
+
+    public PprofByteBufCollectionObserver(IPprofTaskQueryDAO taskDAO, 
+                                         
StreamObserver<PprofCollectionResponse> responseObserver, 
+                                         SourceReceiver sourceReceiver, int 
pprofMaxSize) {
+        this.taskDAO = taskDAO;
+        this.responseObserver = responseObserver;
+        this.sourceReceiver = sourceReceiver;
+        this.pprofMaxSize = pprofMaxSize;
+    }
+
+    @Override
+    public void onNext(PprofData pprofData) {
+        try {
+            if (Objects.isNull(taskMetaData) && pprofData.hasMetadata()) {
+                taskMetaData = parseMetaData(pprofData.getMetadata(), taskDAO);
+            if 
(PprofProfilingStatus.PPROF_PROFILING_SUCCESS.equals(taskMetaData.getType())) {
+                int size = taskMetaData.getContentSize();
+                if (pprofMaxSize >= size) {
+                    buf = ByteBuffer.allocate(size);
+                    // Send success response to allow client to continue 
uploading
+                    
responseObserver.onNext(PprofCollectionResponse.newBuilder()
+                            
.setStatus(PprofProfilingStatus.PPROF_PROFILING_SUCCESS)
+                            .build());
+                } else {
+                    
responseObserver.onNext(PprofCollectionResponse.newBuilder()
+                            
.setStatus(PprofProfilingStatus.PPROF_TERMINATED_BY_OVERSIZE)
+                            .build());
+                    recordPprofTaskLog(taskMetaData.getTask(), 
taskMetaData.getInstanceId(), 
PprofTaskLogOperationType.PPROF_UPLOAD_FILE_TOO_LARGE_ERROR);
+                }
+            } else {
+                responseObserver.onNext(PprofCollectionResponse.newBuilder()
+                        
.setStatus(PprofProfilingStatus.PPROF_EXECUTION_TASK_ERROR)
+                        .build());
+                recordPprofTaskLog(taskMetaData.getTask(), 
taskMetaData.getInstanceId(), PprofTaskLogOperationType.EXECUTION_TASK_ERROR);
+            }
+        } else if (pprofData.hasContent()) {
+            if (buf != null) {
+                pprofData.getContent().copyTo(buf);
+                log.info("Received {} bytes of pprof data", 
pprofData.getContent().size());
+            }
+        }
+        } catch (IOException e) {
+            log.error("Error processing pprof data", e);
+            responseObserver.onError(Status.INTERNAL.withDescription("Error 
processing pprof data: " + e.getMessage()).asRuntimeException());
+        }
+    }
+
+    @Override
+    public void onError(Throwable throwable) {
+        Status status = Status.fromThrowable(throwable);
+        if (Status.CANCELLED.getCode() == status.getCode()) {
+            if (log.isDebugEnabled()) {
+                log.debug(throwable.getMessage(), throwable);
+            }
+            return;
+        }
+        log.error("Error in receiving pprof profiling data", throwable);
+        
+    }
+
+    @Override
+    public void onCompleted() {
+        responseObserver.onCompleted();
+        if (Objects.nonNull(buf)) {
+            buf.flip();
+            try {
+                parseAndStorageData(taskMetaData, buf);
+            } catch (IOException e) {
+                log.error("Failed to parse and store pprof data", e);
+            }
+        }
+    }
+
+    private void parseAndStorageData(PprofCollectionMetaData taskMetaData, 
ByteBuffer buf) throws IOException {
+        PprofTask task = taskMetaData.getTask();
+        if (task == null) {
+            log.error("Pprof instanceId:{} has not been assigned a task but 
still uploaded data", taskMetaData.getInstanceId());
+            return;
+        }
+        recordPprofTaskLog(task, taskMetaData.getInstanceId(), 
PprofTaskLogOperationType.EXECUTION_FINISHED);
+        parsePprofAndStorage(taskMetaData, buf);
+    }
+
+    public void parsePprofAndStorage(PprofCollectionMetaData taskMetaData, 
ByteBuffer buf) throws IOException {
+        log.info("Parsing pprof file for service: {}, instance: {}", 
+        taskMetaData.getServiceId(), taskMetaData.getInstanceId());
+        PprofTask task = taskMetaData.getTask();
+        FrameTree tree = PprofParser.dumpTree(buf);
+        PprofProfilingData data = new PprofProfilingData();
+        
data.setEventType(PprofEventType.valueOfString(task.getEvents().name()));
+        data.setFrameTree(tree);
+        data.setTaskId(task.getId());
+        data.setInstanceId(taskMetaData.getInstanceId());
+        data.setUploadTime(taskMetaData.getUploadTime());
+        log.info("data eventType: {}", data.getEventType());
+        log.info("data frameTree: {}", tree);
+        log.info("data taskId: {}", task.getId());
+        log.info("data instanceId: {}", taskMetaData.getInstanceId());
+        log.info("data uploadTime: {}", taskMetaData.getUploadTime());

Review Comment:
   Are these logs necessary? 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to