mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 00:36:02 +10:00
Merge pull request #479 from emeroad/#472_update_hbase_1.0_api
#472 change hbase 1.0 api
This commit is contained in:
@@ -29,15 +29,22 @@ import org.apache.hadoop.hbase.Cell;
|
||||
import org.apache.hadoop.hbase.CellUtil;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.hadoop.hbase.RowMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Component
|
||||
public class ResponseTimeMapper implements RowMapper<ResponseTime> {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
|
||||
@@ -46,28 +53,33 @@ public class ResponseTimeMapper implements RowMapper<ResponseTime> {
|
||||
if (result.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final byte[] rowKey = result.getRow();
|
||||
|
||||
ResponseTime responseTime = createResponseTime(rowKey);
|
||||
|
||||
for (Cell cell : result.rawCells()) {
|
||||
if (!CellUtil.matchingFamily(cell, HBaseTables.MAP_STATISTICS_SELF_CF_COUNTER)) {
|
||||
continue;
|
||||
if (CellUtil.matchingFamily(cell, HBaseTables.MAP_STATISTICS_SELF_CF_COUNTER)) {
|
||||
recordColumn(responseTime, cell);
|
||||
}
|
||||
byte[] qualifier = CellUtil.cloneQualifier(cell);
|
||||
|
||||
recordColumn(responseTime, qualifier, cell.getValueArray(), cell.getValueOffset());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("unknown column family:{}", Arrays.toString(CellUtil.cloneFamily(cell)));
|
||||
}
|
||||
}
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void recordColumn(ResponseTime responseTime, byte[] qualifier, byte[] value, int valueOffset) {
|
||||
void recordColumn(ResponseTime responseTime, Cell cell) {
|
||||
|
||||
final byte[] qArray = cell.getQualifierArray();
|
||||
final int qOffset = cell.getQualifierOffset();
|
||||
short slotNumber = Bytes.toShort(qArray, qOffset);
|
||||
|
||||
short slotNumber = Bytes.toShort(qualifier);
|
||||
// agentId should be added as data.
|
||||
String agentId = Bytes.toString(qualifier, BytesUtils.SHORT_BYTE_LENGTH, qualifier.length - BytesUtils.SHORT_BYTE_LENGTH);
|
||||
long count = Bytes.toLong(value, valueOffset);
|
||||
String agentId = Bytes.toString(qArray, qOffset + BytesUtils.SHORT_BYTE_LENGTH, cell.getQualifierLength() - BytesUtils.SHORT_BYTE_LENGTH);
|
||||
long count = Bytes.toLong(cell.getValueArray(), cell.getValueOffset());
|
||||
responseTime.addResponseTime(agentId, slotNumber, count);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,12 @@ import com.navercorp.pinpoint.common.buffer.Buffer;
|
||||
import com.navercorp.pinpoint.common.trace.HistogramSlot;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
|
||||
import com.navercorp.pinpoint.web.mapper.ResponseTimeMapper;
|
||||
import com.navercorp.pinpoint.web.vo.ResponseTime;
|
||||
|
||||
import org.apache.hadoop.hbase.Cell;
|
||||
import org.apache.hadoop.hbase.CellUtil;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.KeyValue;
|
||||
import org.junit.Assert;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.junit.Test;
|
||||
@@ -35,16 +38,20 @@ public class ResponseTimeMapperTest {
|
||||
|
||||
@Test
|
||||
public void testResponseTimeMapperTest() throws Exception {
|
||||
ResponseTimeMapper responseTimeMapper = new ResponseTimeMapper();
|
||||
ResponseTime responseTime = new ResponseTime("applicationName", ServiceType.STAND_ALONE, System.currentTimeMillis());
|
||||
|
||||
Buffer buffer = new AutomaticBuffer();
|
||||
HistogramSlot histogramSlot = ServiceType.STAND_ALONE.getHistogramSchema().findHistogramSlot(1000);
|
||||
short histogramSlotTime = histogramSlot.getSlotTime();
|
||||
buffer.put(histogramSlotTime);
|
||||
buffer.put(Bytes.toBytes("agent"));
|
||||
byte[] bufferArray = buffer.getBuffer();
|
||||
byte[] valueArray = Bytes.toBytes(1L);
|
||||
|
||||
responseTimeMapper.recordColumn(responseTime, buffer.getBuffer(), Bytes.toBytes(1L), 0);
|
||||
Cell mockCell = CellUtil.createCell(HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, bufferArray, HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), valueArray);
|
||||
|
||||
ResponseTimeMapper responseTimeMapper = new ResponseTimeMapper();
|
||||
ResponseTime responseTime = new ResponseTime("applicationName", ServiceType.STAND_ALONE, System.currentTimeMillis());
|
||||
responseTimeMapper.recordColumn(responseTime, mockCell);
|
||||
|
||||
Histogram agentHistogram = responseTime.findHistogram("agent");
|
||||
long fastCount = agentHistogram.getFastCount();
|
||||
|
||||
Reference in New Issue
Block a user