Search in sources :

Example 1 with ReferenceDecorator

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;
}
Also used : UniqueId(org.apache.skywalking.apm.network.proto.UniqueId) UnexpectedException(org.apache.skywalking.apm.collector.core.UnexpectedException) SpanDecorator(org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator) ReferenceDecorator(org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator) GraphComputingMetric(org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)

Example 2 with ReferenceDecorator

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;
}
Also used : ServiceReferenceMetric(org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric) ReferenceDecorator(org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator)

Aggregations

ReferenceDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator)2 SpanDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator)1 UnexpectedException (org.apache.skywalking.apm.collector.core.UnexpectedException)1 GraphComputingMetric (org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)1 ServiceReferenceMetric (org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetric)1 UniqueId (org.apache.skywalking.apm.network.proto.UniqueId)1