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/02/02 08:45:15 UTC

[GitHub] [skywalking] kezhenxu94 opened a new pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8

kezhenxu94 opened a new pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8
URL: https://github.com/apache/skywalking/pull/4307
 
 
   ### Motivation:
   
   Codes clean up
   
   ### Modifications:
   
   - Remove v1 header, follow up #4244
   
   - Use built-in Base64 class (since JDK8)
   
   ### Result:
   
   - No more legacy v1 headers
   
   - No unnecessary codes concerns by using built-in ability
   

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


With regards,
Apache Git Services

[GitHub] [skywalking] kezhenxu94 commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8
URL: https://github.com/apache/skywalking/pull/4307#discussion_r373830731
 
 

 ##########
 File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java
 ##########
 @@ -108,53 +103,36 @@ String serialize(HeaderVersion version) {
      * @param text carries {@link #traceSegmentId} and {@link #spanId}, with '|' split.
      */
     ContextCarrier deserialize(String text, HeaderVersion version) {
-        if (text != null) {
-            // if this carrier is initialized by v1 or v2, don't do deserialize again for performance.
-            if (this.isValid(HeaderVersion.v1) || this.isValid(HeaderVersion.v2)) {
-                return this;
-            }
-            if (HeaderVersion.v1.equals(version)) {
-                String[] parts = text.split("\\|", 8);
-                if (parts.length == 8) {
-                    try {
-                        this.traceSegmentId = new ID(parts[0]);
-                        this.spanId = Integer.parseInt(parts[1]);
-                        this.parentServiceInstanceId = Integer.parseInt(parts[2]);
-                        this.entryServiceInstanceId = Integer.parseInt(parts[3]);
-                        this.peerHost = parts[4];
-                        this.entryEndpointName = parts[5];
-                        this.parentEndpointName = parts[6];
-                        this.primaryDistributedTraceId = new PropagatedTraceId(parts[7]);
-                    } catch (NumberFormatException e) {
-
-                    }
-                }
-            } else if (HeaderVersion.v2.equals(version)) {
-                String[] parts = text.split("\\-", 9);
-                if (parts.length == 9) {
-                    try {
-                        // parts[0] is sample flag, always trace if header exists.
-                        this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
-                        this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
-                        this.spanId = Integer.parseInt(parts[3]);
-                        this.parentServiceInstanceId = Integer.parseInt(parts[4]);
-                        this.entryServiceInstanceId = Integer.parseInt(parts[5]);
-                        this.peerHost = Base64.decode2UTFString(parts[6]);
-                        this.entryEndpointName = Base64.decode2UTFString(parts[7]);
-                        this.parentEndpointName = Base64.decode2UTFString(parts[8]);
-                    } catch (NumberFormatException e) {
-
-                    }
+        if (text == null) {
+            return this;
+        }
+        // if this carrier is initialized by v2, don't do deserialize again for performance.
+        if (this.isValid(HeaderVersion.v2)) {
+            return this;
+        }
+        if (HeaderVersion.v2 == version) {
+            String[] parts = text.split("-", 9);
+            if (parts.length == 9) {
+                try {
+                    // parts[0] is sample flag, always trace if header exists.
+                    this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
+                    this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
+                    this.spanId = Integer.parseInt(parts[3]);
+                    this.parentServiceInstanceId = Integer.parseInt(parts[4]);
+                    this.entryServiceInstanceId = Integer.parseInt(parts[5]);
+                    this.peerHost = Base64.decode2UTFString(parts[6]);
+                    this.entryEndpointName = Base64.decode2UTFString(parts[7]);
+                    this.parentEndpointName = Base64.decode2UTFString(parts[8]);
+                } catch (NumberFormatException ignored) {
+
                 }
-            } else {
-                throw new IllegalArgumentException("Unimplemented header version." + version);
             }
         }
-        return this;
+        throw new IllegalArgumentException("Unimplemented header version." + version);
 
 Review comment:
   Just double check the original codes, the exception statement should never be reached, I simply remove them

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


With regards,
Apache Git Services

[GitHub] [skywalking] wu-sheng commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8
URL: https://github.com/apache/skywalking/pull/4307#discussion_r373829673
 
 

 ##########
 File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java
 ##########
 @@ -108,53 +103,36 @@ String serialize(HeaderVersion version) {
      * @param text carries {@link #traceSegmentId} and {@link #spanId}, with '|' split.
      */
     ContextCarrier deserialize(String text, HeaderVersion version) {
-        if (text != null) {
-            // if this carrier is initialized by v1 or v2, don't do deserialize again for performance.
-            if (this.isValid(HeaderVersion.v1) || this.isValid(HeaderVersion.v2)) {
-                return this;
-            }
-            if (HeaderVersion.v1.equals(version)) {
-                String[] parts = text.split("\\|", 8);
-                if (parts.length == 8) {
-                    try {
-                        this.traceSegmentId = new ID(parts[0]);
-                        this.spanId = Integer.parseInt(parts[1]);
-                        this.parentServiceInstanceId = Integer.parseInt(parts[2]);
-                        this.entryServiceInstanceId = Integer.parseInt(parts[3]);
-                        this.peerHost = parts[4];
-                        this.entryEndpointName = parts[5];
-                        this.parentEndpointName = parts[6];
-                        this.primaryDistributedTraceId = new PropagatedTraceId(parts[7]);
-                    } catch (NumberFormatException e) {
-
-                    }
-                }
-            } else if (HeaderVersion.v2.equals(version)) {
-                String[] parts = text.split("\\-", 9);
-                if (parts.length == 9) {
-                    try {
-                        // parts[0] is sample flag, always trace if header exists.
-                        this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
-                        this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
-                        this.spanId = Integer.parseInt(parts[3]);
-                        this.parentServiceInstanceId = Integer.parseInt(parts[4]);
-                        this.entryServiceInstanceId = Integer.parseInt(parts[5]);
-                        this.peerHost = Base64.decode2UTFString(parts[6]);
-                        this.entryEndpointName = Base64.decode2UTFString(parts[7]);
-                        this.parentEndpointName = Base64.decode2UTFString(parts[8]);
-                    } catch (NumberFormatException e) {
-
-                    }
+        if (text == null) {
+            return this;
+        }
+        // if this carrier is initialized by v2, don't do deserialize again for performance.
+        if (this.isValid(HeaderVersion.v2)) {
+            return this;
+        }
+        if (HeaderVersion.v2 == version) {
+            String[] parts = text.split("-", 9);
+            if (parts.length == 9) {
+                try {
+                    // parts[0] is sample flag, always trace if header exists.
+                    this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
+                    this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
+                    this.spanId = Integer.parseInt(parts[3]);
+                    this.parentServiceInstanceId = Integer.parseInt(parts[4]);
+                    this.entryServiceInstanceId = Integer.parseInt(parts[5]);
+                    this.peerHost = Base64.decode2UTFString(parts[6]);
+                    this.entryEndpointName = Base64.decode2UTFString(parts[7]);
+                    this.parentEndpointName = Base64.decode2UTFString(parts[8]);
+                } catch (NumberFormatException ignored) {
+
                 }
-            } else {
-                throw new IllegalArgumentException("Unimplemented header version." + version);
             }
         }
-        return this;
+        throw new IllegalArgumentException("Unimplemented header version." + version);
 
 Review comment:
   Don't throw an exception in agent core API. Output a warning log.

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


With regards,
Apache Git Services

[GitHub] [skywalking] wu-sheng commented on issue #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8
URL: https://github.com/apache/skywalking/pull/4307#issuecomment-581113653
 
 
   Many CI processes fail. Please recheck.

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


With regards,
Apache Git Services

[GitHub] [skywalking] wu-sheng commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8
URL: https://github.com/apache/skywalking/pull/4307#discussion_r373829678
 
 

 ##########
 File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java
 ##########
 @@ -163,27 +141,16 @@ public boolean isValid() {
      * @return true for unbroken {@link ContextCarrier} or no-initialized. Otherwise, false;
      */
     boolean isValid(HeaderVersion version) {
-        if (HeaderVersion.v1.equals(version)) {
-            return traceSegmentId != null
-                && traceSegmentId.isValid()
-                && getSpanId() > -1
-                && parentServiceInstanceId != DictionaryUtil.nullValue()
-                && entryServiceInstanceId != DictionaryUtil.nullValue()
-                && !StringUtil.isEmpty(peerHost)
-                && !StringUtil.isEmpty(entryEndpointName)
-                && !StringUtil.isEmpty(parentEndpointName)
-                && primaryDistributedTraceId != null;
-        } else if (HeaderVersion.v2.equals(version)) {
+        if (HeaderVersion.v2 == version) {
             return traceSegmentId != null
                 && traceSegmentId.isValid()
                 && getSpanId() > -1
                 && parentServiceInstanceId != DictionaryUtil.nullValue()
                 && entryServiceInstanceId != DictionaryUtil.nullValue()
                 && !StringUtil.isEmpty(peerHost)
                 && primaryDistributedTraceId != null;
-        } else {
-            throw new IllegalArgumentException("Unimplemented header version." + version);
         }
+        throw new IllegalArgumentException("Unimplemented header version." + version);
 
 Review comment:
   Same here.

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


With regards,
Apache Git Services

[GitHub] [skywalking] kezhenxu94 merged pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8

Posted by GitBox <gi...@apache.org>.
kezhenxu94 merged pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8
URL: https://github.com/apache/skywalking/pull/4307
 
 
   

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


With regards,
Apache Git Services

[GitHub] [skywalking] kezhenxu94 commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8

Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8
URL: https://github.com/apache/skywalking/pull/4307#discussion_r373829546
 
 

 ##########
 File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java
 ##########
 @@ -108,53 +103,36 @@ String serialize(HeaderVersion version) {
      * @param text carries {@link #traceSegmentId} and {@link #spanId}, with '|' split.
      */
     ContextCarrier deserialize(String text, HeaderVersion version) {
-        if (text != null) {
-            // if this carrier is initialized by v1 or v2, don't do deserialize again for performance.
-            if (this.isValid(HeaderVersion.v1) || this.isValid(HeaderVersion.v2)) {
-                return this;
-            }
-            if (HeaderVersion.v1.equals(version)) {
-                String[] parts = text.split("\\|", 8);
-                if (parts.length == 8) {
-                    try {
-                        this.traceSegmentId = new ID(parts[0]);
-                        this.spanId = Integer.parseInt(parts[1]);
-                        this.parentServiceInstanceId = Integer.parseInt(parts[2]);
-                        this.entryServiceInstanceId = Integer.parseInt(parts[3]);
-                        this.peerHost = parts[4];
-                        this.entryEndpointName = parts[5];
-                        this.parentEndpointName = parts[6];
-                        this.primaryDistributedTraceId = new PropagatedTraceId(parts[7]);
-                    } catch (NumberFormatException e) {
-
-                    }
-                }
-            } else if (HeaderVersion.v2.equals(version)) {
-                String[] parts = text.split("\\-", 9);
-                if (parts.length == 9) {
-                    try {
-                        // parts[0] is sample flag, always trace if header exists.
-                        this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
-                        this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
-                        this.spanId = Integer.parseInt(parts[3]);
-                        this.parentServiceInstanceId = Integer.parseInt(parts[4]);
-                        this.entryServiceInstanceId = Integer.parseInt(parts[5]);
-                        this.peerHost = Base64.decode2UTFString(parts[6]);
-                        this.entryEndpointName = Base64.decode2UTFString(parts[7]);
-                        this.parentEndpointName = Base64.decode2UTFString(parts[8]);
-                    } catch (NumberFormatException e) {
-
-                    }
+        if (text == null) {
+            return this;
+        }
+        // if this carrier is initialized by v2, don't do deserialize again for performance.
+        if (this.isValid(HeaderVersion.v2)) {
+            return this;
+        }
+        if (HeaderVersion.v2 == version) {
+            String[] parts = text.split("-", 9);
+            if (parts.length == 9) {
+                try {
+                    // parts[0] is sample flag, always trace if header exists.
+                    this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
+                    this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
+                    this.spanId = Integer.parseInt(parts[3]);
+                    this.parentServiceInstanceId = Integer.parseInt(parts[4]);
+                    this.entryServiceInstanceId = Integer.parseInt(parts[5]);
+                    this.peerHost = Base64.decode2UTFString(parts[6]);
+                    this.entryEndpointName = Base64.decode2UTFString(parts[7]);
+                    this.parentEndpointName = Base64.decode2UTFString(parts[8]);
+                } catch (NumberFormatException ignored) {
+
 
 Review comment:
   Quick return to reduce nested levels

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


With regards,
Apache Git Services