[강운덕] [LUCYSUS-1744] string cache api추가. jdbc connect시 string cache api 를 사용하는 것으로 변경. 최초 connect시 30개 connection이 생성되는 testcase에서 4k에서 2k로 데이터 사이즈 축소.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@2519 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2013-10-14 10:47:40 +00:00
parent 38dbca9d6f
commit 0fd2a38f8f
4 changed files with 142 additions and 8 deletions
@@ -0,0 +1,13 @@
package com.nhn.pinpoint.web.dao;
import com.nhn.pinpoint.common.bo.SqlMetaDataBo;
import com.nhn.pinpoint.common.bo.StringMetaDataBo;
import java.util.List;
/**
*
*/
public interface StringMetaDataDao {
List<StringMetaDataBo> getStringMetaData(String agentId, int stringId, long time);
}
@@ -0,0 +1,39 @@
package com.nhn.pinpoint.web.dao.hbase;
import com.nhn.pinpoint.common.bo.SqlMetaDataBo;
import com.nhn.pinpoint.common.bo.StringMetaDataBo;
import com.nhn.pinpoint.common.hbase.HBaseTables;
import com.nhn.pinpoint.common.hbase.HbaseOperations2;
import com.nhn.pinpoint.web.dao.StringMetaDataDao;
import org.apache.hadoop.hbase.client.Get;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.hadoop.hbase.RowMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
*
*/
@Repository
public class HbaseStringMetaDataDao implements StringMetaDataDao {
@Autowired
private HbaseOperations2 hbaseOperations2;
@Autowired
@Qualifier("stringMetaDataMapper")
private RowMapper<List<StringMetaDataBo>> stringMetaDataMapper;
@Override
public List<StringMetaDataBo> getStringMetaData(String agentId, int stringId, long time) {
StringMetaDataBo stringMetaData = new StringMetaDataBo(agentId, stringId, time);
byte[] rowKey = stringMetaData.toRowKey();
Get get = new Get(rowKey);
get.addFamily(HBaseTables.STRING_METADATA_CF_STR);
return hbaseOperations2.get(HBaseTables.STRING_METADATA, get, stringMetaDataMapper);
}
}
@@ -0,0 +1,35 @@
package com.nhn.pinpoint.web.mapper;
import com.nhn.pinpoint.common.bo.SqlMetaDataBo;
import com.nhn.pinpoint.common.bo.StringMetaDataBo;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.data.hadoop.hbase.RowMapper;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
@Component
public class StringMetaDataMapper implements RowMapper<List<StringMetaDataBo>> {
@Override
public List<StringMetaDataBo> mapRow(Result result, int rowNum) throws Exception {
byte[] rowKey = result.getRow();
List<StringMetaDataBo> stringMetaDataList = new ArrayList<StringMetaDataBo>();
KeyValue[] keyList = result.raw();
for (KeyValue keyValue : keyList) {
StringMetaDataBo sqlMetaDataBo = new StringMetaDataBo();
sqlMetaDataBo.readRowKey(rowKey);
String stringValue = Bytes.toString(keyValue.getBuffer(), keyValue.getQualifierOffset(), keyValue.getQualifierLength());
sqlMetaDataBo.setStringValue(stringValue);
stringMetaDataList.add(sqlMetaDataBo);
}
return stringMetaDataList;
}
}
@@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.List;
import com.nhn.pinpoint.common.bo.*;
import com.nhn.pinpoint.web.dao.StringMetaDataDao;
import com.nhn.pinpoint.web.vo.TransactionId;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -38,6 +39,9 @@ public class SpanServiceImpl implements SpanService {
@Autowired
private ApiMetaDataDao apiMetaDataDao;
@Autowired
private StringMetaDataDao stringMetaDataDao;
private SqlParser sqlParser = new SqlParser();
private OutputParameterParser outputParameterParser = new OutputParameterParser();
@@ -53,12 +57,13 @@ public class SpanServiceImpl implements SpanService {
// transitionApiId(order);
transitionDynamicApiId(order);
transitionSqlId(order);
transitionCachedString(order);
// TODO root span not found시 row data라도 보여줘야 됨.
return order;
}
private void transitionAnnotation(List<SpanAlign> spans, AnnotationReplacementCallback annotationReplacementCallback) {
private void transitionAnnotation(List<SpanAlign> spans, AnnotationReplacementCallback annotationReplacementCallback) {
for (SpanAlign spanAlign : spans) {
List<AnnotationBo> annotationBoList;
if (spanAlign.isSpan()) {
@@ -186,13 +191,6 @@ public class SpanServiceImpl implements SpanService {
return sb.toString();
}
private String getAgentId(SpanAlign spanAlign) {
if (spanAlign.isSpan()) {
return spanAlign.getSpanBo().getAgentId();
} else {
return spanAlign.getSpanEventBo().getAgentId();
}
}
private void transitionDynamicApiId(List<SpanAlign> spans) {
this.transitionAnnotation(spans, new AnnotationReplacementCallback() {
@@ -233,6 +231,55 @@ public class SpanServiceImpl implements SpanService {
});
}
private void transitionCachedString(List<SpanAlign> spans) {
this.transitionAnnotation(spans, new AnnotationReplacementCallback() {
@Override
public void replacement(SpanAlign spanAlign, List<AnnotationBo> annotationBoList) {
final AgentKey key = getAgentKey(spanAlign);
List<AnnotationBo> cachedStringAnnotation = findCachedStringAnnotation(annotationBoList);
if (cachedStringAnnotation.isEmpty()) {
return;
}
for (AnnotationBo annotationBo : cachedStringAnnotation) {
final int cachedArgsKey = annotationBo.getKey();
int stringMeataDataId = (Integer) annotationBo.getValue();
List<StringMetaDataBo> stringMetaList = stringMetaDataDao.getStringMetaData(key.getAgentId(), stringMeataDataId, key.getAgentStartTime());
int size = stringMetaList.size();
if (size == 0) {
logger.warn("StringMetaData not Found {}/{}/{}", key.getAgentId(), stringMeataDataId, key.getAgentStartTime());
AnnotationBo api = new AnnotationBo();
// API METADATA ERROR가 아님. 추후 수정.
api.setKey(AnnotationKey.ERROR_API_METADATA_NOT_FOUND.getCode());
api.setValue("CACHED-STRING-ID not found. stringId:" + cachedArgsKey);
annotationBoList.add(api);
} else if (size >= 1) {
// key 충돌 경우는 후추 처리한다. 실제 상황에서는 일부러 만들지 않는한 발생할수 없다.
StringMetaDataBo stringMetaDataBo = stringMetaList.get(0);
AnnotationBo stringMetaData = new AnnotationBo();
stringMetaData.setKey(AnnotationKey.cachedArgsToArgs(cachedArgsKey));
stringMetaData.setValue(stringMetaDataBo.getStringValue());
annotationBoList.add(stringMetaData);
if (size > 1) {
logger.warn("stringMetaData size not 1 :{}", stringMetaList);
}
}
}
}
});
}
private List<AnnotationBo> findCachedStringAnnotation(List<AnnotationBo> annotationBoList) {
List<AnnotationBo> findAnnotationBoList = new ArrayList<AnnotationBo>(annotationBoList.size());
for (AnnotationBo annotationBo : annotationBoList) {
if (AnnotationKey.isCachedArgsKey(annotationBo.getKey())) {
findAnnotationBoList.add(annotationBo);
}
}
return findAnnotationBoList;
}
private int getApiId(SpanAlign spanAlign) {
if (spanAlign.isSpan()) {
return spanAlign.getSpanBo().getApiId();