diff --git a/skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java b/skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java index 4fef799b7..915ed0a43 100644 --- a/skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java +++ b/skywalking-protocol/src/main/java/com/ai/cloud/skywalking/protocol/Span.java @@ -192,9 +192,8 @@ public class Span extends SpanData { try { buf = new ByteArrayOutputStream(); Throwable causeException = e; - while (causeException != null - && (causeException.getCause() != null || expMessage - .length() < maxExceptionStackLength)) { + while (expMessage.length() < maxExceptionStackLength && causeException != null + && causeException.getCause() != null) { causeException.printStackTrace(new java.io.PrintWriter(buf, true)); expMessage.append(buf.toString()); @@ -209,7 +208,13 @@ public class Span extends SpanData { "Close exception stack input stream failed", ioe); } } - this.exceptionStack = expMessage.toString(); + + int sublength = maxExceptionStackLength; + if (maxExceptionStackLength > expMessage.length()){ + sublength = expMessage.length(); + } + + this.exceptionStack = expMessage.toString().substring(0, sublength); if (!exclusiveExceptionSet.contains(e.getClass().getName())) { this.statusCode = 1; diff --git a/skywalking-server/src/main/java/com/ai/cloud/skywalking/reciever/CollectionServer.java b/skywalking-server/src/main/java/com/ai/cloud/skywalking/reciever/CollectionServer.java index 22d3e7d8a..436ee2b75 100644 --- a/skywalking-server/src/main/java/com/ai/cloud/skywalking/reciever/CollectionServer.java +++ b/skywalking-server/src/main/java/com/ai/cloud/skywalking/reciever/CollectionServer.java @@ -1,11 +1,12 @@ package com.ai.cloud.skywalking.reciever; +import com.ai.cloud.skywalking.reciever.buffer.DataBufferThreadContainer; +import com.ai.cloud.skywalking.reciever.conf.Config; +import com.ai.cloud.skywalking.reciever.conf.ConfigInitializer; +import com.ai.cloud.skywalking.reciever.handler.CollectionServerDataHandler; +import com.ai.cloud.skywalking.reciever.persistance.PersistenceThreadLauncher; import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.EventLoopGroup; +import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.LengthFieldBasedFrameDecoder; @@ -14,18 +15,11 @@ import io.netty.handler.codec.bytes.ByteArrayDecoder; import io.netty.handler.codec.bytes.ByteArrayEncoder; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; - -import java.io.IOException; -import java.util.Properties; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.ai.cloud.skywalking.reciever.buffer.DataBufferThreadContainer; -import com.ai.cloud.skywalking.reciever.conf.Config; -import com.ai.cloud.skywalking.reciever.conf.ConfigInitializer; -import com.ai.cloud.skywalking.reciever.handler.CollectionServerDataHandler; -import com.ai.cloud.skywalking.reciever.persistance.PersistenceThreadLauncher; +import java.io.IOException; +import java.util.Properties; public class CollectionServer { @@ -49,7 +43,7 @@ public class CollectionServer { @Override public void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); - p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4)); + p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 0)); p.addLast("frameEncoder", new LengthFieldPrepender(4)); p.addLast("decoder", new ByteArrayDecoder()); p.addLast("encoder", new ByteArrayEncoder()); diff --git a/skywalking-server/src/main/java/com/ai/cloud/skywalking/reciever/handler/CollectionServerDataHandler.java b/skywalking-server/src/main/java/com/ai/cloud/skywalking/reciever/handler/CollectionServerDataHandler.java index e660fdf39..cca00fba6 100644 --- a/skywalking-server/src/main/java/com/ai/cloud/skywalking/reciever/handler/CollectionServerDataHandler.java +++ b/skywalking-server/src/main/java/com/ai/cloud/skywalking/reciever/handler/CollectionServerDataHandler.java @@ -12,7 +12,26 @@ public class CollectionServerDataHandler extends SimpleChannelInboundHandler= 0 && msg.length < Config.DataPackage.MAX_DATA_PACKAGE) { - DataBufferThreadContainer.getDataBufferThread().saveTemporarily(msg); + int start = 0; + int end; + while (start < msg.length) { + int length = bytesToInt(msg, start); + start = start + 4; + end = start + length; + byte[] dest = new byte[length]; + System.arraycopy(msg, start, dest, 0, length); + DataBufferThreadContainer.getDataBufferThread().saveTemporarily(dest); + start = end; + } } } + + public static int bytesToInt(byte[] ary, int offset) { + int value; + value = (int) ((ary[offset + 3] & 0xFF) + | ((ary[offset + 2] << 8) & 0xFF00) + | ((ary[offset + 1] << 16) & 0xFF0000) + | ((ary[offset] << 24) & 0xFF000000)); + return value; + } }