diff --git a/README.md b/README.md index 87621ef67..f0d3abc5c 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Sky Walking SkyWalking: Large-Scale Distributed Systems Tracing Infrastructure, also known Distributed Tracer. [![Build Status](https://travis-ci.org/wu-sheng/sky-walking.svg?branch=master)](https://travis-ci.org/wu-sheng/sky-walking) +[![Coverage Status](https://coveralls.io/repos/github/wu-sheng/sky-walking/badge.svg?branch=master)](https://coveralls.io/github/wu-sheng/sky-walking?branch=master) ![license](https://img.shields.io/aur/license/yaourt.svg) [![codebeat badge](https://codebeat.co/badges/579e4dce-1dc7-4f32-a163-c164eafa1335)](https://codebeat.co/projects/github-com-wu-sheng-sky-walking) [![Join the chat at https://gitter.im/sky-walking/Lobby](https://badges.gitter.im/sky-walking/Lobby.svg)](https://gitter.im/sky-walking/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/LogData.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/LogData.java index b50468bdc..1bc7c8f3c 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/LogData.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/LogData.java @@ -12,14 +12,14 @@ import java.util.Map; */ public class LogData { @Expose - @SerializedName(value="ti") + @SerializedName(value="tm") private long time; @Expose @SerializedName(value="fi") - private Map fields; + private Map fields; - LogData(long time, Map fields) { + LogData(long time, Map fields) { this.time = time; if(fields == null){ throw new NullPointerException(); diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/SegmentsMessage.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/SegmentsMessage.java index cc2fc2bc9..ca34b1180 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/SegmentsMessage.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/SegmentsMessage.java @@ -1,6 +1,5 @@ package com.a.eye.skywalking.trace; -import com.a.eye.skywalking.trace.TraceId.PropagatedTraceId; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.TypeAdapter; diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/Span.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/Span.java index 57573fd4e..9ba226cf4 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/Span.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/Span.java @@ -57,8 +57,16 @@ public class Span{ * {@see https://github.com/opentracing/specification/blob/master/specification.md#set-a-span-tag} */ @Expose - @SerializedName(value="ta") - private final Map tags; + @SerializedName(value="ts") + private final Map tagsWithStr; + + @Expose + @SerializedName(value="tb") + private final Map tagsWithBool; + + @Expose + @SerializedName(value="ti") + private final Map tagsWithInt; /** * Log is a concept from OpenTracing spec. @@ -151,7 +159,9 @@ public class Span{ * Create a new/empty span. */ public Span() { - tags = new HashMap(); + tagsWithStr = new HashMap(5); + tagsWithBool = new HashMap(1); + tagsWithInt = new HashMap(2); logs = new LinkedList(); } @@ -194,17 +204,17 @@ public class Span{ * @return this Span instance, for chaining */ public final Span setTag(String key, String value) { - tags.put(key, value); + tagsWithStr.put(key, value); return this; } public final Span setTag(String key, boolean value) { - tags.put(key, value); + tagsWithBool.put(key, value); return this; } - public final Span setTag(String key, Number value) { - tags.put(key, value); + public final Span setTag(String key, Integer value) { + tagsWithInt.put(key, value); return this; } @@ -214,7 +224,11 @@ public class Span{ * @return */ public final Map getTags() { - return Collections.unmodifiableMap(tags); + Map tags = new HashMap(); + tags.putAll(tagsWithStr); + tags.putAll(tagsWithBool); + tags.putAll(tagsWithInt); + return tags; } /** @@ -223,8 +237,16 @@ public class Span{ * @param key the given tag key. * @return tag value. */ - public Object getTag(String key) { - return tags.get(key); + public String getStrTag(String key) { + return tagsWithStr.get(key); + } + + public Boolean getBoolTag(String key) { + return tagsWithBool.get(key); + } + + public Integer getIntTag(String key) { + return tagsWithInt.get(key); } /** @@ -250,7 +272,7 @@ public class Span{ * @return the Span, for chaining * @see Span#log(String) */ - public Span log(Map fields) { + public Span log(Map fields) { logs.add(new LogData(System.currentTimeMillis(), fields)); return this; } diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java index d5c2edbcf..75e11cdcb 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegment.java @@ -26,21 +26,21 @@ public class TraceSegment { * Every segment has its unique-global-id. */ @Expose - @SerializedName(value="ts") + @SerializedName(value = "ts") private String traceSegmentId; /** * The start time of this trace segment. */ @Expose - @SerializedName(value="st") + @SerializedName(value = "st") private long startTime; /** * The end time of this trace segment. */ @Expose - @SerializedName(value="et") + @SerializedName(value = "et") private long endTime; /** @@ -50,7 +50,7 @@ public class TraceSegment { * at this moment, we use this {@link #refs} to link them. */ @Expose - @SerializedName(value="rs") + @SerializedName(value = "rs") private List refs; /** @@ -59,7 +59,7 @@ public class TraceSegment { * All active spans are hold and controlled by "skywalking-api" module. */ @Expose - @SerializedName(value="ss") + @SerializedName(value = "ss") private List spans; /** @@ -69,7 +69,7 @@ public class TraceSegment { * e.g. account_app, billing_app */ @Expose - @SerializedName(value="ac") + @SerializedName(value = "ac") private String applicationCode; /** @@ -86,9 +86,19 @@ public class TraceSegment { * multi {@link TraceSegment}s, only using {@link #refs} is not enough for analysis and ui. */ @Expose - @SerializedName(value="gt") + @SerializedName(value = "gt") private DistributedTraceIds relatedGlobalTraces; + /** + * The sampled is a flag, which represent, when this {@link TraceSegment} finished, it need to be send + * to Collector. + * + * Its value depends on SamplingService. True, by default. + * + * This value is not serialized. + */ + private boolean sampled; + /** * Create a trace segment, by given segmentId. * This segmentId is generated by TraceSegmentRef, AKA, from tracer/agent module. @@ -107,6 +117,7 @@ public class TraceSegment { this.spans = new LinkedList(); this.relatedGlobalTraces = new DistributedTraceIds(); this.relatedGlobalTraces.append(new NewDistributedTraceId()); + this.sampled = true; } /** @@ -118,7 +129,7 @@ public class TraceSegment { if (refs == null) { refs = new LinkedList(); } - if(!refs.contains(refSegment)){ + if (!refs.contains(refSegment)) { refs.add(refSegment); } } @@ -183,6 +194,14 @@ public class TraceSegment { return applicationCode; } + public boolean isSampled() { + return sampled; + } + + public void setSampled(boolean sampled) { + this.sampled = sampled; + } + @Override public String toString() { return "TraceSegment{" + diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java index e900a7182..0a8a6ab21 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/TraceSegmentRef.java @@ -86,25 +86,18 @@ public class TraceSegmentRef{ '}'; } - @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - TraceSegmentRef ref = (TraceSegmentRef)o; + TraceSegmentRef that = (TraceSegmentRef) o; - if (traceSegmentId != null ? !traceSegmentId.equals(ref.traceSegmentId) : ref.traceSegmentId != null) - return false; - return applicationCode != null ? applicationCode.equals(ref.applicationCode) : ref.applicationCode == null; + return traceSegmentId != null ? traceSegmentId.equals(that.traceSegmentId) : that.traceSegmentId == null; } @Override public int hashCode() { - int result = traceSegmentId != null ? traceSegmentId.hashCode() : 0; - result = 31 * result + (applicationCode != null ? applicationCode.hashCode() : 0); - return result; + return traceSegmentId != null ? traceSegmentId.hashCode() : 0; } } diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/AbstractTag.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/AbstractTag.java index 9ffeea26e..e023ac274 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/AbstractTag.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/AbstractTag.java @@ -7,7 +7,7 @@ import com.a.eye.skywalking.trace.Span; * All span's tags inherit from {@link AbstractTag}, * which provide an easy way to * {@link Span#setTag(String, String)} , - * {@link Span#setTag(String, Number)} , + * {@link Span#setTag(String, Integer)} * {@link Span#setTag(String, boolean)} , * * Created by wusheng on 2017/2/17. diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/BooleanTag.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/BooleanTag.java index 9f3a780f2..20c83af35 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/BooleanTag.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/BooleanTag.java @@ -30,13 +30,11 @@ public class BooleanTag extends AbstractTag { */ @Override public Boolean get(Span span) { - Object tagValue = span.getTag(super.key); + Boolean tagValue = span.getBoolTag(super.key); if (tagValue == null) { return defaultValue; - } else if (tagValue instanceof Boolean) { - return (Boolean) tagValue; } else { - return Boolean.valueOf(tagValue.toString()); + return tagValue; } } } diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/IntTag.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/IntTag.java index 8af1fec9a..cc6b36b2e 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/IntTag.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/IntTag.java @@ -26,13 +26,11 @@ public class IntTag extends AbstractTag { */ @Override public Integer get(Span span) { - Object tagValue = span.getTag(super.key); + Integer tagValue = span.getIntTag(super.key); if (tagValue == null) { return null; - } else if(tagValue instanceof Integer){ - return (Integer)tagValue; - }else { - return Integer.valueOf(tagValue.toString()); + } else { + return tagValue; } } } diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/ShortTag.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/ShortTag.java index ebd93a607..b7e8f6585 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/ShortTag.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/ShortTag.java @@ -14,7 +14,7 @@ public class ShortTag extends AbstractTag { @Override public void set(Span span, Short tagValue) { - span.setTag(super.key, tagValue); + span.setTag(super.key, (int)tagValue.shortValue()); } /** @@ -25,12 +25,10 @@ public class ShortTag extends AbstractTag { * @return tag value */ @Override public Short get(Span span) { - Object tagValue = span.getTag(super.key); + Integer tagValue = span.getIntTag(super.key); if (tagValue == null) { return null; - } else if(tagValue instanceof Short){ - return (Short)tagValue; - }else { + } else { return Short.valueOf(tagValue.toString()); } } diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/StringTag.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/StringTag.java index 229521287..e76825c9c 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/StringTag.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/StringTag.java @@ -19,6 +19,6 @@ public class StringTag extends AbstractTag { } @Override public String get(Span span) { - return (String)span.getTag(super.key); + return span.getStrTag(super.key); } } diff --git a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/LogDataTestCase.java b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/LogDataTestCase.java index 316c278ac..f2f616d22 100644 --- a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/LogDataTestCase.java +++ b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/LogDataTestCase.java @@ -11,7 +11,7 @@ import org.junit.Test; public class LogDataTestCase { @Test public void testHoldValue(){ - Map fields = new HashMap(); + Map fields = new HashMap(); LogData logData = new LogData(123L, fields); Assert.assertEquals(123, logData.getTime()); diff --git a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/tag/TagsTest.java b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/tag/TagsTest.java index 3bb2b4d55..7cb908ffc 100644 --- a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/tag/TagsTest.java +++ b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/tag/TagsTest.java @@ -12,13 +12,13 @@ public class TagsTest { public void testLayer(){ Span span = new Span(1, "/test"); Tags.SPAN_LAYER.asDB(span); - Assert.assertEquals("db", span.getTag("span.layer")); + Assert.assertEquals("db", span.getStrTag("span.layer")); Tags.SPAN_LAYER.asRPCFramework(span); - Assert.assertEquals("rpc", span.getTag("span.layer")); + Assert.assertEquals("rpc", span.getStrTag("span.layer")); Tags.SPAN_LAYER.asHttp(span); - Assert.assertEquals("http", span.getTag("span.layer")); + Assert.assertEquals("http", span.getStrTag("span.layer")); } @Test diff --git a/skywalking-sniffer/skywalking-agent/dependency-reduced-pom.xml b/skywalking-sniffer/skywalking-agent/dependency-reduced-pom.xml index 014bb63e4..0d5b89395 100644 --- a/skywalking-sniffer/skywalking-agent/dependency-reduced-pom.xml +++ b/skywalking-sniffer/skywalking-agent/dependency-reduced-pom.xml @@ -36,23 +36,20 @@ + + + com.lmax:* + org.apache.httpcomponents:* + commons-logging:* + commons-codec:* + *:gson + + ${shade.net.bytebuddy.source} ${shade.net.bytebuddy.target} - - ${shade.com.lmax.disruptor.source} - ${shade.com.lmax.disruptor.target} - - - ${shade.com.google.source} - ${shade.com.google.target} - - - ${shade.org.apache.source} - ${shade.org.apache.target} - @@ -61,6 +58,12 @@ + + com.google.code.gson + gson + 2.8.0 + compile + junit junit @@ -120,17 +123,11 @@ - org.apache - com.a.eye.skywalking.dependencies - com.google ${shade.package}.${shade.net.bytebuddy.source} - ${shade.package}.${shade.com.lmax.disruptor.source} + com.a.eye.skywalking.dependencies UTF-8 net.bytebuddy - ${shade.package}.${shade.com.google.source} - ${shade.package}.${shade.org.apache.source} com.a.eye.skywalking.agent.SkyWalkingAgent - com.lmax.disruptor diff --git a/skywalking-sniffer/skywalking-agent/pom.xml b/skywalking-sniffer/skywalking-agent/pom.xml index d807e4a1f..fcc5b7fe8 100644 --- a/skywalking-sniffer/skywalking-agent/pom.xml +++ b/skywalking-sniffer/skywalking-agent/pom.xml @@ -21,13 +21,6 @@ com.a.eye.skywalking.dependencies net.bytebuddy ${shade.package}.${shade.net.bytebuddy.source} - com.lmax.disruptor - ${shade.package}.${shade.com.lmax.disruptor.source} - - com.google - ${shade.package}.${shade.com.google.source} - org.apache - ${shade.package}.${shade.org.apache.source} @@ -123,23 +116,20 @@ + + + com.lmax:* + org.apache.httpcomponents:* + commons-logging:* + commons-codec:* + *:gson + + ${shade.net.bytebuddy.source} ${shade.net.bytebuddy.target} - - ${shade.com.lmax.disruptor.source} - ${shade.com.lmax.disruptor.target} - - - ${shade.com.google.source} - ${shade.com.google.target} - - - ${shade.org.apache.source} - ${shade.org.apache.target} - diff --git a/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java b/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java index ea6ba500e..d2f2a659c 100644 --- a/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java +++ b/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java @@ -99,8 +99,8 @@ public class SkyWalkingAgent { private static void initConfig() { - Config.SkyWalking.IS_PREMAIN_MODE = true; - Config.SkyWalking.AGENT_BASE_PATH = initAgentBasePath(); + Config.Agent.IS_PREMAIN_MODE = true; + Config.Agent.PATH = initAgentBasePath(); SnifferConfigInitializer.initialize(); } diff --git a/skywalking-sniffer/skywalking-api/pom.xml b/skywalking-sniffer/skywalking-api/pom.xml index f57880769..eab817765 100644 --- a/skywalking-sniffer/skywalking-api/pom.xml +++ b/skywalking-sniffer/skywalking-api/pom.xml @@ -17,6 +17,15 @@ UTF-8 9.4.2.v20170220 + + com.a.eye.skywalking.dependencies + com.lmax.disruptor + ${shade.package}.${shade.com.lmax.disruptor.source} + + com.google + ${shade.package}.${shade.com.google.source} + org.apache + ${shade.package}.${shade.org.apache.source} @@ -74,6 +83,40 @@ ${project.build.sourceEncoding} + + org.apache.maven.plugins + maven-shade-plugin + 2.4.1 + + + package + + shade + + + + + net.bytebuddy:byte-buddy:jar: + + + + + ${shade.com.lmax.disruptor.source} + ${shade.com.lmax.disruptor.target} + + + ${shade.com.google.source} + ${shade.com.google.target} + + + ${shade.org.apache.source} + ${shade.org.apache.target} + + + + + + diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClient.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClient.java index 63e6a8b94..b77f95625 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClient.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/CollectorClient.java @@ -1,11 +1,21 @@ package com.a.eye.skywalking.api.client; import com.a.eye.skywalking.api.boot.ServiceManager; +import com.a.eye.skywalking.api.conf.Config; import com.a.eye.skywalking.api.queue.TraceSegmentProcessQueue; import com.a.eye.skywalking.logging.ILog; import com.a.eye.skywalking.logging.LogManager; +import com.a.eye.skywalking.trace.SegmentsMessage; import com.a.eye.skywalking.trace.TraceSegment; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.io.IOException; import java.util.List; +import java.util.Random; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy; import org.apache.http.impl.client.HttpClients; @@ -21,11 +31,18 @@ public class CollectorClient implements Runnable { private static ILog logger = LogManager.getLogger(CollectorClient.class); private static long SLEEP_TIME_MILLIS = 500; private CloseableHttpClient httpclient; + private String[] serverList; + private volatile int selectedServer = -1; public CollectorClient() { + serverList = Config.Collector.SERVERS.split(","); httpclient = HttpClients.custom() .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()) .build(); + Random r = new Random(); + if (serverList.length > 0) { + selectedServer = r.nextInt(serverList.length); + } } @Override @@ -36,13 +53,19 @@ public class CollectorClient implements Runnable { TraceSegmentProcessQueue segmentProcessQueue = ServiceManager.INSTANCE.findService(TraceSegmentProcessQueue.class); List cachedTraceSegments = segmentProcessQueue.getCachedTraceSegments(); if (cachedTraceSegments.size() > 0) { + SegmentsMessage message = null; + int count = 0; for (TraceSegment segment : cachedTraceSegments) { - /** - * No receiver found, means collector server is off-line. - */ - sleepTime = SLEEP_TIME_MILLIS * 10; - break; + if (message == null) { + message = new SegmentsMessage(); + } + message.append(segment); + if (count == Config.Collector.BATCH_SIZE) { + sendToCollector(message); + message = null; + } } + sendToCollector(message); } else { sleepTime = SLEEP_TIME_MILLIS; } @@ -56,6 +79,64 @@ public class CollectorClient implements Runnable { } } + /** + * Send the given {@link SegmentsMessage} to collector. + * + * @param message to be send. + */ + private void sendToCollector(SegmentsMessage message) throws RESTResponseStatusError, IOException { + if (message == null) { + return; + } + Gson gson = new GsonBuilder() + .excludeFieldsWithoutExposeAnnotation() + .create(); + String messageJson = gson.toJson(message); + + try { + HttpPost httpPost = ready2Send(messageJson); + if (httpPost != null) { + CloseableHttpResponse httpResponse = httpclient.execute(httpPost); + int statusCode = httpResponse.getStatusLine().getStatusCode(); + if (200 != statusCode) { + findBackupServer(); + throw new RESTResponseStatusError(statusCode); + } + } + } catch (IOException e) { + findBackupServer(); + throw e; + } + } + + /** + * Prepare the given message for HTTP Post service. + * + * @param messageJson to send + * @return {@link HttpPost}, when is ready to send. otherwise, null. + */ + private HttpPost ready2Send(String messageJson) { + if (selectedServer == -1) { + //no available server + return null; + } + HttpPost post = new HttpPost("http://" + serverList[selectedServer] + Config.Collector.SERVICE_NAME); + StringEntity entity = new StringEntity(messageJson, ContentType.APPLICATION_JSON); + post.setEntity(entity); + + return post; + } + + /** + * Choose the next server in {@link #serverList}, by moving {@link #selectedServer}. + */ + private void findBackupServer() { + selectedServer++; + if (selectedServer == serverList.length) { + selectedServer = 0; + } + } + /** * Try to sleep, and ignore the {@link InterruptedException} * diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/RESTResponseStatusError.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/RESTResponseStatusError.java new file mode 100644 index 000000000..db74873bd --- /dev/null +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/client/RESTResponseStatusError.java @@ -0,0 +1,13 @@ +package com.a.eye.skywalking.api.client; + +/** + * The RESTResponseStatusError represents the REST-Service client got an unexpected response code. + * Most likely, the response code is not 200. + * + * @author wusheng + */ +class RESTResponseStatusError extends Exception { + RESTResponseStatusError(int responseCode){ + super("Unexpected service response code: " + responseCode); + } +} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java index e2cfae6d0..402b4be81 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/Config.java @@ -2,20 +2,26 @@ package com.a.eye.skywalking.api.conf; public class Config { - public static class SkyWalking { + public static class Agent { public static String APPLICATION_CODE = ""; public static boolean IS_PREMAIN_MODE = false; - public static String AGENT_BASE_PATH = ""; + public static String PATH = ""; + public static int SAMPLING_RATE = 10000; + } + + public static class Collector{ public static String SERVERS = ""; public static String SERVICE_NAME = "/segments"; + + public static int BATCH_SIZE = 50; } - public static class Disruptor{ - public static int BUFFER_SIZE = 512; + public static class Buffer { + public static int SIZE = 512; } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/SnifferConfigInitializer.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/SnifferConfigInitializer.java index 6b63b2a44..9c9fd2f17 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/SnifferConfigInitializer.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/conf/SnifferConfigInitializer.java @@ -15,7 +15,7 @@ public class SnifferConfigInitializer { public static void initialize() { InputStream configFileStream; - if (Config.SkyWalking.IS_PREMAIN_MODE) { + if (Config.Agent.IS_PREMAIN_MODE) { configFileStream = fetchAuthFileInputStream(); } else { configFileStream = SnifferConfigInitializer.class.getResourceAsStream("/sky-walking.config"); @@ -35,24 +35,24 @@ public class SnifferConfigInitializer { String applicationCode = System.getProperty("applicationCode"); if (!StringUtil.isEmpty(applicationCode)) { - Config.SkyWalking.APPLICATION_CODE = applicationCode; + Config.Agent.APPLICATION_CODE = applicationCode; } String servers = System.getProperty("servers"); if(!StringUtil.isEmpty(servers)) { - Config.SkyWalking.SERVERS = servers; + Config.Collector.SERVERS = servers; } - if (StringUtil.isEmpty(Config.SkyWalking.APPLICATION_CODE)) { + if (StringUtil.isEmpty(Config.Agent.APPLICATION_CODE)) { throw new ExceptionInInitializerError("'-DapplicationCode=' is missing."); } - if (StringUtil.isEmpty(Config.SkyWalking.SERVERS)) { + if (StringUtil.isEmpty(Config.Collector.SERVERS)) { throw new ExceptionInInitializerError("'-Dservers=' is missing."); } } private static InputStream fetchAuthFileInputStream() { try { - return new FileInputStream(Config.SkyWalking.AGENT_BASE_PATH + File.separator + "sky-walking.config"); + return new FileInputStream(Config.Agent.PATH + File.separator + "sky-walking.config"); } catch (Exception e) { logger.warn("sky-walking.config is missing, use default config."); return null; diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java index 684922194..9c653518b 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/ContextCarrier.java @@ -42,6 +42,11 @@ public class ContextCarrier implements Serializable { */ private List distributedTraceIds; + /** + * {@link TraceSegment#sampled} + */ + private boolean sampled; + /** * Serialize this {@link ContextCarrier} to a {@link String}, * with '|' split. @@ -54,7 +59,8 @@ public class ContextCarrier implements Serializable { this.getSpanId() + "", this.getApplicationCode(), this.getPeerHost(), - this.serializeDistributedTraceIds()); + this.serializeDistributedTraceIds(), + this.isSampled() ? "1" : "0"); } /** @@ -64,14 +70,15 @@ public class ContextCarrier implements Serializable { */ public ContextCarrier deserialize(String text) { if (text != null) { - String[] parts = text.split("\\|", 5); - if (parts.length == 5) { + String[] parts = text.split("\\|", 6); + if (parts.length == 6) { try { setSpanId(Integer.parseInt(parts[1])); setTraceSegmentId(parts[0]); setApplicationCode(parts[2]); setPeerHost(parts[3]); setDistributedTraceIds(deserializeDistributedTraceIds(parts[4])); + setSampled("1".equals(parts[5])); } catch (NumberFormatException e) { } @@ -129,6 +136,14 @@ public class ContextCarrier implements Serializable { return distributedTraceIds; } + public boolean isSampled() { + return sampled; + } + + public void setSampled(boolean sampled) { + this.sampled = sampled; + } + public void setDistributedTraceIds(List distributedTraceIds) { this.distributedTraceIds = distributedTraceIds; } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java index e484e0d4d..a2a6c5b26 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/context/TracerContext.java @@ -1,6 +1,8 @@ package com.a.eye.skywalking.api.context; +import com.a.eye.skywalking.api.boot.ServiceManager; import com.a.eye.skywalking.api.conf.Config; +import com.a.eye.skywalking.api.sampling.SamplingService; import com.a.eye.skywalking.trace.Span; import com.a.eye.skywalking.trace.TraceSegment; import com.a.eye.skywalking.trace.TraceSegmentRef; @@ -34,7 +36,8 @@ public final class TracerContext { * Create a {@link TraceSegment} and init {@link #spanIdGenerator} as 0; */ TracerContext() { - this.segment = new TraceSegment(Config.SkyWalking.APPLICATION_CODE); + this.segment = new TraceSegment(Config.Agent.APPLICATION_CODE); + ServiceManager.INSTANCE.findService(SamplingService.class).trySampling(this.segment); this.spanIdGenerator = 0; } @@ -123,9 +126,10 @@ public final class TracerContext { public void inject(ContextCarrier carrier) { carrier.setTraceSegmentId(this.segment.getTraceSegmentId()); carrier.setSpanId(this.activeSpan().getSpanId()); - carrier.setApplicationCode(Config.SkyWalking.APPLICATION_CODE); + carrier.setApplicationCode(Config.Agent.APPLICATION_CODE); carrier.setPeerHost(Tags.PEER_HOST.get(activeSpan())); carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces()); + carrier.setSampled(this.segment.isSampled()); } /** @@ -137,6 +141,7 @@ public final class TracerContext { public void extract(ContextCarrier carrier) { if(carrier.isValid()) { this.segment.ref(getRef(carrier)); + ServiceManager.INSTANCE.findService(SamplingService.class).setSampleWhenExtract(this.segment, carrier); this.segment.relatedGlobalTraces(carrier.getDistributedTraceIds()); } } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/logging/SyncFileWriter.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/logging/SyncFileWriter.java index 99d081143..72b305f2b 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/logging/SyncFileWriter.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/logging/SyncFileWriter.java @@ -19,7 +19,7 @@ public class SyncFileWriter implements IWriter { private SyncFileWriter() { try { - File logFilePath = new File(Config.SkyWalking.AGENT_BASE_PATH, Config.Logging.LOG_DIR_NAME); + File logFilePath = new File(Config.Agent.PATH, Config.Logging.LOG_DIR_NAME); if (!logFilePath.exists()) { logFilePath.mkdirs(); } diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/logging/WriterFactory.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/logging/WriterFactory.java index fc38edfee..6e5bd4230 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/logging/WriterFactory.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/logging/WriterFactory.java @@ -4,7 +4,7 @@ import com.a.eye.skywalking.api.conf.Config; public class WriterFactory { public static IWriter getLogWriter(){ - if (Config.SkyWalking.IS_PREMAIN_MODE){ + if (Config.Agent.IS_PREMAIN_MODE){ return SyncFileWriter.instance(); }else{ return new STDOutWriter(); diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java index d868de9f4..94ceac768 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/queue/TraceSegmentProcessQueue.java @@ -30,8 +30,8 @@ public class TraceSegmentProcessQueue extends StatusBootService implements Trace private volatile int cacheIndex; public TraceSegmentProcessQueue() { - disruptor = new Disruptor(TraceSegmentHolder.Factory.INSTANCE, Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE); - secondLevelCache = new TraceSegment[Config.Disruptor.BUFFER_SIZE]; + disruptor = new Disruptor(TraceSegmentHolder.Factory.INSTANCE, Config.Buffer.SIZE, DaemonThreadFactory.INSTANCE); + secondLevelCache = new TraceSegment[Config.Buffer.SIZE]; cacheIndex = 0; disruptor.handleEventsWith(this); buffer = disruptor.getRingBuffer(); @@ -43,9 +43,14 @@ public class TraceSegmentProcessQueue extends StatusBootService implements Trace disruptor.start(); } + /** + * Append the given traceSegment to the queue, wait for sending to Collector. + * + * @param traceSegment finished {@link TraceSegment} + */ @Override public void afterFinished(TraceSegment traceSegment) { - if (isStarted()) { + if (isStarted() && traceSegment.isSampled()) { long sequence = this.buffer.next(); // Grab the next sequence try { TraceSegmentHolder data = this.buffer.get(sequence); diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/sampling/IllegalSamplingRateException.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/sampling/IllegalSamplingRateException.java new file mode 100644 index 000000000..bb89d7a86 --- /dev/null +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/sampling/IllegalSamplingRateException.java @@ -0,0 +1,12 @@ +package com.a.eye.skywalking.api.sampling; + +/** + * Use IllegalSamplingRateException, only if the rate can not be supported. + * + * @author wusheng + */ +public class IllegalSamplingRateException extends Exception { + IllegalSamplingRateException(String message) { + super(message); + } +} diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/sampling/SamplingService.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/sampling/SamplingService.java new file mode 100644 index 000000000..6967c203d --- /dev/null +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/sampling/SamplingService.java @@ -0,0 +1,67 @@ +package com.a.eye.skywalking.api.sampling; + +import com.a.eye.skywalking.api.boot.BootService; +import com.a.eye.skywalking.api.conf.Config; +import com.a.eye.skywalking.api.context.ContextCarrier; +import com.a.eye.skywalking.logging.ILog; +import com.a.eye.skywalking.logging.LogManager; +import com.a.eye.skywalking.trace.TraceSegment; + +/** + * The SamplingService take charge of how to sample the {@link TraceSegment}. Every {@link TraceSegment}s + * have been traced, but, considering CPU cost of serialization/deserialization, and network bandwidth, the agent do NOT + * send all of them to collector, if SAMPLING is on. + * + * By default, SAMPLING is off, and {@link Config.Agent#SAMPLING_RATE} == 1000. + * + * @author wusheng + */ +public class SamplingService implements BootService { + private static ILog logger = LogManager.getLogger(SamplingService.class); + + private volatile boolean on = false; + private volatile int rate = 0; + private volatile int rollingSeed = 0; + + @Override + public void bootUp() throws Throwable { + if (Config.Agent.SAMPLING_RATE == 10000) { + return; + } + if (Config.Agent.SAMPLING_RATE > 10000 || Config.Agent.SAMPLING_RATE < 1) { + throw new IllegalSamplingRateException("sampling rate should stay in (0, 10000]."); + } + rate = 10000 / Config.Agent.SAMPLING_RATE; + on = true; + + logger.debug("The trace sampling is on, and the sampling rate is: {}", rate); + } + + public void trySampling(TraceSegment segment) { + if (on) { + if (rollingSeed++ != rate) { + segment.setSampled(false); + } + } + } + + /** + * Set the {@link TraceSegment} to sampled, when {@link ContextCarrier} contains "isSampled" flag. + * + * A -> B, if TraceSegment is sampled in A, then the related TraceSegment in B must be sampled, no matter you + * sampling rate. And reset the {@link #rollingSeed}, in case of too many {@link TraceSegment}s, which started in + * this JVM, are sampled. + * + * @param segment the current TraceSegment. + * @param carrier + */ + public void setSampleWhenExtract(TraceSegment segment, ContextCarrier carrier) { + if(on) { + if (!segment.isSampled() && carrier.isSampled()) { + segment.setSampled(true); + this.rollingSeed = 0; + } + } + } + +} diff --git a/skywalking-sniffer/skywalking-api/src/main/resources/META-INF/services/com.a.eye.skywalking.api.boot.BootService b/skywalking-sniffer/skywalking-api/src/main/resources/META-INF/services/com.a.eye.skywalking.api.boot.BootService index c84f7acac..0a0bbb211 100644 --- a/skywalking-sniffer/skywalking-api/src/main/resources/META-INF/services/com.a.eye.skywalking.api.boot.BootService +++ b/skywalking-sniffer/skywalking-api/src/main/resources/META-INF/services/com.a.eye.skywalking.api.boot.BootService @@ -1,3 +1,4 @@ com.a.eye.skywalking.api.queue.TraceSegmentProcessQueue com.a.eye.skywalking.api.context.ContextManager com.a.eye.skywalking.api.client.CollectorClientService +com.a.eye.skywalking.api.sampling.SamplingService diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/client/HTTPRestServiceTestApp.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/client/HTTPRestServiceTestApp.java index de4a3d068..24f481fb5 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/client/HTTPRestServiceTestApp.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/client/HTTPRestServiceTestApp.java @@ -75,7 +75,7 @@ public class HTTPRestServiceTestApp { baseRequest.setHandled(true); } }); - //server.start(); + server.start(); return server; } diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/conf/SnifferConfigInitializerTest.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/conf/SnifferConfigInitializerTest.java index 4804c74ba..befd85f85 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/conf/SnifferConfigInitializerTest.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/conf/SnifferConfigInitializerTest.java @@ -11,13 +11,13 @@ public class SnifferConfigInitializerTest { @Test public void testInitialize(){ - Config.SkyWalking.IS_PREMAIN_MODE = false; + Config.Agent.IS_PREMAIN_MODE = false; SnifferConfigInitializer.initialize(); - Assert.assertEquals("crmApp", Config.SkyWalking.APPLICATION_CODE); - Assert.assertEquals("127.0.0.1:8080", Config.SkyWalking.SERVERS); + Assert.assertEquals("crmApp", Config.Agent.APPLICATION_CODE); + Assert.assertEquals("127.0.0.1:8080", Config.Collector.SERVERS); - Assert.assertNotNull(Config.Disruptor.BUFFER_SIZE); + Assert.assertNotNull(Config.Buffer.SIZE); Assert.assertNotNull(Config.Logging.LOG_DIR_NAME); Assert.assertNotNull(Config.Logging.LOG_FILE_NAME); Assert.assertNotNull(Config.Logging.MAX_LOG_FILE_LENGTH); @@ -26,12 +26,12 @@ public class SnifferConfigInitializerTest { @Test(expected = ExceptionInInitializerError.class) public void testErrorInitialize(){ - Config.SkyWalking.IS_PREMAIN_MODE = true; + Config.Agent.IS_PREMAIN_MODE = true; SnifferConfigInitializer.initialize(); } @AfterClass public static void reset(){ - Config.SkyWalking.IS_PREMAIN_MODE = false; + Config.Agent.IS_PREMAIN_MODE = false; } } diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java index 269911b79..6809afed6 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextCarrierTestCase.java @@ -18,17 +18,18 @@ public class ContextCarrierTestCase { carrier.setSpanId(100); carrier.setApplicationCode("REMOTE_APP"); carrier.setPeerHost("10.2.3.16:8080"); + carrier.setSampled(true); List ids = new LinkedList(); ids.add(new PropagatedTraceId("Trace.global.id.123")); carrier.setDistributedTraceIds(ids); - Assert.assertEquals("trace_id_A|100|REMOTE_APP|10.2.3.16:8080|Trace.global.id.123", carrier.serialize()); + Assert.assertEquals("trace_id_A|100|REMOTE_APP|10.2.3.16:8080|Trace.global.id.123|1", carrier.serialize()); } @Test public void testDeserialize(){ ContextCarrier carrier = new ContextCarrier(); - carrier.deserialize("trace_id_A|100|REMOTE_APP|10.2.3.16:8080|Trace.global.id.123,Trace.global.id.222"); + carrier.deserialize("trace_id_A|100|REMOTE_APP|10.2.3.16:8080|Trace.global.id.123,Trace.global.id.222|1"); Assert.assertEquals("trace_id_A", carrier.getTraceSegmentId()); Assert.assertEquals(100, carrier.getSpanId()); @@ -36,6 +37,7 @@ public class ContextCarrierTestCase { Assert.assertEquals("10.2.3.16:8080", carrier.getPeerHost()); Assert.assertEquals("Trace.global.id.123", carrier.getDistributedTraceIds().get(0).get()); Assert.assertEquals("Trace.global.id.222", carrier.getDistributedTraceIds().get(1).get()); + Assert.assertEquals(true, carrier.isSampled()); } @Test @@ -62,6 +64,10 @@ public class ContextCarrierTestCase { carrier = new ContextCarrier(); carrier.deserialize("trace_id|100|REMOTE_APP|10.2.3.16:8080|Trace.global.id.123,Trace.global.id.222"); + Assert.assertFalse(carrier.isValid()); + + carrier = new ContextCarrier(); + carrier.deserialize("trace_id|100|REMOTE_APP|10.2.3.16:8080|Trace.global.id.123,Trace.global.id.222|0"); Assert.assertTrue(carrier.isValid()); } } diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextManagerTestCase.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextManagerTestCase.java index f0b092a0b..bef3c3c5d 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextManagerTestCase.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/context/ContextManagerTestCase.java @@ -1,16 +1,23 @@ package com.a.eye.skywalking.api.context; +import com.a.eye.skywalking.api.boot.ServiceManager; import com.a.eye.skywalking.trace.Span; import com.a.eye.skywalking.trace.TraceSegment; import com.a.eye.skywalking.trace.tag.Tags; import org.junit.After; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; /** * Created by wusheng on 2017/2/19. */ public class ContextManagerTestCase { + @BeforeClass + public static void setup(){ + ServiceManager.INSTANCE.boot(); + } + @Test public void testDelegateToTracerContext(){ Span span = ContextManager.createSpan("serviceA"); diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/logging/EasyLoggerTest.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/logging/EasyLoggerTest.java index 0e6cd274c..854798abc 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/logging/EasyLoggerTest.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/logging/EasyLoggerTest.java @@ -26,7 +26,7 @@ public class EasyLoggerTest { @Test public void testLog(){ - Config.SkyWalking.IS_PREMAIN_MODE = false; + Config.Agent.IS_PREMAIN_MODE = false; PrintStream output = Mockito.mock(PrintStream.class); System.setOut(output); diff --git a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/logging/WriterFactoryTest.java b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/logging/WriterFactoryTest.java index eec580928..d7adefd40 100644 --- a/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/logging/WriterFactoryTest.java +++ b/skywalking-sniffer/skywalking-api/src/test/java/com/a/eye/skywalking/api/logging/WriterFactoryTest.java @@ -25,18 +25,18 @@ public class WriterFactoryTest { */ @Test public void testGetLogWriter(){ - Config.SkyWalking.IS_PREMAIN_MODE = true; + Config.Agent.IS_PREMAIN_MODE = true; PrintStream mockStream = Mockito.mock(PrintStream.class); System.setErr(mockStream); Assert.assertEquals(SyncFileWriter.instance(), WriterFactory.getLogWriter()); - Config.SkyWalking.IS_PREMAIN_MODE = false; + Config.Agent.IS_PREMAIN_MODE = false; Assert.assertTrue(WriterFactory.getLogWriter() instanceof STDOutWriter); } @AfterClass public static void reset(){ - Config.SkyWalking.IS_PREMAIN_MODE = false; + Config.Agent.IS_PREMAIN_MODE = false; System.setErr(errRef); } } diff --git a/skywalking-sniffer/skywalking-api/src/test/resources/sky-walking.config b/skywalking-sniffer/skywalking-api/src/test/resources/sky-walking.config index 7817dd446..b563dfb11 100644 --- a/skywalking-sniffer/skywalking-api/src/test/resources/sky-walking.config +++ b/skywalking-sniffer/skywalking-api/src/test/resources/sky-walking.config @@ -1,2 +1,2 @@ -skywalking.application_code = crmApp -skywalking.servers = 127.0.0.1:8080 +agent.application_code = crmApp +collector.servers = 127.0.0.1:8080 diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/pom.xml b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/pom.xml index 1fa1a6eaf..bd8525c12 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/pom.xml +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/pom.xml @@ -18,11 +18,6 @@ - - com.a.eye - skywalking-api - 3.0-2017 - org.springframework spring-context diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java index 4e479b039..75026a8dd 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java @@ -80,7 +80,7 @@ public class DubboInterceptorTest { Mockito.when(RpcContext.getContext()).thenReturn(rpcContext); when(rpcContext.isConsumerSide()).thenReturn(true); when(methodInvokeContext.allArguments()).thenReturn(new Object[]{invoker, invocation}); - Config.SkyWalking.APPLICATION_CODE = "DubboTestCases-APP"; + Config.Agent.APPLICATION_CODE = "DubboTestCases-APP"; } @@ -155,7 +155,7 @@ public class DubboInterceptorTest { @Test public void testProviderWithAttachment() { when(rpcContext.isConsumerSide()).thenReturn(false); - when(rpcContext.getAttachment(DubboInterceptor.ATTACHMENT_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123"); + when(rpcContext.getAttachment(DubboInterceptor.ATTACHMENT_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123|1"); dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result); @@ -168,7 +168,7 @@ public class DubboInterceptorTest { when(rpcContext.isConsumerSide()).thenReturn(false); when(BugFixActive.isActive()).thenReturn(true); - testParam.setTraceContext("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123"); + testParam.setTraceContext("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123|1"); dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml index 4d13cff6b..03708288b 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml @@ -20,13 +20,6 @@ - - com.a.eye - skywalking-api - ${project.version} - - - org.apache.httpcomponents httpclient diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml index db239652d..ebddf6e30 100755 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml @@ -18,11 +18,6 @@ - - com.a.eye - skywalking-api - 3.0-2017 - mysql mysql-connector-java diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptorTest.java index 140bc34f4..e1a75e3a9 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptorTest.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/test/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptorTest.java @@ -94,7 +94,7 @@ public class MotanProviderInterceptorTest { @Test public void testInvokerWithRefSegment() { HashMap attachments = new HashMap(); - attachments.put("SWTraceContext", "302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123"); + attachments.put("SWTraceContext", "302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123|1"); when(request.getAttachments()).thenReturn(attachments); invokeInterceptor.beforeMethod(instanceContext, interceptorContext, null); diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java index 6d2b4e38a..76f01259d 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java @@ -81,7 +81,7 @@ public class TomcatInterceptorTest { @Test public void testWithSerializedContextData() { - when(request.getHeader(TomcatInterceptor.HEADER_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123"); + when(request.getHeader(TomcatInterceptor.HEADER_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1|Trace.globalId.123|1"); tomcatInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); tomcatInterceptor.afterMethod(classInstanceContext, methodInvokeContext, null); diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/pom.xml b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/pom.xml index d159c4e6b..cf91ccd65 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/pom.xml +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/pom.xml @@ -12,11 +12,6 @@ skywalking-toolkit-opentracing-activation - - com.a.eye - skywalking-api - ${project.version} - com.a.eye skywalking-toolkit-opentracing diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/span/interceptor/SpanSetTagInterceptor.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/span/interceptor/SpanSetTagInterceptor.java index 028ea37c6..e3a6e7ba9 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/span/interceptor/SpanSetTagInterceptor.java +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-opentracing-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/opentracing/span/interceptor/SpanSetTagInterceptor.java @@ -24,8 +24,10 @@ public class SpanSetTagInterceptor implements InstanceMethodsAroundInterceptor { ContextManager.activeSpan().setTag(key, (String)value); else if (value instanceof Boolean) ContextManager.activeSpan().setTag(key, (Boolean)value); - else if (value instanceof Number) - ContextManager.activeSpan().setTag(key, (Number)value); + else if (value instanceof Integer) + ContextManager.activeSpan().setTag(key, (Integer)value); + else + ContextManager.activeSpan().setTag(key, value.toString()); } @Override diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/pom.xml b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/pom.xml index c78fd3771..fff2540da 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/pom.xml +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/pom.xml @@ -12,11 +12,4 @@ jar skywalking-toolkit-trace-context-activation - - - com.a.eye - skywalking-api - 3.0-2017 - - diff --git a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextInterceptor.java b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextInterceptor.java index f3715e652..938d0e249 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextInterceptor.java +++ b/skywalking-sniffer/skywalking-toolkit-activation/skywalking-toolkit-trace-context-activation/src/main/java/com/a/eye/skywalking/toolkit/activation/trace/TraceContextInterceptor.java @@ -24,9 +24,7 @@ public class TraceContextInterceptor implements StaticMethodsAroundInterceptor { @Override public Object afterMethod(StaticMethodInvokeContext interceptorContext, Object ret) { - ContextCarrier carrier = new ContextCarrier(); - ContextManager.inject(carrier); - return carrier.getTraceSegmentId(); + return ContextManager.getTraceSegmentId(); } @Override