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;
}
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());
});
});
}
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;
}
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;
}
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;
}
Aggregations