Search in sources :

Example 1 with TraceSegmentObject

use of org.apache.skywalking.apm.network.proto.TraceSegmentObject in project incubator-skywalking by apache.

the class SegmentEsUIDAO method load.

@Override
public TraceSegmentObject load(String segmentId) {
    GetResponse response = getClient().prepareGet(SegmentTable.TABLE, segmentId).get();
    Map<String, Object> source = response.getSource();
    String dataBinaryBase64 = (String) source.get(SegmentTable.COLUMN_DATA_BINARY);
    if (StringUtils.isNotEmpty(dataBinaryBase64)) {
        byte[] dataBinary = Base64.getDecoder().decode(dataBinaryBase64);
        try {
            return TraceSegmentObject.parseFrom(dataBinary);
        } catch (InvalidProtocolBufferException e) {
            logger.error(e.getMessage(), e);
        }
    }
    return null;
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 2 with TraceSegmentObject

use of org.apache.skywalking.apm.network.proto.TraceSegmentObject in project incubator-skywalking by apache.

the class SegmentBase64Printer method main.

public static void main(String[] args) throws InvalidProtocolBufferException {
    String segmentBase64 = "CgwKCgMXjPKUga3WgBsSvAEIARiF7Jq1nywgp+yatZ8sKlASDAoKAnPAqKD5rNaAGxgBIAIqDjEyNy4wLjAuMTo5MDkyOAJCFC9zZW5kTWVzc2FnZS97Y291bnR9UhQvc2VuZE1lc3NhZ2Uve2NvdW50fTocS2Fma2EvVHJhY2UtdG9waWMtMS9Db25zdW1lclgEYBt6GwoJbXEuYnJva2VyEg4xMjcuMC4wLjE6OTA5MnoZCghtcS50b3BpYxINVHJhY2UtdG9waWMtMRImEP///////////wEY/+uatZ8sILTsmrWfLDD///////////8BUAIYAiAD";
    byte[] binarySegment = Base64.getDecoder().decode(segmentBase64);
    TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(binarySegment);
    UniqueId segmentId = segmentObject.getTraceSegmentId();
    StringBuilder segmentIdBuilder = new StringBuilder();
    for (int i = 0; i < segmentId.getIdPartsList().size(); i++) {
        if (i == 0) {
            segmentIdBuilder.append(segmentId.getIdPartsList().get(i));
        } else {
            segmentIdBuilder.append(".").append(segmentId.getIdPartsList().get(i));
        }
    }
    LOGGER.info("SegmentId: {}", segmentIdBuilder.toString());
    LOGGER.info("ApplicationId: {}", segmentObject.getApplicationId());
    LOGGER.info("ApplicationInstanceId: {}", segmentObject.getApplicationInstanceId());
    List<SpanObject> spansList = segmentObject.getSpansList();
    LOGGER.info("Spans:");
    spansList.forEach(span -> {
        LOGGER.info("   Span:");
        LOGGER.info("       SpanId: {}", span.getSpanId());
        LOGGER.info("       ParentSpanId: {}", span.getParentSpanId());
        LOGGER.info("       SpanLayer: {}", span.getSpanLayer());
        LOGGER.info("       SpanType: {}", span.getSpanType());
        LOGGER.info("       StartTime: {}", span.getStartTime());
        LOGGER.info("       EndTime: {}", span.getEndTime());
        LOGGER.info("       ComponentId: {}", span.getComponentId());
        LOGGER.info("       Component: {}", span.getComponent());
        LOGGER.info("       OperationNameId: {}", span.getOperationNameId());
        LOGGER.info("       OperationName: {}", span.getOperationName());
        LOGGER.info("       PeerId: {}", span.getPeerId());
        LOGGER.info("       Peer: {}", span.getPeer());
        LOGGER.info("       IsError: {}", span.getIsError());
        LOGGER.info("       reference:");
        span.getRefsList().forEach(reference -> {
            LOGGER.info("           EntryApplicationInstanceId: {}", reference.getEntryApplicationInstanceId());
            LOGGER.info("           EntryServiceId: {}", reference.getEntryServiceId());
            LOGGER.info("           EntryServiceName: {}", reference.getEntryServiceName());
            LOGGER.info("           ParentTraceSegmentId: {}", reference.getParentTraceSegmentId());
            LOGGER.info("           ParentSpanId: {}", reference.getParentSpanId());
            LOGGER.info("           ParentApplicationInstanceId: {}", reference.getParentApplicationInstanceId());
            LOGGER.info("           ParentServiceId: {}", reference.getParentServiceId());
            LOGGER.info("           ParentServiceName: {}", reference.getParentServiceName());
            LOGGER.info("           NetworkAddressId: {}", reference.getNetworkAddressId());
            LOGGER.info("           NetworkAddress: {}", reference.getNetworkAddress());
        });
    });
}
Also used : UniqueId(org.apache.skywalking.apm.network.proto.UniqueId) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject) SpanObject(org.apache.skywalking.apm.network.proto.SpanObject)

Example 3 with TraceSegmentObject

use of org.apache.skywalking.apm.network.proto.TraceSegmentObject in project incubator-skywalking by apache.

the class SegmentH2UIDAO method load.

@Override
public TraceSegmentObject load(String segmentId) {
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY, SegmentTable.TABLE, SegmentTable.COLUMN_ID);
    Object[] params = new Object[] { segmentId };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        if (rs.next()) {
            byte[] dataBinary = rs.getBytes(SegmentTable.COLUMN_DATA_BINARY);
            try {
                return TraceSegmentObject.parseFrom(dataBinary);
            } catch (InvalidProtocolBufferException e) {
                logger.error(e.getMessage(), e);
            }
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject)

Example 4 with TraceSegmentObject

use of org.apache.skywalking.apm.network.proto.TraceSegmentObject 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 TraceSegmentObject

use of org.apache.skywalking.apm.network.proto.TraceSegmentObject in project incubator-skywalking by apache.

the class TraceStackService method load.

public Trace load(String traceId) {
    Trace trace = new Trace();
    List<String> segmentIds = globalTraceDAO.getSegmentIds(traceId);
    if (CollectionUtils.isNotEmpty(segmentIds)) {
        for (String segmentId : segmentIds) {
            TraceSegmentObject segment = segmentDAO.load(segmentId);
            if (ObjectUtils.isNotEmpty(segment)) {
                trace.getSpans().addAll(buildSpanList(traceId, segmentId, segment.getApplicationId(), segment.getSpansList()));
            }
        }
    }
    List<Span> sortedSpans = new LinkedList<>();
    if (CollectionUtils.isNotEmpty(trace.getSpans())) {
        List<Span> rootSpans = findRoot(trace.getSpans());
        if (CollectionUtils.isNotEmpty(rootSpans)) {
            rootSpans.forEach(span -> {
                List<Span> childrenSpan = new ArrayList<>();
                childrenSpan.add(span);
                findChildren(trace.getSpans(), span, childrenSpan);
                sortedSpans.addAll(childrenSpan);
            });
        }
    }
    // minStartTime(sortedSpans);
    trace.setSpans(sortedSpans);
    return trace;
}
Also used : Trace(org.apache.skywalking.apm.collector.storage.ui.trace.Trace) ArrayList(java.util.ArrayList) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject) Span(org.apache.skywalking.apm.collector.storage.ui.trace.Span) LinkedList(java.util.LinkedList)

Aggregations

TraceSegmentObject (org.apache.skywalking.apm.network.proto.TraceSegmentObject)8 SpanObject (org.apache.skywalking.apm.network.proto.SpanObject)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)2 KeyWithStringValue (org.apache.skywalking.apm.network.proto.KeyWithStringValue)2 LogMessage (org.apache.skywalking.apm.network.proto.LogMessage)2 UniqueId (org.apache.skywalking.apm.network.proto.UniqueId)2 UpstreamSegment (org.apache.skywalking.apm.network.proto.UpstreamSegment)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)1 SegmentDecorator (org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SegmentDecorator)1 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)1 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)1 GraphComputingMetric (org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric)1 ServiceName (org.apache.skywalking.apm.collector.storage.table.register.ServiceName)1