sonatype-lift[bot] commented on code in PR #10069:
URL: https://github.com/apache/skywalking/pull/10069#discussion_r1036896659


##########
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TraceQueryService.java:
##########
@@ -276,29 +277,46 @@ private void appendAttachedEventsToSpan(List<Span> spans, 
List<SpanAttachedEvent
             return;
         }
 
+        // sort by start time
+        events.sort((e1, e2) -> {
+            final int second = Long.compare(e1.getStartTimeSecond(), 
e2.getStartTimeSecond());
+            if (second == 0) {
+                return Long.compare(e1.getStartTimeNanos(), 
e2.getStartTimeNanos());
+            }
+            return second;
+        });
+
+        final HashMap<String, Span> spanMatcher = new HashMap<>();
         for (SpanAttachedEventRecord record : events) {
             if (!StringUtils.isNumeric(record.getTraceSpanId())) {
                 continue;
             }
+            SpanAttachedEvent event = 
SpanAttachedEvent.parseFrom(record.getDataBinary());
+            final String spanMatcherKey = record.getTraceSegmentId() + "_" + 
record.getTraceSpanId();
+            Span span = spanMatcher.get(spanMatcherKey);
+            if (span == null) {
+                // find the matches span
+                final int eventSpanId = 
Integer.parseInt(record.getTraceSpanId());
+                span = spans.stream().filter(s -> 
Objects.equals(s.getSegmentId(), record.getTraceSegmentId()) &&
+                    Objects.equals(s.getSpanId(), 
eventSpanId)).findFirst().orElse(null);

Review Comment:
   ![70% of developers fix this 
issue](https://lift.sonatype.com/api/commentimage/fixrate/70/display.svg)
   
   
*[ObjectEqualsForPrimitives](https://errorprone.info/bugpattern/ObjectEqualsForPrimitives):*
  Avoid unnecessary boxing by using plain == for primitive types.
   
   ---
   
   
   ```suggestion
                       (s.getSpanId() == eventSpanId)).findFirst().orElse(null);
   ```
   
   
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=356962641&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=356962641&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=356962641&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=356962641&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=356962641&lift_comment_rating=5)
 ]



##########
oap-server/server-query-plugin/zipkin-query-plugin/src/main/java/org/apache/skywalking/oap/query/zipkin/handler/ZipkinQueryHandler.java:
##########
@@ -311,34 +311,54 @@ private void appendEvents(List<Span> spans, 
List<SpanAttachedEventRecord> events
 
         final List<Tuple2<Integer, Span>> spanWithIndex = IntStream.range(0, 
spans.size()).mapToObj(i -> Tuple.of(i, 
spans.get(i))).collect(Collectors.toList());
 
-        final Map<String, List<SpanAttachedEventRecord>> namedEvents = 
events.stream().collect(Collectors.groupingBy(SpanAttachedEventRecord::getEvent,
 Collectors.toList()));
-        final Map<Integer, Span.Builder> spanCache = new HashMap<>();
-        for (Map.Entry<String, List<SpanAttachedEventRecord>> entry : 
namedEvents.entrySet()) {
-            for (int i = 1; i <= entry.getValue().size(); i++) {
-                final SpanAttachedEventRecord record = entry.getValue().get(i 
- 1);
-                String eventName = record.getEvent() + 
(entry.getValue().size() == 1 ? "" : "-" + i);
-                Tuple2<Integer, Span> matchesSpan = 
spanWithIndex.stream().filter(s -> Objects.equals(s._2.id(), 
record.getTraceSpanId())).
-                    findFirst().orElse(null);
-                if (matchesSpan == null) {
-                    continue;
-                }
+        // sort by start time
+        events.stream().sorted((e1, e2) -> {

Review Comment:
   
*[ReturnValueIgnored](https://errorprone.info/bugpattern/ReturnValueIgnored):*  
Return value of 'sorted' must be used
   
   ---
   
   <details><summary><b>â„šī¸ Learn about @sonatype-lift commands</b></summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   Was this a good recommendation?
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=356962692&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=356962692&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=356962692&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=356962692&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=356962692&lift_comment_rating=5)
 ]



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