use of com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo in project pinpoint by naver.
the class SpanServiceImpl method transitionSqlId.
private void transitionSqlId(final List<SpanAlign> spans) {
this.transitionAnnotation(spans, new AnnotationReplacementCallback() {
@Override
public void replacement(SpanAlign spanAlign, List<AnnotationBo> annotationBoList) {
AnnotationBo sqlIdAnnotation = findAnnotation(annotationBoList, AnnotationKey.SQL_ID.getCode());
if (sqlIdAnnotation == null) {
return;
}
if (metaDataFilter != null && metaDataFilter.filter(spanAlign, MetaData.SQL)) {
AnnotationBo annotationBo = metaDataFilter.createAnnotationBo(spanAlign, MetaData.SQL);
annotationBoList.add(annotationBo);
return;
}
// value of sqlId's annotation contains multiple values.
final IntStringStringValue sqlValue = (IntStringStringValue) sqlIdAnnotation.getValue();
final int sqlId = sqlValue.getIntValue();
final String sqlParam = sqlValue.getStringValue1();
final List<SqlMetaDataBo> sqlMetaDataList = sqlMetaDataDao.getSqlMetaData(spanAlign.getAgentId(), spanAlign.getAgentStartTime(), sqlId);
final int size = sqlMetaDataList.size();
if (size == 0) {
AnnotationBo api = new AnnotationBo();
api.setKey(AnnotationKey.SQL.getCode());
api.setValue("SQL-ID not found sqlId:" + sqlId);
annotationBoList.add(api);
} else if (size == 1) {
final SqlMetaDataBo sqlMetaDataBo = sqlMetaDataList.get(0);
if (StringUtils.isEmpty(sqlParam)) {
AnnotationBo sqlMeta = new AnnotationBo();
sqlMeta.setKey(AnnotationKey.SQL_METADATA.getCode());
sqlMeta.setValue(sqlMetaDataBo.getSql());
annotationBoList.add(sqlMeta);
// AnnotationBo checkFail = checkIdentifier(spanAlign, sqlMetaDataBo);
// if (checkFail != null) {
// // fail
// annotationBoList.add(checkFail);
// return;
// }
AnnotationBo sql = new AnnotationBo();
sql.setKey(AnnotationKey.SQL.getCode());
sql.setValue(sqlMetaDataBo.getSql().trim());
annotationBoList.add(sql);
} else {
logger.debug("sqlMetaDataBo:{}", sqlMetaDataBo);
final String outputParams = sqlParam;
List<String> parsedOutputParams = outputParameterParser.parseOutputParameter(outputParams);
logger.debug("outputPrams:{}, parsedOutputPrams:{}", outputParams, parsedOutputParams);
String originalSql = sqlParser.combineOutputParams(sqlMetaDataBo.getSql(), parsedOutputParams);
logger.debug("outputPrams{}, originalSql:{}", outputParams, originalSql);
AnnotationBo sqlMeta = new AnnotationBo();
sqlMeta.setKey(AnnotationKey.SQL_METADATA.getCode());
sqlMeta.setValue(sqlMetaDataBo.getSql());
annotationBoList.add(sqlMeta);
AnnotationBo sql = new AnnotationBo();
sql.setKey(AnnotationKey.SQL.getCode());
sql.setValue(originalSql.trim());
annotationBoList.add(sql);
}
} else {
// TODO need improvement
AnnotationBo api = new AnnotationBo();
api.setKey(AnnotationKey.SQL.getCode());
api.setValue(collisionSqlIdCodeMessage(sqlId, sqlMetaDataList));
annotationBoList.add(api);
}
// add if bindValue exists
final String bindValue = sqlValue.getStringValue2();
if (StringUtils.isNotEmpty(bindValue)) {
AnnotationBo bindValueAnnotation = new AnnotationBo();
bindValueAnnotation.setKey(AnnotationKey.SQL_BINDVALUE.getCode());
bindValueAnnotation.setValue(bindValue);
annotationBoList.add(bindValueAnnotation);
}
}
});
}
use of com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo in project pinpoint by naver.
the class GrpcSqlMetaDataHandler method handleSqlMetaData.
private PResult handleSqlMetaData(PSqlMetaData sqlMetaData) {
if (isDebug) {
logger.debug("Handle PSqlMetaData={}", MessageFormatUtils.debugLog(sqlMetaData));
}
try {
final Header agentInfo = ServerContext.getAgentInfo();
final String agentId = agentInfo.getAgentId();
final long agentStartTime = agentInfo.getAgentStartTime();
final SqlMetaDataBo sqlMetaDataBo = new SqlMetaDataBo(agentId, agentStartTime, sqlMetaData.getSqlId(), sqlMetaData.getSql());
sqlMetaDataService.insert(sqlMetaDataBo);
return PResult.newBuilder().setSuccess(true).build();
} catch (Exception e) {
logger.warn("Failed to handle sqlMetaData={}", MessageFormatUtils.debugLog(sqlMetaData), e);
// Avoid detailed error messages.
return PResult.newBuilder().setSuccess(false).setMessage("Internal Server Error").build();
}
}
use of com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo in project pinpoint by naver.
the class HbaseSqlMetaDataDao method insert.
@Override
public void insert(TSqlMetaData sqlMetaData) {
if (sqlMetaData == null) {
throw new NullPointerException("sqlMetaData must not be null");
}
if (logger.isDebugEnabled()) {
logger.debug("insert:{}", sqlMetaData);
}
SqlMetaDataBo sqlMetaDataBo = new SqlMetaDataBo(sqlMetaData.getAgentId(), sqlMetaData.getAgentStartTime(), sqlMetaData.getSqlId());
final byte[] rowKey = getDistributedKey(sqlMetaDataBo.toRowKey());
Put put = new Put(rowKey);
String sql = sqlMetaData.getSql();
byte[] sqlBytes = Bytes.toBytes(sql);
put.addColumn(HBaseTables.SQL_METADATA_VER2_CF_SQL, HBaseTables.SQL_METADATA_VER2_CF_SQL_QUALI_SQLSTATEMENT, sqlBytes);
hbaseTemplate.put(HBaseTables.SQL_METADATA_VER2, put);
}
use of com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo in project pinpoint by naver.
the class ThriftSqlMetaDataHandler method handleSqlMetaData.
private TResult handleSqlMetaData(TSqlMetaData sqlMetaData) {
try {
final SqlMetaDataBo sqlMetaDataBo = new SqlMetaDataBo(sqlMetaData.getAgentId(), sqlMetaData.getAgentStartTime(), sqlMetaData.getSqlId(), sqlMetaData.getSql());
sqlMetaDataService.insert(sqlMetaDataBo);
} catch (Exception e) {
logger.warn("Failed to handle SqlMetaData={}, Caused:{}", sqlMetaData, e.getMessage(), e);
final TResult result = new TResult(false);
result.setMessage(e.getMessage());
return result;
}
return new TResult(true);
}
use of com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo in project pinpoint by naver.
the class SpanServiceImpl method transitionSqlId.
private void transitionSqlId(final List<Align> spans) {
this.transitionAnnotation(spans, new AnnotationReplacementCallback() {
@Override
public void replacement(Align align, List<AnnotationBo> annotationBoList) {
AnnotationBo sqlIdAnnotation = findAnnotation(annotationBoList, AnnotationKey.SQL_ID.getCode());
if (sqlIdAnnotation == null) {
return;
}
if (metaDataFilter != null && metaDataFilter.filter(align, MetaData.SQL)) {
AnnotationBo annotationBo = metaDataFilter.createAnnotationBo(align, MetaData.SQL);
annotationBoList.add(annotationBo);
return;
}
// value of sqlId's annotation contains multiple values.
final IntStringStringValue sqlValue = (IntStringStringValue) sqlIdAnnotation.getValue();
final int sqlId = sqlValue.getIntValue();
final String sqlParam = sqlValue.getStringValue1();
final List<SqlMetaDataBo> sqlMetaDataList = sqlMetaDataDao.getSqlMetaData(align.getAgentId(), align.getAgentStartTime(), sqlId);
final int size = sqlMetaDataList.size();
if (size == 0) {
String errorMessage = "SQL-ID not found sqlId:" + sqlId;
AnnotationBo api = new AnnotationBo(AnnotationKey.SQL.getCode(), errorMessage);
annotationBoList.add(api);
} else if (size == 1) {
final SqlMetaDataBo sqlMetaDataBo = sqlMetaDataList.get(0);
if (StringUtils.isEmpty(sqlParam)) {
AnnotationBo sqlMeta = new AnnotationBo(AnnotationKey.SQL_METADATA.getCode(), sqlMetaDataBo.getSql());
annotationBoList.add(sqlMeta);
// AnnotationBo checkFail = checkIdentifier(spanAlign, sqlMetaDataBo);
// if (checkFail != null) {
// // fail
// annotationBoList.add(checkFail);
// return;
// }
AnnotationBo sql = new AnnotationBo(AnnotationKey.SQL.getCode(), StringUtils.trim(sqlMetaDataBo.getSql()));
annotationBoList.add(sql);
} else {
logger.debug("sqlMetaDataBo:{}", sqlMetaDataBo);
final String outputParams = sqlParam;
List<String> parsedOutputParams = outputParameterParser.parseOutputParameter(outputParams);
logger.debug("outputPrams:{}, parsedOutputPrams:{}", outputParams, parsedOutputParams);
String originalSql = sqlParser.combineOutputParams(sqlMetaDataBo.getSql(), parsedOutputParams);
logger.debug("outputPrams{}, originalSql:{}", outputParams, originalSql);
AnnotationBo sqlMeta = new AnnotationBo(AnnotationKey.SQL_METADATA.getCode(), sqlMetaDataBo.getSql());
annotationBoList.add(sqlMeta);
AnnotationBo sql = new AnnotationBo(AnnotationKey.SQL.getCode(), StringUtils.trim(originalSql));
annotationBoList.add(sql);
}
} else {
// TODO need improvement
String collisionSqlIdCodeMessage = collisionSqlIdCodeMessage(sqlId, sqlMetaDataList);
AnnotationBo api = new AnnotationBo(AnnotationKey.SQL.getCode(), collisionSqlIdCodeMessage);
annotationBoList.add(api);
}
// add if bindValue exists
final String bindValue = sqlValue.getStringValue2();
if (StringUtils.isNotEmpty(bindValue)) {
AnnotationBo bindValueAnnotation = new AnnotationBo(AnnotationKey.SQL_BINDVALUE.getCode(), bindValue);
annotationBoList.add(bindValueAnnotation);
}
}
});
}
Aggregations