diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java index 88e653627..3962173b1 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java @@ -1,15 +1,16 @@ package com.nhn.pinpoint.bootstrap.config; -import java.io.*; -import java.util.*; -import java.util.logging.Level; -import java.util.logging.Logger; - +import com.nhn.pinpoint.bootstrap.util.NumberUtils; import com.nhn.pinpoint.bootstrap.util.spring.PropertyPlaceholderHelper; import com.nhn.pinpoint.common.ServiceType; -import com.nhn.pinpoint.bootstrap.util.NumberUtils; import com.nhn.pinpoint.common.util.PropertyUtils; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * @author emeroad * @author netspider @@ -26,6 +27,7 @@ public class ProfilerConfig { private static class BypassResolver implements ValueResolver { public static final ValueResolver RESOLVER = new BypassResolver(); + @Override public String resolve(String value, Properties properties) { return value; @@ -41,19 +43,19 @@ public class ProfilerConfig { return propertyPlaceholderHelper.replacePlaceholders(value, properties); } } - - public static ProfilerConfig load(String pinpiontConfigFileName) throws IOException { + + public static ProfilerConfig load(String pinpointConfigFileName) throws IOException { try { - Properties properties = PropertyUtils.loadProperty(pinpiontConfigFileName); + Properties properties = PropertyUtils.loadProperty(pinpointConfigFileName); return new ProfilerConfig(properties); } catch (FileNotFoundException fe) { if (logger.isLoggable(Level.WARNING)) { - logger.log(Level.WARNING, pinpiontConfigFileName + " file is not exists. Please check configuration."); + logger.log(Level.WARNING, pinpointConfigFileName + " file is not exists. Please check configuration."); } throw fe; } catch (IOException e) { if (logger.isLoggable(Level.WARNING)) { - logger.log(Level.WARNING, pinpiontConfigFileName + " file read error. Cause:" + e.getMessage(), e); + logger.log(Level.WARNING, pinpointConfigFileName + " file read error. Cause:" + e.getMessage(), e); } throw e; } @@ -81,46 +83,46 @@ public class ProfilerConfig { private int statDataSenderChunkSize = 1024 * 16; private boolean tcpDataSenderCommandAcceptEnable = false; - + private int jdbcSqlCacheSize = 1024; private int jdbcMaxSqlBindValueSize = 1024; - private boolean jdbcProfile = true; + private boolean jdbcProfile = true; - private boolean jdbcProfileMySql = true; + private boolean jdbcProfileMySql = true; private boolean jdbcProfileMySqlSetAutoCommit = false; private boolean jdbcProfileMySqlCommit = false; private boolean jdbcProfileMySqlRollback = false; - private boolean jdbcProfileJtds = true; + private boolean jdbcProfileJtds = true; private boolean jdbcProfileJtdsSetAutoCommit = false; private boolean jdbcProfileJtdsCommit = false; private boolean jdbcProfileJtdsRollback = false; - private boolean jdbcProfileOracle = true; + private boolean jdbcProfileOracle = true; private boolean jdbcProfileOracleSetAutoCommit = false; private boolean jdbcProfileOracleCommit = false; private boolean jdbcProfileOracleRollback = false; - private boolean jdbcProfileCubrid = true; + private boolean jdbcProfileCubrid = true; private boolean jdbcProfileCubridSetAutoCommit = false; private boolean jdbcProfileCubridCommit = false; private boolean jdbcProfileCubridRollback = false; - private boolean jdbcProfileDbcp = true; + private boolean jdbcProfileDbcp = true; private boolean jdbcProfileDbcpConnectionClose = false; - private boolean tomcatHidePinpointHeader = true; - private Filter tomcatExcludeUrlFilter = new SkipFilter(); + private boolean tomcatHidePinpointHeader = true; + private Filter tomcatExcludeUrlFilter = new SkipFilter(); private boolean ibatis = true; - + private boolean mybatis = true; private boolean redis = true; private boolean redisPipeline = true; private boolean nbaseArc = true; private boolean nbaseArcPipeline = true; - + /** * apache http client */ @@ -131,12 +133,12 @@ public class ProfilerConfig { private boolean apacheHttpClient4ProfileEntity = false; private DumpType apacheHttpClient4ProfileEntityDumpType = DumpType.EXCEPTION; private int apacheHttpClient4ProfileEntitySamplingRate = 1; - + /** * apache nio http client */ private boolean apacheNIOHttpClient4Profile = true; - + /** * ning async http client */ @@ -170,30 +172,33 @@ public class ProfilerConfig { private int samplingRate = 1; // span buffering에 대한 설정. - private boolean ioBufferingEnable; - private int ioBufferingBufferSize; + private boolean ioBufferingEnable; + private int ioBufferingBufferSize; - private int profileJvmCollectInterval; - - private Filter profilableClassFilter = new SkipFilter(); + private int profileJvmCollectInterval; - private final long DEFAULT_AGENT_INFO_SEND_RETRY_INTERVAL = 5*60*1000L; - private long agentInfoSendRetryInterval = DEFAULT_AGENT_INFO_SEND_RETRY_INTERVAL; + private Filter profilableClassFilter = new SkipFilter(); - private ServiceType applicationServerType; - - public ProfilerConfig() { - this.properties = new Properties(); - } + private final long DEFAULT_AGENT_INFO_SEND_RETRY_INTERVAL = 5 * 60 * 1000L; + private long agentInfoSendRetryInterval = DEFAULT_AGENT_INFO_SEND_RETRY_INTERVAL; + + private ServiceType applicationServerType; + + public ProfilerConfig() { + this.properties = new Properties(); + } public ProfilerConfig(Properties properties) { + if (properties == null) { + throw new NullPointerException("properties must not be null"); + } this.properties = properties; readPropertyValues(); - } + } public String getCollectorSpanServerIp() { - return collectorSpanServerIp; - } + return collectorSpanServerIp; + } public int getCollectorSpanServerPort() { return collectorSpanServerPort; @@ -204,8 +209,8 @@ public class ProfilerConfig { } public int getCollectorStatServerPort() { - return collectorStatServerPort; - } + return collectorStatServerPort; + } public String getCollectorTcpServerIp() { return collectorTcpServerIp; @@ -234,9 +239,9 @@ public class ProfilerConfig { public int getSpanDataSenderSocketSendBufferSize() { return spanDataSenderSocketSendBufferSize; } - + public boolean isTcpDataSenderCommandAcceptEnable() { - return tcpDataSenderCommandAcceptEnable; + return tcpDataSenderCommandAcceptEnable; } public int getSpanDataSenderSocketTimeout() { @@ -252,12 +257,12 @@ public class ProfilerConfig { } public boolean isProfileEnable() { - return profileEnable; - } + return profileEnable; + } - public boolean isJdbcProfile() { - return jdbcProfile; - } + public boolean isJdbcProfile() { + return jdbcProfile; + } public int getJdbcSqlCacheSize() { return jdbcSqlCacheSize; @@ -268,9 +273,9 @@ public class ProfilerConfig { } // mysql start ----------------------------------------------------- - public boolean isJdbcProfileMySql() { - return jdbcProfileMySql; - } + public boolean isJdbcProfileMySql() { + return jdbcProfileMySql; + } public boolean isJdbcProfileMySqlSetAutoCommit() { return jdbcProfileMySqlSetAutoCommit; @@ -286,8 +291,8 @@ public class ProfilerConfig { // mysql end----------------------------------------------------- public boolean isJdbcProfileJtds() { - return jdbcProfileJtds; - } + return jdbcProfileJtds; + } public boolean isJdbcProfileJtdsSetAutoCommit() { return jdbcProfileJtdsSetAutoCommit; @@ -302,9 +307,9 @@ public class ProfilerConfig { } // oracle start ----------------------------------------------------- - public boolean isJdbcProfileOracle() { - return jdbcProfileOracle; - } + public boolean isJdbcProfileOracle() { + return jdbcProfileOracle; + } public boolean isJdbcProfileOracleSetAutoCommit() { return jdbcProfileOracleSetAutoCommit; @@ -321,8 +326,8 @@ public class ProfilerConfig { // cubrid start ----------------------------------------------------- public boolean isJdbcProfileCubrid() { - return jdbcProfileCubrid; - } + return jdbcProfileCubrid; + } public boolean isJdbcProfileCubridSetAutoCommit() { return jdbcProfileCubridSetAutoCommit; @@ -347,20 +352,20 @@ public class ProfilerConfig { } public boolean isIoBufferingEnable() { - return ioBufferingEnable; - } + return ioBufferingEnable; + } - public int getIoBufferingBufferSize() { - return ioBufferingBufferSize; - } + public int getIoBufferingBufferSize() { + return ioBufferingBufferSize; + } - public int getProfileJvmCollectInterval() { - return profileJvmCollectInterval; - } - - public long getAgentInfoSendRetryInterval() { - return agentInfoSendRetryInterval; - } + public int getProfileJvmCollectInterval() { + return profileJvmCollectInterval; + } + + public long getAgentInfoSendRetryInterval() { + return agentInfoSendRetryInterval; + } public boolean isJdbcProfileDbcp() { return jdbcProfileDbcp; @@ -370,13 +375,13 @@ public class ProfilerConfig { return jdbcProfileDbcpConnectionClose; } - public boolean isTomcatHidePinpointHeader() { - return tomcatHidePinpointHeader; - } + public boolean isTomcatHidePinpointHeader() { + return tomcatHidePinpointHeader; + } - public Filter getTomcatExcludeUrlFilter() { - return tomcatExcludeUrlFilter; - } + public Filter getTomcatExcludeUrlFilter() { + return tomcatExcludeUrlFilter; + } //----------------------------------------- // http apache client @@ -412,70 +417,70 @@ public class ProfilerConfig { //----------------------------------------- // org/apache/http/impl/nio/* public boolean getApacheNIOHttpClient4Profile() { - return apacheNIOHttpClient4Profile; + return apacheNIOHttpClient4Profile; } - + //----------------------------------------- // com/ning/http/client/AsyncHttpClient - public boolean isNingAsyncHttpClientProfile() { - return ningAsyncHttpClientProfile; - } + public boolean isNingAsyncHttpClientProfile() { + return ningAsyncHttpClientProfile; + } - public boolean isNingAsyncHttpClientProfileCookie() { - return ningAsyncHttpClientProfileCookie; - } + public boolean isNingAsyncHttpClientProfileCookie() { + return ningAsyncHttpClientProfileCookie; + } - public DumpType getNingAsyncHttpClientProfileCookieDumpType() { - return ningAsyncHttpClientProfileCookieDumpType; - } - - public int getNingAsyncHttpClientProfileCookieDumpSize() { - return ningAsyncHttpClientProfileCookieDumpSize; - } + public DumpType getNingAsyncHttpClientProfileCookieDumpType() { + return ningAsyncHttpClientProfileCookieDumpType; + } - public int getNingAsyncHttpClientProfileCookieSamplingRate() { - return ningAsyncHttpClientProfileCookieSamplingRate; - } + public int getNingAsyncHttpClientProfileCookieDumpSize() { + return ningAsyncHttpClientProfileCookieDumpSize; + } - public boolean isNingAsyncHttpClientProfileEntity() { - return ningAsyncHttpClientProfileEntity; - } + public int getNingAsyncHttpClientProfileCookieSamplingRate() { + return ningAsyncHttpClientProfileCookieSamplingRate; + } - public DumpType getNingAsyncHttpClientProfileEntityDumpType() { - return ningAsyncHttpClientProfileEntityDumpType; - } - - public int getNingAsyncHttpClientProfileEntityDumpSize() { - return ningAsyncHttpClientProfileEntityDumpSize; - } + public boolean isNingAsyncHttpClientProfileEntity() { + return ningAsyncHttpClientProfileEntity; + } + + public DumpType getNingAsyncHttpClientProfileEntityDumpType() { + return ningAsyncHttpClientProfileEntityDumpType; + } + + public int getNingAsyncHttpClientProfileEntityDumpSize() { + return ningAsyncHttpClientProfileEntityDumpSize; + } + + public int getNingAsyncHttpClientProfileEntitySamplingRate() { + return ningAsyncHttpClientProfileEntitySamplingRate; + } + + public boolean isNingAsyncHttpClientProfileParam() { + return ningAsyncHttpClientProfileParam; + } + + public DumpType getNingAsyncHttpClientProfileParamDumpType() { + return ningAsyncHttpClientProfileParamDumpType; + } + + public int getNingAsyncHttpClientProfileParamDumpSize() { + return ningAsyncHttpClientProfileParamDumpSize; + } + + public int getNingAsyncHttpClientProfileParamSamplingRate() { + return ningAsyncHttpClientProfileParamSamplingRate; + } - public int getNingAsyncHttpClientProfileEntitySamplingRate() { - return ningAsyncHttpClientProfileEntitySamplingRate; - } - - public boolean isNingAsyncHttpClientProfileParam() { - return ningAsyncHttpClientProfileParam; - } - - public DumpType getNingAsyncHttpClientProfileParamDumpType() { - return ningAsyncHttpClientProfileParamDumpType; - } - - public int getNingAsyncHttpClientProfileParamDumpSize() { - return ningAsyncHttpClientProfileParamDumpSize; - } - - public int getNingAsyncHttpClientProfileParamSamplingRate() { - return ningAsyncHttpClientProfileParamSamplingRate; - } - public int getLineGameNettyParamDumpSize() { - return lineGameNettyParamDumpSize; - } + return lineGameNettyParamDumpSize; + } - public int getLineGameNettyEntityDumpSize() { - return lineGameNettyEntityDumpSize; - } + public int getLineGameNettyEntityDumpSize() { + return lineGameNettyEntityDumpSize; + } public boolean isSpringBeansEnabled() { return springBeans; @@ -492,39 +497,39 @@ public class ProfilerConfig { public String getSpringBeansAnnotations() { return springBeansAnnotations; } - - public boolean isIBatisEnabled() { - return ibatis; - } - - public boolean isMyBatisEnabled() { - return mybatis; - } - public boolean isRedisEnabled() { - return redis; - } - - public boolean isRedisPipelineEnabled() { - return redisPipeline; - } - - public boolean isNbaseArcEnabled() { - return nbaseArc; - } - - public boolean isNbaseArcPipelineEnabled() { - return nbaseArcPipeline; - } - - + public boolean isIBatisEnabled() { + return ibatis; + } + + public boolean isMyBatisEnabled() { + return mybatis; + } + + public boolean isRedisEnabled() { + return redis; + } + + public boolean isRedisPipelineEnabled() { + return redisPipeline; + } + + public boolean isNbaseArcEnabled() { + return nbaseArc; + } + + public boolean isNbaseArcPipelineEnabled() { + return nbaseArcPipeline; + } + + public Filter getProfilableClassFilter() { - return profilableClassFilter; + return profilableClassFilter; + } + + public ServiceType getApplicationServerType() { + return applicationServerType; } - - public ServiceType getApplicationServerType() { - return applicationServerType; - } public void setApplicationServerType(ServiceType applicationServerType) { this.applicationServerType = applicationServerType; @@ -559,49 +564,49 @@ public class ProfilerConfig { this.tcpDataSenderCommandAcceptEnable = readBoolean("profiler.tcpdatasender.command.accept.enable", false); - // JDBC - this.jdbcProfile = readBoolean("profiler.jdbc", true); + // JDBC + this.jdbcProfile = readBoolean("profiler.jdbc", true); this.jdbcSqlCacheSize = readInt("profiler.jdbc.sqlcachesize", 1024); this.jdbcMaxSqlBindValueSize = readInt("profiler.jdbc.maxsqlbindvaluesize", 1024); - this.jdbcProfileMySql = readBoolean("profiler.jdbc.mysql", true); + this.jdbcProfileMySql = readBoolean("profiler.jdbc.mysql", true); this.jdbcProfileMySqlSetAutoCommit = readBoolean("profiler.jdbc.mysql.setautocommit", false); this.jdbcProfileMySqlCommit = readBoolean("profiler.jdbc.mysql.commit", false); this.jdbcProfileMySqlRollback = readBoolean("profiler.jdbc.mysql.rollback", false); - this.jdbcProfileJtds = readBoolean("profiler.jdbc.jtds", true); + this.jdbcProfileJtds = readBoolean("profiler.jdbc.jtds", true); this.jdbcProfileJtdsSetAutoCommit = readBoolean("profiler.jdbc.jtds.setautocommit", false); this.jdbcProfileJtdsCommit = readBoolean("profiler.jdbc.jtds.commit", false); this.jdbcProfileJtdsRollback = readBoolean("profiler.jdbc.jtds.rollback", false); - this.jdbcProfileOracle = readBoolean("profiler.jdbc.oracle", true); + this.jdbcProfileOracle = readBoolean("profiler.jdbc.oracle", true); this.jdbcProfileOracleSetAutoCommit = readBoolean("profiler.jdbc.oracle.setautocommit", false); this.jdbcProfileOracleCommit = readBoolean("profiler.jdbc.oracle.commit", false); this.jdbcProfileOracleRollback = readBoolean("profiler.jdbc.oracle.rollback", false); - this.jdbcProfileCubrid = readBoolean("profiler.jdbc.cubrid", true); + this.jdbcProfileCubrid = readBoolean("profiler.jdbc.cubrid", true); this.jdbcProfileCubridSetAutoCommit = readBoolean("profiler.jdbc.cubrid.setautocommit", false); this.jdbcProfileCubridCommit = readBoolean("profiler.jdbc.cubrid.commit", false); this.jdbcProfileCubridRollback = readBoolean("profiler.jdbc.cubrid.rollback", false); - this.jdbcProfileDbcp = readBoolean("profiler.jdbc.dbcp", true); + this.jdbcProfileDbcp = readBoolean("profiler.jdbc.dbcp", true); this.jdbcProfileDbcpConnectionClose = readBoolean("profiler.jdbc.dbcp.connectionclose", false); - this.tomcatHidePinpointHeader = readBoolean("profiler.tomcat.hidepinpointheader", true); - final String tomcatExcludeURL = readString("profiler.tomcat.excludeurl", ""); - if (!tomcatExcludeURL.isEmpty()) { - this.tomcatExcludeUrlFilter = new ExcludeUrlFilter(tomcatExcludeURL); - } + this.tomcatHidePinpointHeader = readBoolean("profiler.tomcat.hidepinpointheader", true); + final String tomcatExcludeURL = readString("profiler.tomcat.excludeurl", ""); + if (!tomcatExcludeURL.isEmpty()) { + this.tomcatExcludeUrlFilter = new ExcludeUrlFilter(tomcatExcludeURL); + } - /** - * apache http client 4 - */ + /** + * apache http client 4 + */ this.apacheHttpClient4Profile = readBoolean("profiler.apache.httpclient4", true); this.apacheHttpClient4ProfileCookie = readBoolean("profiler.apache.httpclient4.cookie", false); this.apacheHttpClient4ProfileCookieDumpType = readDumpType("profiler.apache.httpclient4.cookie.dumptype", DumpType.EXCEPTION); @@ -615,7 +620,7 @@ public class ProfilerConfig { * apache nio http client */ this.apacheNIOHttpClient4Profile = readBoolean("profiler.apache.nio.httpclient4", true); - + /** * ning.async http client */ @@ -624,7 +629,7 @@ public class ProfilerConfig { this.ningAsyncHttpClientProfileCookieDumpType = readDumpType("profiler.ning.asynchttpclient.cookie.dumptype", DumpType.EXCEPTION); this.ningAsyncHttpClientProfileCookieDumpSize = readInt("profiler.ning.asynchttpclient.cookie.dumpsize", 1024); this.ningAsyncHttpClientProfileCookieSamplingRate = readInt("profiler.ning.asynchttpclient.cookie.sampling.rate", 1); - + this.ningAsyncHttpClientProfileEntity = readBoolean("profiler.ning.asynchttpclient.entity", false); this.ningAsyncHttpClientProfileEntityDumpType = readDumpType("profiler.ning.asynchttpclient.entity.dumptype", DumpType.EXCEPTION); this.ningAsyncHttpClientProfileEntityDumpSize = readInt("profiler.ning.asynchttpclient.entity.dumpsize", 1024); @@ -640,15 +645,15 @@ public class ProfilerConfig { this.redisPipeline = readBoolean("profiler.redis.pipeline", true); this.nbaseArc = readBoolean("profiler.nbase_arc", true); this.nbaseArcPipeline = readBoolean("profiler.nbase_arc.pipeline", true); - + // // FIXME 임시용, line game netty configuration // this.lineGameNettyParamDumpSize = readInt("profiler.line.game.netty.param.dumpsize", 512); this.lineGameNettyEntityDumpSize = readInt("profiler.line.game.netty.entity.dumpsize", 512); - + this.ibatis = readBoolean("profiler.orm.ibatis", true); - + this.mybatis = readBoolean("profiler.orm.mybatis", true); this.springBeans = readBoolean("profiler.spring.beans", false); @@ -658,31 +663,31 @@ public class ProfilerConfig { this.samplingEnable = readBoolean("profiler.sampling.enable", true); this.samplingRate = readInt("profiler.sampling.rate", 1); - - // 샘플링 + io 조절 bufferSize 결정 - this.ioBufferingEnable = readBoolean("profiler.io.buffering.enable", true); + + // 샘플링 + io 조절 bufferSize 결정 + this.ioBufferingEnable = readBoolean("profiler.io.buffering.enable", true); // 버퍼 사이즈는 여기에 있는것은 문제가 있는것도 같음. 설정 조정의 필요성이 있음. - this.ioBufferingBufferSize = readInt("profiler.io.buffering.buffersize", 20); + this.ioBufferingBufferSize = readInt("profiler.io.buffering.buffersize", 20); - // JVM - this.profileJvmCollectInterval = readInt("profiler.jvm.collect.interval", 1000); + // JVM + this.profileJvmCollectInterval = readInt("profiler.jvm.collect.interval", 1000); - this.agentInfoSendRetryInterval = readLong("profiler.agentInfo.send.retry.interval", DEFAULT_AGENT_INFO_SEND_RETRY_INTERVAL); - - // service type - this.applicationServerType = readServiceType("profiler.applicationservertype"); - - // profile package include - // TODO 제거, 서비스 적용에 call stack view가 잘 보이는지 테스트하려고 추가함. - // 수집 데이터 크기 문제로 실 서비스에서는 사용 안함. - // 나중에 필요에 따라 정규식으로 바꿔도 되고... - final String profileableClass = readString("profiler.include", ""); - if (!profileableClass.isEmpty()) { - this.profilableClassFilter = new ProfilableClassFilter(profileableClass); - } + this.agentInfoSendRetryInterval = readLong("profiler.agentInfo.send.retry.interval", DEFAULT_AGENT_INFO_SEND_RETRY_INTERVAL); + + // service type + this.applicationServerType = readServiceType("profiler.applicationservertype"); + + // profile package include + // TODO 제거, 서비스 적용에 call stack view가 잘 보이는지 테스트하려고 추가함. + // 수집 데이터 크기 문제로 실 서비스에서는 사용 안함. + // 나중에 필요에 따라 정규식으로 바꿔도 되고... + final String profileableClass = readString("profiler.include", ""); + if (!profileableClass.isEmpty()) { + this.profilableClassFilter = new ProfilableClassFilter(profileableClass); + } logger.info("configuration loaded successfully."); - } + } public String readString(String propertyName, String defaultValue) { @@ -702,15 +707,15 @@ public class ProfilerConfig { } public int readInt(String propertyName, int defaultValue) { - String value = properties.getProperty(propertyName); - int result = NumberUtils.parseInteger(value, defaultValue); - if (logger.isLoggable(Level.INFO)) { - logger.info(propertyName + "=" + result); - } - return result; - } + String value = properties.getProperty(propertyName); + int result = NumberUtils.parseInteger(value, defaultValue); + if (logger.isLoggable(Level.INFO)) { + logger.info(propertyName + "=" + result); + } + return result; + } - public DumpType readDumpType(String propertyName, DumpType defaultDump) { + public DumpType readDumpType(String propertyName, DumpType defaultDump) { String propertyValue = properties.getProperty(propertyName); if (propertyValue == null) { propertyValue = defaultDump.name(); @@ -729,25 +734,25 @@ public class ProfilerConfig { } public long readLong(String propertyName, long defaultValue) { - String value = properties.getProperty(propertyName); - long result = NumberUtils.parseLong(value, defaultValue); - if (logger.isLoggable(Level.INFO)) { - logger.info(propertyName + "=" + result); - } - return result; - } - - public ServiceType readServiceType(String propertyName) { - String value = properties.getProperty(propertyName); + String value = properties.getProperty(propertyName); + long result = NumberUtils.parseLong(value, defaultValue); + if (logger.isLoggable(Level.INFO)) { + logger.info(propertyName + "=" + result); + } + return result; + } + + public ServiceType readServiceType(String propertyName) { + String value = properties.getProperty(propertyName); if (value == null) { return null; } - ServiceType serviceType = getServiceType(value); - if (logger.isLoggable(Level.INFO)) { - logger.info(propertyName + "=" + serviceType); - } - return serviceType; - } + ServiceType serviceType = getServiceType(value); + if (logger.isLoggable(Level.INFO)) { + logger.info(propertyName + "=" + serviceType); + } + return serviceType; + } public ServiceType getServiceType(String defaultValue) { try { @@ -759,13 +764,13 @@ public class ProfilerConfig { } public boolean readBoolean(String propertyName, boolean defaultValue) { - String value = properties.getProperty(propertyName, Boolean.toString(defaultValue)); - boolean result = Boolean.parseBoolean(value); - if (logger.isLoggable(Level.INFO)) { - logger.info(propertyName + "=" + result); - } - return result; - } + String value = properties.getProperty(propertyName, Boolean.toString(defaultValue)); + boolean result = Boolean.parseBoolean(value); + if (logger.isLoggable(Level.INFO)) { + logger.info(propertyName + "=" + result); + } + return result; + } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformation.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformation.java index ee7043202..2c3cba953 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformation.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInformation.java @@ -1,5 +1,7 @@ package com.nhn.pinpoint.profiler; +import com.nhn.pinpoint.common.ServiceType; + import java.util.HashMap; import java.util.Map; @@ -16,6 +18,7 @@ public class AgentInformation { private final String machineName; private final String hostIp; private final short serverType; + private final ServiceType serverServiceType; private final String version; public AgentInformation(String agentId, String applicationName, long startTime, int pid, String machineName, String hostIp, short serverType, String version) { @@ -38,6 +41,7 @@ public class AgentInformation { this.machineName = machineName; this.hostIp = hostIp; this.serverType = serverType; + this.serverServiceType = ServiceType.findServiceType(serverType); this.version = version; } @@ -71,6 +75,10 @@ public class AgentInformation { return serverType; } + public ServiceType getServerServiceType() { + return serverServiceType; + } + public String getVersion() { return version; } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContext.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContext.java index a150ef8bf..3f3c6ab91 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContext.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContext.java @@ -113,12 +113,14 @@ public class DefaultTraceContext implements TraceContext { @Override public Trace disableSampling() { - return null; -// TODO STATDISABLE 통계 코드 일단 제거 -// return traceFactory.disableSampling(); + // return null; is bug. #93 + return traceFactory.disableSampling(); } public void setProfilerConfig(final ProfilerConfig profilerConfig) { + if (profilerConfig == null) { + throw new NullPointerException("profilerConfig must not be null"); + } this.profilerConfig = profilerConfig; } @@ -174,7 +176,7 @@ public class DefaultTraceContext implements TraceContext { @Override public String getServerType() { - return ServiceType.findServiceType(this.agentInformation.getServerType()).getDesc(); + return this.agentInformation.getServerServiceType().getDesc(); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ThreadLocalTraceFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ThreadLocalTraceFactory.java index a10a4e90c..382b91782 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ThreadLocalTraceFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/ThreadLocalTraceFactory.java @@ -94,7 +94,7 @@ public class ThreadLocalTraceFactory implements TraceFactory { threadLocal.set(metricTrace); // return metricTrace; // TODO STATDISABLE 잠시 통계기능을 disable시키기 위해서 null리턴 - return null; + return metricTrace; } // remote 에서 샘플링 대상으로 선정된 경우. diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/linegame/interceptor/InvokeTaskRunInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/linegame/interceptor/InvokeTaskRunInterceptor.java index 3367debf7..04080c5e3 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/linegame/interceptor/InvokeTaskRunInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/linegame/interceptor/InvokeTaskRunInterceptor.java @@ -133,7 +133,8 @@ public class InvokeTaskRunInterceptor extends SpanSimpleAroundInterceptor implem // 한다. // sampling 대상이 아닐경우 rpc 호출에서 sampling 대상이 아닌 것에 rpc호출 파라미터에 // sampling disable 파라미터를 박을수 있다. - final Trace trace = getTraceContext().disableSampling(); + final TraceContext traceContext = getTraceContext(); + final Trace trace = traceContext.disableSampling(); if (isDebug) { String requestURL = request.getUri(); String remoteAddr = getRemoteAddress(channel); @@ -146,7 +147,8 @@ public class InvokeTaskRunInterceptor extends SpanSimpleAroundInterceptor implem if (traceId != null) { // TODO remote에서 sampling flag로 마크가되는 대상으로 왔을 경우도 추가로 샘플링 칠수 있어야 // 할것으로 보임. - final Trace trace = getTraceContext().continueTraceObject(traceId); + final TraceContext traceContext = getTraceContext(); + final Trace trace = traceContext.continueTraceObject(traceId); if (trace.canSampled()) { if (isDebug) { String requestURL = request.getUri(); @@ -164,7 +166,8 @@ public class InvokeTaskRunInterceptor extends SpanSimpleAroundInterceptor implem return trace; } } else { - final Trace trace = getTraceContext().newTraceObject(); + TraceContext traceContext = getTraceContext(); + final Trace trace = traceContext.newTraceObject(); if (trace.canSampled()) { if (isDebug) { String requestURL = request.getUri(); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java index f4bd9e0b5..5d7674488 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/tomcat/interceptor/StandardHostValveInvokeInterceptor.java @@ -55,19 +55,20 @@ public class StandardHostValveInvokeInterceptor extends SpanSimpleAroundIntercep @Override protected Trace createTrace(Object target, Object[] args) { final HttpServletRequest request = (HttpServletRequest) args[0]; - final String requestURI = request.getRequestURI(); - if (excludeUrlFilter.filter(requestURI)) { - if (isTrace) { - logger.trace("filter requestURI:{}", requestURI); - } - return null; - } + final String requestURI = request.getRequestURI(); + if (excludeUrlFilter.filter(requestURI)) { + if (isTrace) { + logger.trace("filter requestURI:{}", requestURI); + } + return null; + } // remote call에 sampling flag가 설정되어있을 경우는 샘플링 대상으로 삼지 않는다. final boolean sampling = samplingEnable(request); if (!sampling) { // 샘플링 대상이 아닐 경우도 TraceObject를 생성하여, sampling 대상이 아니라는것을 명시해야 한다. // sampling 대상이 아닐경우 rpc 호출에서 sampling 대상이 아닌 것에 rpc호출 파라미터에 sampling disable 파라미터를 박을수 있다. - final Trace trace = getTraceContext().disableSampling(); + final TraceContext traceContext = getTraceContext(); + final Trace trace = traceContext.disableSampling(); if (isDebug) { logger.debug("remotecall sampling flag found. skip trace requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr()); } @@ -78,7 +79,8 @@ public class StandardHostValveInvokeInterceptor extends SpanSimpleAroundIntercep final TraceId traceId = populateTraceIdFromRequest(request); if (traceId != null) { // TODO remote에서 sampling flag로 마크가되는 대상으로 왔을 경우도 추가로 샘플링 칠수 있어야 할것으로 보임. - final Trace trace = getTraceContext().continueTraceObject(traceId); + final TraceContext traceContext = getTraceContext(); + final Trace trace = traceContext.continueTraceObject(traceId); // 서버 맵을 통계정보에서 조회하려면 remote로 호출되는 WAS의 관계를 알아야해서 부모의 application name을 전달받음. if (trace.canSampled()) { @@ -92,7 +94,8 @@ public class StandardHostValveInvokeInterceptor extends SpanSimpleAroundIntercep } return trace; } else { - final Trace trace = getTraceContext().newTraceObject(); + final TraceContext traceContext = getTraceContext(); + final Trace trace = traceContext.newTraceObject(); if (trace.canSampled()) { if (isDebug) { logger.debug("TraceID not exist. start new trace. requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr()); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContextTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContextTest.java index e4c9f3fd8..8e94f430e 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContextTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceContextTest.java @@ -1,8 +1,13 @@ package com.nhn.pinpoint.profiler.context; +import com.nhn.pinpoint.bootstrap.context.Trace; import com.nhn.pinpoint.bootstrap.context.TraceId; +import com.nhn.pinpoint.common.ServiceType; +import com.nhn.pinpoint.common.Version; import com.nhn.pinpoint.common.util.TransactionId; import com.nhn.pinpoint.common.util.TransactionIdUtils; +import com.nhn.pinpoint.profiler.AgentInformation; +import com.nhn.pinpoint.profiler.util.RuntimeMXBeanUtils; import junit.framework.Assert; import org.junit.Test; import org.slf4j.Logger; @@ -31,4 +36,35 @@ public class DefaultTraceContextTest { Assert.assertEquals(transactionid.getTransactionSequence(), agentTransactionCount); } + + @Test + public void disableTrace() { + DefaultTraceContext traceContext = new DefaultTraceContext(); + Trace trace = traceContext.disableSampling(); + Assert.assertNotNull(trace); + Assert.assertFalse(trace.canSampled()); + + traceContext.detachTraceObject(); + + } + + @Test + public void threadLocalBindTest() { + AgentInformation agentInformation = new AgentInformation("d", "d", System.currentTimeMillis(), 123, "machineName", "127.0.0.1", ServiceType.TEST_STAND_ALONE.getCode(), Version.VERSION); + + DefaultTraceContext traceContext1 = new DefaultTraceContext(); + traceContext1.setAgentInformation(agentInformation); + Assert.assertNotNull(traceContext1.newTraceObject()); + + DefaultTraceContext traceContext2 = new DefaultTraceContext(); + traceContext2.setAgentInformation(agentInformation); + Trace notExist = traceContext2.currentRawTraceObject(); + Assert.assertNull(notExist); + + Assert.assertNotNull(traceContext1.currentRawTraceObject()); + traceContext1.detachTraceObject(); + Assert.assertNull(traceContext1.currentRawTraceObject()); + + + } } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java index a95087c34..cfb632d5b 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java @@ -26,7 +26,7 @@ public class TraceTest { @Test public void trace() { DefaultTraceId traceID = new DefaultTraceId("agent", 0, 1); - DefaultTraceContext defaultTraceConetxt = getDefaultTraceConetxt(); + DefaultTraceContext defaultTraceConetxt = getDefaultTraceContext(); DefaultTrace trace = new DefaultTrace(defaultTraceConetxt , traceID); trace.setStorage(new SpanStorage(LoggingDataSender.DEFAULT_LOGGING_DATA_SENDER)); trace.traceBlockBegin(); @@ -50,7 +50,7 @@ public class TraceTest { @Test public void popEventTest() { DefaultTraceId traceID = new DefaultTraceId("agent", 0, 1); - DefaultTraceContext defaultTraceConetxt = getDefaultTraceConetxt(); + DefaultTraceContext defaultTraceConetxt = getDefaultTraceContext(); DefaultTrace trace = new DefaultTrace(defaultTraceConetxt, traceID); TestDataSender dataSender = new TestDataSender(); trace.setStorage(new SpanStorage(LoggingDataSender.DEFAULT_LOGGING_DATA_SENDER)); @@ -63,7 +63,7 @@ public class TraceTest { logger.info(String.valueOf(dataSender.event)); } - private DefaultTraceContext getDefaultTraceConetxt() { + private DefaultTraceContext getDefaultTraceContext() { DefaultTraceContext defaultTraceContext = new DefaultTraceContext(); defaultTraceContext.setAgentInformation(new AgentInformation("agentId", "applicationName", System.currentTimeMillis(), 10, "test", "127.0.0.1", ServiceType.TOMCAT.getCode(), Version.VERSION)); return defaultTraceContext;