Search in sources :

Example 1 with AgentStatDecodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext in project pinpoint by naver.

the class AgentStatCodecTestBase method runTest.

private void runTest() {
    // Given
    final long initialTimestamp = System.currentTimeMillis();
    final long baseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp);
    final long timestampDelta = initialTimestamp - baseTimestamp;
    final List<T> expectedAgentStats = createAgentStats(AGENT_ID, AGENT_START_TIMESTAMP, initialTimestamp);
    // When
    Buffer encodedValueBuffer = new AutomaticBuffer();
    getCodec().encodeValues(encodedValueBuffer, expectedAgentStats);
    // Then
    AgentStatDecodingContext decodingContext = new AgentStatDecodingContext();
    decodingContext.setAgentId(AGENT_ID);
    decodingContext.setBaseTimestamp(baseTimestamp);
    decodingContext.setTimestampDelta(timestampDelta);
    Buffer valueBuffer = new FixedBuffer(encodedValueBuffer.getBuffer());
    List<T> actualAgentStats = getCodec().decodeValues(valueBuffer, decodingContext);
    Assert.assertEquals(expectedAgentStats.size(), actualAgentStats.size());
    for (int i = 0; i < expectedAgentStats.size(); ++i) {
        T expectedAgentStat = expectedAgentStats.get(i);
        T actualAgentStat = actualAgentStats.get(i);
        verify(expectedAgentStat, actualAgentStat);
    }
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) AgentStatDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) AgentStatDataPoint(com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint)

Example 2 with AgentStatDecodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext in project pinpoint by naver.

the class AgentStatEncoderTest method stats_should_be_encoded_and_decoded_into_same_value.

@Test
public void stats_should_be_encoded_and_decoded_into_same_value() {
    long initialTimestamp = System.currentTimeMillis();
    int numStats = RANDOM.nextInt(20) + 1;
    List<TestAgentStat> expectedAgentStats = this.createTestAgentStats(initialTimestamp, numStats);
    long baseTimestamp = AgentStatUtils.getBaseTimestamp(initialTimestamp);
    long timestampDelta = initialTimestamp - baseTimestamp;
    ByteBuffer qualifierBuffer = encoder.encodeQualifier(timestampDelta);
    ByteBuffer valueBuffer = encoder.encodeValue(expectedAgentStats);
    Buffer encodedQualifierBuffer = new FixedBuffer(qualifierBuffer.array());
    Buffer encodedValueBuffer = new FixedBuffer(valueBuffer.array());
    AgentStatDecodingContext context = new AgentStatDecodingContext();
    context.setAgentId(AGENT_ID);
    context.setBaseTimestamp(baseTimestamp);
    List<TestAgentStat> decodedAgentStats = decode(encodedQualifierBuffer, encodedValueBuffer, context);
    verify(expectedAgentStats, decodedAgentStats);
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) AgentStatDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) ByteBuffer(java.nio.ByteBuffer) AgentStatDataPoint(com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint) Test(org.junit.Test)

Example 3 with AgentStatDecodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext 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)

Aggregations

Buffer (com.navercorp.pinpoint.common.buffer.Buffer)3 AgentStatDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext)3 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)2 AgentStatDataPoint (com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint)2 AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)1 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Cell (org.apache.hadoop.hbase.Cell)1 Test (org.junit.Test)1