Search in sources :

Example 1 with OffsetFixedBuffer

use of com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer in project pinpoint by naver.

the class SpanBoTest method serialize_V1.

@Test
public void serialize_V1() {
    final SpanBo spanBo = new SpanBo();
    spanBo.setAgentId("agentId");
    spanBo.setApplicationId("applicationId");
    spanBo.setEndPoint("end");
    spanBo.setRpc("rpc");
    spanBo.setParentSpanId(5);
    spanBo.setAgentStartTime(1);
    TransactionId transactionId = new TransactionId("agentId", 2, 3);
    spanBo.setTransactionId(transactionId);
    spanBo.setElapsed(4);
    spanBo.setStartTime(5);
    spanBo.setServiceType(ServiceType.STAND_ALONE.getCode());
    spanBo.setLoggingTransactionInfo(LoggingInfo.INFO.getCode());
    spanBo.setExceptionInfo(1000, "Exception");
    ByteBuffer bytes = spanSerializer.writeColumnValue(spanBo);
    SpanBo newSpanBo = new SpanBo();
    Buffer valueBuffer = new OffsetFixedBuffer(bytes.array(), bytes.arrayOffset(), bytes.remaining());
    int i = spanDecoder.readSpan(newSpanBo, valueBuffer);
    logger.debug("length:{}", i);
    Assert.assertEquals(bytes.limit(), i);
    Assert.assertEquals(newSpanBo.getAgentId(), spanBo.getAgentId());
    Assert.assertEquals(newSpanBo.getApplicationId(), spanBo.getApplicationId());
    Assert.assertEquals(newSpanBo.getAgentStartTime(), spanBo.getAgentStartTime());
    Assert.assertEquals(newSpanBo.getElapsed(), spanBo.getElapsed());
    Assert.assertEquals(newSpanBo.getEndPoint(), spanBo.getEndPoint());
    Assert.assertEquals(newSpanBo.getErrCode(), spanBo.getErrCode());
    Assert.assertEquals(newSpanBo.getFlag(), spanBo.getFlag());
    //        not included for serialization
    //        Assert.assertEquals(newSpanBo.getTraceAgentStartTime(), spanBo.getTraceAgentStartTime());
    //        Assert.assertEquals(newSpanBo.getTraceTransactionSequence(), spanBo.getTraceTransactionSequence());
    Assert.assertEquals(newSpanBo.getParentSpanId(), spanBo.getParentSpanId());
    Assert.assertEquals(newSpanBo.getServiceType(), spanBo.getServiceType());
    Assert.assertEquals(newSpanBo.getApplicationServiceType(), spanBo.getServiceType());
    Assert.assertEquals(newSpanBo.getVersion(), spanBo.getVersion());
    Assert.assertEquals(newSpanBo.getLoggingTransactionInfo(), spanBo.getLoggingTransactionInfo());
    Assert.assertEquals(newSpanBo.getExceptionId(), spanBo.getExceptionId());
    Assert.assertEquals(newSpanBo.getExceptionMessage(), spanBo.getExceptionMessage());
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) ByteBuffer(java.nio.ByteBuffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) ByteBuffer(java.nio.ByteBuffer) TransactionId(com.navercorp.pinpoint.common.util.TransactionId) Test(org.junit.Test)

Example 2 with OffsetFixedBuffer

use of com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer in project pinpoint by naver.

the class SpanBoTest method serialize2_V1.

@Test
public void serialize2_V1() {
    SpanBo spanBo = new SpanBo();
    spanBo.setAgentId("agent");
    String service = createString(5);
    spanBo.setApplicationId(service);
    String endPoint = createString(127);
    spanBo.setEndPoint(endPoint);
    String rpc = createString(255);
    spanBo.setRpc(rpc);
    spanBo.setServiceType(ServiceType.STAND_ALONE.getCode());
    spanBo.setApplicationServiceType(ServiceType.UNKNOWN.getCode());
    final ByteBuffer bytes = spanSerializer.writeColumnValue(spanBo);
    SpanBo newSpanBo = new SpanBo();
    Buffer valueBuffer = new OffsetFixedBuffer(bytes.array(), bytes.arrayOffset(), bytes.remaining());
    int i = spanDecoder.readSpan(newSpanBo, valueBuffer);
    logger.debug("length:{}", i);
    Assert.assertEquals(bytes.limit(), i);
    Assert.assertEquals(spanBo.getServiceType(), spanBo.getServiceType());
    Assert.assertEquals(spanBo.getApplicationServiceType(), spanBo.getApplicationServiceType());
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) ByteBuffer(java.nio.ByteBuffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with OffsetFixedBuffer

use of com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer in project pinpoint by naver.

the class TransactionIdMapper method parseVarTransactionId.

public static TransactionId parseVarTransactionId(byte[] bytes, int offset, int length) {
    if (bytes == null) {
        throw new NullPointerException("bytes must not be null");
    }
    final Buffer buffer = new OffsetFixedBuffer(bytes, offset, length);
    // skip elapsed time (not used) hbase column prefix - only used for filtering.
    // Not sure if we can reduce the data size any further.
    // buffer.readInt();
    String agentId = buffer.readPrefixedString();
    long agentStartTime = buffer.readSVLong();
    long transactionSequence = buffer.readVLong();
    return new TransactionId(agentId, agentStartTime, transactionSequence);
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) TransactionId(com.navercorp.pinpoint.common.util.TransactionId)

Example 4 with OffsetFixedBuffer

use of com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer in project pinpoint by naver.

the class AgentStatMapperV2 method mapRow.

@Override
public List<T> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    final byte[] distributedRowKey = result.getRow();
    final String agentId = this.hbaseOperationFactory.getAgentId(distributedRowKey);
    final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey);
    List<T> dataPoints = new ArrayList<>();
    for (Cell cell : result.rawCells()) {
        if (CellUtil.matchingFamily(cell, HBaseTables.AGENT_STAT_CF_STATISTICS)) {
            Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
            long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer);
            AgentStatDecodingContext decodingContext = new AgentStatDecodingContext();
            decodingContext.setAgentId(agentId);
            decodingContext.setBaseTimestamp(baseTimestamp);
            decodingContext.setTimestampDelta(timestampDelta);
            List<T> candidates = this.decoder.decodeValue(valueBuffer, decodingContext);
            for (T candidate : candidates) {
                if (filter(candidate)) {
                    continue;
                }
                dataPoints.add(candidate);
            }
        }
    }
    // Reverse sort as timestamp is stored in a reversed order.
    Collections.sort(dataPoints, REVERSE_TIMESTAMP_COMPARATOR);
    return dataPoints;
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) AgentStatDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext) ArrayList(java.util.ArrayList) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) Cell(org.apache.hadoop.hbase.Cell)

Example 5 with OffsetFixedBuffer

use of com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer 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);
    for (Cell cell : rawCells) {
        SpanDecoder spanDecoder = null;
        // only if family name is "span"
        if (CellUtil.matchingFamily(cell, HBaseTables.TRACE_V2_CF_SPAN)) {
            decodingContext.setCollectorAcceptedTime(cell.getTimestamp());
            final Buffer qualifier = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            final Buffer columnValue = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
            spanDecoder = resolveDecoder(columnValue);
            final Object decodeObject = spanDecoder.decode(qualifier, columnValue, decodingContext);
            if (decodeObject instanceof SpanBo) {
                SpanBo spanBo = (SpanBo) decodeObject;
                if (logger.isDebugEnabled()) {
                    logger.debug("spanBo:{}", spanBo);
                }
                AgentKey agentKey = newAgentKey(spanBo);
                spanMap.put(agentKey, spanBo);
            } else if (decodeObject instanceof SpanChunkBo) {
                SpanChunkBo spanChunkBo = (SpanChunkBo) decodeObject;
                if (logger.isDebugEnabled()) {
                    logger.debug("spanChunkBo:{}", spanChunkBo);
                }
                spanChunkList.add(spanChunkBo);
            }
        } else {
            logger.warn("Unknown ColumnFamily :{}", Bytes.toStringBinary(CellUtil.cloneFamily(cell)));
        }
        nextCell(spanDecoder, decodingContext);
    }
    decodingContext.finish();
    return buildSpanBoList(spanMap, spanChunkList);
}
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.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) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) TransactionId(com.navercorp.pinpoint.common.util.TransactionId) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

Buffer (com.navercorp.pinpoint.common.buffer.Buffer)14 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)14 TransactionId (com.navercorp.pinpoint.common.util.TransactionId)7 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)6 Test (org.junit.Test)5 ByteBuffer (java.nio.ByteBuffer)4 Cell (org.apache.hadoop.hbase.Cell)4 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)3 Dot (com.navercorp.pinpoint.web.vo.scatter.Dot)3 AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)2 SpanDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext)2 Application (com.navercorp.pinpoint.web.vo.Application)2 ArrayList (java.util.ArrayList)2 AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)1 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)1 SpanChunkBo (com.navercorp.pinpoint.common.server.bo.SpanChunkBo)1 AgentStatDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext)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