未验证 提交 c6ada8c9 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Support new v2 protocol and make concept consistently (#1937)

* Update new protocol

* Support new protocol at agent side.

* Fix test case.

* Make backend supports new trace protocol

* Fix tests.

* Make all new services available in gRPC.

* Fix bugs.

* Finish new document for v2 trace protocol.

* Fix wrong version requirement of zk

* Fix trace query bug.

* Find a client side dictionary bug.

* Fix register bugs.

* Fix break doc links.
上级 0ae26f8e
Subproject commit e7fc69462955c86d70f3f7f33712dfe33ecefbc6
Subproject commit b66fa070fd647662f06497e4ed3657eb258cb6e9
......@@ -40,7 +40,7 @@ public class Config {
* Application code is showed in sky-walking-ui. Suggestion: set an unique name for each application, one
* application's nodes share the same code.
*/
public static String APPLICATION_CODE = "";
public static String SERVICE_NAME = "";
/**
* Authentication active is based on backend setting, see application.yml for more details.
......@@ -114,9 +114,9 @@ public class Config {
/**
* The buffer size of application codes and peer
*/
public static int APPLICATION_CODE_BUFFER_SIZE = 10 * 10000;
public static int SERVICE_CODE_BUFFER_SIZE = 10 * 10000;
public static int OPERATION_NAME_BUFFER_SIZE = 1000 * 10000;
public static int ENDPOINT_NAME_BUFFER_SIZE = 1000 * 10000;
}
public static class Logging {
......
......@@ -29,8 +29,8 @@ import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
*/
public class RemoteDownstreamConfig {
public static class Agent {
public volatile static int APPLICATION_ID = DictionaryUtil.nullValue();
public volatile static int SERVICE_ID = DictionaryUtil.nullValue();
public volatile static int APPLICATION_INSTANCE_ID = DictionaryUtil.nullValue();
public volatile static int SERVICE_INSTANCE_ID = DictionaryUtil.nullValue();
}
}
......@@ -87,8 +87,8 @@ public class SnifferConfigInitializer {
}
}
if (StringUtil.isEmpty(Config.Agent.APPLICATION_CODE)) {
throw new ExceptionInInitializerError("`agent.application_code` is missing.");
if (StringUtil.isEmpty(Config.Agent.SERVICE_NAME)) {
throw new ExceptionInInitializerError("`agent.service_code` is missing.");
}
if (StringUtil.isEmpty(Config.Collector.BACKEND_SERVICE)) {
throw new ExceptionInInitializerError("`collector.direct_servers` and `collector.servers` cannot be empty at the same time.");
......
......@@ -49,12 +49,12 @@ public class ContextCarrier implements Serializable {
/**
* id of parent application instance, it's the id assigned by collector.
*/
private int parentApplicationInstanceId = DictionaryUtil.nullValue();
private int parentServiceInstanceId = DictionaryUtil.nullValue();
/**
* id of first application instance in this distributed trace, it's the id assigned by collector.
*/
private int entryApplicationInstanceId = DictionaryUtil.nullValue();
private int entryServiceInstanceId = DictionaryUtil.nullValue();
/**
* peer(ipv4s/ipv6/hostname + port) of the server, from client side.
......@@ -64,12 +64,12 @@ public class ContextCarrier implements Serializable {
/**
* Operation/Service name of the first one in this distributed trace. This name may be compressed to an integer.
*/
private String entryOperationName;
private String entryEndpointName;
/**
* Operation/Service name of the parent one in this distributed trace. This name may be compressed to an integer.
*/
private String parentOperationName;
private String parentEndpointName;
/**
* {@link DistributedTraceId}, also known as TraceId
......@@ -106,11 +106,11 @@ public class ContextCarrier implements Serializable {
return StringUtil.join('|',
this.getTraceSegmentId().encode(),
this.getSpanId() + "",
this.getParentApplicationInstanceId() + "",
this.getEntryApplicationInstanceId() + "",
this.getParentServiceInstanceId() + "",
this.getEntryServiceInstanceId() + "",
this.getPeerHost(),
this.getEntryOperationName(),
this.getParentOperationName(),
this.getEntryEndpointName(),
this.getParentEndpointName(),
this.getPrimaryDistributedTraceId().encode());
} else {
return "";
......@@ -122,11 +122,11 @@ public class ContextCarrier implements Serializable {
Base64.encode(this.getPrimaryDistributedTraceId().encode()),
Base64.encode(this.getTraceSegmentId().encode()),
this.getSpanId() + "",
this.getParentApplicationInstanceId() + "",
this.getEntryApplicationInstanceId() + "",
this.getParentServiceInstanceId() + "",
this.getEntryServiceInstanceId() + "",
Base64.encode(this.getPeerHost()),
Base64.encode(this.getEntryOperationName()),
Base64.encode(this.getParentOperationName()));
Base64.encode(this.getEntryEndpointName()),
Base64.encode(this.getParentEndpointName()));
} else {
return "";
}
......@@ -153,11 +153,11 @@ public class ContextCarrier implements Serializable {
try {
this.traceSegmentId = new ID(parts[0]);
this.spanId = Integer.parseInt(parts[1]);
this.parentApplicationInstanceId = Integer.parseInt(parts[2]);
this.entryApplicationInstanceId = Integer.parseInt(parts[3]);
this.parentServiceInstanceId = Integer.parseInt(parts[2]);
this.entryServiceInstanceId = Integer.parseInt(parts[3]);
this.peerHost = parts[4];
this.entryOperationName = parts[5];
this.parentOperationName = parts[6];
this.entryEndpointName = parts[5];
this.parentEndpointName = parts[6];
this.primaryDistributedTraceId = new PropagatedTraceId(parts[7]);
} catch (NumberFormatException e) {
......@@ -171,11 +171,11 @@ public class ContextCarrier implements Serializable {
this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
this.spanId = Integer.parseInt(parts[3]);
this.parentApplicationInstanceId = Integer.parseInt(parts[4]);
this.entryApplicationInstanceId = Integer.parseInt(parts[5]);
this.parentServiceInstanceId = Integer.parseInt(parts[4]);
this.entryServiceInstanceId = Integer.parseInt(parts[5]);
this.peerHost = Base64.decode2UTFString(parts[6]);
this.entryOperationName = Base64.decode2UTFString(parts[7]);
this.parentOperationName = Base64.decode2UTFString(parts[8]);
this.entryEndpointName = Base64.decode2UTFString(parts[7]);
this.parentEndpointName = Base64.decode2UTFString(parts[8]);
} catch (NumberFormatException e) {
}
......@@ -201,18 +201,18 @@ public class ContextCarrier implements Serializable {
return traceSegmentId != null
&& traceSegmentId.isValid()
&& getSpanId() > -1
&& parentApplicationInstanceId != DictionaryUtil.nullValue()
&& entryApplicationInstanceId != DictionaryUtil.nullValue()
&& parentServiceInstanceId != DictionaryUtil.nullValue()
&& entryServiceInstanceId != DictionaryUtil.nullValue()
&& !StringUtil.isEmpty(peerHost)
&& !StringUtil.isEmpty(entryOperationName)
&& !StringUtil.isEmpty(parentOperationName)
&& !StringUtil.isEmpty(entryEndpointName)
&& !StringUtil.isEmpty(parentEndpointName)
&& primaryDistributedTraceId != null;
} else if (HeaderVersion.v2.equals(version)) {
return traceSegmentId != null
&& traceSegmentId.isValid()
&& getSpanId() > -1
&& parentApplicationInstanceId != DictionaryUtil.nullValue()
&& entryApplicationInstanceId != DictionaryUtil.nullValue()
&& parentServiceInstanceId != DictionaryUtil.nullValue()
&& entryServiceInstanceId != DictionaryUtil.nullValue()
&& !StringUtil.isEmpty(peerHost)
&& primaryDistributedTraceId != null;
} else {
......@@ -220,24 +220,24 @@ public class ContextCarrier implements Serializable {
}
}
public String getEntryOperationName() {
return entryOperationName;
public String getEntryEndpointName() {
return entryEndpointName;
}
void setEntryOperationName(String entryOperationName) {
this.entryOperationName = '#' + entryOperationName;
void setEntryEndpointName(String entryEndpointName) {
this.entryEndpointName = '#' + entryEndpointName;
}
void setEntryOperationId(int entryOperationId) {
this.entryOperationName = entryOperationId + "";
void setEntryEndpointId(int entryOperationId) {
this.entryEndpointName = entryOperationId + "";
}
void setParentOperationName(String parentOperationName) {
this.parentOperationName = '#' + parentOperationName;
void setParentEndpointName(String parentEndpointName) {
this.parentEndpointName = '#' + parentEndpointName;
}
void setParentOperationId(int parentOperationId) {
this.parentOperationName = parentOperationId + "";
void setParentEndpointId(int parentOperationId) {
this.parentEndpointName = parentOperationId + "";
}
public ID getTraceSegmentId() {
......@@ -256,12 +256,12 @@ public class ContextCarrier implements Serializable {
this.spanId = spanId;
}
public int getParentApplicationInstanceId() {
return parentApplicationInstanceId;
public int getParentServiceInstanceId() {
return parentServiceInstanceId;
}
void setParentApplicationInstanceId(int parentApplicationInstanceId) {
this.parentApplicationInstanceId = parentApplicationInstanceId;
void setParentServiceInstanceId(int parentServiceInstanceId) {
this.parentServiceInstanceId = parentServiceInstanceId;
}
public String getPeerHost() {
......@@ -288,16 +288,16 @@ public class ContextCarrier implements Serializable {
return primaryDistributedTraceId;
}
public String getParentOperationName() {
return parentOperationName;
public String getParentEndpointName() {
return parentEndpointName;
}
public int getEntryApplicationInstanceId() {
return entryApplicationInstanceId;
public int getEntryServiceInstanceId() {
return entryServiceInstanceId;
}
public void setEntryApplicationInstanceId(int entryApplicationInstanceId) {
this.entryApplicationInstanceId = entryApplicationInstanceId;
public void setEntryServiceInstanceId(int entryServiceInstanceId) {
this.entryServiceInstanceId = entryServiceInstanceId;
}
public enum HeaderVersion {
......
......@@ -57,8 +57,8 @@ public class ContextManager implements TracingContextListener, BootService, Igno
}
context = new IgnoredTracerContext();
} else {
if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue()
&& RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue()
if (RemoteDownstreamConfig.Agent.SERVICE_ID != DictionaryUtil.nullValue()
&& RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID != DictionaryUtil.nullValue()
) {
context = EXTEND_SERVICE.createTraceContext(operationName, forceSampling);
} else {
......
......@@ -112,7 +112,7 @@ public class TracingContext implements AbstractTracerContext {
carrier.setTraceSegmentId(this.segment.getTraceSegmentId());
carrier.setSpanId(span.getSpanId());
carrier.setParentApplicationInstanceId(segment.getApplicationInstanceId());
carrier.setParentServiceInstanceId(segment.getApplicationInstanceId());
if (DictionaryUtil.isNull(peerId)) {
carrier.setPeerHost(peer);
......@@ -125,30 +125,30 @@ public class TracingContext implements AbstractTracerContext {
int entryApplicationInstanceId;
if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0);
operationId = ref.getEntryOperationId();
operationName = ref.getEntryOperationName();
entryApplicationInstanceId = ref.getEntryApplicationInstanceId();
operationId = ref.getEntryEndpointId();
operationName = ref.getEntryEndpointName();
entryApplicationInstanceId = ref.getEntryServiceInstanceId();
} else {
AbstractSpan firstSpan = first();
operationId = firstSpan.getOperationId();
operationName = firstSpan.getOperationName();
entryApplicationInstanceId = this.segment.getApplicationInstanceId();
}
carrier.setEntryApplicationInstanceId(entryApplicationInstanceId);
carrier.setEntryServiceInstanceId(entryApplicationInstanceId);
if (operationId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(operationName)) {
carrier.setEntryOperationName(operationName);
carrier.setEntryEndpointName(operationName);
}
} else {
carrier.setEntryOperationId(operationId);
carrier.setEntryEndpointId(operationId);
}
int parentOperationId = first().getOperationId();
if (parentOperationId == DictionaryUtil.nullValue()) {
carrier.setParentOperationName(first().getOperationName());
carrier.setParentEndpointName(first().getOperationName());
} else {
carrier.setParentOperationId(parentOperationId);
carrier.setParentEndpointId(parentOperationId);
}
carrier.setDistributedTraceIds(this.segment.getRelatedGlobalTraces());
......@@ -188,9 +188,9 @@ public class TracingContext implements AbstractTracerContext {
AbstractSpan firstSpan = first();
if (refs != null && refs.size() > 0) {
TraceSegmentRef ref = refs.get(0);
entryOperationId = ref.getEntryOperationId();
entryOperationName = ref.getEntryOperationName();
entryApplicationInstanceId = ref.getEntryApplicationInstanceId();
entryOperationId = ref.getEntryEndpointId();
entryOperationName = ref.getEntryEndpointName();
entryApplicationInstanceId = ref.getEntryServiceInstanceId();
} else {
entryOperationId = firstSpan.getOperationId();
entryOperationName = firstSpan.getOperationName();
......@@ -251,8 +251,8 @@ public class TracingContext implements AbstractTracerContext {
final AbstractSpan parentSpan = peek();
final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
if (parentSpan != null && parentSpan.isEntry()) {
entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection()
.findOnly(segment.getApplicationId(), operationName)
entrySpan = (AbstractTracingSpan)DictionaryManager.findEndpointSection()
.findOnly(segment.getServiceId(), operationName)
.doInCondition(new PossibleFound.FoundAndObtain() {
@Override public Object doProcess(int operationId) {
return parentSpan.setOperationId(operationId);
......@@ -264,8 +264,8 @@ public class TracingContext implements AbstractTracerContext {
});
return entrySpan.start();
} else {
entrySpan = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection()
.findOnly(segment.getApplicationId(), operationName)
entrySpan = (AbstractTracingSpan)DictionaryManager.findEndpointSection()
.findOnly(segment.getServiceId(), operationName)
.doInCondition(new PossibleFound.FoundAndObtain() {
@Override public Object doProcess(int operationId) {
return new EntrySpan(spanIdGenerator++, parentSpanId, operationId);
......@@ -294,19 +294,11 @@ public class TracingContext implements AbstractTracerContext {
}
AbstractSpan parentSpan = peek();
final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
AbstractTracingSpan span = (AbstractTracingSpan)DictionaryManager.findOperationNameCodeSection()
.findOrPrepare4Register(segment.getApplicationId(), operationName, false, false)
.doInCondition(new PossibleFound.FoundAndObtain() {
@Override
public Object doProcess(int operationId) {
return new LocalSpan(spanIdGenerator++, parentSpanId, operationId);
}
}, new PossibleFound.NotFoundAndObtain() {
@Override
public Object doProcess() {
return new LocalSpan(spanIdGenerator++, parentSpanId, operationName);
}
});
/**
* From v6.0.0-beta, local span doesn't do op name register.
* All op name register is related to entry and exit spans only.
*/
AbstractTracingSpan span = new LocalSpan(spanIdGenerator++, parentSpanId, operationName);
span.start();
return push(span);
}
......@@ -336,8 +328,8 @@ public class TracingContext implements AbstractTracerContext {
return new NoopExitSpan(peerId);
}
return DictionaryManager.findOperationNameCodeSection()
.findOnly(segment.getApplicationId(), operationName)
return DictionaryManager.findEndpointSection()
.findOnly(segment.getServiceId(), operationName)
.doInCondition(
new PossibleFound.FoundAndObtain() {
@Override
......@@ -359,8 +351,8 @@ public class TracingContext implements AbstractTracerContext {
return new NoopExitSpan(remotePeer);
}
return DictionaryManager.findOperationNameCodeSection()
.findOnly(segment.getApplicationId(), operationName)
return DictionaryManager.findEndpointSection()
.findOnly(segment.getServiceId(), operationName)
.doInCondition(
new PossibleFound.FoundAndObtain() {
@Override
......
......@@ -52,13 +52,13 @@ public final class GlobalIdGenerator {
* @return an array contains three long numbers, which represents a unique id.
*/
public static ID generate() {
if (RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID == DictionaryUtil.nullValue()) {
if (RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID == DictionaryUtil.nullValue()) {
throw new IllegalStateException();
}
IDContext context = THREAD_ID_SEQUENCE.get();
return new ID(
RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID,
RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID,
Thread.currentThread().getId(),
context.nextSeq()
);
......
......@@ -25,6 +25,7 @@ import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair;
import org.apache.skywalking.apm.agent.core.context.util.ThrowableTransformer;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import org.apache.skywalking.apm.network.trace.component.Component;
/**
......@@ -244,8 +245,8 @@ public abstract class AbstractTracingSpan implements AbstractSpan {
return this;
}
public SpanObject.Builder transform() {
SpanObject.Builder spanBuilder = SpanObject.newBuilder();
public SpanObjectV2.Builder transform() {
SpanObjectV2.Builder spanBuilder = SpanObjectV2.newBuilder();
spanBuilder.setSpanId(this.spanId);
spanBuilder.setParentSpanId(parentSpanId);
......
......@@ -20,8 +20,7 @@
package org.apache.skywalking.apm.agent.core.context.trace;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import org.apache.skywalking.apm.network.trace.component.Component;
/**
......@@ -119,8 +118,8 @@ public class ExitSpan extends StackBasedTracingSpan implements WithPeerInfo {
return this;
}
@Override public SpanObject.Builder transform() {
SpanObject.Builder spanBuilder = super.transform();
@Override public SpanObjectV2.Builder transform() {
SpanObjectV2.Builder spanBuilder = super.transform();
if (peerId != DictionaryUtil.nullValue()) {
spanBuilder.setPeerId(peerId);
} else {
......
......@@ -16,17 +16,16 @@
*
*/
package org.apache.skywalking.apm.agent.core.context.trace;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.util.KeyValuePair;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.v2.Log;
/**
* The <code>LogDataEntity</code> represents a collection of {@link KeyValuePair},
* contains several fields of a logging operation.
* The <code>LogDataEntity</code> represents a collection of {@link KeyValuePair}, contains several fields of a logging
* operation.
*
* @author wusheng
*/
......@@ -62,8 +61,8 @@ public class LogDataEntity {
}
}
public LogMessage transform() {
LogMessage.Builder logMessageBuilder = LogMessage.newBuilder();
public Log transform() {
Log.Builder logMessageBuilder = Log.newBuilder();
for (KeyValuePair log : logs) {
logMessageBuilder.addData(log.transform());
}
......
......@@ -46,8 +46,8 @@ public abstract class StackBasedTracingSpan extends AbstractTracingSpan {
public boolean finish(TraceSegment owner) {
if (--stackDepth == 0) {
if (this.operationId == DictionaryUtil.nullValue()) {
this.operationId = (Integer)DictionaryManager.findOperationNameCodeSection()
.findOrPrepare4Register(owner.getApplicationId(), operationName, this.isEntry(), this.isExit())
this.operationId = (Integer)DictionaryManager.findEndpointSection()
.findOrPrepare4Register(owner.getServiceId(), operationName, this.isEntry(), this.isExit())
.doInCondition(
new PossibleFound.FoundAndObtain() {
@Override public Object doProcess(int value) {
......
......@@ -28,6 +28,7 @@ import org.apache.skywalking.apm.agent.core.context.ids.GlobalIdGenerator;
import org.apache.skywalking.apm.agent.core.context.ids.ID;
import org.apache.skywalking.apm.agent.core.context.ids.NewDistributedTraceId;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
/**
* {@link TraceSegment} is a segment or fragment of the distributed trace. See https://github.com/opentracing/specification/blob/master/specification.md#the-opentracing-data-model
......@@ -124,8 +125,8 @@ public class TraceSegment {
return traceSegmentId;
}
public int getApplicationId() {
return RemoteDownstreamConfig.Agent.APPLICATION_ID;
public int getServiceId() {
return RemoteDownstreamConfig.Agent.SERVICE_ID;
}
public boolean hasRef() {
......@@ -162,7 +163,7 @@ public class TraceSegment {
for (DistributedTraceId distributedTraceId : getRelatedGlobalTraces()) {
upstreamBuilder = upstreamBuilder.addGlobalTraceIds(distributedTraceId.toUniqueId());
}
TraceSegmentObject.Builder traceSegmentBuilder = TraceSegmentObject.newBuilder();
SegmentObject.Builder traceSegmentBuilder = SegmentObject.newBuilder();
/**
* Trace Segment
*/
......@@ -173,8 +174,8 @@ public class TraceSegment {
for (AbstractTracingSpan span : this.spans) {
traceSegmentBuilder.addSpans(span.transform());
}
traceSegmentBuilder.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID);
traceSegmentBuilder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID);
traceSegmentBuilder.setServiceId(RemoteDownstreamConfig.Agent.SERVICE_ID);
traceSegmentBuilder.setServiceInstanceId(RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID);
traceSegmentBuilder.setIsSizeLimited(this.isSizeLimited);
upstreamBuilder.setSegment(traceSegmentBuilder.build().toByteString());
......@@ -192,6 +193,6 @@ public class TraceSegment {
}
public int getApplicationInstanceId() {
return RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID;
return RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID;
}
}
......@@ -24,7 +24,7 @@ import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.ids.ID;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.network.language.agent.RefType;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentReference;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentReference;
import org.apache.skywalking.apm.util.StringUtil;
/**
......@@ -44,17 +44,17 @@ public class TraceSegmentRef {
private String peerHost;
private int entryApplicationInstanceId = DictionaryUtil.nullValue();
private int entryServiceInstanceId = DictionaryUtil.nullValue();
private int parentApplicationInstanceId = DictionaryUtil.nullValue();
private int parentServiceInstanceId = DictionaryUtil.nullValue();
private String entryOperationName;
private String entryEndpointName;
private int entryOperationId = DictionaryUtil.nullValue();
private int entryEndpointId = DictionaryUtil.nullValue();
private String parentOperationName;
private String parentEndpointName;
private int parentOperationId = DictionaryUtil.nullValue();
private int parentEndpointId = DictionaryUtil.nullValue();
/**
* Transform a {@link ContextCarrier} to the <code>TraceSegmentRef</code>
......@@ -65,28 +65,28 @@ public class TraceSegmentRef {
this.type = SegmentRefType.CROSS_PROCESS;
this.traceSegmentId = carrier.getTraceSegmentId();
this.spanId = carrier.getSpanId();
this.parentApplicationInstanceId = carrier.getParentApplicationInstanceId();
this.entryApplicationInstanceId = carrier.getEntryApplicationInstanceId();
this.parentServiceInstanceId = carrier.getParentServiceInstanceId();
this.entryServiceInstanceId = carrier.getEntryServiceInstanceId();
String host = carrier.getPeerHost();
if (host.charAt(0) == '#') {
this.peerHost = host.substring(1);
} else {
this.peerId = Integer.parseInt(host);
}
String entryOperationName = carrier.getEntryOperationName();
String entryOperationName = carrier.getEntryEndpointName();
if (!StringUtil.isEmpty(entryOperationName)) {
if (entryOperationName.charAt(0) == '#') {
this.entryOperationName = entryOperationName.substring(1);
this.entryEndpointName = entryOperationName.substring(1);
} else {
this.entryOperationId = Integer.parseInt(entryOperationName);
this.entryEndpointId = Integer.parseInt(entryOperationName);
}
}
String parentOperationName = carrier.getParentOperationName();
String parentOperationName = carrier.getParentEndpointName();
if (!StringUtil.isEmpty(parentOperationName)) {
if (parentOperationName.charAt(0) == '#') {
this.parentOperationName = parentOperationName.substring(1);
this.parentEndpointName = parentOperationName.substring(1);
} else {
this.parentOperationId = Integer.parseInt(parentOperationName);
this.parentEndpointId = Integer.parseInt(parentOperationName);
}
}
}
......@@ -95,40 +95,40 @@ public class TraceSegmentRef {
this.type = SegmentRefType.CROSS_THREAD;
this.traceSegmentId = snapshot.getTraceSegmentId();
this.spanId = snapshot.getSpanId();
this.parentApplicationInstanceId = RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID;
this.entryApplicationInstanceId = snapshot.getEntryApplicationInstanceId();
this.parentServiceInstanceId = RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID;
this.entryServiceInstanceId = snapshot.getEntryApplicationInstanceId();
String entryOperationName = snapshot.getEntryOperationName();
if (!StringUtil.isEmpty(entryOperationName)) {
if (entryOperationName.charAt(0) == '#') {
this.entryOperationName = entryOperationName.substring(1);
this.entryEndpointName = entryOperationName.substring(1);
} else {
this.entryOperationId = Integer.parseInt(entryOperationName);
this.entryEndpointId = Integer.parseInt(entryOperationName);
}
}
String parentOperationName = snapshot.getParentOperationName();
if (!StringUtil.isEmpty(parentOperationName)) {
if (parentOperationName.charAt(0) == '#') {
this.parentOperationName = parentOperationName.substring(1);
this.parentEndpointName = parentOperationName.substring(1);
} else {
this.parentOperationId = Integer.parseInt(parentOperationName);
this.parentEndpointId = Integer.parseInt(parentOperationName);
}
}
}
public String getEntryOperationName() {
return entryOperationName;
public String getEntryEndpointName() {
return entryEndpointName;
}
public int getEntryOperationId() {
return entryOperationId;
public int getEntryEndpointId() {
return entryEndpointId;
}
public int getEntryApplicationInstanceId() {
return entryApplicationInstanceId;
public int getEntryServiceInstanceId() {
return entryServiceInstanceId;
}
public TraceSegmentReference transform() {
TraceSegmentReference.Builder refBuilder = TraceSegmentReference.newBuilder();
public SegmentReference transform() {
SegmentReference.Builder refBuilder = SegmentReference.newBuilder();
if (SegmentRefType.CROSS_PROCESS.equals(type)) {
refBuilder.setRefType(RefType.CrossProcess);
if (peerId == DictionaryUtil.nullValue()) {
......@@ -140,28 +140,28 @@ public class TraceSegmentRef {
refBuilder.setRefType(RefType.CrossThread);
}
refBuilder.setParentApplicationInstanceId(parentApplicationInstanceId);
refBuilder.setEntryApplicationInstanceId(entryApplicationInstanceId);
refBuilder.setParentServiceInstanceId(parentServiceInstanceId);
refBuilder.setEntryServiceInstanceId(entryServiceInstanceId);
refBuilder.setParentTraceSegmentId(traceSegmentId.transform());
refBuilder.setParentSpanId(spanId);
/**
* entryOperationId/entryOperationName and parentOperationId/parentOperationName could be empty at same time.
* entryEndpointId/entryEndpointName and parentEndpointId/parentEndpointName could be empty at same time.
* This is accepted in v2 format.
*
*/
if (entryOperationId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(entryOperationName)) {
refBuilder.setEntryServiceName(entryOperationName);
if (entryEndpointId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(entryEndpointName)) {
refBuilder.setEntryEndpoint(entryEndpointName);
}
} else {
refBuilder.setEntryServiceId(entryOperationId);
refBuilder.setEntryEndpointId(entryEndpointId);
}
if (parentOperationId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(parentOperationName)) {
refBuilder.setParentServiceName(parentOperationName);
if (parentEndpointId == DictionaryUtil.nullValue()) {
if (!StringUtil.isEmpty(parentEndpointName)) {
refBuilder.setParentEndpoint(parentEndpointName);
}
} else {
refBuilder.setParentServiceId(parentOperationId);
refBuilder.setParentEndpointId(parentEndpointId);
}
return refBuilder.build();
}
......
......@@ -19,7 +19,7 @@
package org.apache.skywalking.apm.agent.core.context.util;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
/**
* The <code>KeyValuePair</code> represents a object which contains a string key and a string value.
......@@ -43,8 +43,8 @@ public class KeyValuePair {
return value;
}
public KeyWithStringValue transform() {
KeyWithStringValue.Builder keyValueBuilder = KeyWithStringValue.newBuilder();
public KeyStringValuePair transform() {
KeyStringValuePair.Builder keyValueBuilder = KeyStringValuePair.newBuilder();
keyValueBuilder.setKey(key);
if (value != null) {
keyValueBuilder.setValue(value);
......
......@@ -31,9 +31,9 @@ public class DictionaryManager {
}
/**
* @return {@link OperationNameDictionary} to find service id.
* @return {@link EndpointNameDictionary} to find service id.
*/
public static OperationNameDictionary findOperationNameCodeSection() {
return OperationNameDictionary.INSTANCE;
public static EndpointNameDictionary findEndpointSection() {
return EndpointNameDictionary.INSTANCE;
}
}
......@@ -22,92 +22,100 @@ import io.netty.util.internal.ConcurrentSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.network.common.DetectPoint;
import org.apache.skywalking.apm.network.register.v2.Endpoint;
import org.apache.skywalking.apm.network.register.v2.EndpointMapping;
import org.apache.skywalking.apm.network.register.v2.EndpointMappingElement;
import org.apache.skywalking.apm.network.register.v2.Enpoints;
import org.apache.skywalking.apm.network.register.v2.RegisterGrpc;
import static org.apache.skywalking.apm.agent.core.conf.Config.Dictionary.OPERATION_NAME_BUFFER_SIZE;
import static org.apache.skywalking.apm.agent.core.conf.Config.Dictionary.ENDPOINT_NAME_BUFFER_SIZE;
/**
* @author wusheng
*/
public enum OperationNameDictionary {
public enum EndpointNameDictionary {
INSTANCE;
private Map<OperationNameKey, Integer> operationNameDictionary = new ConcurrentHashMap<OperationNameKey, Integer>();
private Set<OperationNameKey> unRegisterOperationNames = new ConcurrentSet<OperationNameKey>();
private static final ILog logger = LogManager.getLogger(EndpointNameDictionary.class);
public PossibleFound findOrPrepare4Register(int applicationId, String operationName,
private Map<OperationNameKey, Integer> endpointDictionary = new ConcurrentHashMap<OperationNameKey, Integer>();
private Set<OperationNameKey> unRegisterEndpoints = new ConcurrentSet<OperationNameKey>();
public PossibleFound findOrPrepare4Register(int serviceId, String endpointName,
boolean isEntry, boolean isExit) {
return find0(applicationId, operationName, isEntry, isExit, true);
return find0(serviceId, endpointName, isEntry, isExit, true);
}
public PossibleFound findOnly(int applicationId, String operationName) {
return find0(applicationId, operationName, false, false, false);
public PossibleFound findOnly(int serviceId, String endpointName) {
return find0(serviceId, endpointName, false, false, false);
}
private PossibleFound find0(int applicationId, String operationName,
private PossibleFound find0(int serviceId, String endpointName,
boolean isEntry, boolean isExit, boolean registerWhenNotFound) {
if (operationName == null || operationName.length() == 0) {
if (endpointName == null || endpointName.length() == 0) {
return new NotFound();
}
OperationNameKey key = new OperationNameKey(applicationId, operationName, isEntry, isExit);
Integer operationId = operationNameDictionary.get(key);
OperationNameKey key = new OperationNameKey(serviceId, endpointName, isEntry, isExit);
Integer operationId = endpointDictionary.get(key);
if (operationId != null) {
return new Found(operationId);
} else {
if (registerWhenNotFound &&
operationNameDictionary.size() + unRegisterOperationNames.size() < OPERATION_NAME_BUFFER_SIZE) {
unRegisterOperationNames.add(key);
endpointDictionary.size() + unRegisterEndpoints.size() < ENDPOINT_NAME_BUFFER_SIZE) {
unRegisterEndpoints.add(key);
}
return new NotFound();
}
}
public void syncRemoteDictionary(
ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceBlockingStub serviceNameDiscoveryServiceBlockingStub) {
if (unRegisterOperationNames.size() > 0) {
ServiceNameCollection.Builder builder = ServiceNameCollection.newBuilder();
for (OperationNameKey operationNameKey : unRegisterOperationNames) {
ServiceNameElement serviceNameElement = ServiceNameElement.newBuilder()
.setApplicationId(operationNameKey.getApplicationId())
.setServiceName(operationNameKey.getOperationName())
.setSrcSpanType(operationNameKey.getSpanType())
RegisterGrpc.RegisterBlockingStub serviceNameDiscoveryServiceBlockingStub) {
if (unRegisterEndpoints.size() > 0) {
Enpoints.Builder builder = Enpoints.newBuilder();
for (OperationNameKey operationNameKey : unRegisterEndpoints) {
Endpoint endpoint = Endpoint.newBuilder()
.setServiceId(operationNameKey.getServiceId())
.setEndpointName(operationNameKey.getEndpointName())
.setFrom(operationNameKey.getSpanType())
.build();
builder.addElements(serviceNameElement);
builder.addEndpoints(endpoint);
}
ServiceNameMappingCollection serviceNameMappingCollection = serviceNameDiscoveryServiceBlockingStub.discovery(builder.build());
EndpointMapping serviceNameMappingCollection = serviceNameDiscoveryServiceBlockingStub.doEndpointRegister(builder.build());
if (serviceNameMappingCollection.getElementsCount() > 0) {
for (ServiceNameMappingElement serviceNameMappingElement : serviceNameMappingCollection.getElementsList()) {
ServiceNameElement element = serviceNameMappingElement.getElement();
for (EndpointMappingElement element : serviceNameMappingCollection.getElementsList()) {
OperationNameKey key = new OperationNameKey(
element.getApplicationId(),
element.getServiceName(),
SpanType.Entry.equals(element.getSrcSpanType()),
SpanType.Exit.equals(element.getSrcSpanType()));
unRegisterOperationNames.remove(key);
operationNameDictionary.put(key, serviceNameMappingElement.getServiceId());
element.getServiceId(),
element.getEndpointName(),
DetectPoint.server.equals(element.getFrom()),
DetectPoint.client.equals(element.getFrom()));
unRegisterEndpoints.remove(key);
endpointDictionary.put(key, element.getEndpointId());
}
}
}
}
private class OperationNameKey {
private int applicationId;
private String operationName;
private int serviceId;
private String endpointName;
private boolean isEntry;
private boolean isExit;
public OperationNameKey(int applicationId, String operationName, boolean isEntry, boolean isExit) {
this.applicationId = applicationId;
this.operationName = operationName;
public OperationNameKey(int serviceId, String endpointName, boolean isEntry, boolean isExit) {
this.serviceId = serviceId;
this.endpointName = endpointName;
this.isEntry = isEntry;
this.isExit = isExit;
}
public int getApplicationId() {
return applicationId;
public int getServiceId() {
return serviceId;
}
public String getOperationName() {
return operationName;
public String getEndpointName() {
return endpointName;
}
@Override public boolean equals(Object o) {
......@@ -118,19 +126,17 @@ public enum OperationNameDictionary {
OperationNameKey key = (OperationNameKey)o;
boolean isApplicationMatch = false;
if (applicationId == key.applicationId) {
isApplicationMatch = true;
} else if (operationName.equals(key.operationName)) {
isApplicationMatch = true;
boolean isServiceEndpointMatch = false;
if (serviceId == key.serviceId && endpointName.equals(key.endpointName)) {
isServiceEndpointMatch = true;
}
return isApplicationMatch && isEntry == key.isEntry
return isServiceEndpointMatch && isEntry == key.isEntry
&& isExit == key.isExit;
}
@Override public int hashCode() {
int result = applicationId;
result = 31 * result + operationName.hashCode();
int result = serviceId;
result = 31 * result + endpointName.hashCode();
return result;
}
......@@ -142,14 +148,23 @@ public enum OperationNameDictionary {
return isExit;
}
SpanType getSpanType() {
DetectPoint getSpanType() {
if (isEntry) {
return SpanType.Entry;
return DetectPoint.server;
} else if (isExit) {
return SpanType.Exit;
return DetectPoint.client;
} else {
return SpanType.Local;
return DetectPoint.UNRECOGNIZED;
}
}
@Override public String toString() {
return "OperationNameKey{" +
"serviceId=" + serviceId +
", endpointName='" + endpointName + '\'' +
", isEntry=" + isEntry +
", isExit=" + isExit +
'}';
}
}
}
......@@ -23,9 +23,13 @@ import io.netty.util.internal.ConcurrentSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.skywalking.apm.network.common.KeyIntValuePair;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.register.v2.NetAddressMapping;
import org.apache.skywalking.apm.network.register.v2.NetAddresses;
import org.apache.skywalking.apm.network.register.v2.RegisterGrpc;
import static org.apache.skywalking.apm.agent.core.conf.Config.Dictionary.APPLICATION_CODE_BUFFER_SIZE;
import static org.apache.skywalking.apm.agent.core.conf.Config.Dictionary.SERVICE_CODE_BUFFER_SIZE;
/**
* Map of network address id to network literal address, which is from the collector side.
......@@ -35,28 +39,28 @@ import static org.apache.skywalking.apm.agent.core.conf.Config.Dictionary.APPLIC
public enum NetworkAddressDictionary {
INSTANCE;
private Map<String, Integer> applicationDictionary = new ConcurrentHashMap<String, Integer>();
private Set<String> unRegisterApplications = new ConcurrentSet<String>();
private Set<String> unRegisterServices = new ConcurrentSet<String>();
public PossibleFound find(String networkAddress) {
Integer applicationId = applicationDictionary.get(networkAddress);
if (applicationId != null) {
return new Found(applicationId);
} else {
if (applicationDictionary.size() + unRegisterApplications.size() < APPLICATION_CODE_BUFFER_SIZE) {
unRegisterApplications.add(networkAddress);
if (applicationDictionary.size() + unRegisterServices.size() < SERVICE_CODE_BUFFER_SIZE) {
unRegisterServices.add(networkAddress);
}
return new NotFound();
}
}
public void syncRemoteDictionary(
NetworkAddressRegisterServiceGrpc.NetworkAddressRegisterServiceBlockingStub networkAddressRegisterServiceBlockingStub) {
if (unRegisterApplications.size() > 0) {
NetworkAddressMappings networkAddressMappings = networkAddressRegisterServiceBlockingStub.batchRegister(
NetworkAddresses.newBuilder().addAllAddresses(unRegisterApplications).build());
RegisterGrpc.RegisterBlockingStub networkAddressRegisterServiceBlockingStub) {
if (unRegisterServices.size() > 0) {
NetAddressMapping networkAddressMappings = networkAddressRegisterServiceBlockingStub.doNetworkAddressRegister(
NetAddresses.newBuilder().addAllAddresses(unRegisterServices).build());
if (networkAddressMappings.getAddressIdsCount() > 0) {
for (KeyWithIntegerValue keyWithIntegerValue : networkAddressMappings.getAddressIdsList()) {
unRegisterApplications.remove(keyWithIntegerValue.getKey());
for (KeyIntValuePair keyWithIntegerValue : networkAddressMappings.getAddressIdsList()) {
unRegisterServices.remove(keyWithIntegerValue.getKey());
applicationDictionary.put(keyWithIntegerValue.getKey(), keyWithIntegerValue.getValue());
}
}
......
......@@ -19,6 +19,11 @@
package org.apache.skywalking.apm.agent.core.jvm;
import io.grpc.Channel;
import java.util.LinkedList;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.apache.skywalking.apm.agent.core.boot.BootService;
import org.apache.skywalking.apm.agent.core.boot.DefaultImplementor;
import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
......@@ -35,19 +40,14 @@ import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.agent.core.remote.GRPCChannelListener;
import org.apache.skywalking.apm.agent.core.remote.GRPCChannelManager;
import org.apache.skywalking.apm.agent.core.remote.GRPCChannelStatus;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.JVMMetric;
import org.apache.skywalking.apm.network.language.agent.v2.JVMMetricCollection;
import org.apache.skywalking.apm.network.language.agent.v2.JVMMetricReportServiceGrpc;
import org.apache.skywalking.apm.util.RunnableWithExceptionProtection;
import java.util.LinkedList;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* The <code>JVMService</code> represents a timer,
* which collectors JVM cpu, memory, memorypool and gc info,
* and send the collected info to Collector through the channel provided by {@link GRPCChannelManager}
* The <code>JVMService</code> represents a timer, which collectors JVM cpu, memory, memorypool and gc info, and send
* the collected info to Collector through the channel provided by {@link GRPCChannelManager}
*
* @author wusheng
*/
......@@ -98,9 +98,9 @@ public class JVMService implements BootService, Runnable {
@Override
public void run() {
if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue()
&& RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue()
) {
if (RemoteDownstreamConfig.Agent.SERVICE_ID != DictionaryUtil.nullValue()
&& RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID != DictionaryUtil.nullValue()
) {
long currentTimeMillis = System.currentTimeMillis();
try {
JVMMetric.Builder jvmBuilder = JVMMetric.newBuilder();
......@@ -123,21 +123,21 @@ public class JVMService implements BootService, Runnable {
private class Sender implements Runnable, GRPCChannelListener {
private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
private volatile JVMMetricsServiceGrpc.JVMMetricsServiceBlockingStub stub = null;
private volatile JVMMetricReportServiceGrpc.JVMMetricReportServiceBlockingStub stub = null;
@Override
public void run() {
if (RemoteDownstreamConfig.Agent.APPLICATION_ID != DictionaryUtil.nullValue()
&& RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID != DictionaryUtil.nullValue()
) {
if (RemoteDownstreamConfig.Agent.SERVICE_ID != DictionaryUtil.nullValue()
&& RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID != DictionaryUtil.nullValue()
) {
if (status == GRPCChannelStatus.CONNECTED) {
try {
JVMMetrics.Builder builder = JVMMetrics.newBuilder();
JVMMetricCollection.Builder builder = JVMMetricCollection.newBuilder();
LinkedList<JVMMetric> buffer = new LinkedList<JVMMetric>();
queue.drainTo(buffer);
if (buffer.size() > 0) {
builder.addAllMetrics(buffer);
builder.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID);
builder.setServiceInstanceId(RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID);
stub.collect(builder.build());
}
} catch (Throwable t) {
......@@ -151,7 +151,7 @@ public class JVMService implements BootService, Runnable {
public void statusChanged(GRPCChannelStatus status) {
if (GRPCChannelStatus.CONNECTED.equals(status)) {
Channel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getChannel();
stub = JVMMetricsServiceGrpc.newBlockingStub(channel);
stub = JVMMetricReportServiceGrpc.newBlockingStub(channel);
}
this.status = status;
}
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.agent.core.os;
import java.lang.management.ManagementFactory;
......@@ -25,10 +24,11 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
/**
* @author wusheng
......@@ -95,21 +95,24 @@ public class OSUtil {
return PROCESS_NO;
}
public static OSInfo buildOSInfo() {
OSInfo.Builder builder = OSInfo.newBuilder();
public static List<KeyStringValuePair> buildOSInfo() {
List<KeyStringValuePair> osInfo = new ArrayList<KeyStringValuePair>();
String osName = getOsName();
if (osName != null) {
builder.setOsName(osName);
osInfo.add(KeyStringValuePair.newBuilder().setKey("OSName").setValue(osName).build());
}
String hostName = getHostName();
if (hostName != null) {
builder.setHostname(hostName);
osInfo.add(KeyStringValuePair.newBuilder().setKey("hostname").setValue(hostName).build());
}
List<String> allIPV4 = getAllIPV4();
if (allIPV4.size() > 0) {
builder.addAllIpv4S(allIPV4);
for (String ipv4 : allIPV4) {
osInfo.add(KeyStringValuePair.newBuilder().setKey("ipv4").setValue(ipv4).build());
}
}
builder.setProcessNo(getProcessNo());
return builder.build();
osInfo.add(KeyStringValuePair.newBuilder().setKey("ProcessNo").setValue(getProcessNo() + "").build());
return osInfo;
}
}
......@@ -30,49 +30,45 @@ import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.apache.skywalking.apm.agent.core.dictionary.DictionaryUtil;
import org.apache.skywalking.apm.agent.core.dictionary.EndpointNameDictionary;
import org.apache.skywalking.apm.agent.core.dictionary.NetworkAddressDictionary;
import org.apache.skywalking.apm.agent.core.dictionary.OperationNameDictionary;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.agent.core.os.OSUtil;
import org.apache.skywalking.apm.network.language.agent.Application;
import org.apache.skywalking.apm.network.language.agent.ApplicationInstance;
import org.apache.skywalking.apm.network.language.agent.ApplicationInstanceHeartbeat;
import org.apache.skywalking.apm.network.language.agent.ApplicationInstanceMapping;
import org.apache.skywalking.apm.network.language.agent.ApplicationMapping;
import org.apache.skywalking.apm.network.language.agent.ApplicationRegisterServiceGrpc;
import org.apache.skywalking.apm.network.language.agent.InstanceDiscoveryServiceGrpc;
import org.apache.skywalking.apm.network.language.agent.NetworkAddressRegisterServiceGrpc;
import org.apache.skywalking.apm.network.language.agent.ServiceNameDiscoveryServiceGrpc;
import org.apache.skywalking.apm.network.common.KeyIntValuePair;
import org.apache.skywalking.apm.network.register.v2.RegisterGrpc;
import org.apache.skywalking.apm.network.register.v2.Service;
import org.apache.skywalking.apm.network.register.v2.ServiceInstance;
import org.apache.skywalking.apm.network.register.v2.ServiceInstancePingGrpc;
import org.apache.skywalking.apm.network.register.v2.ServiceInstancePingPkg;
import org.apache.skywalking.apm.network.register.v2.ServiceInstanceRegisterMapping;
import org.apache.skywalking.apm.network.register.v2.ServiceInstances;
import org.apache.skywalking.apm.network.register.v2.ServiceRegisterMapping;
import org.apache.skywalking.apm.network.register.v2.Services;
import org.apache.skywalking.apm.util.RunnableWithExceptionProtection;
/**
* @author wusheng
*/
@DefaultImplementor
public class AppAndServiceRegisterClient implements BootService, Runnable, GRPCChannelListener {
private static final ILog logger = LogManager.getLogger(AppAndServiceRegisterClient.class);
public class ServiceAndEndpointRegisterClient implements BootService, Runnable, GRPCChannelListener {
private static final ILog logger = LogManager.getLogger(ServiceAndEndpointRegisterClient.class);
private static final String PROCESS_UUID = UUID.randomUUID().toString().replaceAll("-", "");
private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
private volatile ApplicationRegisterServiceGrpc.ApplicationRegisterServiceBlockingStub applicationRegisterServiceBlockingStub;
private volatile InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceBlockingStub instanceDiscoveryServiceBlockingStub;
private volatile ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceBlockingStub serviceNameDiscoveryServiceBlockingStub;
private volatile NetworkAddressRegisterServiceGrpc.NetworkAddressRegisterServiceBlockingStub networkAddressRegisterServiceBlockingStub;
private volatile RegisterGrpc.RegisterBlockingStub registerBlockingStub;
private volatile ServiceInstancePingGrpc.ServiceInstancePingBlockingStub serviceInstancePingStub;
private volatile ScheduledFuture<?> applicationRegisterFuture;
@Override
public void statusChanged(GRPCChannelStatus status) {
if (GRPCChannelStatus.CONNECTED.equals(status)) {
Channel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getChannel();
applicationRegisterServiceBlockingStub = ApplicationRegisterServiceGrpc.newBlockingStub(channel);
instanceDiscoveryServiceBlockingStub = InstanceDiscoveryServiceGrpc.newBlockingStub(channel);
serviceNameDiscoveryServiceBlockingStub = ServiceNameDiscoveryServiceGrpc.newBlockingStub(channel);
networkAddressRegisterServiceBlockingStub = NetworkAddressRegisterServiceGrpc.newBlockingStub(channel);
registerBlockingStub = RegisterGrpc.newBlockingStub(channel);
serviceInstancePingStub = ServiceInstancePingGrpc.newBlockingStub(channel);
} else {
applicationRegisterServiceBlockingStub = null;
instanceDiscoveryServiceBlockingStub = null;
serviceNameDiscoveryServiceBlockingStub = null;
registerBlockingStub = null;
serviceInstancePingStub = null;
}
this.status = status;
}
......@@ -85,7 +81,7 @@ public class AppAndServiceRegisterClient implements BootService, Runnable, GRPCC
@Override
public void boot() throws Throwable {
applicationRegisterFuture = Executors
.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("AppAndServiceRegisterClient"))
.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("ServiceAndEndpointRegisterClient"))
.scheduleAtFixedRate(new RunnableWithExceptionProtection(this, new RunnableWithExceptionProtection.CallbackWhenException() {
@Override
public void handle(Throwable t) {
......@@ -105,47 +101,58 @@ public class AppAndServiceRegisterClient implements BootService, Runnable, GRPCC
@Override
public void run() {
logger.debug("AppAndServiceRegisterClient running, status:{}.", status);
logger.debug("ServiceAndEndpointRegisterClient running, status:{}.", status);
boolean shouldTry = true;
while (GRPCChannelStatus.CONNECTED.equals(status) && shouldTry) {
shouldTry = false;
try {
if (RemoteDownstreamConfig.Agent.APPLICATION_ID == DictionaryUtil.nullValue()) {
if (applicationRegisterServiceBlockingStub != null) {
ApplicationMapping applicationMapping = applicationRegisterServiceBlockingStub.applicationCodeRegister(
Application.newBuilder().setApplicationCode(Config.Agent.APPLICATION_CODE).build());
if (applicationMapping != null) {
RemoteDownstreamConfig.Agent.APPLICATION_ID = applicationMapping.getApplication().getValue();
shouldTry = true;
if (RemoteDownstreamConfig.Agent.SERVICE_ID == DictionaryUtil.nullValue()) {
if (registerBlockingStub != null) {
ServiceRegisterMapping serviceRegisterMapping = registerBlockingStub.doServiceRegister(
Services.newBuilder().addServices(Service.newBuilder().setServiceName(Config.Agent.SERVICE_NAME)).build());
if (serviceRegisterMapping != null) {
for (KeyIntValuePair registered : serviceRegisterMapping.getServicesList()) {
if (Config.Agent.SERVICE_NAME.equals(registered.getKey())) {
RemoteDownstreamConfig.Agent.SERVICE_ID = registered.getValue();
shouldTry = true;
}
}
}
}
} else {
if (instanceDiscoveryServiceBlockingStub != null) {
if (RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID == DictionaryUtil.nullValue()) {
if (registerBlockingStub != null) {
if (RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID == DictionaryUtil.nullValue()) {
ApplicationInstanceMapping instanceMapping = instanceDiscoveryServiceBlockingStub.registerInstance(ApplicationInstance.newBuilder()
.setApplicationId(RemoteDownstreamConfig.Agent.APPLICATION_ID)
.setAgentUUID(PROCESS_UUID)
.setRegisterTime(System.currentTimeMillis())
.setOsinfo(OSUtil.buildOSInfo())
.build());
if (instanceMapping.getApplicationInstanceId() != DictionaryUtil.nullValue()) {
RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID
= instanceMapping.getApplicationInstanceId();
ServiceInstanceRegisterMapping instanceMapping = registerBlockingStub.doServiceInstanceRegister(ServiceInstances.newBuilder()
.addInstances(
ServiceInstance.newBuilder()
.setServiceId(RemoteDownstreamConfig.Agent.SERVICE_ID)
.setInstanceUUID(PROCESS_UUID)
.setTime(System.currentTimeMillis())
.addAllProperties(OSUtil.buildOSInfo())
).build());
for (KeyIntValuePair serviceInstance : instanceMapping.getServiceInstancesList()) {
if (PROCESS_UUID.equals(serviceInstance.getKey())) {
int serviceInstanceId = serviceInstance.getValue();
if (serviceInstanceId != DictionaryUtil.nullValue()) {
RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID = serviceInstanceId;
}
}
}
} else {
instanceDiscoveryServiceBlockingStub.heartbeat(ApplicationInstanceHeartbeat.newBuilder()
.setApplicationInstanceId(RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID)
.setHeartbeatTime(System.currentTimeMillis())
serviceInstancePingStub.doPing(ServiceInstancePingPkg.newBuilder()
.setServiceInstanceId(RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID)
.setTime(System.currentTimeMillis())
.setServiceInstanceUUID(PROCESS_UUID)
.build());
NetworkAddressDictionary.INSTANCE.syncRemoteDictionary(networkAddressRegisterServiceBlockingStub);
OperationNameDictionary.INSTANCE.syncRemoteDictionary(serviceNameDiscoveryServiceBlockingStub);
NetworkAddressDictionary.INSTANCE.syncRemoteDictionary(registerBlockingStub);
EndpointNameDictionary.INSTANCE.syncRemoteDictionary(registerBlockingStub);
}
}
}
} catch (Throwable t) {
logger.error(t, "AppAndServiceRegisterClient execute fail.");
logger.error(t, "ServiceAndEndpointRegisterClient execute fail.");
ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(t);
}
}
......
......@@ -33,7 +33,9 @@ import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.commons.datacarrier.DataCarrier;
import org.apache.skywalking.apm.commons.datacarrier.buffer.BufferStrategy;
import org.apache.skywalking.apm.commons.datacarrier.consumer.IConsumer;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.v2.TraceSegmentReportServiceGrpc;
import static org.apache.skywalking.apm.agent.core.conf.Config.Buffer.BUFFER_SIZE;
import static org.apache.skywalking.apm.agent.core.conf.Config.Buffer.CHANNEL_SIZE;
......@@ -51,7 +53,7 @@ public class TraceSegmentServiceClient implements BootService, IConsumer<TraceSe
private long segmentUplinkedCounter;
private long segmentAbandonedCounter;
private volatile DataCarrier<TraceSegment> carrier;
private volatile TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub;
private volatile TraceSegmentReportServiceGrpc.TraceSegmentReportServiceStub serviceStub;
private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
@Override
......@@ -88,9 +90,9 @@ public class TraceSegmentServiceClient implements BootService, IConsumer<TraceSe
public void consume(List<TraceSegment> data) {
if (CONNECTED.equals(status)) {
final GRPCStreamServiceStatus status = new GRPCStreamServiceStatus(false);
StreamObserver<UpstreamSegment> upstreamSegmentStreamObserver = serviceStub.collect(new StreamObserver<Downstream>() {
StreamObserver<UpstreamSegment> upstreamSegmentStreamObserver = serviceStub.collect(new StreamObserver<Commands>() {
@Override
public void onNext(Downstream downstream) {
public void onNext(Commands commands) {
}
......@@ -169,7 +171,7 @@ public class TraceSegmentServiceClient implements BootService, IConsumer<TraceSe
public void statusChanged(GRPCChannelStatus status) {
if (CONNECTED.equals(status)) {
Channel channel = ServiceManager.INSTANCE.findService(GRPCChannelManager.class).getChannel();
serviceStub = TraceSegmentServiceGrpc.newStub(channel);
serviceStub = TraceSegmentReportServiceGrpc.newStub(channel);
}
this.status = status;
}
......
......@@ -21,5 +21,5 @@ org.apache.skywalking.apm.agent.core.context.ContextManager
org.apache.skywalking.apm.agent.core.sampling.SamplingService
org.apache.skywalking.apm.agent.core.remote.GRPCChannelManager
org.apache.skywalking.apm.agent.core.jvm.JVMService
org.apache.skywalking.apm.agent.core.remote.AppAndServiceRegisterClient
org.apache.skywalking.apm.agent.core.remote.ServiceAndEndpointRegisterClient
org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService
......@@ -35,38 +35,38 @@ public class SnifferConfigInitializerTest {
@Test
public void testLoadConfigFromJavaAgentDir() throws AgentPackageNotFoundException, ConfigNotFoundException {
System.setProperty("skywalking.agent.application_code", "testApp");
System.setProperty("skywalking.agent.service_name", "testApp");
System.setProperty("skywalking.collector.backend_service", "127.0.0.1:8090");
System.setProperty("skywalking.logging.level", "info");
SnifferConfigInitializer.initialize(null);
assertThat(Config.Agent.APPLICATION_CODE, is("testApp"));
assertThat(Config.Agent.SERVICE_NAME, is("testApp"));
assertThat(Config.Collector.BACKEND_SERVICE, is("127.0.0.1:8090"));
assertThat(Config.Logging.LEVEL, is(LogLevel.INFO));
}
@Test
public void testLoadConfigFromAgentOptions() throws AgentPackageNotFoundException, ConfigNotFoundException {
String agentOptions = "agent.application_code=testApp,collector.backend_service=127.0.0.1:8090,logging.level=info";
String agentOptions = "agent.service_name=testApp,collector.backend_service=127.0.0.1:8090,logging.level=info";
SnifferConfigInitializer.initialize(agentOptions);
assertThat(Config.Agent.APPLICATION_CODE, is("testApp"));
assertThat(Config.Agent.SERVICE_NAME, is("testApp"));
assertThat(Config.Collector.BACKEND_SERVICE, is("127.0.0.1:8090"));
assertThat(Config.Logging.LEVEL, is(LogLevel.INFO));
}
@Test
public void testConfigOverriding() throws AgentPackageNotFoundException, ConfigNotFoundException {
System.setProperty("skywalking.agent.application_code", "testAppFromSystem");
System.setProperty("skywalking.agent.service_name", "testAppFromSystem");
System.setProperty("skywalking.collector.backend_service", "127.0.0.1:8090");
String agentOptions = "agent.application_code=testAppFromAgentOptions,logging.level=debug";
String agentOptions = "agent.service_name=testAppFromAgentOptions,logging.level=debug";
SnifferConfigInitializer.initialize(agentOptions);
assertThat(Config.Agent.APPLICATION_CODE, is("testAppFromAgentOptions"));
assertThat(Config.Agent.SERVICE_NAME, is("testAppFromAgentOptions"));
assertThat(Config.Collector.BACKEND_SERVICE, is("127.0.0.1:8090"));
assertThat(Config.Logging.LEVEL, is(LogLevel.DEBUG));
}
@Test
public void testAgentOptionsSeparator() throws AgentPackageNotFoundException, ConfigNotFoundException {
System.setProperty("skywalking.agent.application_code", "testApp");
System.setProperty("skywalking.agent.service_name", "testApp");
System.setProperty("skywalking.collector.backend_service", "127.0.0.1:8090");
String agentOptions = "agent.ignore_suffix='.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg'";
SnifferConfigInitializer.initialize(agentOptions);
......@@ -76,16 +76,16 @@ public class SnifferConfigInitializerTest {
@Test
public void testAgentOptionsParser() throws AgentPackageNotFoundException, ConfigNotFoundException {
System.setProperty("skywalking.collector.backend_service", "127.0.0.1:8090");
String agentOptions = "agent.application_code=test=abc";
String agentOptions = "agent.service_name=test=abc";
try {
SnifferConfigInitializer.initialize(agentOptions);
fail("test=abc without quotes is not a valid value");
} catch (ExceptionInInitializerError e) {
// ignore
}
agentOptions = "agent.application_code='test=abc'";
agentOptions = "agent.service_name='test=abc'";
SnifferConfigInitializer.initialize(agentOptions);
assertThat(Config.Agent.APPLICATION_CODE, is("test=abc"));
assertThat(Config.Agent.SERVICE_NAME, is("test=abc"));
}
@After
......@@ -98,7 +98,7 @@ public class SnifferConfigInitializerTest {
}
}
Config.Agent.APPLICATION_CODE = "";
Config.Agent.SERVICE_NAME = "";
Config.Logging.LEVEL = LogLevel.DEBUG;
}
}
......@@ -98,11 +98,11 @@ public class ContextCarrierV2HeaderTest {
contextCarrier.setTraceSegmentId(new ID(1, 2, 3));
contextCarrier.setDistributedTraceIds(distributedTraceIds);
contextCarrier.setSpanId(4);
contextCarrier.setEntryApplicationInstanceId(1);
contextCarrier.setParentApplicationInstanceId(1);
contextCarrier.setEntryServiceInstanceId(1);
contextCarrier.setParentServiceInstanceId(1);
contextCarrier.setPeerHost("127.0.0.1:8080");
contextCarrier.setEntryOperationName("/portal");
contextCarrier.setParentOperationId(123);
contextCarrier.setEntryEndpointName("/portal");
contextCarrier.setParentEndpointId(123);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
......@@ -152,11 +152,11 @@ public class ContextCarrierV2HeaderTest {
contextCarrier.setTraceSegmentId(new ID(1, 2, 3));
contextCarrier.setDistributedTraceIds(distributedTraceIds);
contextCarrier.setSpanId(4);
contextCarrier.setEntryApplicationInstanceId(1);
contextCarrier.setParentApplicationInstanceId(1);
contextCarrier.setEntryServiceInstanceId(1);
contextCarrier.setParentServiceInstanceId(1);
contextCarrier.setPeerHost("127.0.0.1:8080");
contextCarrier.setEntryOperationName("/portal");
contextCarrier.setParentOperationId(123);
contextCarrier.setEntryEndpointName("/portal");
contextCarrier.setParentEndpointId(123);
CarrierItem next = contextCarrier.items();
String headerValue = null;
......@@ -188,8 +188,8 @@ public class ContextCarrierV2HeaderTest {
Assert.assertEquals(contextCarrier.getPeerHost(), contextCarrier2.getPeerHost());
Assert.assertEquals(contextCarrier.getDistributedTraceId(), contextCarrier2.getDistributedTraceId());
Assert.assertEquals(contextCarrier.getTraceSegmentId(), contextCarrier2.getTraceSegmentId());
Assert.assertEquals(contextCarrier.getEntryOperationName(), contextCarrier2.getEntryOperationName());
Assert.assertEquals(contextCarrier.getEntryApplicationInstanceId(), contextCarrier2.getEntryApplicationInstanceId());
Assert.assertEquals(contextCarrier.getParentApplicationInstanceId(), contextCarrier2.getParentApplicationInstanceId());
Assert.assertEquals(contextCarrier.getEntryEndpointName(), contextCarrier2.getEntryEndpointName());
Assert.assertEquals(contextCarrier.getEntryServiceInstanceId(), contextCarrier2.getEntryServiceInstanceId());
Assert.assertEquals(contextCarrier.getParentServiceInstanceId(), contextCarrier2.getParentServiceInstanceId());
}
}
......@@ -68,8 +68,8 @@ public class ContextManagerTest {
@Before
public void setUp() throws Exception {
RemoteDownstreamConfig.Agent.APPLICATION_ID = 1;
RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1;
RemoteDownstreamConfig.Agent.SERVICE_ID = 1;
RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID = 1;
}
@AfterClass
......@@ -137,8 +137,8 @@ public class ContextManagerTest {
TraceSegmentRef ref = actualSegment.getRefs().get(0);
MatcherAssert.assertThat(TraceSegmentRefHelper.getPeerHost(ref), is("127.0.0.1:8080"));
assertThat(ref.getEntryOperationName(), is("/portal/"));
assertThat(ref.getEntryOperationId(), is(0));
assertThat(ref.getEntryEndpointName(), is("/portal/"));
assertThat(ref.getEntryEndpointId(), is(0));
List<AbstractTracingSpan> spanList = SegmentHelper.getSpan(actualSegment);
assertThat(spanList.size(), is(2));
......@@ -160,7 +160,7 @@ public class ContextManagerTest {
assertThat(logs.get(0).getLogs().size(), is(4));
assertThat(injectContextCarrier.getSpanId(), is(1));
assertThat(injectContextCarrier.getEntryOperationName(), is("#/portal/"));
assertThat(injectContextCarrier.getEntryEndpointName(), is("#/portal/"));
assertThat(injectContextCarrier.getPeerHost(), is("#127.0.0.1:12800"));
}
......@@ -211,18 +211,18 @@ public class ContextManagerTest {
assertThat(firstExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
assertThat(firstExitSpanContextCarrier.getSpanId(), is(1));
assertThat(firstExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
assertThat(firstExitSpanContextCarrier.getEntryEndpointName(), is("#/testEntrySpan"));
assertThat(secondExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
assertThat(secondExitSpanContextCarrier.getSpanId(), is(1));
assertThat(secondExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
assertThat(secondExitSpanContextCarrier.getEntryEndpointName(), is("#/testEntrySpan"));
}
@After
public void tearDown() throws Exception {
RemoteDownstreamConfig.Agent.APPLICATION_ID = DictionaryUtil.nullValue();
RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = DictionaryUtil.nullValue();
RemoteDownstreamConfig.Agent.SERVICE_ID = DictionaryUtil.nullValue();
RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID = DictionaryUtil.nullValue();
}
@Test
......
......@@ -48,8 +48,8 @@ public class IgnoredTracerContextTest {
@Before
public void setUp() throws Exception {
RemoteDownstreamConfig.Agent.APPLICATION_ID = 1;
RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1;
RemoteDownstreamConfig.Agent.SERVICE_ID = 1;
RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID = 1;
}
@AfterClass
......@@ -99,7 +99,7 @@ public class IgnoredTracerContextTest {
ContextManager.stopSpan();
assertThat(abstractSpan.getClass().getName(), is(NoopSpan.class.getName()));
assertNull(contextCarrier.getEntryOperationName());
assertNull(contextCarrier.getEntryEndpointName());
assertThat(contextCarrier.getSpanId(), is(-1));
assertNull(contextCarrier.getPeerHost());
......
......@@ -16,36 +16,37 @@
*
*/
package org.apache.skywalking.apm.agent.core.remote;
import com.google.protobuf.InvalidProtocolBufferException;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcServerRule;
import java.util.ArrayList;
import java.util.List;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.agent.core.test.tools.TracingSegmentRunner;
import org.junit.*;
import org.junit.runner.RunWith;
import org.powermock.reflect.Whitebox;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.test.tools.SegmentStorage;
import org.apache.skywalking.apm.agent.core.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.network.language.agent.Downstream;
import org.apache.skywalking.apm.network.language.agent.SpanObject;
import org.apache.skywalking.apm.agent.core.test.tools.TracingSegmentRunner;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.language.agent.SpanType;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentObject;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentServiceGrpc;
import org.apache.skywalking.apm.network.language.agent.UpstreamSegment;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import org.apache.skywalking.apm.network.language.agent.v2.TraceSegmentReportServiceGrpc;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.reflect.Whitebox;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
......@@ -66,9 +67,9 @@ public class TraceSegmentServiceClientTest {
private TraceSegmentServiceClient serviceClient = new TraceSegmentServiceClient();
private List<UpstreamSegment> upstreamSegments;
private TraceSegmentServiceGrpc.TraceSegmentServiceImplBase serviceImplBase = new TraceSegmentServiceGrpc.TraceSegmentServiceImplBase() {
private TraceSegmentReportServiceGrpc.TraceSegmentReportServiceImplBase serviceImplBase = new TraceSegmentReportServiceGrpc.TraceSegmentReportServiceImplBase() {
@Override
public StreamObserver<UpstreamSegment> collect(final StreamObserver<Downstream> responseObserver) {
public StreamObserver<UpstreamSegment> collect(final StreamObserver<Commands> responseObserver) {
return new StreamObserver<UpstreamSegment>() {
@Override
public void onNext(UpstreamSegment value) {
......@@ -81,7 +82,7 @@ public class TraceSegmentServiceClientTest {
@Override
public void onCompleted() {
responseObserver.onNext(Downstream.getDefaultInstance());
responseObserver.onNext(Commands.getDefaultInstance());
responseObserver.onCompleted();
}
};
......@@ -90,8 +91,8 @@ public class TraceSegmentServiceClientTest {
@BeforeClass
public static void setUpBeforeClass() {
RemoteDownstreamConfig.Agent.APPLICATION_ID = 1;
RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1;
RemoteDownstreamConfig.Agent.SERVICE_ID = 1;
RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID = 1;
}
@AfterClass
......@@ -105,7 +106,7 @@ public class TraceSegmentServiceClientTest {
spy(serviceClient);
Whitebox.setInternalState(serviceClient, "serviceStub",
TraceSegmentServiceGrpc.newStub(grpcServerRule.getChannel()));
TraceSegmentReportServiceGrpc.newStub(grpcServerRule.getChannel()));
Whitebox.setInternalState(serviceClient, "status", GRPCChannelStatus.CONNECTED);
upstreamSegments = new ArrayList<UpstreamSegment>();
......@@ -127,11 +128,11 @@ public class TraceSegmentServiceClientTest {
assertThat(upstreamSegments.size(), is(1));
UpstreamSegment upstreamSegment = upstreamSegments.get(0);
assertThat(upstreamSegment.getGlobalTraceIdsCount(), is(1));
TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(upstreamSegment.getSegment());
SegmentObject traceSegmentObject = SegmentObject.parseFrom(upstreamSegment.getSegment());
assertThat(traceSegmentObject.getSpans(0).getRefsCount(), is(0));
assertThat(traceSegmentObject.getSpansCount(), is(1));
SpanObject spanObject = traceSegmentObject.getSpans(0);
SpanObjectV2 spanObject = traceSegmentObject.getSpans(0);
assertThat(spanObject.getSpanType(), is(SpanType.Entry));
assertThat(spanObject.getSpanId(), is(0));
assertThat(spanObject.getParentSpanId(), is(-1));
......
......@@ -14,6 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
agent.application_code = crmApp
agent.service_name = crmApp
collector.backend_service = 127.0.0.1:8080
logging.level=info
......@@ -107,7 +107,7 @@ public class DubboInterceptorTest {
when(rpcContext.isConsumerSide()).thenReturn(true);
allArguments = new Object[] {invoker, invocation};
argumentTypes = new Class[] {invoker.getClass(), invocation.getClass()};
Config.Agent.APPLICATION_CODE = "DubboTestCases-APP";
Config.Agent.SERVICE_NAME = "DubboTestCases-APP";
}
@After
......@@ -199,7 +199,7 @@ public class DubboInterceptorTest {
private void assertTraceSegmentRef(TraceSegmentRef actual) {
assertThat(SegmentRefHelper.getSpanId(actual), is(3));
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(actual), is(1));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(actual), is(1));
assertThat(SegmentRefHelper.getTraceSegmentId(actual).toString(), is("1.323.4433"));
}
......
......@@ -146,7 +146,7 @@ public class HandleInterceptorTest {
}
private void assertTraceSegmentRef(TraceSegmentRef ref) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getSpanId(ref), is(3));
assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111"));
}
......
......@@ -139,7 +139,7 @@ public class CallbackInterceptorTest {
TraceSegmentRef segmentRef = refs.get(0);
SegmentRefAssert.assertSpanId(segmentRef, 1);
assertThat(segmentRef.getEntryOperationName(), is("/for-test-entryOperationName"));
assertThat(segmentRef.getEntryEndpointName(), is("/for-test-entryOperationName"));
}
private void assertCallbackSpan(AbstractTracingSpan span) {
......
......@@ -143,7 +143,7 @@ public class KafkaConsumerInterceptorTest {
}
private void assertTraceSegmentRef(TraceSegmentRef ref) {
MatcherAssert.assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
MatcherAssert.assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(1));
MatcherAssert.assertThat(SegmentRefHelper.getSpanId(ref), is(3));
MatcherAssert.assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111"));
}
......
......@@ -163,7 +163,7 @@ public class MotanProviderInterceptorTest {
private void assertRefSegment(TraceSegmentRef primaryRef) {
assertThat(SegmentRefHelper.getTraceSegmentId(primaryRef).toString(), is("1.123.456"));
assertThat(SegmentRefHelper.getSpanId(primaryRef), is(3));
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(primaryRef), is(1));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(primaryRef), is(1));
assertThat(SegmentRefHelper.getPeerHost(primaryRef), is("192.168.1.8:18002"));
}
......
......@@ -100,7 +100,7 @@ public class ProducerOperationHandlerInterceptorTest {
when(statusType.getStatusCode()).thenReturn(200);
when(method.getName()).thenReturn("producer");
when(invocation.getInvocationType()).thenReturn(InvocationType.PRODUCER);
Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP";
Config.Agent.SERVICE_NAME = "serviceComnTestCases-APP";
allArguments = new Object[] {invocation,};
argumentsType = new Class[] {};
......
......@@ -99,7 +99,7 @@ public class TransportClientHandlerInterceptorTest {
when(invocation.getStatus()).thenReturn(statusType);
when(statusType.getStatusCode()).thenReturn(200);
when(invocation.getInvocationType()).thenReturn(InvocationType.CONSUMER);
Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP";
Config.Agent.SERVICE_NAME = "serviceComnTestCases-APP";
allArguments = new Object[] {invocation,};
argumentsType = new Class[] {};
......
......@@ -100,7 +100,7 @@ public class ProducerOperationHandlerInterceptorTest {
when(statusType.getStatusCode()).thenReturn(200);
when(method.getName()).thenReturn("producer");
when(invocation.getInvocationType()).thenReturn(InvocationType.PRODUCER);
Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP";
Config.Agent.SERVICE_NAME = "serviceComnTestCases-APP";
allArguments = new Object[] {invocation,};
argumentsType = new Class[] {};
......
......@@ -99,7 +99,7 @@ public class TransportClientHandlerInterceptorTest {
when(invocation.getStatus()).thenReturn(statusType);
when(statusType.getStatusCode()).thenReturn(200);
when(invocation.getInvocationType()).thenReturn(InvocationType.CONSUMER);
Config.Agent.APPLICATION_CODE = "serviceComnTestCases-APP";
Config.Agent.SERVICE_NAME = "serviceComnTestCases-APP";
allArguments = new Object[] {invocation,};
argumentsType = new Class[] {};
......
......@@ -100,7 +100,7 @@ public class SofaRpcConsumerInterceptorTest {
when(rpcContext.getProviderInfo()).thenReturn(providerInfo);
allArguments = new Object[] {sofaRequest};
argumentTypes = new Class[] {sofaRequest.getClass()};
Config.Agent.APPLICATION_CODE = "SOFARPC-TestCases-APP";
Config.Agent.SERVICE_NAME = "SOFARPC-TestCases-APP";
}
@Test
......
......@@ -110,7 +110,7 @@ public class SofaRpcProviderInterceptorTest {
when(rpcContext.getProviderInfo()).thenReturn(providerInfo);
allArguments = new Object[] {sofaRequest};
argumentTypes = new Class[] {sofaRequest.getClass()};
Config.Agent.APPLICATION_CODE = "SOFARPC-TestCases-APP";
Config.Agent.SERVICE_NAME = "SOFARPC-TestCases-APP";
}
@After
......@@ -138,7 +138,7 @@ public class SofaRpcProviderInterceptorTest {
private void assertTraceSegmentRef(TraceSegmentRef actual) {
assertThat(SegmentRefHelper.getSpanId(actual), is(3));
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(actual), is(1));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(actual), is(1));
assertThat(SegmentRefHelper.getTraceSegmentId(actual).toString(), is("1.323.4433"));
}
......
......@@ -155,7 +155,7 @@ public class RequestMappingMethodInterceptorTest {
}
private void assertTraceSegmentRef(TraceSegmentRef ref) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getSpanId(ref), is(3));
assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555"));
}
......
......@@ -286,7 +286,7 @@ public class RestMappingMethodInterceptorTest {
}
private void assertTraceSegmentRef(TraceSegmentRef ref) {
MatcherAssert.assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
MatcherAssert.assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getSpanId(ref), is(3));
MatcherAssert.assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.444.555"));
}
......
......@@ -161,7 +161,7 @@ public class Struts2InterceptorTest {
}
private void assertTraceSegmentRef(TraceSegmentRef ref) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getSpanId(ref), is(3));
assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111"));
}
......
......@@ -161,7 +161,7 @@ public class TomcatInvokeInterceptorTest {
}
private void assertTraceSegmentRef(TraceSegmentRef ref) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getSpanId(ref), is(3));
assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111"));
}
......
......@@ -172,7 +172,7 @@ public class ExecuteRootHandlerInterceptorTest {
}
private void assertTraceSegmentRef(TraceSegmentRef ref) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(1));
assertThat(SegmentRefHelper.getSpanId(ref), is(3));
assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111"));
}
......
......@@ -50,9 +50,9 @@ public class SegmentRefHelper {
return -1;
}
public static int getEntryApplicationInstanceId(TraceSegmentRef ref) {
public static int getEntryServiceInstanceId(TraceSegmentRef ref) {
try {
return FieldGetter.getValue(ref, "entryApplicationInstanceId");
return FieldGetter.getValue(ref, "entryServiceInstanceId");
} catch (Exception e) {
}
......
......@@ -53,7 +53,7 @@ public class AgentServiceRule extends ExternalResource {
AgentClassLoader.initDefaultLoader();
Config.Logging.LEVEL = LogLevel.OFF;
ServiceManager.INSTANCE.boot();
RemoteDownstreamConfig.Agent.APPLICATION_ID = 1;
RemoteDownstreamConfig.Agent.APPLICATION_INSTANCE_ID = 1;
RemoteDownstreamConfig.Agent.SERVICE_ID = 1;
RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID = 1;
}
}
......@@ -39,7 +39,7 @@ public class SegmentRefAssert {
}
public static void assertEntryApplicationInstanceId(TraceSegmentRef ref, int entryApplicationInstanceID) {
assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(entryApplicationInstanceID));
assertThat(SegmentRefHelper.getEntryServiceInstanceId(ref), is(entryApplicationInstanceID));
}
}
......@@ -17,8 +17,8 @@
# The agent namespace
# agent.namespace=default-namespace
# The application name in UI
agent.application_code=Your_ApplicationName
# The service name in UI
agent.service_name=Your_ApplicationName
# The number of sampled traces per 3 seconds
# Negative number means sample traces as many as possible, most likely 100%
......
......@@ -76,19 +76,19 @@ ContextManager provides all major and primary APIs.
1. Create EntrySpan
```java
public static AbstractSpan createEntrySpan(String operationName, ContextCarrier carrier)
public static AbstractSpan createEntrySpan(String endpointName, ContextCarrier carrier)
```
Create EntrySpan by operation name(e.g. service name, uri) and **ContextCarrier**.
2. Create LocalSpan
```java
public static AbstractSpan createLocalSpan(String operationName)
public static AbstractSpan createLocalSpan(String endpointName)
```
Create LocalSpan by operation name(e.g. full method signature)
3. Create ExitSpan
```java
public static AbstractSpan createExitSpan(String operationName, ContextCarrier carrier, String remotePeer)
public static AbstractSpan createExitSpan(String endpointName, ContextCarrier carrier, String remotePeer)
```
Create ExitSpan by operation name(e.g. service name, uri) and new **ContextCarrier** and peer address
(e.g. ip+port, hostname+port)
......@@ -145,7 +145,7 @@ Create ExitSpan by operation name(e.g. service name, uri) and new **ContextCarri
*
* @return this Span instance, for chaining
*/
AbstractSpan setOperationName(String operationName);
AbstractSpan setOperationName(String endpointName);
```
Besides set operation name, tags and logs, two attributes shoule be set, which are component and layer,
especially for EntrySpan and ExitSpan
......
......@@ -21,12 +21,22 @@ service ID.
### Language based native agent protocol
This protocol is combined from two parts:
* [**SW6** Cross Process Propagation Headers Protocol](Skywalking-Cross-Process-Propagation-Headers-Protocol-v2.md) is the new protocol for
There is two types of protocols to make language agents work in distributed environments.
1. **Cross Process Propagation Headers Protocol** is in wire data format, agent/SDK usually uses HTTP/MQ/HTTP2 headers
to carry the data with rpc request. The remote agent will receive this in the request handler, and bind the context
with this specific request.
1. **Trace Data Protocol** is out of wire data, agent/SDK uses this to send traces and metrics to skywalking or other
compatible backend.
Header protocol have two formats for compatible. Using v2 in default.
* [Cross Process Propagation Headers Protocol v2](Skywalking-Cross-Process-Propagation-Headers-Protocol-v2.md) is the new protocol for
in-wire context propagation, started in 6.0.0-beta release. It will replace the old **SW3** protocol in the future, now both of them are supported.
* [**SW3** Cross Process Propagation Headers Protocol](Skywalking-Cross-Process-Propagation-Headers-Protocol-v1.md) is for in-wire propagation.
* [Cross Process Propagation Headers Protocol v1](Skywalking-Cross-Process-Propagation-Headers-Protocol-v1.md) is for in-wire propagation.
By following this protocol, the trace segments in different processes could be linked.
* [SkyWalking Trace Data Protocol](Trace-Data-Protocol.md) define the communication way and format between agent and backend.
Since SkyWalking v6.0.0-beta, SkyWalking agent and backend are using Trace Data Protocol v2, and v1 is still supported in backend.
* [SkyWalking Trace Data Protocol v2](Trace-Data-Protocol-v2.md) define the communication way and format between agent and backend
* [SkyWalking Trace Data Protocol v1](Trace-Data-Protocol.md). This protocol is used in old version. Still supported.
### Service Mesh probe protocol
......@@ -55,6 +65,7 @@ Query protocol follows GraphQL grammar, provides data query capabilities, which
There are 5 dimensionality data is provided.
1. Metadata. Metadata includes the brief info of the whole under monitoring services and their instances, endpoints, etc.
Use multiple ways to query this meta data.
1. Topology. Show the topology and dependency graph of services or endpoints. Including direct relationship or global map.
1. Metric. Metric query targets all the objects defined in [OAL script](../concepts-and-designs/oal.md). You could get the
metric data in linear or thermodynamic matrix formats based on the aggregation functions in script.
1. Aggregation. Aggregation query means the metric data need a secondary aggregation in query stage, which makes the query
......@@ -64,4 +75,4 @@ by the values.
1. Trace. Query distributed traces by this.
1. Alarm. Through alarm query, you can have alarm trend and details.
The actual query GraphQL scrips could be found in [here](../../../apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql-v6).
\ No newline at end of file
The actual query GraphQL scrips could be found in [here](../../../oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol).
\ No newline at end of file
......@@ -8,7 +8,7 @@ uplink data to the SkyWalking backend.
- Other services, includes Register, Trace, etc., provided by HTTP/JSON and gRPC both.
### Version
v2.0
v1
#### gRPC proto files
[gRPC proto files](https://github.com/apache/incubator-skywalking-data-collect-protocol/tree/v2.0)
......@@ -20,7 +20,7 @@ v2.0
- UniqueId represents segmentId and globalTraceId. It have 3 parts(Longs), 1) applicationInstanceId, 2) ThreadId, 3) Timestamp + 10000 + seq(seq is in [0, 100000) )
- Span data please refs to [Plugin Development Guide](../guides/Java-Plugin-Development-Guide.md)
- Id and name both exist, please use id if possible.
- operationNameId/operationName
- operationNameId/endpointName
- networkAddress/networkAddressId
- entryServiceName/entryServiceId
- parentServiceName/parentServiceId
......@@ -36,7 +36,7 @@ Input:
"gt": [[230150, 185809, 24040000]],
"sg": { //TraceSegmentObject
"ts": [137150, 185809, 48780000],
"ai": 2, //applicationId
"ai": 2, //serviceId
"ii": 3, //applicationInstanceId
"ss": [ //SpanObject
{
......@@ -49,20 +49,20 @@ Input:
"ci": 3, //componentId
"cn": "", //component
"oi": 0, //operationNameId
"on": "org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()", //operationName
"on": "org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()", //endpointName
"pi": 0, //peerId
"pn": "", //peer
"ie": false, //isError
"rs": [ //TraceSegmentReference
{
"pts": [230150, 185809, 24040000], //parentTraceSegmentId
"pii": 2, //parentApplicationInstanceId
"pii": 2, //parentServiceInstanceId
"psp": 1, //parentSpanId
"psi": 0, //parentServiceId
"psn": "/dubbox-case/case/dubbox-rest", //parentServiceName
"ni": 0, //networkAddressId
"nn": "172.25.0.4:20880", //networkAddress
"eii": 2, //entryApplicationInstanceId
"eii": 2, //entryServiceInstanceId
"esi": 0, //entryServiceId
"esn": "/dubbox-case/case/dubbox-rest", //entryServiceName
"rv": 0 //RefTypeValue
......@@ -140,7 +140,7 @@ HTTP format http://ip:port/instance/register(default: localhost:12800)
Input:
```
{
ai: x, #applicationId
ai: x, #serviceId
au: "", #agentUUID
rt: x, #registerTime
oi: "", #osinfo
......@@ -150,7 +150,7 @@ Input:
Output:
```
{
ai: x, #applicationId
ai: x, #serviceId
ii: x, #applicationInstanceId
}
```
......@@ -185,7 +185,7 @@ HTTP format http://ip:port/servicename/discovery(default: localhost:12800)
Input:
```
{
ai: x, #applicationId
ai: x, #serviceId
sn: "", #serviceName
st: x, #srcSpanType
}
......@@ -196,7 +196,7 @@ Output:
{
si: x, #osinfo
el: { #element
ai: x, #applicationId
ai: x, #serviceId
sn: "", #serviceName
st: x, #srcSpanType
}
......
# Trace Data Protocol v2
Trace Data Protocol describes the data format between SkyWalking agent/sniffer and backend.
## Overview
Trace data protocol is defined and provided in [gRPC format](../../../apm-protocol/apm-network/src/main/proto).
For each agent/SDK, it needs to register service id and service instance id before reporting any kind of trace
or metric data.
### Step 1. Do register
[Register service](../../../apm-protocol/apm-network/src/main/proto/register/Register.proto) takes charge of
all register methods. At step 1, we need `doServiceRegister`, then `doServiceInstanceRegister`.
1. First of all, do `doServiceRegister`, input is **serviceName**, which could be declared by any UTF-8 String. The return
value is KeyValue pair, **serviceName** as key, **service id** as value. Batch is also supported.
1. After have **service id**, use `doServiceInstanceRegister` to do instance register. Input is **service id**, **UUID**,
and **register time**. UUID should be unique in the whole distributed environments. The return value is still KeyValue pair,
**UUID** as key, **service instance id** as value. Batch is also supported.
For register, the most important notice is that, the process is expected as async in backend, so, the return could be **NULL**.
In most cases, you need to set a timer to call these services repeated, until you got the response. Suggestion loop cycle, 10s.
Because batch is supported, even for most language agent/SDK, no scenario to do batch register. We suggest to check the `serviceName`
and `UUID` in response, and match with your expected value.
### Step 2. Send trace and metric
After you have trace id and trace instance id, you could send traces and metric. Now we
have
1. `TraceSegmentReportService#collect` for skywalking native trace format
1. `JVMMetricReportService#collect` for skywalking native jvm format
For trace format, there are some notices
1. Segment is a concept in SkyWalking, it should include all span for per request in a single OS process, usually single thread based on language.
2. Span has 3 different groups.
* EntrySpan
EntrySpan represents a service provider, also the endpoint of server side. As an APM system, we are targeting the
application servers. So almost all the services and MQ-comsumer are EntrySpan(s).
* LocalSpan
LocalSpan represents a normal Java method, which don't relate with remote service, neither a MQ producer/comsumer
nor a service(e.g. HTTP service) provider/consumer.
* ExitSpan
ExitSpan represents a client of service or MQ-producer, as named as `LeafSpan` at early age of SkyWalking.
e.g. accessing DB by JDBC, reading Redis/Memcached are cataloged an ExitSpan.
3. Span parent info called Reference, which is included in span. Reference carries more fields besides
trace id, parent segment id, span id. Others are **entry service instance id**, **parent service instance id**,
**entry endpoint**, **parent endpoint** and **network address**. Follow [SkyWalking Trace Data Protocol v2](Trace-Data-Protocol-v2.md),
you will know how to get all these fields.
### Step 3. Keep alive.
`ServiceInstancePing#doPing` should be called per several seconds. Make the backend know this instance is still
alive. Existed **service instance id** and **UUID** used in `doServiceInstanceRegister` are required.
\ No newline at end of file
......@@ -14,10 +14,7 @@ by using k8s native APIs to manage cluster.
Zookeeper is a very common and wide used cluster coordinator. Set the **cluster** module's implementor
to **zookeeper** in the yml to active.
Required Zookeeper version, 3.5+
Zookeeper version is required above 3.5 by Curator 4.0 lib, but actually Curator 4.0 is compatible with ZooKeeper 3.4.x.
To make ZooKeeper 3.4.x works, please replace the ZooKeeper 3.5+ library jar in `oap-libs` folder with ZooKeeper 3.4.x library.
Required Zookeeper version, 3.4+
```yaml
cluster:
......
# Setup java agent
1. Find `agent` folder in SkyWalking release package
1. Set `agent.service_name` in `config/agent.config`. Could be any String in English.
1. Set `collector.backend_service` in `config/agent.config`. Default point to `127.0.0.1:11800`, only works for local backend.
1. Add `-javaagent:/path/to/skywalking-package/agenxt/skywalking-agent.jar` to JVM argument. And make sure to add it before the `-jar` argument.
The agent release dist is included in Apache [official release](http://skywalking.apache.org/downloads/). New agent package looks like this.
......
......@@ -40,6 +40,7 @@ public class SegmentDispatcher implements SourceDispatcher<Segment> {
segment.setIsError(source.getIsError());
segment.setDataBinary(source.getDataBinary());
segment.setTimeBucket(source.getTimeBucket());
segment.setVersion(source.getVersion());
RecordProcess.INSTANCE.in(segment);
}
......
......@@ -18,15 +18,20 @@
package org.apache.skywalking.oap.server.core.analysis.manual.segment;
import java.util.*;
import lombok.*;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.record.Record;
import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordType;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.core.storage.annotation.Column;
import org.apache.skywalking.oap.server.core.storage.annotation.IDColumn;
import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntity;
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
/**
......@@ -47,6 +52,7 @@ public class SegmentRecord extends Record {
public static final String LATENCY = "latency";
public static final String IS_ERROR = "is_error";
public static final String DATA_BINARY = "data_binary";
public static final String VERSION = "version";
@Setter @Getter @Column(columnName = SEGMENT_ID) @IDColumn private String segmentId;
@Setter @Getter @Column(columnName = TRACE_ID) @IDColumn private String traceId;
......@@ -58,6 +64,7 @@ public class SegmentRecord extends Record {
@Setter @Getter @Column(columnName = LATENCY) @IDColumn private int latency;
@Setter @Getter @Column(columnName = IS_ERROR) @IDColumn private int isError;
@Setter @Getter @Column(columnName = DATA_BINARY) @IDColumn private byte[] dataBinary;
@Setter @Getter @Column(columnName = VERSION) @IDColumn private int version;
@Override public String id() {
return segmentId;
......@@ -82,6 +89,7 @@ public class SegmentRecord extends Record {
} else {
map.put(DATA_BINARY, new String(Base64.getEncoder().encode(storageData.getDataBinary())));
}
map.put(VERSION, storageData.getVersion());
return map;
}
......@@ -102,6 +110,7 @@ public class SegmentRecord extends Record {
} else {
record.setDataBinary(Base64.getDecoder().decode((String)dbMap.get(DATA_BINARY)));
}
record.setVersion(((Number)dbMap.get(VERSION)).intValue());
return record;
}
}
......
......@@ -21,6 +21,8 @@ package org.apache.skywalking.oap.server.core.query;
import java.io.IOException;
import java.util.*;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
import org.apache.skywalking.oap.server.core.cache.*;
......@@ -87,7 +89,8 @@ public class TraceQueryService implements Service {
return componentLibraryCatalogService;
}
public TraceBrief queryBasicTraces(final int serviceId, final int endpointId, final String traceId, final String endpointName,
public TraceBrief queryBasicTraces(final int serviceId, final int endpointId, final String traceId,
final String endpointName,
final int minTraceDuration, int maxTraceDuration, final TraceState traceState, final QueryOrder queryOrder,
final Pagination paging, final long startTB, final long endTB) throws IOException {
PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(paging);
......@@ -102,8 +105,15 @@ public class TraceQueryService implements Service {
List<SegmentRecord> segmentRecords = getTraceQueryDAO().queryByTraceId(traceId);
for (SegmentRecord segment : segmentRecords) {
if (nonNull(segment)) {
TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(segment.getDataBinary());
trace.getSpans().addAll(buildSpanList(traceId, segment.getSegmentId(), segment.getServiceId(), segmentObject.getSpansList()));
if (segment.getVersion() == 1) {
TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(segment.getDataBinary());
trace.getSpans().addAll(buildSpanList(traceId, segment.getSegmentId(), segment.getServiceId(), segmentObject.getSpansList()));
} else if (segment.getVersion() == 2) {
SegmentObject segmentObject = SegmentObject.parseFrom(segment.getDataBinary());
trace.getSpans().addAll(buildSpanV2List(traceId, segment.getSegmentId(), segment.getServiceId(), segmentObject.getSpansList()));
} else {
throw new UnexpectedException("Unsupported version=" + segment.getVersion());
}
}
}
......@@ -126,6 +136,111 @@ public class TraceQueryService implements Service {
return trace;
}
private List<Span> buildSpanV2List(String traceId, String segmentId, int serviceId,
List<SpanObjectV2> spanObjects) {
List<Span> spans = new ArrayList<>();
spanObjects.forEach(spanObject -> {
Span span = new Span();
span.setTraceId(traceId);
span.setSegmentId(segmentId);
span.setSpanId(spanObject.getSpanId());
span.setParentSpanId(spanObject.getParentSpanId());
span.setStartTime(spanObject.getStartTime());
span.setEndTime(spanObject.getEndTime());
span.setError(spanObject.getIsError());
span.setLayer(spanObject.getSpanLayer().name());
span.setType(spanObject.getSpanType().name());
String segmentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanObject.getSpanId());
span.setSegmentSpanId(segmentSpanId);
String segmentParentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanObject.getParentSpanId());
span.setSegmentParentSpanId(segmentParentSpanId);
if (spanObject.getPeerId() == 0) {
span.setPeer(spanObject.getPeer());
} else {
span.setPeer(getNetworkAddressInventoryCache().get(spanObject.getPeerId()).getName());
}
String endpointName = spanObject.getOperationName();
if (spanObject.getOperationNameId() != 0) {
EndpointInventory endpointInventory = getEndpointInventoryCache().get(spanObject.getOperationNameId());
if (nonNull(endpointInventory)) {
endpointName = endpointInventory.getName();
} else {
endpointName = Const.EMPTY_STRING;
}
}
span.setEndpointName(endpointName);
String serviceCode = getServiceInventoryCache().get(serviceId).getName();
span.setServiceCode(serviceCode);
if (spanObject.getComponentId() == 0) {
span.setComponent(spanObject.getComponent());
} else {
span.setComponent(getComponentLibraryCatalogService().getComponentName(spanObject.getComponentId()));
}
spanObject.getRefsList().forEach(reference -> {
Ref ref = new Ref();
ref.setTraceId(traceId);
switch (reference.getRefType()) {
case CrossThread:
ref.setType(RefType.CROSS_THREAD);
break;
case CrossProcess:
ref.setType(RefType.CROSS_PROCESS);
break;
}
ref.setParentSpanId(reference.getParentSpanId());
UniqueId uniqueId = reference.getParentTraceSegmentId();
StringBuilder segmentIdBuilder = new StringBuilder();
for (int i = 0; i < uniqueId.getIdPartsList().size(); i++) {
if (i == 0) {
segmentIdBuilder.append(String.valueOf(uniqueId.getIdPartsList().get(i)));
} else {
segmentIdBuilder.append(".").append(String.valueOf(uniqueId.getIdPartsList().get(i)));
}
}
ref.setParentSegmentId(segmentIdBuilder.toString());
span.setSegmentParentSpanId(ref.getParentSegmentId() + Const.SEGMENT_SPAN_SPLIT + String.valueOf(ref.getParentSpanId()));
span.getRefs().add(ref);
});
spanObject.getTagsList().forEach(tag -> {
KeyValue keyValue = new KeyValue();
keyValue.setKey(tag.getKey());
keyValue.setValue(tag.getValue());
span.getTags().add(keyValue);
});
spanObject.getLogsList().forEach(log -> {
LogEntity logEntity = new LogEntity();
logEntity.setTime(log.getTime());
log.getDataList().forEach(data -> {
KeyValue keyValue = new KeyValue();
keyValue.setKey(data.getKey());
keyValue.setValue(data.getValue());
logEntity.getData().add(keyValue);
});
span.getLogs().add(logEntity);
});
spans.add(span);
});
return spans;
}
private List<Span> buildSpanList(String traceId, String segmentId, int serviceId,
List<SpanObject> spanObjects) {
List<Span> spans = new ArrayList<>();
......
......@@ -39,7 +39,7 @@ public enum DetectPoint {
}
}
public static DetectPoint fromMeshDetectPoint(org.apache.skywalking.apm.network.common.DetectPoint detectPoint) {
public static DetectPoint fromNetworkProtocolDetectPoint(org.apache.skywalking.apm.network.common.DetectPoint detectPoint) {
switch (detectPoint) {
case client:
return CLIENT;
......
......@@ -45,4 +45,5 @@ public class Segment extends Source {
@Setter @Getter private int latency;
@Setter @Getter private int isError;
@Setter @Getter private byte[] dataBinary;
@Setter @Getter private int version;
}
......@@ -20,8 +20,11 @@ package org.apache.skywalking.oap.server.receiver.jvm.provider;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.ModuleProvider;
import org.apache.skywalking.oap.server.receiver.jvm.module.JVMModule;
import org.apache.skywalking.oap.server.receiver.jvm.provider.handler.JVMMetricReportServiceHandler;
import org.apache.skywalking.oap.server.receiver.jvm.provider.handler.JVMMetricsServiceHandler;
/**
......@@ -47,6 +50,7 @@ public class JVMModuleProvider extends ModuleProvider {
@Override public void start() {
GRPCHandlerRegister grpcHandlerRegister = getManager().find(CoreModule.NAME).provider().getService(GRPCHandlerRegister.class);
grpcHandlerRegister.addHandler(new JVMMetricsServiceHandler(getManager()));
grpcHandlerRegister.addHandler(new JVMMetricReportServiceHandler(getManager()));
}
@Override public void notifyAfterCompleted() {
......
/*
* 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.oap.server.receiver.jvm.provider.handler;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.language.agent.v2.JVMMetricCollection;
import org.apache.skywalking.apm.network.language.agent.v2.JVMMetricReportServiceGrpc;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.apache.skywalking.oap.server.library.util.TimeBucketUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JVMMetricReportServiceHandler extends JVMMetricReportServiceGrpc.JVMMetricReportServiceImplBase implements GRPCHandler {
private static final Logger logger = LoggerFactory.getLogger(JVMMetricReportServiceHandler.class);
private final JVMSourceDispatcher jvmSourceDispatcher;
public JVMMetricReportServiceHandler(ModuleManager moduleManager) {
this.jvmSourceDispatcher = new JVMSourceDispatcher(moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class));
}
@Override public void collect(JVMMetricCollection request, StreamObserver<Commands> responseObserver) {
int serviceInstanceId = request.getServiceInstanceId();
if (logger.isDebugEnabled()) {
logger.debug("receive the jvm metric from service instance, id: {}", serviceInstanceId);
}
request.getMetricsList().forEach(metric -> {
long minuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(metric.getTime());
jvmSourceDispatcher.sendMetric(serviceInstanceId, minuteTimeBucket, metric);
});
responseObserver.onNext(Commands.newBuilder().build());
responseObserver.onCompleted();
}
}
......@@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.receiver.jvm.provider.handler;
import io.grpc.stub.StreamObserver;
import java.util.List;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.source.GCPhrase;
import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.apm.network.language.agent.Downstream;
import org.apache.skywalking.apm.network.language.agent.JVMMetrics;
import org.apache.skywalking.apm.network.language.agent.JVMMetricsServiceGrpc;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.apache.skywalking.oap.server.library.util.TimeBucketUtils;
import org.slf4j.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
......@@ -36,120 +37,26 @@ public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsSe
private static final Logger logger = LoggerFactory.getLogger(JVMMetricsServiceHandler.class);
private final SourceReceiver sourceReceiver;
private final JVMSourceDispatcher jvmSourceDispatcher;
public JVMMetricsServiceHandler(ModuleManager moduleManager) {
this.sourceReceiver = moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
this.jvmSourceDispatcher = new JVMSourceDispatcher(moduleManager.find(CoreModule.NAME).provider().getService(SourceReceiver.class));
}
@Override public void collect(JVMMetrics request, StreamObserver<Downstream> responseObserver) {
int serviceInstanceId = request.getApplicationInstanceId();
if (logger.isDebugEnabled()) {
logger.debug("receive the jvm metric from application instance, id: {}", serviceInstanceId);
logger.debug("receive the jvm metric from service instance, id: {}", serviceInstanceId);
}
request.getMetricsList().forEach(metric -> {
long minuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(metric.getTime());
sendToCpuMetricProcess(serviceInstanceId, minuteTimeBucket, metric.getCpu());
sendToMemoryMetricProcess(serviceInstanceId, minuteTimeBucket, metric.getMemoryList());
sendToMemoryPoolMetricProcess(serviceInstanceId, minuteTimeBucket, metric.getMemoryPoolList());
sendToGCMetricProcess(serviceInstanceId, minuteTimeBucket, metric.getGcList());
jvmSourceDispatcher.sendMetric(serviceInstanceId, minuteTimeBucket, metric);
});
responseObserver.onNext(Downstream.newBuilder().build());
responseObserver.onCompleted();
}
private void sendToCpuMetricProcess(int serviceInstanceId, long timeBucket, CPU cpu) {
ServiceInstanceJVMCPU serviceInstanceJVMCPU = new ServiceInstanceJVMCPU();
serviceInstanceJVMCPU.setId(serviceInstanceId);
serviceInstanceJVMCPU.setName(Const.EMPTY_STRING);
serviceInstanceJVMCPU.setServiceInstanceId(serviceInstanceId);
serviceInstanceJVMCPU.setServiceName(Const.EMPTY_STRING);
serviceInstanceJVMCPU.setUsePercent(cpu.getUsagePercent());
serviceInstanceJVMCPU.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMCPU);
}
private void sendToGCMetricProcess(int serviceInstanceId, long timeBucket, List<GC> gcs) {
gcs.forEach(gc -> {
ServiceInstanceJVMGC serviceInstanceJVMGC = new ServiceInstanceJVMGC();
serviceInstanceJVMGC.setId(serviceInstanceId);
serviceInstanceJVMGC.setName(Const.EMPTY_STRING);
serviceInstanceJVMGC.setServiceInstanceId(serviceInstanceId);
serviceInstanceJVMGC.setServiceName(Const.EMPTY_STRING);
switch (gc.getPhrase()) {
case NEW:
serviceInstanceJVMGC.setPhrase(GCPhrase.NEW);
break;
case OLD:
serviceInstanceJVMGC.setPhrase(GCPhrase.OLD);
break;
}
serviceInstanceJVMGC.setTime(gc.getTime());
serviceInstanceJVMGC.setCount(gc.getCount());
serviceInstanceJVMGC.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMGC);
});
}
private void sendToMemoryMetricProcess(int serviceInstanceId, long timeBucket, List<Memory> memories) {
memories.forEach(memory -> {
ServiceInstanceJVMMemory serviceInstanceJVMMemory = new ServiceInstanceJVMMemory();
serviceInstanceJVMMemory.setId(serviceInstanceId);
serviceInstanceJVMMemory.setName(Const.EMPTY_STRING);
serviceInstanceJVMMemory.setServiceInstanceId(serviceInstanceId);
serviceInstanceJVMMemory.setServiceName(Const.EMPTY_STRING);
serviceInstanceJVMMemory.setHeapStatus(memory.getIsHeap());
serviceInstanceJVMMemory.setInit(memory.getInit());
serviceInstanceJVMMemory.setMax(memory.getMax());
serviceInstanceJVMMemory.setUsed(memory.getUsed());
serviceInstanceJVMMemory.setCommitted(memory.getCommitted());
serviceInstanceJVMMemory.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMMemory);
});
}
private void sendToMemoryPoolMetricProcess(int serviceInstanceId, long timeBucket,
List<MemoryPool> memoryPools) {
memoryPools.forEach(memoryPool -> {
ServiceInstanceJVMMemoryPool serviceInstanceJVMMemoryPool = new ServiceInstanceJVMMemoryPool();
serviceInstanceJVMMemoryPool.setId(serviceInstanceId);
serviceInstanceJVMMemoryPool.setName(Const.EMPTY_STRING);
serviceInstanceJVMMemoryPool.setServiceInstanceId(serviceInstanceId);
serviceInstanceJVMMemoryPool.setServiceName(Const.EMPTY_STRING);
switch (memoryPool.getType()) {
case NEWGEN_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.NEWGEN_USAGE);
break;
case OLDGEN_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.OLDGEN_USAGE);
break;
case PERMGEN_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.PERMGEN_USAGE);
break;
case SURVIVOR_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.SURVIVOR_USAGE);
break;
case METASPACE_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.METASPACE_USAGE);
break;
case CODE_CACHE_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.CODE_CACHE_USAGE);
break;
}
serviceInstanceJVMMemoryPool.setInit(memoryPool.getInit());
serviceInstanceJVMMemoryPool.setMax(memoryPool.getMax());
serviceInstanceJVMMemoryPool.setUsed(memoryPool.getUsed());
serviceInstanceJVMMemoryPool.setCommitted(memoryPool.getCommited());
serviceInstanceJVMMemoryPool.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMMemoryPool);
});
}
}
/*
* 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.oap.server.receiver.jvm.provider.handler;
import java.util.List;
import org.apache.skywalking.apm.network.language.agent.CPU;
import org.apache.skywalking.apm.network.language.agent.GC;
import org.apache.skywalking.apm.network.language.agent.JVMMetric;
import org.apache.skywalking.apm.network.language.agent.Memory;
import org.apache.skywalking.apm.network.language.agent.MemoryPool;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.source.GCPhrase;
import org.apache.skywalking.oap.server.core.source.MemoryPoolType;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceJVMCPU;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceJVMGC;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceJVMMemory;
import org.apache.skywalking.oap.server.core.source.ServiceInstanceJVMMemoryPool;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
/**
* @author wusheng
*/
public class JVMSourceDispatcher {
private SourceReceiver sourceReceiver;
public JVMSourceDispatcher(SourceReceiver sourceReceiver) {
this.sourceReceiver = sourceReceiver;
}
void sendMetric(int serviceInstanceId, long minuteTimeBucket, JVMMetric metric) {
this.sendToCpuMetricProcess(serviceInstanceId, minuteTimeBucket, metric.getCpu());
this.sendToMemoryMetricProcess(serviceInstanceId, minuteTimeBucket, metric.getMemoryList());
this.sendToMemoryPoolMetricProcess(serviceInstanceId, minuteTimeBucket, metric.getMemoryPoolList());
this.sendToGCMetricProcess(serviceInstanceId, minuteTimeBucket, metric.getGcList());
}
private void sendToCpuMetricProcess(int serviceInstanceId, long timeBucket, CPU cpu) {
ServiceInstanceJVMCPU serviceInstanceJVMCPU = new ServiceInstanceJVMCPU();
serviceInstanceJVMCPU.setId(serviceInstanceId);
serviceInstanceJVMCPU.setName(Const.EMPTY_STRING);
serviceInstanceJVMCPU.setServiceInstanceId(serviceInstanceId);
serviceInstanceJVMCPU.setServiceName(Const.EMPTY_STRING);
serviceInstanceJVMCPU.setUsePercent(cpu.getUsagePercent());
serviceInstanceJVMCPU.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMCPU);
}
private void sendToGCMetricProcess(int serviceInstanceId, long timeBucket, List<GC> gcs) {
gcs.forEach(gc -> {
ServiceInstanceJVMGC serviceInstanceJVMGC = new ServiceInstanceJVMGC();
serviceInstanceJVMGC.setId(serviceInstanceId);
serviceInstanceJVMGC.setName(Const.EMPTY_STRING);
serviceInstanceJVMGC.setServiceInstanceId(serviceInstanceId);
serviceInstanceJVMGC.setServiceName(Const.EMPTY_STRING);
switch (gc.getPhrase()) {
case NEW:
serviceInstanceJVMGC.setPhrase(GCPhrase.NEW);
break;
case OLD:
serviceInstanceJVMGC.setPhrase(GCPhrase.OLD);
break;
}
serviceInstanceJVMGC.setTime(gc.getTime());
serviceInstanceJVMGC.setCount(gc.getCount());
serviceInstanceJVMGC.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMGC);
});
}
private void sendToMemoryMetricProcess(int serviceInstanceId, long timeBucket, List<Memory> memories) {
memories.forEach(memory -> {
ServiceInstanceJVMMemory serviceInstanceJVMMemory = new ServiceInstanceJVMMemory();
serviceInstanceJVMMemory.setId(serviceInstanceId);
serviceInstanceJVMMemory.setName(Const.EMPTY_STRING);
serviceInstanceJVMMemory.setServiceInstanceId(serviceInstanceId);
serviceInstanceJVMMemory.setServiceName(Const.EMPTY_STRING);
serviceInstanceJVMMemory.setHeapStatus(memory.getIsHeap());
serviceInstanceJVMMemory.setInit(memory.getInit());
serviceInstanceJVMMemory.setMax(memory.getMax());
serviceInstanceJVMMemory.setUsed(memory.getUsed());
serviceInstanceJVMMemory.setCommitted(memory.getCommitted());
serviceInstanceJVMMemory.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMMemory);
});
}
private void sendToMemoryPoolMetricProcess(int serviceInstanceId, long timeBucket,
List<MemoryPool> memoryPools) {
memoryPools.forEach(memoryPool -> {
ServiceInstanceJVMMemoryPool serviceInstanceJVMMemoryPool = new ServiceInstanceJVMMemoryPool();
serviceInstanceJVMMemoryPool.setId(serviceInstanceId);
serviceInstanceJVMMemoryPool.setName(Const.EMPTY_STRING);
serviceInstanceJVMMemoryPool.setServiceInstanceId(serviceInstanceId);
serviceInstanceJVMMemoryPool.setServiceName(Const.EMPTY_STRING);
switch (memoryPool.getType()) {
case NEWGEN_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.NEWGEN_USAGE);
break;
case OLDGEN_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.OLDGEN_USAGE);
break;
case PERMGEN_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.PERMGEN_USAGE);
break;
case SURVIVOR_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.SURVIVOR_USAGE);
break;
case METASPACE_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.METASPACE_USAGE);
break;
case CODE_CACHE_USAGE:
serviceInstanceJVMMemoryPool.setPoolType(MemoryPoolType.CODE_CACHE_USAGE);
break;
}
serviceInstanceJVMMemoryPool.setInit(memoryPool.getInit());
serviceInstanceJVMMemoryPool.setMax(memoryPool.getMax());
serviceInstanceJVMMemoryPool.setUsed(memoryPool.getUsed());
serviceInstanceJVMMemoryPool.setCommitted(memoryPool.getCommited());
serviceInstanceJVMMemoryPool.setTimeBucket(timeBucket);
sourceReceiver.receive(serviceInstanceJVMMemoryPool);
});
}
}
......@@ -90,12 +90,12 @@ public class ServiceMeshMetricDataDecorator {
if (DetectPoint.client.equals(point)) {
if (sourceServiceId != Const.NONE) {
endpointId = CoreRegisterLinker.getEndpointInventoryRegister().getOrCreate(sourceServiceId, endpoint,
org.apache.skywalking.oap.server.core.source.DetectPoint.fromMeshDetectPoint(point));
org.apache.skywalking.oap.server.core.source.DetectPoint.fromNetworkProtocolDetectPoint(point));
}
} else {
if (destServiceId != Const.NONE) {
endpointId = CoreRegisterLinker.getEndpointInventoryRegister().getOrCreate(destServiceId, endpoint,
org.apache.skywalking.oap.server.core.source.DetectPoint.fromMeshDetectPoint(point));
org.apache.skywalking.oap.server.core.source.DetectPoint.fromNetworkProtocolDetectPoint(point));
}
}
......
......@@ -19,14 +19,23 @@
package org.apache.skywalking.oap.server.receiver.register.provider;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.server.*;
import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
import org.apache.skywalking.oap.server.core.server.JettyHandlerRegister;
import org.apache.skywalking.oap.server.library.module.ModuleConfig;
import org.apache.skywalking.oap.server.library.module.ModuleDefine;
import org.apache.skywalking.oap.server.library.module.ModuleProvider;
import org.apache.skywalking.oap.server.receiver.register.module.RegisterModule;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc.ApplicationRegisterHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc.InstanceDiscoveryServiceHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc.NetworkAddressRegisterServiceHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc.ServiceNameDiscoveryHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest.*;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest.ApplicationRegisterServletHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest.InstanceDiscoveryServletHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest.InstanceHeartBeatServletHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest.NetworkAddressRegisterServletHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.rest.ServiceNameDiscoveryServiceHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v6.grpc.RegisterServiceHandler;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v6.grpc.ServiceInstancePingServiceHandler;
/**
* @author peng-yongsheng
......@@ -55,6 +64,10 @@ public class RegisterModuleProvider extends ModuleProvider {
grpcHandlerRegister.addHandler(new ServiceNameDiscoveryHandler(getManager()));
grpcHandlerRegister.addHandler(new NetworkAddressRegisterServiceHandler(getManager()));
// v2
grpcHandlerRegister.addHandler(new RegisterServiceHandler(getManager()));
grpcHandlerRegister.addHandler(new ServiceInstancePingServiceHandler(getManager()));
JettyHandlerRegister jettyHandlerRegister = getManager().find(CoreModule.NAME).provider().getService(JettyHandlerRegister.class);
jettyHandlerRegister.addHandler(new ApplicationRegisterServletHandler(getManager()));
jettyHandlerRegister.addHandler(new InstanceDiscoveryServletHandler(getManager()));
......
/*
* 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.oap.server.receiver.register.provider.handler.v6.grpc;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.common.KeyIntValuePair;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
import org.apache.skywalking.apm.network.register.v2.EndpointMapping;
import org.apache.skywalking.apm.network.register.v2.EndpointMappingElement;
import org.apache.skywalking.apm.network.register.v2.Enpoints;
import org.apache.skywalking.apm.network.register.v2.NetAddressMapping;
import org.apache.skywalking.apm.network.register.v2.NetAddresses;
import org.apache.skywalking.apm.network.register.v2.RegisterGrpc;
import org.apache.skywalking.apm.network.register.v2.ServiceAndNetworkAddressMappings;
import org.apache.skywalking.apm.network.register.v2.ServiceInstanceRegisterMapping;
import org.apache.skywalking.apm.network.register.v2.ServiceInstances;
import org.apache.skywalking.apm.network.register.v2.ServiceRegisterMapping;
import org.apache.skywalking.apm.network.register.v2.Services;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.register.service.IEndpointInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.receiver.register.provider.handler.v5.grpc.InstanceDiscoveryServiceHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author wusheng
*/
public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implements GRPCHandler {
private static final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServiceHandler.class);
private final ServiceInventoryCache serviceInventoryCache;
private final ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private final IServiceInventoryRegister serviceInventoryRegister;
private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
private final IEndpointInventoryRegister inventoryService;
private final INetworkAddressInventoryRegister networkAddressInventoryRegister;
public RegisterServiceHandler(ModuleManager moduleManager) {
this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
this.inventoryService = moduleManager.find(CoreModule.NAME).provider().getService(IEndpointInventoryRegister.class);
this.networkAddressInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(INetworkAddressInventoryRegister.class);
}
@Override public void doServiceRegister(Services request, StreamObserver<ServiceRegisterMapping> responseObserver) {
ServiceRegisterMapping.Builder builder = ServiceRegisterMapping.newBuilder();
request.getServicesList().forEach(service -> {
String serviceName = service.getServiceName();
if (logger.isDebugEnabled()) {
logger.debug("Register service, service code: {}", serviceName);
}
int serviceId = serviceInventoryRegister.getOrCreate(serviceName);
if (serviceId != Const.NONE) {
KeyIntValuePair value = KeyIntValuePair.newBuilder().setKey(serviceName).setValue(serviceId).build();
builder.addServices(value);
}
});
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}
@Override public void doServiceInstanceRegister(ServiceInstances request,
StreamObserver<ServiceInstanceRegisterMapping> responseObserver) {
ServiceInstanceRegisterMapping.Builder builder = ServiceInstanceRegisterMapping.newBuilder();
request.getInstancesList().forEach(instance -> {
ServiceInventory serviceInventory = serviceInventoryCache.get(instance.getServiceId());
ServiceInstanceInventory.AgentOsInfo agentOsInfo = new ServiceInstanceInventory.AgentOsInfo();
for (KeyStringValuePair property : instance.getPropertiesList()) {
String key = property.getKey();
switch (key) {
case "OSName":
agentOsInfo.setOsName(property.getValue());
break;
case "hostname":
agentOsInfo.setHostname(property.getValue());
break;
case "ipv4":
agentOsInfo.getIpv4s().add(property.getValue());
break;
case "ProcessNo":
agentOsInfo.setProcessNo(Integer.parseInt(property.getValue()));
break;
}
}
String instanceName = serviceInventory.getName();
if (agentOsInfo.getProcessNo() != 0) {
instanceName += "-pid:" + agentOsInfo.getProcessNo();
}
if (StringUtils.isNotEmpty(agentOsInfo.getHostname())) {
instanceName += "@" + agentOsInfo.getHostname();
}
int serviceInstanceId = serviceInstanceInventoryRegister.getOrCreate(instance.getServiceId(), instanceName, instance.getInstanceUUID(), instance.getTime(), agentOsInfo);
if (serviceInstanceId != Const.NONE) {
logger.info("register service instance id={} [UUID:{}]", serviceInstanceId, instance.getInstanceUUID());
builder.addServiceInstances(KeyIntValuePair.newBuilder().setKey(instance.getInstanceUUID()).setValue(serviceInstanceId));
}
});
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}
@Override public void doEndpointRegister(Enpoints request, StreamObserver<EndpointMapping> responseObserver) {
EndpointMapping.Builder builder = EndpointMapping.newBuilder();
request.getEndpointsList().forEach(endpoint -> {
int serviceId = endpoint.getServiceId();
String endpointName = endpoint.getEndpointName();
int endpointId = inventoryService.getOrCreate(serviceId, endpointName, DetectPoint.fromNetworkProtocolDetectPoint(endpoint.getFrom()));
if (endpointId != Const.NONE) {
builder.addElements(EndpointMappingElement.newBuilder()
.setServiceId(serviceId)
.setEndpointName(endpointName)
.setEndpointId(endpointId)
.setFrom(endpoint.getFrom()));
}
});
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}
@Override
public void doNetworkAddressRegister(NetAddresses request, StreamObserver<NetAddressMapping> responseObserver) {
NetAddressMapping.Builder builder = NetAddressMapping.newBuilder();
request.getAddressesList().forEach(networkAddress -> {
int addressId = networkAddressInventoryRegister.getOrCreate(networkAddress);
if (addressId != Const.NONE) {
builder.addAddressIds(KeyIntValuePair.newBuilder().setKey(networkAddress).setValue(addressId));
}
});
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}
@Override public void doServiceAndNetworkAddressMappingRegister(ServiceAndNetworkAddressMappings request,
StreamObserver<Commands> responseObserver) {
request.getMappingsList().forEach(mapping -> {
int serviceId = mapping.getServiceId();
if (serviceId == Const.NONE) {
int serviceInstanceId = mapping.getServiceInstanceId();
if (serviceInstanceId == Const.NONE) {
serviceId = serviceInstanceInventoryCache.get(serviceInstanceId).getServiceId();
} else {
return;
}
}
if (serviceId == Const.NONE) {
return;
}
int networkAddressId = mapping.getNetworkAddressId();
if (networkAddressId == Const.NONE) {
String address = mapping.getNetworkAddress();
if (StringUtil.isEmpty(address)) {
return;
}
networkAddressId = networkAddressInventoryRegister.getOrCreate(address);
if (networkAddressId == Const.NONE) {
return;
}
}
serviceInventoryRegister.updateMapping(networkAddressId, serviceId);
});
responseObserver.onNext(Commands.getDefaultInstance());
responseObserver.onCompleted();
}
}
/*
* 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.oap.server.receiver.register.provider.handler.v6.grpc;
import io.grpc.stub.StreamObserver;
import java.util.Objects;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.register.v2.ServiceInstancePingGrpc;
import org.apache.skywalking.apm.network.register.v2.ServiceInstancePingPkg;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author wusheng
*/
public class ServiceInstancePingServiceHandler extends ServiceInstancePingGrpc.ServiceInstancePingImplBase implements GRPCHandler {
private static final Logger logger = LoggerFactory.getLogger(ServiceInstancePingServiceHandler.class);
private final ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private final IServiceInventoryRegister serviceInventoryRegister;
private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
public ServiceInstancePingServiceHandler(ModuleManager moduleManager) {
this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInstanceInventoryRegister.class);
}
@Override public void doPing(ServiceInstancePingPkg request, StreamObserver<Commands> responseObserver) {
int serviceInstanceId = request.getServiceInstanceId();
long heartBeatTime = request.getTime();
serviceInstanceInventoryRegister.heartbeat(serviceInstanceId, heartBeatTime);
ServiceInstanceInventory serviceInstanceInventory = serviceInstanceInventoryCache.get(serviceInstanceId);
if (Objects.nonNull(serviceInstanceInventory)) {
serviceInventoryRegister.heartbeat(serviceInstanceInventory.getServiceId(), heartBeatTime);
} else {
logger.warn("Can't found service by service instance id from cache, service instance id is: {}", serviceInstanceId);
}
responseObserver.onNext(Commands.getDefaultInstance());
responseObserver.onCompleted();
}
}
......@@ -25,6 +25,7 @@ import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.receiver.trace.module.TraceModule;
import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.grpc.TraceSegmentServiceHandler;
import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.rest.TraceSegmentServletHandler;
import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v6.grpc.TraceSegmentReportServiceHandler;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.*;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.endpoint.MultiScopesSpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.segment.SegmentSpanListener;
......@@ -38,6 +39,7 @@ public class TraceModuleProvider extends ModuleProvider {
private final TraceServiceModuleConfig moduleConfig;
private SegmentParse.Producer segmentProducer;
private SegmentParseV2.Producer segmentProducerV2;
public TraceModuleProvider() {
this.moduleConfig = new TraceServiceModuleConfig();
......@@ -62,7 +64,15 @@ public class TraceModuleProvider extends ModuleProvider {
listenerManager.add(new SegmentSpanListener.Factory());
segmentProducer = new SegmentParse.Producer(getManager(), listenerManager);
this.registerServiceImplementation(ISegmentParserService.class, new SegmentParserServiceImpl(segmentProducer));
listenerManager = new SegmentParserListenerManager();
listenerManager.add(new MultiScopesSpanListener.Factory());
listenerManager.add(new ServiceMappingSpanListener.Factory());
listenerManager.add(new SegmentSpanListener.Factory());
segmentProducerV2 = new SegmentParseV2.Producer(getManager(), listenerManager);
this.registerServiceImplementation(ISegmentParserService.class, new SegmentParserServiceImpl(segmentProducerV2));
}
@Override public void start() throws ModuleStartException {
......@@ -71,10 +81,14 @@ public class TraceModuleProvider extends ModuleProvider {
try {
grpcHandlerRegister.addHandler(new TraceSegmentServiceHandler(segmentProducer));
grpcHandlerRegister.addHandler(new TraceSegmentReportServiceHandler(segmentProducerV2));
jettyHandlerRegister.addHandler(new TraceSegmentServletHandler(segmentProducer));
SegmentStandardizationWorker standardizationWorker = new SegmentStandardizationWorker(segmentProducer, moduleConfig.getBufferPath(), moduleConfig.getBufferOffsetMaxFileSize(), moduleConfig.getBufferDataMaxFileSize(), moduleConfig.isBufferFileCleanWhenRestart());
SegmentStandardizationWorker standardizationWorker = new SegmentStandardizationWorker(segmentProducer, moduleConfig.getBufferPath() + "-v5", moduleConfig.getBufferOffsetMaxFileSize(), moduleConfig.getBufferDataMaxFileSize(), moduleConfig.isBufferFileCleanWhenRestart());
segmentProducer.setStandardizationWorker(standardizationWorker);
SegmentStandardizationWorker standardizationWorker2 = new SegmentStandardizationWorker(segmentProducer, moduleConfig.getBufferPath(), moduleConfig.getBufferOffsetMaxFileSize(), moduleConfig.getBufferDataMaxFileSize(), moduleConfig.isBufferFileCleanWhenRestart());
segmentProducerV2.setStandardizationWorker(standardizationWorker2);
} catch (IOException e) {
throw new ModuleStartException(e.getMessage(), e);
}
......
/*
* 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.oap.server.receiver.trace.provider.handler.v6.grpc;
import io.grpc.stub.StreamObserver;
import org.apache.skywalking.apm.network.common.Commands;
import org.apache.skywalking.apm.network.language.agent.UpstreamSegment;
import org.apache.skywalking.apm.network.language.agent.v2.TraceSegmentReportServiceGrpc;
import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
import org.apache.skywalking.oap.server.receiver.trace.provider.handler.v5.grpc.TraceSegmentServiceHandler;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.SegmentParseV2;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.SegmentSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TraceSegmentReportServiceHandler extends TraceSegmentReportServiceGrpc.TraceSegmentReportServiceImplBase implements GRPCHandler {
private static final Logger logger = LoggerFactory.getLogger(TraceSegmentServiceHandler.class);
private final Boolean debug;
private final SegmentParseV2.Producer segmentProducer;
public TraceSegmentReportServiceHandler(SegmentParseV2.Producer segmentProducer) {
this.debug = System.getProperty("debug") != null;
this.segmentProducer = segmentProducer;
}
@Override public StreamObserver<UpstreamSegment> collect(StreamObserver<Commands> responseObserver) {
return new StreamObserver<UpstreamSegment>() {
@Override public void onNext(UpstreamSegment segment) {
if (logger.isDebugEnabled()) {
logger.debug("receive segment");
}
segmentProducer.send(segment, SegmentSource.Agent);
}
@Override public void onError(Throwable throwable) {
logger.error(throwable.getMessage(), throwable);
responseObserver.onCompleted();
}
@Override public void onCompleted() {
responseObserver.onNext(Commands.newBuilder().build());
responseObserver.onCompleted();
}
};
}
}
......@@ -19,16 +19,32 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.*;
import java.util.LinkedList;
import java.util.List;
import lombok.Setter;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.SpanType;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentObject;
import org.apache.skywalking.apm.network.language.agent.UniqueId;
import org.apache.skywalking.apm.network.language.agent.UpstreamSegment;
import org.apache.skywalking.oap.server.library.buffer.DataStreamReader;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.util.TimeBucketUtils;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.*;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.*;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.*;
import org.slf4j.*;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.ReferenceDecorator;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SegmentCoreInfo;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SegmentDecorator;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SpanDecorator;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.EntrySpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.ExitSpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.FirstSpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.GlobalTraceIdsListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.LocalSpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.SpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.ReferenceIdExchanger;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.SegmentStandardization;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.SegmentStandardizationWorker;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.SpanIdExchanger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
......@@ -50,6 +66,7 @@ public class SegmentParse {
this.segmentCoreInfo = new SegmentCoreInfo();
this.segmentCoreInfo.setStartTime(Long.MAX_VALUE);
this.segmentCoreInfo.setEndTime(Long.MIN_VALUE);
this.segmentCoreInfo.setV2(false);
}
public boolean parse(UpstreamSegment segment, Source source) {
......@@ -103,19 +120,20 @@ public class SegmentParse {
}
segmentCoreInfo.setSegmentId(segmentIdBuilder.toString());
segmentCoreInfo.setApplicationId(segmentDecorator.getApplicationId());
segmentCoreInfo.setApplicationInstanceId(segmentDecorator.getApplicationInstanceId());
segmentCoreInfo.setServiceId(segmentDecorator.getServiceId());
segmentCoreInfo.setServiceInstanceId(segmentDecorator.getServiceInstanceId());
segmentCoreInfo.setDataBinary(segmentDecorator.toByteArray());
segmentCoreInfo.setV2(false);
for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, segmentCoreInfo.getApplicationId())) {
if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, segmentCoreInfo.getServiceId())) {
return false;
} else {
for (int j = 0; j < spanDecorator.getRefsCount(); j++) {
ReferenceDecorator referenceDecorator = spanDecorator.getRefs(j);
if (!ReferenceIdExchanger.getInstance(moduleManager).exchange(referenceDecorator, segmentCoreInfo.getApplicationId())) {
if (!ReferenceIdExchanger.getInstance(moduleManager).exchange(referenceDecorator, segmentCoreInfo.getServiceId())) {
return false;
}
}
......
/*
* 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.oap.server.receiver.trace.provider.parser;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.LinkedList;
import java.util.List;
import lombok.Setter;
import org.apache.skywalking.apm.network.language.agent.SpanType;
import org.apache.skywalking.apm.network.language.agent.UniqueId;
import org.apache.skywalking.apm.network.language.agent.UpstreamSegment;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
import org.apache.skywalking.oap.server.library.buffer.DataStreamReader;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.util.TimeBucketUtils;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.ReferenceDecorator;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SegmentCoreInfo;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SegmentDecorator;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SpanDecorator;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.EntrySpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.ExitSpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.FirstSpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.GlobalTraceIdsListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.LocalSpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.SpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.ReferenceIdExchanger;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.SegmentStandardization;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.SegmentStandardizationWorker;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.standardization.SpanIdExchanger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* SegmentParseV2 is a replication of SegmentParse, but be compatible with v2 trace protocol.
*
* @author wusheng
*/
public class SegmentParseV2 {
private static final Logger logger = LoggerFactory.getLogger(SegmentParseV2.class);
private final ModuleManager moduleManager;
private final List<SpanListener> spanListeners;
private final SegmentParserListenerManager listenerManager;
private final SegmentCoreInfo segmentCoreInfo;
@Setter private SegmentStandardizationWorker standardizationWorker;
private SegmentParseV2(ModuleManager moduleManager, SegmentParserListenerManager listenerManager) {
this.moduleManager = moduleManager;
this.listenerManager = listenerManager;
this.spanListeners = new LinkedList<>();
this.segmentCoreInfo = new SegmentCoreInfo();
this.segmentCoreInfo.setStartTime(Long.MAX_VALUE);
this.segmentCoreInfo.setEndTime(Long.MIN_VALUE);
this.segmentCoreInfo.setV2(true);
}
public boolean parse(UpstreamSegment segment, SegmentSource source) {
createSpanListeners();
try {
List<UniqueId> traceIds = segment.getGlobalTraceIdsList();
SegmentObject segmentObject = parseBinarySegment(segment);
SegmentDecorator segmentDecorator = new SegmentDecorator(segmentObject);
if (!preBuild(traceIds, segmentDecorator)) {
if (logger.isDebugEnabled()) {
logger.debug("This segment id exchange not success, write to buffer file, id: {}", segmentCoreInfo.getSegmentId());
}
if (source.equals(SegmentSource.Agent)) {
writeToBufferFile(segmentCoreInfo.getSegmentId(), segment);
}
return false;
} else {
if (logger.isDebugEnabled()) {
logger.debug("This segment id exchange success, id: {}", segmentCoreInfo.getSegmentId());
}
notifyListenerToBuild();
return true;
}
} catch (Throwable e) {
logger.error(e.getMessage(), e);
return true;
}
}
private SegmentObject parseBinarySegment(UpstreamSegment segment) throws InvalidProtocolBufferException {
return SegmentObject.parseFrom(segment.getSegment());
}
private boolean preBuild(List<UniqueId> traceIds, SegmentDecorator segmentDecorator) {
StringBuilder segmentIdBuilder = new StringBuilder();
for (int i = 0; i < segmentDecorator.getTraceSegmentId().getIdPartsList().size(); i++) {
if (i == 0) {
segmentIdBuilder.append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i));
} else {
segmentIdBuilder.append(".").append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i));
}
}
for (UniqueId uniqueId : traceIds) {
notifyGlobalsListener(uniqueId);
}
segmentCoreInfo.setSegmentId(segmentIdBuilder.toString());
segmentCoreInfo.setServiceId(segmentDecorator.getServiceId());
segmentCoreInfo.setServiceInstanceId(segmentDecorator.getServiceInstanceId());
segmentCoreInfo.setDataBinary(segmentDecorator.toByteArray());
segmentCoreInfo.setV2(true);
for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, segmentCoreInfo.getServiceId())) {
return false;
} else {
for (int j = 0; j < spanDecorator.getRefsCount(); j++) {
ReferenceDecorator referenceDecorator = spanDecorator.getRefs(j);
if (!ReferenceIdExchanger.getInstance(moduleManager).exchange(referenceDecorator, segmentCoreInfo.getServiceId())) {
return false;
}
}
}
if (segmentCoreInfo.getStartTime() > spanDecorator.getStartTime()) {
segmentCoreInfo.setStartTime(spanDecorator.getStartTime());
}
if (segmentCoreInfo.getEndTime() < spanDecorator.getEndTime()) {
segmentCoreInfo.setEndTime(spanDecorator.getEndTime());
}
segmentCoreInfo.setError(spanDecorator.getIsError() || segmentCoreInfo.isError());
}
long minuteTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(segmentCoreInfo.getStartTime());
segmentCoreInfo.setMinuteTimeBucket(minuteTimeBucket);
for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
if (spanDecorator.getSpanId() == 0) {
notifyFirstListener(spanDecorator);
}
if (SpanType.Exit.equals(spanDecorator.getSpanType())) {
notifyExitListener(spanDecorator);
} else if (SpanType.Entry.equals(spanDecorator.getSpanType())) {
notifyEntryListener(spanDecorator);
} else if (SpanType.Local.equals(spanDecorator.getSpanType())) {
notifyLocalListener(spanDecorator);
} else {
logger.error("span type value was unexpected, span type name: {}", spanDecorator.getSpanType().name());
}
}
return true;
}
private void writeToBufferFile(String id, UpstreamSegment upstreamSegment) {
if (logger.isDebugEnabled()) {
logger.debug("push to segment buffer write worker, id: {}", id);
}
SegmentStandardization standardization = new SegmentStandardization(id);
standardization.setUpstreamSegment(upstreamSegment);
standardizationWorker.in(standardization);
}
private void notifyListenerToBuild() {
spanListeners.forEach(SpanListener::build);
}
private void notifyExitListener(SpanDecorator spanDecorator) {
spanListeners.forEach(listener -> {
if (listener.containsPoint(SpanListener.Point.Exit)) {
((ExitSpanListener)listener).parseExit(spanDecorator, segmentCoreInfo);
}
});
}
private void notifyEntryListener(SpanDecorator spanDecorator) {
spanListeners.forEach(listener -> {
if (listener.containsPoint(SpanListener.Point.Entry)) {
((EntrySpanListener)listener).parseEntry(spanDecorator, segmentCoreInfo);
}
});
}
private void notifyLocalListener(SpanDecorator spanDecorator) {
spanListeners.forEach(listener -> {
if (listener.containsPoint(SpanListener.Point.Local)) {
((LocalSpanListener)listener).parseLocal(spanDecorator, segmentCoreInfo);
}
});
}
private void notifyFirstListener(SpanDecorator spanDecorator) {
spanListeners.forEach(listener -> {
if (listener.containsPoint(SpanListener.Point.First)) {
((FirstSpanListener)listener).parseFirst(spanDecorator, segmentCoreInfo);
}
});
}
private void notifyGlobalsListener(UniqueId uniqueId) {
spanListeners.forEach(listener -> {
if (listener.containsPoint(SpanListener.Point.TraceIds)) {
((GlobalTraceIdsListener)listener).parseGlobalTraceId(uniqueId, segmentCoreInfo);
}
});
}
private void createSpanListeners() {
listenerManager.getSpanListenerFactories().forEach(spanListenerFactory -> spanListeners.add(spanListenerFactory.create(moduleManager)));
}
public static class Producer implements DataStreamReader.CallBack<UpstreamSegment> {
@Setter private SegmentStandardizationWorker standardizationWorker;
private final ModuleManager moduleManager;
private final SegmentParserListenerManager listenerManager;
public Producer(ModuleManager moduleManager, SegmentParserListenerManager listenerManager) {
this.moduleManager = moduleManager;
this.listenerManager = listenerManager;
}
public void send(UpstreamSegment segment, SegmentSource source) {
SegmentParseV2 segmentParse = new SegmentParseV2(moduleManager, listenerManager);
segmentParse.setStandardizationWorker(standardizationWorker);
segmentParse.parse(segment, source);
}
@Override public boolean call(UpstreamSegment segment) {
SegmentParseV2 segmentParse = new SegmentParseV2(moduleManager, listenerManager);
segmentParse.setStandardizationWorker(standardizationWorker);
return segmentParse.parse(segment, SegmentSource.Buffer);
}
}
}
......@@ -24,15 +24,15 @@ import org.apache.skywalking.apm.network.language.agent.UpstreamSegment;
* @author wusheng
*/
public class SegmentParserServiceImpl implements ISegmentParserService {
private final SegmentParse.Producer segmentProducer;
private final SegmentParseV2.Producer segmentProducer;
public SegmentParserServiceImpl(
SegmentParse.Producer segmentProducer) {
SegmentParseV2.Producer segmentProducer) {
this.segmentProducer = segmentProducer;
}
@Override
public void send(UpstreamSegment segment) {
segmentProducer.send(segment, SegmentParse.Source.Agent);
segmentProducer.send(segment,SegmentSource.Agent);
}
}
/*
* 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.oap.server.receiver.trace.provider.parser;
/**
* @author wusheng
*/
public enum SegmentSource {
Agent, Buffer
}
......@@ -18,7 +18,10 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.RefType;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentReference;
import org.apache.skywalking.apm.network.language.agent.UniqueId;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentReference;
/**
* @author peng-yongsheng
......@@ -29,131 +32,165 @@ public class ReferenceDecorator implements StandardBuilder {
private StandardBuilder standardBuilder;
private TraceSegmentReference referenceObject;
private TraceSegmentReference.Builder referenceBuilder;
private final boolean isV2;
private SegmentReference referenceObjectV2;
private SegmentReference.Builder referenceBuilderV2;
public ReferenceDecorator(TraceSegmentReference referenceObject, StandardBuilder standardBuilder) {
this.referenceObject = referenceObject;
this.standardBuilder = standardBuilder;
isV2 = false;
}
public ReferenceDecorator(TraceSegmentReference.Builder referenceBuilder, StandardBuilder standardBuilder) {
this.referenceBuilder = referenceBuilder;
this.standardBuilder = standardBuilder;
this.isOrigin = false;
isV2 = false;
}
public ReferenceDecorator(SegmentReference referenceObject, StandardBuilder standardBuilder) {
this.referenceObjectV2 = referenceObject;
this.standardBuilder = standardBuilder;
isV2 = true;
}
public ReferenceDecorator(SegmentReference.Builder referenceBuilder, StandardBuilder standardBuilder) {
this.referenceBuilderV2 = referenceBuilder;
this.standardBuilder = standardBuilder;
this.isOrigin = false;
isV2 = true;
}
public RefType getRefType() {
if (isOrigin) {
return referenceObject.getRefType();
return isV2 ? referenceObjectV2.getRefType() : referenceObject.getRefType();
} else {
return referenceBuilder.getRefType();
return isV2 ? referenceBuilderV2.getRefType() : referenceBuilder.getRefType();
}
}
public int getRefTypeValue() {
if (isOrigin) {
return referenceObject.getRefTypeValue();
return isV2 ? referenceObjectV2.getRefTypeValue() : referenceObject.getRefTypeValue();
} else {
return referenceBuilder.getRefTypeValue();
return isV2 ? referenceBuilderV2.getRefTypeValue() : referenceBuilder.getRefTypeValue();
}
}
public int getEntryServiceId() {
public int getEntryEndpointId() {
if (isOrigin) {
return referenceObject.getEntryServiceId();
return isV2 ? referenceObjectV2.getEntryEndpointId() : referenceObject.getEntryServiceId();
} else {
return referenceBuilder.getEntryServiceId();
return isV2 ? referenceBuilderV2.getEntryEndpointId() : referenceBuilder.getEntryServiceId();
}
}
public void setEntryServiceId(int value) {
public void setEntryEndpointId(int value) {
if (isOrigin) {
toBuilder();
}
referenceBuilder.setEntryServiceId(value);
if (isV2) {
referenceBuilderV2.setEntryEndpointId(value);
} else {
referenceBuilder.setEntryServiceId(value);
}
}
public String getEntryServiceName() {
public String getEntryEndpointName() {
if (isOrigin) {
return referenceObject.getEntryServiceName();
return isV2 ? referenceObjectV2.getEntryEndpoint() : referenceObject.getEntryServiceName();
} else {
return referenceBuilder.getEntryServiceName();
return isV2 ? referenceBuilderV2.getEntryEndpoint() : referenceBuilder.getEntryServiceName();
}
}
public void setEntryServiceName(String value) {
public void setEntryEndpointName(String value) {
if (isOrigin) {
toBuilder();
}
referenceBuilder.setEntryServiceName(value);
if (isV2) {
referenceBuilderV2.setEntryEndpoint(value);
} else {
referenceBuilder.setEntryServiceName(value);
}
}
public int getEntryApplicationInstanceId() {
public int getEntryServiceInstanceId() {
if (isOrigin) {
return referenceObject.getEntryApplicationInstanceId();
return isV2 ? referenceObjectV2.getEntryServiceInstanceId() : referenceObject.getEntryApplicationInstanceId();
} else {
return referenceBuilder.getEntryApplicationInstanceId();
return isV2 ? referenceBuilderV2.getEntryServiceInstanceId() : referenceBuilder.getEntryApplicationInstanceId();
}
}
public int getParentApplicationInstanceId() {
public int getParentServiceInstanceId() {
if (isOrigin) {
return referenceObject.getParentApplicationInstanceId();
return isV2 ? referenceObjectV2.getParentServiceInstanceId() : referenceObject.getParentApplicationInstanceId();
} else {
return referenceBuilder.getParentApplicationInstanceId();
return isV2 ? referenceBuilderV2.getParentServiceInstanceId() : referenceBuilder.getParentApplicationInstanceId();
}
}
public int getParentServiceId() {
public int getParentEndpointId() {
if (isOrigin) {
return referenceObject.getParentServiceId();
return isV2 ? referenceObjectV2.getParentEndpointId() : referenceObject.getParentServiceId();
} else {
return referenceBuilder.getParentServiceId();
return isV2 ? referenceBuilderV2.getParentEndpointId() : referenceBuilder.getParentServiceId();
}
}
public void setParentServiceId(int value) {
public void setParentEndpointId(int value) {
if (isOrigin) {
toBuilder();
}
referenceBuilder.setParentServiceId(value);
if (isV2) {
referenceBuilderV2.setParentEndpointId(value);
} else {
referenceBuilder.setParentServiceId(value);
}
}
public int getParentSpanId() {
if (isOrigin) {
return referenceObject.getParentSpanId();
return isV2 ? referenceObjectV2.getParentSpanId() : referenceObject.getParentSpanId();
} else {
return referenceBuilder.getParentSpanId();
return isV2 ? referenceBuilderV2.getParentSpanId() : referenceBuilder.getParentSpanId();
}
}
public String getParentServiceName() {
public String getParentEndpointName() {
if (isOrigin) {
return referenceObject.getParentServiceName();
return isV2 ? referenceObjectV2.getParentEndpoint() : referenceObject.getParentServiceName();
} else {
return referenceBuilder.getParentServiceName();
return isV2 ? referenceBuilderV2.getParentEndpoint() : referenceBuilder.getParentServiceName();
}
}
public void setParentServiceName(String value) {
public void setParentEndpointName(String value) {
if (isOrigin) {
toBuilder();
}
referenceBuilder.setParentServiceName(value);
if (isV2) {
referenceBuilderV2.setParentEndpoint(value);
} else {
referenceBuilder.setParentServiceName(value);
}
}
public UniqueId getParentTraceSegmentId() {
if (isOrigin) {
return referenceObject.getParentTraceSegmentId();
return isV2 ? referenceObjectV2.getParentTraceSegmentId() : referenceObject.getParentTraceSegmentId();
} else {
return referenceBuilder.getParentTraceSegmentId();
return isV2 ? referenceBuilderV2.getParentTraceSegmentId() : referenceBuilder.getParentTraceSegmentId();
}
}
public int getNetworkAddressId() {
if (isOrigin) {
return referenceObject.getNetworkAddressId();
return isV2 ? referenceObjectV2.getNetworkAddressId() : referenceObject.getNetworkAddressId();
} else {
return referenceBuilder.getNetworkAddressId();
return isV2 ? referenceBuilderV2.getNetworkAddressId() : referenceBuilder.getNetworkAddressId();
}
}
......@@ -161,14 +198,18 @@ public class ReferenceDecorator implements StandardBuilder {
if (isOrigin) {
toBuilder();
}
referenceBuilder.setNetworkAddressId(value);
if (isV2) {
referenceBuilderV2.setNetworkAddressId(value);
} else {
referenceBuilder.setNetworkAddressId(value);
}
}
public String getNetworkAddress() {
if (isOrigin) {
return referenceObject.getNetworkAddress();
return isV2 ? referenceObjectV2.getNetworkAddress() : referenceObject.getNetworkAddress();
} else {
return referenceBuilder.getNetworkAddress();
return isV2 ? referenceBuilderV2.getNetworkAddress() : referenceBuilder.getNetworkAddress();
}
}
......@@ -176,13 +217,21 @@ public class ReferenceDecorator implements StandardBuilder {
if (isOrigin) {
toBuilder();
}
referenceBuilder.setNetworkAddress(value);
if (isV2) {
referenceBuilderV2.setNetworkAddress(value);
} else {
referenceBuilder.setNetworkAddress(value);
}
}
@Override public void toBuilder() {
if (this.isOrigin) {
this.isOrigin = false;
referenceBuilder = referenceObject.toBuilder();
if (isV2) {
referenceBuilderV2 = referenceObjectV2.toBuilder();
} else {
referenceBuilder = referenceObject.toBuilder();
}
standardBuilder.toBuilder();
}
}
......
......@@ -27,11 +27,12 @@ import lombok.*;
@Setter
public class SegmentCoreInfo {
private String segmentId;
private int applicationId;
private int applicationInstanceId;
private int serviceId;
private int serviceInstanceId;
private long startTime;
private long endTime;
private boolean isError;
private long minuteTimeBucket;
private byte[] dataBinary;
private boolean isV2;
}
......@@ -18,7 +18,9 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentObject;
import org.apache.skywalking.apm.network.language.agent.UniqueId;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
import static java.util.Objects.isNull;
......@@ -29,35 +31,55 @@ public class SegmentDecorator implements StandardBuilder {
private boolean isOrigin = true;
private final TraceSegmentObject segmentObject;
private TraceSegmentObject.Builder segmentBuilder;
private final boolean isV2;
private final SegmentObject segmentObjectV2;
private SegmentObject.Builder segmentBuilderV2;
private final SpanDecorator[] spanDecorators;
public SegmentDecorator(TraceSegmentObject segmentObject) {
this.segmentObject = segmentObject;
this.segmentObjectV2 = null;
this.spanDecorators = new SpanDecorator[segmentObject.getSpansCount()];
isV2 = false;
}
public int getApplicationId() {
return segmentObject.getApplicationId();
public SegmentDecorator(SegmentObject segmentObjectV2) {
this.segmentObjectV2 = segmentObjectV2;
this.segmentObject = null;
this.spanDecorators = new SpanDecorator[segmentObjectV2.getSpansCount()];
isV2 = true;
}
public int getApplicationInstanceId() {
return segmentObject.getApplicationInstanceId();
public int getServiceId() {
return isV2 ? segmentObjectV2.getServiceId() : segmentObject.getApplicationId();
}
public int getServiceInstanceId() {
return isV2 ? segmentObjectV2.getServiceInstanceId() : segmentObject.getApplicationInstanceId();
}
public UniqueId getTraceSegmentId() {
return segmentObject.getTraceSegmentId();
return isV2 ? segmentObjectV2.getTraceSegmentId() : segmentObject.getTraceSegmentId();
}
public int getSpansCount() {
return segmentObject.getSpansCount();
return isV2 ? segmentObjectV2.getSpansCount() : segmentObject.getSpansCount();
}
public SpanDecorator getSpans(int index) {
if (isNull(spanDecorators[index])) {
if (isOrigin) {
spanDecorators[index] = new SpanDecorator(segmentObject.getSpans(index), this);
if (isV2) {
spanDecorators[index] = new SpanDecorator(segmentObjectV2.getSpans(index), this);
} else {
spanDecorators[index] = new SpanDecorator(segmentObject.getSpans(index), this);
}
} else {
spanDecorators[index] = new SpanDecorator(segmentBuilder.getSpansBuilder(index), this);
if (isV2) {
spanDecorators[index] = new SpanDecorator(segmentBuilderV2.getSpansBuilder(index), this);
} else {
spanDecorators[index] = new SpanDecorator(segmentBuilder.getSpansBuilder(index), this);
}
}
}
return spanDecorators[index];
......@@ -65,7 +87,7 @@ public class SegmentDecorator implements StandardBuilder {
public byte[] toByteArray() {
if (isOrigin) {
return segmentObject.toByteArray();
return isV2 ? segmentObjectV2.toByteArray() : segmentObject.toByteArray();
} else {
return segmentBuilder.build().toByteArray();
}
......@@ -74,7 +96,11 @@ public class SegmentDecorator implements StandardBuilder {
@Override public void toBuilder() {
if (isOrigin) {
this.isOrigin = false;
this.segmentBuilder = segmentObject.toBuilder();
if (isV2) {
this.segmentBuilderV2 = segmentObjectV2.toBuilder();
} else {
this.segmentBuilder = segmentObject.toBuilder();
}
}
}
}
......@@ -18,7 +18,10 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.network.language.agent.SpanLayer;
import org.apache.skywalking.apm.network.language.agent.SpanObject;
import org.apache.skywalking.apm.network.language.agent.SpanType;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import static java.util.Objects.isNull;
......@@ -26,16 +29,20 @@ import static java.util.Objects.isNull;
* @author peng-yongsheng
*/
public class SpanDecorator implements StandardBuilder {
private final boolean isV2;
private boolean isOrigin = true;
private StandardBuilder standardBuilder;
private SpanObject spanObject;
private SpanObjectV2 spanObjectV2;
private SpanObject.Builder spanBuilder;
private SpanObjectV2.Builder spanBuilderV2;
private final ReferenceDecorator[] referenceDecorators;
public SpanDecorator(SpanObject spanObject, StandardBuilder standardBuilder) {
this.spanObject = spanObject;
this.standardBuilder = standardBuilder;
this.referenceDecorators = new ReferenceDecorator[spanObject.getRefsCount()];
this.isV2 = false;
}
public SpanDecorator(SpanObject.Builder spanBuilder, StandardBuilder standardBuilder) {
......@@ -43,77 +50,93 @@ public class SpanDecorator implements StandardBuilder {
this.standardBuilder = standardBuilder;
this.isOrigin = false;
this.referenceDecorators = new ReferenceDecorator[spanBuilder.getRefsCount()];
this.isV2 = false;
}
public SpanDecorator(SpanObjectV2 spanObject, StandardBuilder standardBuilder) {
this.spanObjectV2 = spanObject;
this.standardBuilder = standardBuilder;
this.referenceDecorators = new ReferenceDecorator[spanObject.getRefsCount()];
this.isV2 = true;
}
public SpanDecorator(SpanObjectV2.Builder spanBuilder, StandardBuilder standardBuilder) {
this.spanBuilderV2 = spanBuilder;
this.standardBuilder = standardBuilder;
this.isOrigin = false;
this.referenceDecorators = new ReferenceDecorator[spanBuilder.getRefsCount()];
this.isV2 = true;
}
public int getSpanId() {
if (isOrigin) {
return spanObject.getSpanId();
return isV2 ? spanObjectV2.getSpanId() : spanObject.getSpanId();
} else {
return spanBuilder.getSpanId();
return isV2 ? spanBuilderV2.getSpanId() : spanBuilder.getSpanId();
}
}
public int getParentSpanId() {
if (isOrigin) {
return spanObject.getParentSpanId();
return isV2 ? spanObjectV2.getParentSpanId() : spanObject.getParentSpanId();
} else {
return spanBuilder.getParentSpanId();
return isV2 ? spanBuilderV2.getParentSpanId() : spanBuilder.getParentSpanId();
}
}
public SpanType getSpanType() {
if (isOrigin) {
return spanObject.getSpanType();
return isV2 ? spanObjectV2.getSpanType() : spanObject.getSpanType();
} else {
return spanBuilder.getSpanType();
return isV2 ? spanBuilderV2.getSpanType() : spanBuilder.getSpanType();
}
}
public int getSpanTypeValue() {
if (isOrigin) {
return spanObject.getSpanTypeValue();
return isV2 ? spanObjectV2.getSpanTypeValue() : spanObject.getSpanTypeValue();
} else {
return spanBuilder.getSpanTypeValue();
return isV2 ? spanBuilderV2.getSpanTypeValue() : spanBuilder.getSpanTypeValue();
}
}
public SpanLayer getSpanLayer() {
if (isOrigin) {
return spanObject.getSpanLayer();
return isV2 ? spanObjectV2.getSpanLayer() : spanObject.getSpanLayer();
} else {
return spanBuilder.getSpanLayer();
return isV2 ? spanBuilderV2.getSpanLayer() : spanBuilder.getSpanLayer();
}
}
public int getSpanLayerValue() {
if (isOrigin) {
return spanObject.getSpanLayerValue();
return isV2 ? spanObjectV2.getSpanLayerValue() : spanObject.getSpanLayerValue();
} else {
return spanBuilder.getSpanLayerValue();
return isV2 ? spanBuilderV2.getSpanLayerValue() : spanBuilder.getSpanLayerValue();
}
}
public long getStartTime() {
if (isOrigin) {
return spanObject.getStartTime();
return isV2 ? spanObjectV2.getStartTime() : spanObject.getStartTime();
} else {
return spanBuilder.getStartTime();
return isV2 ? spanBuilderV2.getStartTime() : spanBuilder.getStartTime();
}
}
public long getEndTime() {
if (isOrigin) {
return spanObject.getEndTime();
return isV2 ? spanObjectV2.getEndTime() : spanObject.getEndTime();
} else {
return spanBuilder.getEndTime();
return isV2 ? spanBuilderV2.getEndTime() : spanBuilder.getEndTime();
}
}
public int getComponentId() {
if (isOrigin) {
return spanObject.getComponentId();
return isV2 ? spanObjectV2.getComponentId() : spanObject.getComponentId();
} else {
return spanBuilder.getComponentId();
return isV2 ? spanBuilderV2.getComponentId() : spanBuilder.getComponentId();
}
}
......@@ -121,14 +144,18 @@ public class SpanDecorator implements StandardBuilder {
if (isOrigin) {
toBuilder();
}
spanBuilder.setComponentId(value);
if (isV2) {
spanBuilderV2.setComponentId(value);
} else {
spanBuilder.setComponentId(value);
}
}
public String getComponent() {
if (isOrigin) {
return spanObject.getComponent();
return isV2 ? spanObjectV2.getComponent() : spanObject.getComponent();
} else {
return spanBuilder.getComponent();
return isV2 ? spanBuilderV2.getComponent() : spanBuilder.getComponent();
}
}
......@@ -136,14 +163,18 @@ public class SpanDecorator implements StandardBuilder {
if (isOrigin) {
toBuilder();
}
spanBuilder.setComponent(value);
if (isV2) {
spanBuilderV2.setComponent(value);
} else {
spanBuilder.setComponent(value);
}
}
public int getPeerId() {
if (isOrigin) {
return spanObject.getPeerId();
return isV2 ? spanObjectV2.getPeerId() : spanObject.getPeerId();
} else {
return spanBuilder.getPeerId();
return isV2 ? spanBuilderV2.getPeerId() : spanBuilder.getPeerId();
}
}
......@@ -151,14 +182,18 @@ public class SpanDecorator implements StandardBuilder {
if (isOrigin) {
toBuilder();
}
spanBuilder.setPeerId(peerId);
if (isV2) {
spanBuilderV2.setPeerId(peerId);
} else {
spanBuilder.setPeerId(peerId);
}
}
public String getPeer() {
if (isOrigin) {
return spanObject.getPeer();
return isV2 ? spanObjectV2.getPeer() : spanObject.getPeer();
} else {
return spanBuilder.getPeer();
return isV2 ? spanBuilderV2.getPeer() : spanBuilder.getPeer();
}
}
......@@ -166,14 +201,18 @@ public class SpanDecorator implements StandardBuilder {
if (isOrigin) {
toBuilder();
}
spanBuilder.setPeer(peer);
if (isV2) {
spanBuilderV2.setPeer(peer);
} else {
spanBuilder.setPeer(peer);
}
}
public int getOperationNameId() {
if (isOrigin) {
return spanObject.getOperationNameId();
return isV2 ? spanObjectV2.getOperationNameId() : spanObject.getOperationNameId();
} else {
return spanBuilder.getOperationNameId();
return isV2 ? spanBuilderV2.getOperationNameId() : spanBuilder.getOperationNameId();
}
}
......@@ -181,14 +220,18 @@ public class SpanDecorator implements StandardBuilder {
if (isOrigin) {
toBuilder();
}
spanBuilder.setOperationNameId(value);
if (isV2) {
spanBuilderV2.setOperationNameId(value);
} else {
spanBuilder.setOperationNameId(value);
}
}
public String getOperationName() {
if (isOrigin) {
return spanObject.getOperationName();
return isV2 ? spanObjectV2.getOperationName() : spanObject.getOperationName();
} else {
return spanBuilder.getOperationName();
return isV2 ? spanBuilderV2.getOperationName() : spanBuilder.getOperationName();
}
}
......@@ -196,31 +239,43 @@ public class SpanDecorator implements StandardBuilder {
if (isOrigin) {
toBuilder();
}
spanBuilder.setOperationName(value);
if (isV2) {
spanBuilderV2.setOperationName(value);
} else {
spanBuilder.setOperationName(value);
}
}
public boolean getIsError() {
if (isOrigin) {
return spanObject.getIsError();
return isV2 ? spanObjectV2.getIsError() : spanObject.getIsError();
} else {
return spanBuilder.getIsError();
return isV2 ? spanBuilderV2.getIsError() : spanBuilder.getIsError();
}
}
public int getRefsCount() {
if (isOrigin) {
return spanObject.getRefsCount();
return isV2 ? spanObjectV2.getRefsCount() : spanObject.getRefsCount();
} else {
return spanBuilder.getRefsCount();
return isV2 ? spanBuilderV2.getRefsCount() : spanBuilder.getRefsCount();
}
}
public ReferenceDecorator getRefs(int index) {
if (isNull(referenceDecorators[index])) {
if (isOrigin) {
referenceDecorators[index] = new ReferenceDecorator(spanObject.getRefs(index), this);
if (isV2) {
referenceDecorators[index] = new ReferenceDecorator(spanObjectV2.getRefs(index), this);
} else {
referenceDecorators[index] = new ReferenceDecorator(spanObject.getRefs(index), this);
}
} else {
referenceDecorators[index] = new ReferenceDecorator(spanBuilder.getRefsBuilder(index), this);
if (isV2) {
referenceDecorators[index] = new ReferenceDecorator(spanBuilderV2.getRefsBuilder(index), this);
} else {
referenceDecorators[index] = new ReferenceDecorator(spanBuilder.getRefsBuilder(index), this);
}
}
}
return referenceDecorators[index];
......@@ -229,7 +284,11 @@ public class SpanDecorator implements StandardBuilder {
@Override public void toBuilder() {
if (this.isOrigin) {
this.isOrigin = false;
spanBuilder = spanObject.toBuilder();
if (isV2) {
spanBuilderV2 = spanObjectV2.toBuilder();
} else {
spanBuilder = spanObject.toBuilder();
}
standardBuilder.toBuilder();
}
}
......
......@@ -18,15 +18,28 @@
package org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.endpoint;
import java.util.*;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.network.language.agent.SpanLayer;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.cache.*;
import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
import org.apache.skywalking.oap.server.core.source.EndpointRelation;
import org.apache.skywalking.oap.server.core.source.RequestType;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.*;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.*;
import org.slf4j.*;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.ReferenceDecorator;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SegmentCoreInfo;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.decorator.SpanDecorator;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.EntrySpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.ExitSpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.SpanListener;
import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener.SpanListenerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.Objects.nonNull;
......@@ -74,7 +87,7 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
for (int i = 0; i < spanDecorator.getRefsCount(); i++) {
ReferenceDecorator reference = spanDecorator.getRefs(i);
SourceBuilder sourceBuilder = new SourceBuilder();
sourceBuilder.setSourceEndpointId(reference.getParentServiceId());
sourceBuilder.setSourceEndpointId(reference.getParentEndpointId());
if (spanDecorator.getSpanLayer().equals(SpanLayer.MQ)) {
int serviceIdByPeerId = serviceInventoryCache.getServiceId(reference.getNetworkAddressId());
......@@ -82,12 +95,12 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
sourceBuilder.setSourceServiceInstanceId(instanceIdByPeerId);
sourceBuilder.setSourceServiceId(serviceIdByPeerId);
} else {
sourceBuilder.setSourceServiceInstanceId(reference.getParentApplicationInstanceId());
sourceBuilder.setSourceServiceId(instanceInventoryCache.get(reference.getParentApplicationInstanceId()).getServiceId());
sourceBuilder.setSourceServiceInstanceId(reference.getParentServiceInstanceId());
sourceBuilder.setSourceServiceId(instanceInventoryCache.get(reference.getParentServiceInstanceId()).getServiceId());
}
sourceBuilder.setDestEndpointId(spanDecorator.getOperationNameId());
sourceBuilder.setDestServiceInstanceId(segmentCoreInfo.getApplicationInstanceId());
sourceBuilder.setDestServiceId(segmentCoreInfo.getApplicationId());
sourceBuilder.setDestServiceInstanceId(segmentCoreInfo.getServiceInstanceId());
sourceBuilder.setDestServiceId(segmentCoreInfo.getServiceId());
sourceBuilder.setDetectPoint(DetectPoint.SERVER);
sourceBuilder.setComponentId(spanDecorator.getComponentId());
setPublicAttrs(sourceBuilder, spanDecorator);
......@@ -99,8 +112,8 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
sourceBuilder.setSourceServiceInstanceId(Const.USER_INSTANCE_ID);
sourceBuilder.setSourceServiceId(Const.USER_SERVICE_ID);
sourceBuilder.setDestEndpointId(spanDecorator.getOperationNameId());
sourceBuilder.setDestServiceInstanceId(segmentCoreInfo.getApplicationInstanceId());
sourceBuilder.setDestServiceId(segmentCoreInfo.getApplicationId());
sourceBuilder.setDestServiceInstanceId(segmentCoreInfo.getServiceInstanceId());
sourceBuilder.setDestServiceId(segmentCoreInfo.getServiceId());
sourceBuilder.setDetectPoint(DetectPoint.SERVER);
sourceBuilder.setComponentId(spanDecorator.getComponentId());
......@@ -126,8 +139,8 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
int destInstanceId = instanceInventoryCache.getServiceInstanceId(destServiceId, peerId);
sourceBuilder.setSourceEndpointId(Const.USER_ENDPOINT_ID);
sourceBuilder.setSourceServiceInstanceId(segmentCoreInfo.getApplicationInstanceId());
sourceBuilder.setSourceServiceId(segmentCoreInfo.getApplicationId());
sourceBuilder.setSourceServiceInstanceId(segmentCoreInfo.getServiceInstanceId());
sourceBuilder.setSourceServiceId(segmentCoreInfo.getServiceId());
sourceBuilder.setDestEndpointId(spanDecorator.getOperationNameId());
sourceBuilder.setDestServiceInstanceId(destInstanceId);
if (Const.NONE == mappingServiceId) {
......
......@@ -55,13 +55,17 @@ public class SegmentSpanListener implements FirstSpanListener, EntrySpanListener
long timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(segmentCoreInfo.getStartTime());
segment.setSegmentId(segmentCoreInfo.getSegmentId());
segment.setServiceId(segmentCoreInfo.getApplicationId());
segment.setServiceId(segmentCoreInfo.getServiceId());
segment.setLatency((int)(segmentCoreInfo.getEndTime() - segmentCoreInfo.getStartTime()));
segment.setStartTime(segmentCoreInfo.getStartTime());
segment.setEndTime(segmentCoreInfo.getEndTime());
segment.setIsError(BooleanUtils.booleanToValue(segmentCoreInfo.isError()));
segment.setTimeBucket(timeBucket);
segment.setDataBinary(segmentCoreInfo.getDataBinary());
/**
* Only consider v1, v2 compatible for now.
*/
segment.setVersion(segmentCoreInfo.isV2() ? 2 : 1);
firstEndpointId = spanDecorator.getOperationNameId();
}
......
......@@ -59,10 +59,10 @@ public class ServiceMappingSpanListener implements EntrySpanListener {
for (int i = 0; i < spanDecorator.getRefsCount(); i++) {
int serviceId = serviceInventoryCache.getServiceId(spanDecorator.getRefs(i).getNetworkAddressId());
int mappingServiceId = serviceInventoryCache.get(serviceId).getMappingServiceId();
if (mappingServiceId != segmentCoreInfo.getApplicationId()) {
if (mappingServiceId != segmentCoreInfo.getServiceId()) {
ServiceMapping serviceMapping = new ServiceMapping();
serviceMapping.setServiceId(serviceId);
serviceMapping.setMappingServiceId(segmentCoreInfo.getApplicationId());
serviceMapping.setMappingServiceId(segmentCoreInfo.getServiceId());
serviceMappings.add(serviceMapping);
}
}
......
......@@ -53,37 +53,37 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
}
@Override public boolean exchange(ReferenceDecorator standardBuilder, int serviceId) {
if (standardBuilder.getEntryServiceId() == 0) {
String entryEndpointName = StringUtils.isNotEmpty(standardBuilder.getEntryServiceName()) ? standardBuilder.getEntryServiceName() : Const.DOMAIN_OPERATION_NAME;
int entryEndpointId = endpointInventoryRegister.get(serviceInstanceInventoryCache.get(standardBuilder.getEntryApplicationInstanceId()).getServiceId(), entryEndpointName, DetectPoint.SERVER.ordinal());
if (standardBuilder.getEntryEndpointId() == 0) {
String entryEndpointName = StringUtils.isNotEmpty(standardBuilder.getEntryEndpointName()) ? standardBuilder.getEntryEndpointName() : Const.DOMAIN_OPERATION_NAME;
int entryEndpointId = endpointInventoryRegister.get(serviceInstanceInventoryCache.get(standardBuilder.getEntryServiceInstanceId()).getServiceId(), entryEndpointName, DetectPoint.SERVER.ordinal());
if (entryEndpointId == 0) {
if (logger.isDebugEnabled()) {
int entryServiceId = serviceInstanceInventoryCache.get(standardBuilder.getEntryApplicationInstanceId()).getServiceId();
int entryServiceId = serviceInstanceInventoryCache.get(standardBuilder.getEntryServiceInstanceId()).getServiceId();
logger.debug("entry endpoint name: {} from service id: {} exchange failed", entryEndpointName, entryServiceId);
}
return false;
} else {
standardBuilder.toBuilder();
standardBuilder.setEntryServiceId(entryEndpointId);
standardBuilder.setEntryServiceName(Const.EMPTY_STRING);
standardBuilder.setEntryEndpointId(entryEndpointId);
standardBuilder.setEntryEndpointName(Const.EMPTY_STRING);
}
}
if (standardBuilder.getParentServiceId() == 0) {
String parentEndpointName = StringUtils.isNotEmpty(standardBuilder.getParentServiceName()) ? standardBuilder.getParentServiceName() : Const.DOMAIN_OPERATION_NAME;
int parentEndpointId = endpointInventoryRegister.get(serviceInstanceInventoryCache.get(standardBuilder.getParentApplicationInstanceId()).getServiceId(), parentEndpointName, DetectPoint.SERVER.ordinal());
if (standardBuilder.getParentEndpointId() == 0) {
String parentEndpointName = StringUtils.isNotEmpty(standardBuilder.getParentEndpointName()) ? standardBuilder.getParentEndpointName() : Const.DOMAIN_OPERATION_NAME;
int parentEndpointId = endpointInventoryRegister.get(serviceInstanceInventoryCache.get(standardBuilder.getParentServiceInstanceId()).getServiceId(), parentEndpointName, DetectPoint.SERVER.ordinal());
if (parentEndpointId == 0) {
if (logger.isDebugEnabled()) {
int parentServiceId = serviceInstanceInventoryCache.get(standardBuilder.getParentApplicationInstanceId()).getServiceId();
int parentServiceId = serviceInstanceInventoryCache.get(standardBuilder.getParentServiceInstanceId()).getServiceId();
logger.debug("parent endpoint name: {} from service id: {} exchange failed", parentEndpointName, parentServiceId);
}
return false;
} else {
standardBuilder.toBuilder();
standardBuilder.setParentServiceId(parentEndpointId);
standardBuilder.setParentServiceName(Const.EMPTY_STRING);
standardBuilder.setParentEndpointId(parentEndpointId);
standardBuilder.setParentEndpointName(Const.EMPTY_STRING);
}
}
......
......@@ -20,18 +20,18 @@ package org.apache.skywalking.oap.server.receiver.zipkin.data;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentObject;
import org.apache.skywalking.apm.network.language.agent.UniqueId;
import org.apache.skywalking.apm.network.language.agent.UpstreamSegment;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
/**
* Each SkyWalkingTrace consists of segments in each application, original from {@link ZipkinTrace}s
*/
public class SkyWalkingTrace {
private UniqueId globalTraceId;
private List<TraceSegmentObject.Builder> segmentList;
private List<SegmentObject.Builder> segmentList;
public SkyWalkingTrace(UniqueId globalTraceId, List<TraceSegmentObject.Builder> segmentList) {
public SkyWalkingTrace(UniqueId globalTraceId, List<SegmentObject.Builder> segmentList) {
this.globalTraceId = globalTraceId;
this.segmentList = segmentList;
}
......@@ -51,7 +51,7 @@ public class SkyWalkingTrace {
return globalTraceId;
}
public List<TraceSegmentObject.Builder> getSegmentList() {
public List<SegmentObject.Builder> getSegmentList() {
return segmentList;
}
}
......@@ -27,14 +27,14 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.logging.log4j.util.Strings;
import org.apache.skywalking.apm.network.language.agent.KeyWithStringValue;
import org.apache.skywalking.apm.network.language.agent.LogMessage;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
import org.apache.skywalking.apm.network.language.agent.RefType;
import org.apache.skywalking.apm.network.language.agent.SpanObject;
import org.apache.skywalking.apm.network.language.agent.SpanType;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentObject;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentReference;
import org.apache.skywalking.apm.network.language.agent.UniqueId;
import org.apache.skywalking.apm.network.language.agent.v2.Log;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentReference;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.receiver.zipkin.CoreRegisterLinker;
import org.apache.skywalking.oap.server.receiver.zipkin.ZipkinTraceOSInfoBuilder;
......@@ -91,7 +91,7 @@ public class SegmentBuilder {
timestamp = rootSpan.timestampAsLong();
builder.context.addApp(applicationCode, rootSpan.timestampAsLong() / 1000);
SpanObject.Builder rootSpanBuilder = builder.initSpan(null, null, rootSpan, true);
SpanObjectV2.Builder rootSpanBuilder = builder.initSpan(null, null, rootSpan, true);
builder.context.currentSegment().addSpan(rootSpanBuilder);
builder.scanSpansFromRoot(rootSpanBuilder, rootSpan, childSpanMap);
......@@ -99,19 +99,19 @@ public class SegmentBuilder {
}
}
List<TraceSegmentObject.Builder> segmentBuilders = new LinkedList<>();
List<SegmentObject.Builder> segmentBuilders = new LinkedList<>();
// microseconds -> million seconds
long finalTimestamp = timestamp / 1000;
builder.segments.forEach(segment -> {
TraceSegmentObject.Builder traceSegmentBuilder = segment.freeze();
SegmentObject.Builder traceSegmentBuilder = segment.freeze();
segmentBuilders.add(traceSegmentBuilder);
CoreRegisterLinker.getServiceInventoryRegister().heartbeat(traceSegmentBuilder.getApplicationId(), finalTimestamp);
CoreRegisterLinker.getServiceInstanceInventoryRegister().heartbeat(traceSegmentBuilder.getApplicationInstanceId(), finalTimestamp);
CoreRegisterLinker.getServiceInventoryRegister().heartbeat(traceSegmentBuilder.getServiceId(), finalTimestamp);
CoreRegisterLinker.getServiceInstanceInventoryRegister().heartbeat(traceSegmentBuilder.getServiceInstanceId(), finalTimestamp);
});
return new SkyWalkingTrace(builder.generateTraceOrSegmentId(), segmentBuilders);
}
private void scanSpansFromRoot(SpanObject.Builder parentSegmentSpan, Span parent,
private void scanSpansFromRoot(SpanObjectV2.Builder parentSegmentSpan, Span parent,
Map<String, List<Span>> childSpanMap) throws Exception {
String parentId = parent.id();
// get child spans by parent span id
......@@ -132,7 +132,7 @@ public class SegmentBuilder {
if (isNewApp) {
context.addApp(localServiceName, childSpan.timestampAsLong() / 1000);
}
SpanObject.Builder childSpanBuilder = initSpan(parentSegmentSpan, parent, childSpan, isNewApp);
SpanObjectV2.Builder childSpanBuilder = initSpan(parentSegmentSpan, parent, childSpan, isNewApp);
context.currentSegment().addSpan(childSpanBuilder);
scanSpansFromRoot(childSpanBuilder, childSpan, childSpanMap);
......@@ -145,9 +145,9 @@ public class SegmentBuilder {
}
}
private SpanObject.Builder initSpan(SpanObject.Builder parentSegmentSpan, Span parentSpan, Span span,
private SpanObjectV2.Builder initSpan(SpanObjectV2.Builder parentSegmentSpan, Span parentSpan, Span span,
boolean isSegmentRoot) {
SpanObject.Builder spanBuilder = SpanObject.newBuilder();
SpanObjectV2.Builder spanBuilder = SpanObjectV2.newBuilder();
spanBuilder.setSpanId(context.currentIDs().nextSpanId());
if (isSegmentRoot) {
// spanId = -1, means no parent span
......@@ -201,19 +201,19 @@ public class SegmentBuilder {
spanBuilder.setEndTime(startTime + duration);
span.tags().forEach((tagKey, tagValue) -> spanBuilder.addTags(
KeyWithStringValue.newBuilder().setKey(tagKey).setValue(tagValue).build())
KeyStringValuePair.newBuilder().setKey(tagKey).setValue(tagValue).build())
);
span.annotations().forEach(annotation ->
spanBuilder.addLogs(LogMessage.newBuilder().setTime(annotation.timestamp() / 1000).addData(
KeyWithStringValue.newBuilder().setKey("zipkin.annotation").setValue(annotation.value()).build()
spanBuilder.addLogs(Log.newBuilder().setTime(annotation.timestamp() / 1000).addData(
KeyStringValuePair.newBuilder().setKey("zipkin.annotation").setValue(annotation.value()).build()
))
);
return spanBuilder;
}
private void buildRef(SpanObject.Builder spanBuilder, Span span, SpanObject.Builder parentSegmentSpan,
private void buildRef(SpanObjectV2.Builder spanBuilder, Span span, SpanObjectV2.Builder parentSegmentSpan,
Span parentSpan) {
Segment parentSegment = context.parentSegment();
if (parentSegment == null) {
......@@ -241,27 +241,27 @@ public class SegmentBuilder {
return;
}
TraceSegmentReference.Builder refBuilder = TraceSegmentReference.newBuilder();
refBuilder.setEntryApplicationInstanceId(rootSegment.builder().getApplicationInstanceId());
int serviceId = rootSegment.getEntryServiceId();
if (serviceId == 0) {
refBuilder.setEntryServiceName(rootSegment.getEntryServiceName());
SegmentReference.Builder refBuilder = SegmentReference.newBuilder();
refBuilder.setEntryServiceInstanceId(rootSegment.builder().getServiceInstanceId());
int endpointId = rootSegment.getEntryEndpointId();
if (endpointId == 0) {
refBuilder.setEntryEndpoint(rootSegment.getEntryEndpointName());
} else {
refBuilder.setEntryServiceId(serviceId);
refBuilder.setEntryEndpointId(endpointId);
}
refBuilder.setEntryApplicationInstanceId(rootSegment.builder().getApplicationInstanceId());
refBuilder.setEntryServiceInstanceId(rootSegment.builder().getServiceInstanceId());
// parent ref info
refBuilder.setNetworkAddress(peer);
parentSegmentSpan.setPeer(refBuilder.getNetworkAddress());
refBuilder.setParentApplicationInstanceId(parentSegment.builder().getApplicationInstanceId());
refBuilder.setParentServiceInstanceId(parentSegment.builder().getServiceInstanceId());
refBuilder.setParentSpanId(parentSegmentSpan.getSpanId());
refBuilder.setParentTraceSegmentId(parentSegment.builder().getTraceSegmentId());
int parentServiceId = parentSegment.getEntryServiceId();
if (parentServiceId == 0) {
refBuilder.setParentServiceName(parentSegment.getEntryServiceName());
int parentEndpointId = parentSegment.getEntryEndpointId();
if (parentEndpointId == 0) {
refBuilder.setParentEndpoint(parentSegment.getEntryEndpointName());
} else {
refBuilder.setParentServiceId(parentServiceId);
refBuilder.setParentEndpointId(parentEndpointId);
}
refBuilder.setRefType(RefType.CrossProcess);
......@@ -312,19 +312,19 @@ public class SegmentBuilder {
return StringUtils.isNotEmpty(applicationCode) && !applicationCode.equals(currentIDs().applicationCode);
}
private Segment addApp(String applicationCode, long registerTime) throws Exception {
private Segment addApp(String serviceCode, long registerTime) throws Exception {
int serviceId = waitForExchange(() ->
CoreRegisterLinker.getServiceInventoryRegister().getOrCreate(applicationCode),
CoreRegisterLinker.getServiceInventoryRegister().getOrCreate(serviceCode),
10
);
int serviceInstanceId = waitForExchange(() ->
CoreRegisterLinker.getServiceInstanceInventoryRegister().getOrCreate(serviceId, applicationCode, applicationCode,
registerTime, ZipkinTraceOSInfoBuilder.getOSInfoForZipkin(applicationCode)),
CoreRegisterLinker.getServiceInstanceInventoryRegister().getOrCreate(serviceId, serviceCode, serviceCode,
registerTime, ZipkinTraceOSInfoBuilder.getOSInfoForZipkin(serviceCode)),
10
);
Segment segment = new Segment(applicationCode, serviceId, serviceInstanceId);
Segment segment = new Segment(serviceCode, serviceId, serviceInstanceId);
segmentsStack.add(segment);
return segment;
}
......@@ -372,44 +372,44 @@ public class SegmentBuilder {
}
private class Segment {
private TraceSegmentObject.Builder segmentBuilder;
private SegmentObject.Builder segmentBuilder;
private IDCollection ids;
private int entryServiceId = 0;
private String entryServiceName = null;
private List<SpanObject.Builder> spans;
private int entryEndpointId = 0;
private String entryEndpointName = null;
private List<SpanObjectV2.Builder> spans;
private long endTime = 0;
private Segment(String applicationCode, int serviceId, int serviceInstanceId) {
ids = new IDCollection(applicationCode, serviceId, serviceInstanceId);
private Segment(String serviceCode, int serviceId, int serviceInstanceId) {
ids = new IDCollection(serviceCode, serviceId, serviceInstanceId);
spans = new LinkedList<>();
segmentBuilder = TraceSegmentObject.newBuilder();
segmentBuilder.setApplicationId(serviceId);
segmentBuilder.setApplicationInstanceId(serviceInstanceId);
segmentBuilder = SegmentObject.newBuilder();
segmentBuilder.setServiceId(serviceId);
segmentBuilder.setServiceInstanceId(serviceInstanceId);
segmentBuilder.setTraceSegmentId(generateTraceOrSegmentId());
}
private TraceSegmentObject.Builder builder() {
private SegmentObject.Builder builder() {
return segmentBuilder;
}
private void addSpan(SpanObject.Builder spanBuilder) {
private void addSpan(SpanObjectV2.Builder spanBuilder) {
String operationName = spanBuilder.getOperationName();
if (entryServiceId == 0 && StringUtils.isNotEmpty(operationName)) {
if (entryEndpointId == 0 && StringUtils.isNotEmpty(operationName)) {
if (SpanType.Entry == spanBuilder.getSpanType()) {
if (StringUtils.isNotEmpty(operationName)) {
entryServiceName = operationName;
entryEndpointName = operationName;
} else {
entryServiceId = spanBuilder.getOperationNameId();
entryEndpointId = spanBuilder.getOperationNameId();
}
}
}
// init by root span
if (spanBuilder.getSpanId() == 1 && entryServiceId == 0) {
if (spanBuilder.getSpanId() == 1 && entryEndpointId == 0) {
if (StringUtils.isNotEmpty(operationName)) {
entryServiceName = operationName;
entryEndpointName = operationName;
} else {
entryServiceId = spanBuilder.getOperationNameId();
entryEndpointId = spanBuilder.getOperationNameId();
}
}
......@@ -419,20 +419,20 @@ public class SegmentBuilder {
}
}
public int getEntryServiceId() {
return entryServiceId;
public int getEntryEndpointId() {
return entryEndpointId;
}
public String getEntryServiceName() {
return entryServiceName;
public String getEntryEndpointName() {
return entryEndpointName;
}
private IDCollection ids() {
return ids;
}
public TraceSegmentObject.Builder freeze() {
for (SpanObject.Builder span : spans) {
public SegmentObject.Builder freeze() {
for (SpanObjectV2.Builder span : spans) {
segmentBuilder.addSpans(span);
}
return segmentBuilder;
......@@ -471,9 +471,9 @@ public class SegmentBuilder {
private class ClientSideSpan {
private Span span;
private SpanObject.Builder builder;
private SpanObjectV2.Builder builder;
public ClientSideSpan(Span span, SpanObject.Builder builder) {
public ClientSideSpan(Span span, SpanObjectV2.Builder builder) {
this.span = span;
this.builder = builder;
}
......@@ -482,7 +482,7 @@ public class SegmentBuilder {
return span;
}
public SpanObject.Builder getBuilder() {
public SpanObjectV2.Builder getBuilder() {
return builder;
}
}
......
......@@ -18,10 +18,15 @@
package org.apache.skywalking.oap.server.receiver.zipkin.transform;
import org.apache.skywalking.apm.network.language.agent.SpanObject;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.skywalking.apm.network.language.agent.SpanType;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentObject;
import org.apache.skywalking.apm.network.language.agent.TraceSegmentReference;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentObject;
import org.apache.skywalking.apm.network.language.agent.v2.SegmentReference;
import org.apache.skywalking.apm.network.language.agent.v2.SpanObjectV2;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
......@@ -34,12 +39,6 @@ import org.powermock.reflect.Whitebox;
import zipkin2.Span;
import zipkin2.codec.SpanBytesDecoder;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* @author wusheng
*/
......@@ -143,19 +142,19 @@ public class SpringSleuthSegmentBuilderTest implements SegmentListener {
@Override
public void notify(SkyWalkingTrace trace) {
List<TraceSegmentObject.Builder> segments = trace.getSegmentList();
List<SegmentObject.Builder> segments = trace.getSegmentList();
Assert.assertEquals(2, segments.size());
TraceSegmentObject.Builder builder = segments.get(0);
TraceSegmentObject.Builder builder1 = segments.get(1);
TraceSegmentObject.Builder front, end;
if (builder.getApplicationId() == applicationRegister.get("AppCode:frontend")) {
SegmentObject.Builder builder = segments.get(0);
SegmentObject.Builder builder1 = segments.get(1);
SegmentObject.Builder front, end;
if (builder.getServiceId() == applicationRegister.get("AppCode:frontend")) {
front = builder;
end = builder1;
Assert.assertEquals(applicationRegister.get("AppCode:backend").longValue(), builder1.getApplicationId());
} else if (builder.getApplicationId() == applicationRegister.get("AppCode:backend")) {
Assert.assertEquals(applicationRegister.get("AppCode:backend").longValue(), builder1.getServiceId());
} else if (builder.getServiceId() == applicationRegister.get("AppCode:backend")) {
end = builder;
front = builder1;
Assert.assertEquals(applicationRegister.get("AppCode:frontend").longValue(), builder1.getApplicationId());
Assert.assertEquals(applicationRegister.get("AppCode:frontend").longValue(), builder1.getServiceId());
} else {
Assert.fail("Can't find frontend and backend applications. ");
return;
......@@ -182,12 +181,12 @@ public class SpringSleuthSegmentBuilderTest implements SegmentListener {
Assert.assertTrue(spanObject.getTagsCount() > 0);
});
SpanObject spanObject = end.getSpans(0);
SpanObjectV2 spanObject = end.getSpans(0);
Assert.assertEquals(1, spanObject.getRefsCount());
TraceSegmentReference spanObjectRef = spanObject.getRefs(0);
Assert.assertEquals("get", spanObjectRef.getEntryServiceName());
Assert.assertEquals("get", spanObjectRef.getParentServiceName());
SegmentReference spanObjectRef = spanObject.getRefs(0);
Assert.assertEquals("get", spanObjectRef.getEntryEndpoint());
Assert.assertEquals("get", spanObjectRef.getParentEndpoint());
//Assert.assertEquals("192.168.72.220", spanObjectRef.getNetworkAddress());
Assert.assertEquals(1, spanObjectRef.getParentSpanId());
Assert.assertEquals(front.getTraceSegmentId(), spanObjectRef.getParentTraceSegmentId());
......
......@@ -19,15 +19,24 @@
package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import org.apache.skywalking.oap.server.core.analysis.manual.segment.SegmentRecord;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.query.entity.BasicTrace;
import org.apache.skywalking.oap.server.core.query.entity.QueryOrder;
import org.apache.skywalking.oap.server.core.query.entity.TraceBrief;
import org.apache.skywalking.oap.server.core.query.entity.TraceState;
import org.apache.skywalking.oap.server.core.storage.query.ITraceQueryDAO;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.oap.server.library.util.*;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.apache.skywalking.oap.server.library.util.StringUtils;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.*;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
......@@ -138,6 +147,7 @@ public class TraceQueryEsDAO extends EsDAO implements ITraceQueryDAO {
if (StringUtils.isNotEmpty(dataBinaryBase64)) {
segmentRecord.setDataBinary(Base64.getDecoder().decode(dataBinaryBase64));
}
segmentRecord.setVersion(((Number)searchHit.getSourceAsMap().get(SegmentRecord.VERSION)).intValue());
segmentRecords.add(segmentRecord);
}
return segmentRecords;
......
......@@ -160,6 +160,7 @@ public class H2TraceQueryDAO implements ITraceQueryDAO {
if (StringUtils.isNotEmpty(dataBinaryBase64)) {
segmentRecord.setDataBinary(Base64.getDecoder().decode(dataBinaryBase64));
}
segmentRecord.setVersion(resultSet.getInt(SegmentRecord.VERSION));
segmentRecords.add(segmentRecord);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册