Search in sources :

Example 1 with GraphComputingMetric

use of org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric in project incubator-skywalking by apache.

the class ServiceMetricTracing method intercept.

@RuntimeType
public Object intercept(@This Object inst, @SuperCall Callable<?> zuper, @AllArguments Object[] allArguments, @Origin Method method) throws Throwable {
    ServiceMetric metric = this.metrics.get(method);
    if (metric == null) {
        GraphComputingMetric annotation = method.getAnnotation(GraphComputingMetric.class);
        String metricName = annotation.name();
        synchronized (inst) {
            MetricTree.MetricNode metricNode = MetricTree.INSTANCE.lookup(metricName);
            ServiceMetric serviceMetric = metricNode.getMetric(method, allArguments);
            metrics.put(method, serviceMetric);
            metric = serviceMetric;
        }
    }
    boolean occurError = false;
    long startNano = System.nanoTime();
    long endNano;
    try {
        return zuper.call();
    } catch (Throwable t) {
        occurError = true;
        throw t;
    } finally {
        endNano = System.nanoTime();
        metric.trace(endNano - startNano, occurError, allArguments);
    }
}
Also used : GraphComputingMetric(org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric) RuntimeType(net.bytebuddy.implementation.bind.annotation.RuntimeType)

Example 2 with GraphComputingMetric

use of org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric in project incubator-skywalking by apache.

the class SegmentParse method buildSegment.

@GraphComputingMetric(name = "/segment/parse/buildSegment")
private void buildSegment(String id, byte[] dataBinary) {
    Segment segment = new Segment();
    segment.setId(id);
    segment.setDataBinary(dataBinary);
    segment.setTimeBucket(timeBucket);
    Graph<Segment> graph = GraphManager.INSTANCE.findGraph(GraphIdDefine.SEGMENT_PERSISTENCE_GRAPH_ID, Segment.class);
    graph.start(segment);
}
Also used : Segment(org.apache.skywalking.apm.collector.storage.table.segment.Segment) UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) GraphComputingMetric(org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)

Example 3 with GraphComputingMetric

use of org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric in project incubator-skywalking by apache.

the class SegmentParse method writeToBufferFile.

@GraphComputingMetric(name = "/segment/parse/bufferFile/write")
private void writeToBufferFile(String id, UpstreamSegment upstreamSegment) {
    logger.debug("push to segment buffer write worker, id: {}", id);
    SegmentStandardization standardization = new SegmentStandardization(id);
    standardization.setUpstreamSegment(upstreamSegment);
    Graph<SegmentStandardization> graph = GraphManager.INSTANCE.findGraph(GraphIdDefine.SEGMENT_STANDARDIZATION_GRAPH_ID, SegmentStandardization.class);
    graph.start(standardization);
}
Also used : SegmentStandardization(org.apache.skywalking.apm.collector.analysis.segment.parser.provider.parser.standardization.SegmentStandardization) GraphComputingMetric(org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)

Example 4 with GraphComputingMetric

use of org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric in project incubator-skywalking by apache.

the class SegmentParse method parse.

@GraphComputingMetric(name = "/segment/parse")
public boolean parse(UpstreamSegment segment, ISegmentParseService.Source source) {
    createSpanListeners();
    try {
        List<UniqueId> traceIds = segment.getGlobalTraceIdsList();
        TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(segment.getSegment());
        SegmentDecorator segmentDecorator = new SegmentDecorator(segmentObject);
        if (!preBuild(traceIds, segmentDecorator)) {
            logger.debug("This segment id exchange not success, write to buffer file, id: {}", segmentId);
            if (source.equals(ISegmentParseService.Source.Agent)) {
                writeToBufferFile(segmentId, segment);
            }
            return false;
        } else {
            logger.debug("This segment id exchange success, id: {}", segmentId);
            notifyListenerToBuild();
            buildSegment(segmentId, segmentDecorator.toByteArray());
            return true;
        }
    } catch (InvalidProtocolBufferException e) {
        logger.error(e.getMessage(), e);
    }
    return false;
}
Also used : UniqueId(org.apache.skywalking.apm.network.proto.UniqueId) SegmentDecorator(org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SegmentDecorator) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject) GraphComputingMetric(org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)

Example 5 with GraphComputingMetric

use of org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric 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)

Aggregations

GraphComputingMetric (org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)5 UniqueId (org.apache.skywalking.apm.network.proto.UniqueId)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 RuntimeType (net.bytebuddy.implementation.bind.annotation.RuntimeType)1 ReferenceDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator)1 SegmentDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SegmentDecorator)1 SpanDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator)1 SegmentStandardization (org.apache.skywalking.apm.collector.analysis.segment.parser.provider.parser.standardization.SegmentStandardization)1 UnexpectedException (org.apache.skywalking.apm.collector.core.UnexpectedException)1 Segment (org.apache.skywalking.apm.collector.storage.table.segment.Segment)1 TraceSegmentObject (org.apache.skywalking.apm.network.proto.TraceSegmentObject)1 UpstreamSegment (org.apache.skywalking.apm.network.proto.UpstreamSegment)1