提交 43eb0f42 编写于 作者: P pengys5

Fixed bug #203.

The nextString method in JsonReader class return a non quote value, some special character e.g. ‘, ” ,\ , / , it will be trigger an exception when Segment entity build a json string to insert into elasticsearch.
上级 30b79503
......@@ -6,8 +6,8 @@ import com.a.eye.skywalking.collector.actor.LocalAsyncWorkerRef;
import com.a.eye.skywalking.collector.actor.LocalWorkerContext;
import com.a.eye.skywalking.collector.actor.Role;
import com.a.eye.skywalking.collector.worker.segment.entity.Segment;
import com.a.eye.skywalking.collector.worker.segment.entity.SegmentJsonReader;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import java.io.BufferedReader;
import java.io.IOException;
import javax.servlet.ServletException;
......@@ -57,12 +57,12 @@ public abstract class AbstractPost extends AbstractLocalAsyncWorker {
}
private void streamReader(BufferedReader bufferedReader) throws Exception {
try (JsonReader reader = new JsonReader(bufferedReader)) {
try (SegmentJsonReader reader = new SegmentJsonReader(bufferedReader)) {
readSegmentArray(reader);
}
}
private void readSegmentArray(JsonReader reader) throws Exception {
private void readSegmentArray(SegmentJsonReader reader) throws Exception {
reader.beginArray();
while (reader.hasNext()) {
Segment segment = new Segment();
......
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
/**
......@@ -14,8 +12,8 @@ public class GlobalTraceId extends DeserializeObject {
return globalTraceId;
}
public GlobalTraceId deserialize(JsonReader reader) throws IOException {
this.globalTraceId = reader.nextString();
public GlobalTraceId deserialize(SegmentJsonReader reader) throws IOException {
this.globalTraceId = reader.nextString().getNonQuoteValue();
this.setJsonStr("\"" + globalTraceId + "\"");
return this;
}
......
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
......@@ -21,7 +19,7 @@ public class LogData extends DeserializeObject {
return fields;
}
public LogData deserialize(JsonReader reader) throws IOException {
public LogData deserialize(SegmentJsonReader reader) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("{");
......@@ -40,7 +38,7 @@ public class LogData extends DeserializeObject {
while (reader.hasNext()) {
String key = reader.nextName();
String value = reader.nextString();
String value = reader.nextString().getQuoteValue();
fields.put(key, value);
}
reader.endObject();
......
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
......@@ -46,7 +44,7 @@ public class Segment extends DeserializeObject {
return relatedGlobalTraces;
}
public Segment deserialize(JsonReader reader) throws IOException {
public Segment deserialize(SegmentJsonReader reader) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("{");
......@@ -55,14 +53,14 @@ public class Segment extends DeserializeObject {
while (reader.hasNext()) {
switch (reader.nextName()) {
case "ts":
String ts = reader.nextString();
this.traceSegmentId = ts;
JsonBuilder.INSTANCE.append(stringBuilder, "ts", ts, first);
SegmentJsonReader.StringValue ts = reader.nextString();
this.traceSegmentId = ts.getNonQuoteValue();
JsonBuilder.INSTANCE.append(stringBuilder, "ts", ts.getQuoteValue(), first);
break;
case "ac":
String ac = reader.nextString();
this.applicationCode = ac;
JsonBuilder.INSTANCE.append(stringBuilder, "ac", ac, first);
SegmentJsonReader.StringValue ac = reader.nextString();
this.applicationCode = ac.getNonQuoteValue();
JsonBuilder.INSTANCE.append(stringBuilder, "ac", ac.getQuoteValue(), first);
break;
case "st":
long st = reader.nextLong();
......
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
......@@ -15,7 +13,7 @@ public enum SegmentDeserialize {
INSTANCE;
public Segment deserializeSingle(String singleSegmentJsonStr) throws IOException {
JsonReader reader = new JsonReader(new StringReader(singleSegmentJsonStr));
SegmentJsonReader reader = new SegmentJsonReader(new StringReader(singleSegmentJsonStr));
Segment segment = new Segment();
segment.deserialize(reader);
return segment;
......@@ -28,12 +26,12 @@ public enum SegmentDeserialize {
}
private void streamReader(List<Segment> segmentList, FileReader fileReader) throws Exception {
try (JsonReader reader = new JsonReader(fileReader)) {
try (SegmentJsonReader reader = new SegmentJsonReader(fileReader)) {
readSegmentArray(segmentList, reader);
}
}
private void readSegmentArray(List<Segment> segmentList, JsonReader reader) throws Exception {
private void readSegmentArray(List<Segment> segmentList, SegmentJsonReader reader) throws Exception {
reader.beginArray();
while (reader.hasNext()) {
Segment segment = new Segment();
......
package com.a.eye.skywalking.collector.worker.segment.entity;
/**
* Copy from {@link com.google.gson.stream.JsonScope}, this class is invisible, {@link SegmentJsonReader} can not use it
* because of the package is different
*
* @author pengys5
*/
public class SegmentJsonScope {
/**
* An array with no elements requires no separators or newlines before
* it is closed.
*/
static final int EMPTY_ARRAY = 1;
/**
* A array with at least one value requires a comma and newline before
* the next element.
*/
static final int NONEMPTY_ARRAY = 2;
/**
* An object with no name/value pairs requires no separators or newlines
* before it is closed.
*/
static final int EMPTY_OBJECT = 3;
/**
* An object whose most recent element is a key. The next element must
* be a value.
*/
static final int DANGLING_NAME = 4;
/**
* An object with at least one name/value pair requires a comma and
* newline before the next element.
*/
static final int NONEMPTY_OBJECT = 5;
/**
* No object or array has been started.
*/
static final int EMPTY_DOCUMENT = 6;
/**
* A document with at an array or object.
*/
static final int NONEMPTY_DOCUMENT = 7;
/**
* A document that's been closed and cannot be accessed.
*/
static final int CLOSED = 8;
}
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -58,7 +56,7 @@ public class Span extends DeserializeObject {
return logs;
}
public Span deserialize(JsonReader reader) throws IOException {
public Span deserialize(SegmentJsonReader reader) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("{");
......@@ -87,7 +85,7 @@ public class Span extends DeserializeObject {
JsonBuilder.INSTANCE.append(stringBuilder, "et", et, first);
break;
case "on":
String on = reader.nextString();
String on = reader.nextString().getNonQuoteValue();
this.operationName = on;
JsonBuilder.INSTANCE.append(stringBuilder, "on", on, first);
break;
......@@ -97,7 +95,7 @@ public class Span extends DeserializeObject {
while (reader.hasNext()) {
String key = reader.nextName();
String value = reader.nextString();
String value = reader.nextString().getQuoteValue();
tagsWithStr.put(key, value);
}
reader.endObject();
......
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
/**
......@@ -32,7 +31,7 @@ public class TraceSegmentRef extends DeserializeObject {
return peerHost;
}
public TraceSegmentRef deserialize(JsonReader reader) throws IOException {
public TraceSegmentRef deserialize(SegmentJsonReader reader) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("{");
......@@ -41,7 +40,7 @@ public class TraceSegmentRef extends DeserializeObject {
while (reader.hasNext()) {
switch (reader.nextName()) {
case "ts":
String ts = reader.nextString();
String ts = reader.nextString().getNonQuoteValue();
this.traceSegmentId = ts;
JsonBuilder.INSTANCE.append(stringBuilder, "ts", ts, first);
break;
......@@ -51,12 +50,12 @@ public class TraceSegmentRef extends DeserializeObject {
JsonBuilder.INSTANCE.append(stringBuilder, "si", si, first);
break;
case "ac":
String ac = reader.nextString();
String ac = reader.nextString().getNonQuoteValue();
this.applicationCode = ac;
JsonBuilder.INSTANCE.append(stringBuilder, "ac", ac, first);
break;
case "ph":
String ph = reader.nextString();
String ph = reader.nextString().getNonQuoteValue();
this.peerHost = ph;
JsonBuilder.INSTANCE.append(stringBuilder, "ph", ph, first);
break;
......
......@@ -42,7 +42,7 @@ public enum PersistenceTimer {
List<AbstractLocalSyncWorker> workers = PersistenceWorkerListener.INSTANCE.getWorkers();
for (AbstractLocalSyncWorker worker : workers) {
logger.info("worker role name: %s", worker.getRole().roleName());
logger.debug("worker role name: %s", worker.getRole().roleName());
try {
worker.allocateJob(new FlushAndSwitch(), dataList);
} catch (Exception e) {
......
......@@ -16,7 +16,7 @@
</RollingFile>
</Appenders>
<Loggers>
<logger name="com.a.eye.skywalking.collector" level="debug">
<logger name="com.a.eye.skywalking.collector" level="INFO">
<AppenderRef ref="RollingFile"/>
</logger>
<Root level="INFO">
......
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Map;
......@@ -16,7 +15,7 @@ public class LogDataTestCase {
public void deserialize() throws IOException {
LogData logData = new LogData();
JsonReader reader = new JsonReader(new StringReader("{\"tm\":1, \"fi\": {\"test1\":\"test1\",\"test2\":\"test2\"}, \"skip\":\"skip\"}"));
SegmentJsonReader reader = new SegmentJsonReader(new StringReader("{\"tm\":1, \"fi\": {\"test1\":\"test1\",\"test2\":\"test2\"}, \"skip\":\"skip\"}"));
logData.deserialize(reader);
Assert.assertEquals(1L, logData.getTime());
......
package com.a.eye.skywalking.collector.worker.segment.entity;
import com.google.gson.stream.JsonReader;
import java.io.IOException;
import java.io.StringReader;
import org.junit.Assert;
......@@ -14,7 +13,7 @@ public class TraceSegmentRefTestCase {
@Test
public void deserialize() throws IOException {
TraceSegmentRef traceSegmentRef = new TraceSegmentRef();
JsonReader reader = new JsonReader(new StringReader("{\"ts\" :\"ts\",\"si\":0,\"ac\":\"ac\",\"ph\":\"ph\", \"skip\":\"skip\"}"));
SegmentJsonReader reader = new SegmentJsonReader(new StringReader("{\"ts\" :\"ts\",\"si\":0,\"ac\":\"ac\",\"ph\":\"ph\", \"skip\":\"skip\"}"));
traceSegmentRef.deserialize(reader);
Assert.assertEquals("ts", traceSegmentRef.getTraceSegmentId());
......
......@@ -357,11 +357,19 @@
"ts": {
"span.layer": "rpc",
"component": "Motan",
"span.kind": "server"
"span.kind": "server",
"sql": "select * from table where column=\"value\""
},
"tb": {},
"ti": {},
"lo": []
"lo": [
{
"tm": 1490923010332,
"fi": {
"special.character": "\'\" \\ /"
}
}
]
}
],
"ac": "cache-service",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册