use of org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator in project incubator-skywalking by apache.
the class SegmentParse method preBuild.
@GraphComputingMetric(name = "/segment/parse/preBuild")
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));
}
}
segmentId = segmentIdBuilder.toString();
for (UniqueId uniqueId : traceIds) {
notifyGlobalsListener(uniqueId);
}
int applicationId = segmentDecorator.getApplicationId();
int applicationInstanceId = segmentDecorator.getApplicationInstanceId();
int entrySpanCount = 0;
for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, applicationId)) {
return false;
} else {
for (int j = 0; j < spanDecorator.getRefsCount(); j++) {
ReferenceDecorator referenceDecorator = spanDecorator.getRefs(j);
if (!ReferenceIdExchanger.getInstance(moduleManager).exchange(referenceDecorator, applicationId)) {
return false;
}
}
}
if (SpanType.Entry.equals(spanDecorator.getSpanType())) {
entrySpanCount++;
}
if (entrySpanCount > 1) {
throw new UnexpectedException("This segment contains multiple entry span.");
}
}
for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
if (spanDecorator.getSpanId() == 0) {
notifyFirstListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
}
if (SpanType.Exit.equals(spanDecorator.getSpanType())) {
notifyExitListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
} else if (SpanType.Entry.equals(spanDecorator.getSpanType())) {
notifyEntryListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
} else if (SpanType.Local.equals(spanDecorator.getSpanType())) {
notifyLocalListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
} else {
logger.error("span type value was unexpected, span type name: {}", spanDecorator.getSpanType().name());
}
}
return true;
}
use of org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator in project incubator-skywalking by apache.
the class ServiceReferenceMetricSpanListener method parseEntry.
@Override
public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) {
if (spanDecorator.getRefsCount() > 0) {
for (int i = 0; i < spanDecorator.getRefsCount(); i++) {
ReferenceDecorator reference = spanDecorator.getRefs(i);
ServiceReferenceMetric serviceReferenceMetric = new ServiceReferenceMetric();
serviceReferenceMetric.setFrontServiceId(reference.getParentServiceId());
if (spanDecorator.getSpanLayer().equals(SpanLayer.MQ)) {
int applicationIdByPeerId = applicationCacheService.getApplicationIdByAddressId(reference.getNetworkAddressId());
int instanceIdByPeerId = instanceCacheService.getInstanceIdByAddressId(applicationIdByPeerId, reference.getNetworkAddressId());
serviceReferenceMetric.setFrontInstanceId(instanceIdByPeerId);
serviceReferenceMetric.setFrontApplicationId(applicationIdByPeerId);
} else {
serviceReferenceMetric.setFrontInstanceId(reference.getParentApplicationInstanceId());
serviceReferenceMetric.setFrontApplicationId(instanceCacheService.getApplicationId(reference.getParentApplicationInstanceId()));
}
serviceReferenceMetric.setBehindServiceId(spanDecorator.getOperationNameId());
serviceReferenceMetric.setBehindInstanceId(instanceId);
serviceReferenceMetric.setBehindApplicationId(applicationId);
serviceReferenceMetric.setSourceValue(MetricSource.Callee.getValue());
calculateDuration(serviceReferenceMetric, spanDecorator);
entryReferenceMetric.add(serviceReferenceMetric);
}
} else {
ServiceReferenceMetric serviceReferenceMetric = new ServiceReferenceMetric();
serviceReferenceMetric.setFrontServiceId(Const.NONE_SERVICE_ID);
serviceReferenceMetric.setFrontInstanceId(Const.NONE_INSTANCE_ID);
serviceReferenceMetric.setFrontApplicationId(Const.NONE_APPLICATION_ID);
serviceReferenceMetric.setBehindServiceId(spanDecorator.getOperationNameId());
serviceReferenceMetric.setBehindInstanceId(instanceId);
serviceReferenceMetric.setBehindApplicationId(applicationId);
serviceReferenceMetric.setSourceValue(MetricSource.Callee.getValue());
calculateDuration(serviceReferenceMetric, spanDecorator);
entryReferenceMetric.add(serviceReferenceMetric);
}
this.entrySpanDecorator = spanDecorator;
}
Aggregations