Search in sources :

Example 1 with UnexpectedException

use of org.apache.skywalking.apm.collector.core.UnexpectedException 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 UnexpectedException

use of org.apache.skywalking.apm.collector.core.UnexpectedException in project incubator-skywalking by apache.

the class TraceQuery method queryBasicTraces.

public TraceBrief queryBasicTraces(TraceQueryCondition condition) throws ParseException {
    long startSecondTimeBucket = 0;
    long endSecondTimeBucket = 0;
    String traceId = Const.EMPTY_STRING;
    if (StringUtils.isNotEmpty(condition.getTraceId())) {
        traceId = condition.getTraceId();
    } else if (ObjectUtils.isNotEmpty(condition.getQueryDuration())) {
        startSecondTimeBucket = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getStart());
        endSecondTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getEnd());
    } else {
        throw new UnexpectedException("The condition must contains either queryDuration or traceId.");
    }
    long minDuration = condition.getMinTraceDuration();
    long maxDuration = condition.getMaxTraceDuration();
    String operationName = condition.getOperationName();
    int applicationId = condition.getApplicationId();
    PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(condition.getPaging());
    return getSegmentTopService().loadTop(startSecondTimeBucket, endSecondTimeBucket, minDuration, maxDuration, operationName, traceId, applicationId, page.getLimit(), page.getFrom());
}
Also used : UnexpectedException(org.apache.skywalking.apm.collector.core.UnexpectedException) PaginationUtils(org.apache.skywalking.apm.collector.ui.utils.PaginationUtils)

Aggregations

UnexpectedException (org.apache.skywalking.apm.collector.core.UnexpectedException)2 ReferenceDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator)1 SpanDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator)1 GraphComputingMetric (org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)1 PaginationUtils (org.apache.skywalking.apm.collector.ui.utils.PaginationUtils)1 UniqueId (org.apache.skywalking.apm.network.proto.UniqueId)1