Skip to content

Commit

Permalink
[#11310] Abbreviate sql in sql metadata if sql is too long
Browse files Browse the repository at this point in the history
  • Loading branch information
kojandy committed Aug 5, 2024
1 parent 1b56061 commit 7467ee7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class CollectorProperties {
@Value("${collector.statistics.agent-state.enable:false}")
private boolean statisticsAgentStateEnable;

@Value("${collector.metadata.sql.max-length:65536}")
private int maxSqlLength;


public List<String> getL4IpList() {
return List.of(l4IpList);
Expand Down Expand Up @@ -129,6 +132,10 @@ public boolean isStatisticsAgentStateEnable() {
return statisticsAgentStateEnable;
}

public int getMaxSqlLength() {
return maxSqlLength;
}

@PostConstruct
public void log() {
logger.info("{}", this);
Expand All @@ -138,15 +145,18 @@ public void log() {

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("CollectorConfiguration{");
sb.append(", l4IpList=").append(Arrays.toString(l4IpList));
sb.append(", metricJmxEnable=").append(metricJmxEnable);
sb.append(", metricJmxDomainName='").append(metricJmxDomainName).append('\'');
sb.append(", spanSamplingEnable=").append(spanSamplingEnable);
sb.append(", spanSamplingType=").append(spanSamplingType);
sb.append(", uriStatEnable=").append(uriStatEnable);
sb.append(", statisticsAgentStateEnable=").append(statisticsAgentStateEnable);
sb.append('}');
return sb.toString();
return "CollectorProperties{" +
"logger=" + logger +
", l4IpList=" + Arrays.toString(l4IpList) +
", metricJmxEnable=" + metricJmxEnable +
", metricJmxDomainName='" + metricJmxDomainName + '\'' +
", spanSamplingEnable=" + spanSamplingEnable +
", spanSamplingType='" + spanSamplingType + '\'' +
", spanModSamplingRate=" + spanModSamplingRate +
", spanPercentSamplingRate='" + spanPercentSamplingRate + '\'' +
", uriStatEnable=" + uriStatEnable +
", statisticsAgentStateEnable=" + statisticsAgentStateEnable +
", maxSqlLength=" + maxSqlLength +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.navercorp.pinpoint.collector.service;

import com.navercorp.pinpoint.collector.config.CollectorProperties;
import com.navercorp.pinpoint.collector.dao.SqlMetaDataDao;
import com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo;
import com.navercorp.pinpoint.common.util.StringUtils;
import jakarta.validation.Valid;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
Expand All @@ -29,12 +31,20 @@
public class HbaseSqlMetaDataService implements SqlMetaDataService {
private final SqlMetaDataDao sqlMetaDataDao;

public HbaseSqlMetaDataService(SqlMetaDataDao sqlMetaDataDao) {
private final int maxSqlLength;

public HbaseSqlMetaDataService(SqlMetaDataDao sqlMetaDataDao, CollectorProperties collectorProperties) {
this.sqlMetaDataDao = Objects.requireNonNull(sqlMetaDataDao, "sqlMetaDataDao");
Objects.requireNonNull(collectorProperties, "collectorProperties");
this.maxSqlLength = collectorProperties.getMaxSqlLength();
}

@Override
public void insert(@Valid final SqlMetaDataBo sqlMetaDataBo) {
public void insert(@Valid SqlMetaDataBo sqlMetaDataBo) {
if (sqlMetaDataBo.getSql().length() > maxSqlLength) {
String sql = StringUtils.abbreviate(sqlMetaDataBo.getSql(), maxSqlLength);
sqlMetaDataBo = new SqlMetaDataBo(sqlMetaDataBo.getAgentId(), sqlMetaDataBo.getAgentStartTime(), sqlMetaDataBo.getId(), sql);
}
this.sqlMetaDataDao.insert(sqlMetaDataBo);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.navercorp.pinpoint.collector.service;

import com.navercorp.pinpoint.collector.config.CollectorProperties;
import com.navercorp.pinpoint.collector.dao.SqlUidMetaDataDao;
import com.navercorp.pinpoint.common.server.bo.SqlUidMetaDataBo;
import com.navercorp.pinpoint.common.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;
Expand All @@ -10,12 +12,20 @@
public class HbaseSqlUidMetaDataService implements SqlUidMetaDataService {
private final SqlUidMetaDataDao sqlUidMetaDataDao;

public HbaseSqlUidMetaDataService(SqlUidMetaDataDao sqlUidMetaDataDao) {
private final int maxSqlLength;

public HbaseSqlUidMetaDataService(SqlUidMetaDataDao sqlUidMetaDataDao, CollectorProperties collectorProperties) {
this.sqlUidMetaDataDao = Objects.requireNonNull(sqlUidMetaDataDao, "sqlUidMetaDataDao");
Objects.requireNonNull(collectorProperties, "collectorProperties");
this.maxSqlLength = collectorProperties.getMaxSqlLength();
}

@Override
public void insert(SqlUidMetaDataBo sqlUidMetaDataBo) {
if (sqlUidMetaDataBo.getSql().length() > maxSqlLength) {
String sql = StringUtils.abbreviate(sqlUidMetaDataBo.getSql(), maxSqlLength);
sqlUidMetaDataBo = new SqlUidMetaDataBo(sqlUidMetaDataBo.getAgentId(), sqlUidMetaDataBo.getAgentStartTime(), sqlUidMetaDataBo.getApplicationName(), sqlUidMetaDataBo.getUid(), sql);
}
this.sqlUidMetaDataDao.insert(sqlUidMetaDataBo);
}
}

0 comments on commit 7467ee7

Please sign in to comment.