wu-sheng commented on a change in pull request #5416:
URL: https://github.com/apache/skywalking/pull/5416#discussion_r480201830



##########
File path: 
oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/ExceptionAnalyzerStrategy.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.analyzer.provider.trace.parser;
+
+import lombok.Getter;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.AnyExceptionAnalyzer;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.EntryFirstExceptionAnalyzer;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.ExceptionAnalyzer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * define the strategy to analysis segment status
+ */
+public enum ExceptionAnalyzerStrategy {
+    ANY(AnyExceptionAnalyzer.class),
+
+    ENTRY_FIRST(EntryFirstExceptionAnalyzer.class);
+
+    private final Logger log = 
LoggerFactory.getLogger(ExceptionAnalyzerStrategy.class);

Review comment:
       Use annotation.

##########
File path: 
oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/ExceptionAnalyzerStrategy.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.analyzer.provider.trace.parser;
+
+import lombok.Getter;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.AnyExceptionAnalyzer;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.EntryFirstExceptionAnalyzer;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.ExceptionAnalyzer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * define the strategy to analysis segment status
+ */
+public enum ExceptionAnalyzerStrategy {
+    ANY(AnyExceptionAnalyzer.class),
+
+    ENTRY_FIRST(EntryFirstExceptionAnalyzer.class);
+
+    private final Logger log = 
LoggerFactory.getLogger(ExceptionAnalyzerStrategy.class);
+    @Getter
+    private ExceptionAnalyzer exceptionAnalyzer;

Review comment:
       Use `final` and annotation for the constructor directly.

##########
File path: 
oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/ExceptionAnalyzerStrategy.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.analyzer.provider.trace.parser;
+
+import lombok.Getter;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.AnyExceptionAnalyzer;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.EntryFirstExceptionAnalyzer;
+import 
org.apache.skywalking.oap.server.analyzer.provider.trace.parser.listener.strategy.ExceptionAnalyzer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * define the strategy to analysis segment status
+ */
+public enum ExceptionAnalyzerStrategy {
+    ANY(AnyExceptionAnalyzer.class),
+
+    ENTRY_FIRST(EntryFirstExceptionAnalyzer.class);
+
+    private final Logger log = 
LoggerFactory.getLogger(ExceptionAnalyzerStrategy.class);
+    @Getter
+    private ExceptionAnalyzer exceptionAnalyzer;
+
+    ExceptionAnalyzerStrategy(final Class<? extends ExceptionAnalyzer> clazz) {
+        try {
+            this.exceptionAnalyzer = clazz.newInstance();

Review comment:
       Even reflect cost is limited, but it is not necessary. 
`ExceptionAnalyzer` implementors are stateless, you could have the instance in 
the constructor directly. 

##########
File path: 
oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/AnalyzerModuleConfig.java
##########
@@ -80,9 +83,19 @@
     private final String configPath = "meter-receive-config";
 
     /**
-     * Sample the trace segment if the segment has span(s) tagged as error 
status, and ignore the sampleRate configuration.
+     * Sample the trace segment if the segment has span(s) tagged as error 
status, and ignore the sampleRate
+     * configuration.
      */
     @Setter
     @Getter
     private boolean forceSampleErrorSegment = true;
+
+    /**
+     * the strategy is to extract the status of segment from span collection
+     *
+     * @see ExceptionAnalyzerStrategy
+     */
+    @Setter
+    @Getter
+    private String exceptionAnalyzerStrategy = ENTRY_FIRST.name();

Review comment:
       I think the initializer has supported the enum. You don't need to do 
this.

##########
File path: 
oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/strategy/ExceptionAnalyzer.java
##########
@@ -0,0 +1,31 @@
+/*
+ * 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.analyzer.provider.trace.parser.listener.strategy;
+
+import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject;
+
+/**
+ * judge the status of spanObject
+ */
+public interface ExceptionAnalyzer {
+    /**
+     * extract error status from the span collection in segmentObject
+     */
+    boolean isError(SegmentObject segmentObject);

Review comment:
       This is a low-performance method design. In the 
`SegmentAnalysisListener#parseSegment`, we have the span list iteration 
already, this interface forces the implementation to do it again. 
   ```suggestion
       boolean isError(SpanObject span);
   ```

##########
File path: 
oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/strategy/ExceptionAnalyzer.java
##########
@@ -0,0 +1,31 @@
+/*
+ * 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.analyzer.provider.trace.parser.listener.strategy;
+
+import org.apache.skywalking.apm.network.language.agent.v3.SegmentObject;
+
+/**
+ * judge the status of spanObject
+ */
+public interface ExceptionAnalyzer {

Review comment:
       ```suggestion
   public interface SegmentStatusAnalyzer {
   ```




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


Reply via email to