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 2020/10/15 07:06:58 UTC

[GitHub] [skywalking] wu-sheng commented on a change in pull request #5666: add transmission latency

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



##########
File path: test/plugin/scenarios/kafka-scenario/config/expectedData.yaml
##########
@@ -156,6 +157,7 @@ segmentItems:
         tags:
           - {key: mq.broker, value: 'kafka-server:9092'}
           - {key: mq.topic, value: test.}
+          - {key: transmission.latency, value: not null}

Review comment:
       Why only Kafka test case updated? I am assuming this should relate to all MQ plugins.

##########
File path: oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/MultiScopesAnalysisListener.java
##########
@@ -234,6 +234,12 @@ public void parseExit(SpanObject span, SegmentObject segmentObject) {
 
     private void setPublicAttrs(SourceBuilder sourceBuilder, SpanObject span) {

Review comment:
       Rename this to `parseRPC`, as it does more than it used to be.

##########
File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ExtensionContext.java
##########
@@ -33,13 +36,20 @@
      */
     private boolean skipAnalysis;
 
+    /**
+     * The sending timestamp of the exit span.
+     */
+    @Getter
+    @Setter
+    private long sendingTimestamp = 0;
+
     /**
      * Serialize this {@link ExtensionContext} to a {@link String}
      *
      * @return the serialization string.
      */
     String serialize() {
-        return skipAnalysis ? "1" : "0";
+        return skipAnalysis ? "1" : "0" + "-" + sendingTimestamp;

Review comment:
       You should not transport the timestamp if it is a `0`, otherwise, `0` would provide a super huge false latency for this RPC.

##########
File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ExtensionContext.java
##########
@@ -54,6 +64,7 @@ void deserialize(String value) {
         // only try to read it when it exist.
         if (extensionParts.length > 0) {
             this.skipAnalysis = Objects.equals(extensionParts[0], "1");
+            this.sendingTimestamp = Long.parseLong(extensionParts[1]);

Review comment:
       This is optional, you should add `if (extensionParts.length > 1) {`, then get (1) and parsing. Also, you need `if not empty` and `try/catch` to avoid the empty string as it is optional, and illegal character.

##########
File path: oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/MultiScopesAnalysisListener.java
##########
@@ -234,6 +234,12 @@ public void parseExit(SpanObject span, SegmentObject segmentObject) {
 
     private void setPublicAttrs(SourceBuilder sourceBuilder, SpanObject span) {
         long latency = span.getEndTime() - span.getStartTime();
+        for (final KeyStringValuePair keyStringValuePair : span.getTagsList()) {
+            if (keyStringValuePair.getKey().equals(SpanTags.TRANSMISSION_LATENCY)) {
+                latency += Integer.parseInt(keyStringValuePair.getValue());
+                break;
+            }
+        }

Review comment:
       We have a `for span` in the L240-L248 already, please don't do duplicated iteration.

##########
File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java
##########
@@ -124,4 +124,10 @@
      * Should skip analysis in the backend.
      */
     void skipAnalysis();
+
+    /**
+     * Get the start time stamp of this span.
+     */
+    long getStartTime();

Review comment:
       This should be removed.

##########
File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ExtensionContext.java
##########
@@ -78,19 +89,25 @@ void handle(AbstractSpan span) {
         if (this.skipAnalysis) {
             span.skipAnalysis();
         }
+        if (this.sendingTimestamp != 0) {
+            Tags.TRANSMISSION_LATENCY.set(span, String.valueOf(span.getStartTime() - sendingTimestamp));
+        }

Review comment:
       Should not be`span.getStartTime() - sendingTimestamp`. At here, for you, the latency is `current time - sending timestamp`

##########
File path: oap-server/analyzer/agent-analyzer/src/main/java/org/apache/skywalking/oap/server/analyzer/provider/trace/parser/listener/MultiScopesAnalysisListener.java
##########
@@ -234,6 +234,12 @@ public void parseExit(SpanObject span, SegmentObject segmentObject) {
 
     private void setPublicAttrs(SourceBuilder sourceBuilder, SpanObject span) {
         long latency = span.getEndTime() - span.getStartTime();
+        for (final KeyStringValuePair keyStringValuePair : span.getTagsList()) {
+            if (keyStringValuePair.getKey().equals(SpanTags.TRANSMISSION_LATENCY)) {
+                latency += Integer.parseInt(keyStringValuePair.getValue());
+                break;
+            }
+        }

Review comment:
       Why rewrite the latency of this? We never said the latency of span/segment/service including the network when we talked about the server-side latency.

##########
File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ExtensionInjector.java
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.apm.agent.core.context;
+
+/**
+ * Inject or read the extension protocol fields,such as {@link ExtensionContext#sendingTimestamp}.
+ */
+public class ExtensionInjector {
+
+    private final ExtensionContext extensionContext;
+
+    ExtensionInjector(final ExtensionContext extensionContext) {
+        this.extensionContext = extensionContext;
+    }
+
+    public void injectSendingTimestamp() {
+        extensionContext.setSendingTimestamp(System.currentTimeMillis());
+    }
+
+    public long readSendingTimestamp() {

Review comment:
       `long` -> `Long`, as it could be NULL if don't exist in the in-wire context.




----------------------------------------------------------------
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:
users@infra.apache.org