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