Search in sources :

Example 1 with SpanDecodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v1.SpanDecodingContext in project pinpoint by naver.

the class SpanMapperV2 method mapRow.

@Override
public List<SpanBo> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    byte[] rowKey = result.getRow();
    final TransactionId transactionId = this.rowKeyDecoder.decodeRowKey(rowKey);
    final Cell[] rawCells = result.rawCells();
    ListMultimap<AgentKey, SpanBo> spanMap = LinkedListMultimap.create();
    List<SpanChunkBo> spanChunkList = new ArrayList<>();
    final SpanDecodingContext decodingContext = new SpanDecodingContext();
    decodingContext.setTransactionId(transactionId);
    final BufferFactory bufferFactory = new BufferFactory(cacheSize);
    for (Cell cell : rawCells) {
        SpanDecoder spanDecoder = null;
        // only if family name is "span"
        if (CellUtil.matchingFamily(cell, HbaseColumnFamily.TRACE_V2_SPAN.getName())) {
            decodingContext.setCollectorAcceptedTime(cell.getTimestamp());
            final Buffer qualifier = bufferFactory.createBuffer(CellUtil.cloneQualifier(cell));
            final Buffer columnValue = bufferFactory.createBuffer(CellUtil.cloneValue(cell));
            spanDecoder = resolveDecoder(columnValue);
            final Object decodeObject = spanDecoder.decode(qualifier, columnValue, decodingContext);
            if (decodeObject instanceof SpanBo) {
                SpanBo spanBo = (SpanBo) decodeObject;
                if (logger.isTraceEnabled()) {
                    logger.trace("spanBo:{}", spanBo);
                }
                AgentKey agentKey = newAgentKey(spanBo);
                spanMap.put(agentKey, spanBo);
            } else if (decodeObject instanceof SpanChunkBo) {
                SpanChunkBo spanChunkBo = (SpanChunkBo) decodeObject;
                if (logger.isTraceEnabled()) {
                    logger.trace("spanChunkBo:{}", spanChunkBo);
                }
                spanChunkList.add(spanChunkBo);
            }
        } else {
            if (logger.isWarnEnabled()) {
                String columnFamily = Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
                logger.warn("Unknown ColumnFamily :{}", columnFamily);
            }
        }
        nextCell(spanDecoder, decodingContext);
    }
    decodingContext.finish();
    return buildSpanBoList(spanMap, spanChunkList);
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) ByteBuffer(java.nio.ByteBuffer) StringCacheableBuffer(com.navercorp.pinpoint.common.buffer.StringCacheableBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) SpanDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext) SpanChunkBo(com.navercorp.pinpoint.common.server.bo.SpanChunkBo) SpanDecoder(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecoder) ArrayList(java.util.ArrayList) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) TransactionId(com.navercorp.pinpoint.common.profiler.util.TransactionId) Cell(org.apache.hadoop.hbase.Cell)

Example 2 with SpanDecodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v1.SpanDecodingContext in project pinpoint by naver.

the class SpanMapperV2Test method test.

@Test
public void test() {
    SpanBo span = new SpanBo();
    span.setServiceType((short) 1000);
    span.setExceptionInfo(1, "spanException");
    SpanEventBo firstSpanEventBo = new SpanEventBo();
    firstSpanEventBo.setExceptionInfo(2, "first");
    firstSpanEventBo.setEndElapsed(100);
    AnnotationBo annotationBo = newAnnotation(200, "annotation");
    firstSpanEventBo.setAnnotationBoList(Collections.singletonList(annotationBo));
    firstSpanEventBo.setServiceType((short) 1003);
    firstSpanEventBo.setSequence((short) 0);
    span.addSpanEvent(firstSpanEventBo);
    // // next
    SpanEventBo nextSpanEventBo = new SpanEventBo();
    nextSpanEventBo.setEndElapsed(200);
    nextSpanEventBo.setServiceType((short) 2003);
    nextSpanEventBo.setSequence((short) 1);
    span.addSpanEvent(nextSpanEventBo);
    SpanEncodingContext<SpanBo> encodingContext = new SpanEncodingContext<>(span);
    SpanEncoder encoder = new SpanEncoderV0();
    ByteBuffer byteBuffer = encoder.encodeSpanColumnValue(encodingContext);
    Buffer buffer = new OffsetFixedBuffer(byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.remaining());
    SpanBo readSpan = new SpanBo();
    SpanDecodingContext decodingContext = new SpanDecodingContext();
    decoder.readSpanValue(buffer, readSpan, decodingContext);
    Assert.assertEquals(readSpan.getSpanEventBoList().size(), 2);
    // span
    Assert.assertEquals(readSpan.getServiceType(), 1000);
    Assert.assertEquals(readSpan.hasException(), true);
    Assert.assertEquals(readSpan.getExceptionId(), 1);
    Assert.assertEquals(readSpan.getExceptionMessage(), "spanException");
    List<SpanEventBo> spanEventBoList = readSpan.getSpanEventBoList();
    SpanEventBo readFirst = spanEventBoList.get(0);
    SpanEventBo readNext = spanEventBoList.get(1);
    Assert.assertEquals(readFirst.getEndElapsed(), 100);
    Assert.assertEquals(readNext.getEndElapsed(), 200);
    Assert.assertEquals(readFirst.getExceptionId(), 2);
    Assert.assertEquals(readNext.hasException(), false);
    Assert.assertEquals(readFirst.getServiceType(), 1003);
    Assert.assertEquals(readNext.getServiceType(), 2003);
    Assert.assertEquals(readFirst.getSequence(), 0);
    Assert.assertEquals(readNext.getSequence(), 1);
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) ByteBuffer(java.nio.ByteBuffer) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) SpanEncodingContext(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext) SpanDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext) SpanEncoder(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoder) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) SpanEncoderV0(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoderV0) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) ByteBuffer(java.nio.ByteBuffer) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo) Test(org.junit.Test)

Example 3 with SpanDecodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v1.SpanDecodingContext in project pinpoint by naver.

the class SpanMapper method mapRow.

@Override
public List<SpanBo> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    byte[] rowKey = result.getRow();
    final TransactionId transactionId = this.rowKeyDecoder.decodeRowKey(rowKey);
    final Cell[] rawCells = result.rawCells();
    Map<AgentKey, SpanBo> spanMap = new LinkedHashMap<>();
    ListMultimap<AgentKey, SpanEventBo> spanEventBoListMap = ArrayListMultimap.create();
    ListMultimap<Long, AnnotationBo> annotationBoListMap = ArrayListMultimap.create();
    final SpanDecodingContext decodingContext = new SpanDecodingContext();
    decodingContext.setTransactionId(transactionId);
    for (Cell cell : rawCells) {
        decodingContext.setCollectorAcceptedTime(cell.getTimestamp());
        // only if family name is "span"
        if (CellUtil.matchingFamily(cell, HBaseTables.TRACES_CF_SPAN)) {
            Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
            final SpanBo spanBo = spanDecoder.decodeSpanBo(qualifierBuffer, valueBuffer, decodingContext);
            AgentKey agentKey = newAgentKey(spanBo);
            spanMap.put(agentKey, spanBo);
        } else if (CellUtil.matchingFamily(cell, HBaseTables.TRACES_CF_TERMINALSPAN)) {
            final Buffer qualifier = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            final Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
            SpanEventBo spanEventBo = spanDecoder.decodeSpanEventBo(qualifier, valueBuffer, decodingContext);
            AgentKey agentKey = newAgentKey(decodingContext);
            spanEventBoListMap.put(agentKey, spanEventBo);
        } else if (CellUtil.matchingFamily(cell, HBaseTables.TRACES_CF_ANNOTATION)) {
            final Buffer qualifier = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            final Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
            List<AnnotationBo> annotationBoList = annotationBoDecoder.decode(qualifier, valueBuffer, decodingContext);
            if (CollectionUtils.isNotEmpty(annotationBoList)) {
                long spanId = decodingContext.getSpanId();
                annotationBoListMap.putAll(spanId, annotationBoList);
            }
        }
        spanDecoder.next(decodingContext);
    }
    decodingContext.finish();
    for (Map.Entry<AgentKey, SpanEventBo> spanBoEntry : spanEventBoListMap.entries()) {
        final AgentKey agentKey = spanBoEntry.getKey();
        SpanBo spanBo = spanMap.get(agentKey);
        if (spanBo != null) {
            SpanEventBo value = spanBoEntry.getValue();
            spanBo.addSpanEvent(value);
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("Span not exist spanId:{} spanEvent:{}", spanBoEntry.getKey(), spanBoEntry.getValue());
            }
        }
    }
    List<SpanBo> spanList = Lists.newArrayList(spanMap.values());
    if (!annotationBoListMap.isEmpty()) {
        addAnnotation(spanList, annotationBoListMap);
    }
    return spanList;
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) SpanDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.trace.v1.SpanDecodingContext) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) TransactionId(com.navercorp.pinpoint.common.util.TransactionId) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) Cell(org.apache.hadoop.hbase.Cell) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo)

Aggregations

Buffer (com.navercorp.pinpoint.common.buffer.Buffer)3 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)3 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)2 AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)2 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)2 SpanDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext)2 ByteBuffer (java.nio.ByteBuffer)2 Cell (org.apache.hadoop.hbase.Cell)2 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)1 StringCacheableBuffer (com.navercorp.pinpoint.common.buffer.StringCacheableBuffer)1 TransactionId (com.navercorp.pinpoint.common.profiler.util.TransactionId)1 SpanChunkBo (com.navercorp.pinpoint.common.server.bo.SpanChunkBo)1 SpanDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.trace.v1.SpanDecodingContext)1 SpanDecoder (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecoder)1 SpanEncoder (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoder)1 SpanEncoderV0 (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoderV0)1 SpanEncodingContext (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext)1 TransactionId (com.navercorp.pinpoint.common.util.TransactionId)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1