diff --git a/agent/src/main/resources/profiles/local/log4j.xml b/agent/src/main/resources/profiles/local/log4j.xml
index 91786f0314ee..3caf93fcebbc 100644
--- a/agent/src/main/resources/profiles/local/log4j.xml
+++ b/agent/src/main/resources/profiles/local/log4j.xml
@@ -37,6 +37,11 @@
+
+
+
+
+
diff --git a/agent/src/main/resources/profiles/release/log4j.xml b/agent/src/main/resources/profiles/release/log4j.xml
index 6549d547ea07..8dd71d7ff16b 100644
--- a/agent/src/main/resources/profiles/release/log4j.xml
+++ b/agent/src/main/resources/profiles/release/log4j.xml
@@ -37,6 +37,11 @@
+
+
+
+
+
diff --git a/agent/src/main/resources/profiles/release/pinpoint-env.config b/agent/src/main/resources/profiles/release/pinpoint-env.config
index 25fb02b50b62..cf74a0b72ea2 100644
--- a/agent/src/main/resources/profiles/release/pinpoint-env.config
+++ b/agent/src/main/resources/profiles/release/pinpoint-env.config
@@ -1121,4 +1121,12 @@ profiler.jdk.concurrent.completable-future=true
# which package of runnable(callable) instance can be thread plugin trace
# Set the package name to track
# eg) profiler.thread.match.package=com.company.shopping.cart, com.company.payment
-profiler.thread.match.package=
\ No newline at end of file
+profiler.thread.match.package=
+
+profiler.remote.config.init.enable=true
+profiler.remote.config.addr=127.0.0.1\:8848,127.0.0.2\:8848,127.0.0.3\:8848
+profiler.remote.config.additional.enable=true
+profiler.remote.config.additional.type=2
+profiler.remote.config.additional.type1.gap=86400000
+profiler.remote.config.additional.type2.gap=300000
+profiler.agent.enable=true
\ No newline at end of file
diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java
index 3e52a37b4804..a37be762dbc1 100644
--- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java
+++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java
@@ -46,7 +46,7 @@ public class DefaultProfilerConfig implements ProfilerConfig {
// TestAgent only
public static final String IMPORT_PLUGIN = "profiler.plugin.import-plugin";
- private final Properties properties;
+ private Properties properties;
public static final String INSTRUMENT_ENGINE_ASM = "ASM";
@@ -166,6 +166,11 @@ private static Properties loadProperties(String pinpointConfigFileName) throws I
private boolean customMetricEnable = false;
private int customMetricLimitSize = 10;
+ private boolean remoteEnable = false;
+ private String remoteAddr = "";
+ private String remoteType = "";
+ private long remoteType1Gap;
+ private long remoteType2Gap;
public DefaultProfilerConfig() {
this.properties = new Properties();
@@ -173,6 +178,9 @@ public DefaultProfilerConfig() {
}
public DefaultProfilerConfig(Properties properties) {
+ resetDefaultProfilerConfig(properties);
+ }
+ public void resetDefaultProfilerConfig(Properties properties) {
if (properties == null) {
throw new NullPointerException("properties");
}
@@ -674,6 +682,32 @@ public int getCustomMetricLimitSize() {
return customMetricLimitSize;
}
+ @Override
+ public boolean getRemoteEnable() {
+ return remoteEnable;
+ }
+ @Override
+ public String getRemoteAddr() {
+ return remoteAddr;
+ }
+ @Override
+ public String getRemoteType() {
+ return remoteType;
+ }
+ @Override
+ public long getRemoteType1Gap() {
+ return remoteType1Gap;
+ }
+ @Override
+ public long getRemoteType2Gap() {
+ return remoteType2Gap;
+ }
+
+ @Override
+ public Properties getProperties() {
+ return properties;
+ }
+
// for test
void readPropertyValues() {
@@ -771,9 +805,21 @@ void readPropertyValues() {
this.customMetricEnable = readBoolean("profiler.custommetric.enable", false);
this.customMetricLimitSize = readInt("profiler.custommetric.limit.size", 10);
+ buildAndSetRemoteConfig();
+
logger.info("configuration loaded successfully.");
}
+ private void buildAndSetRemoteConfig(){
+ this.remoteEnable = readBoolean("profiler.remote.config.additional.enable", false);
+ if(this.remoteEnable){
+ this.remoteAddr = readString("profiler.remote.config.addr", "");
+ this.remoteType =readString("profiler.remote.config.additional.type", "1");
+ this.remoteType1Gap =readLong("profiler.remote.config.additional.type1.gap", 86400000);
+ this.remoteType2Gap =readLong("profiler.remote.config.additional.type2.gap", 300000);
+ }
+ }
+
private ThriftTransportConfig readThriftTransportConfig(DefaultProfilerConfig profilerConfig) {
DefaultThriftTransportConfig binaryTransportConfig = new DefaultThriftTransportConfig();
binaryTransportConfig.read(profilerConfig);
@@ -785,7 +831,7 @@ private ThriftTransportConfig readThriftTransportConfig(DefaultProfilerConfig pr
public String readString(String propertyName, String defaultValue) {
return readString(propertyName, defaultValue, BypassResolver.RESOLVER);
}
-
+ @Override
public String readString(String propertyName, String defaultValue, ValueResolver valueResolver) {
if (valueResolver == null) {
throw new NullPointerException("valueResolver");
@@ -840,10 +886,13 @@ public long readLong(String propertyName, long defaultValue) {
@Override
public List readList(String propertyName) {
String value = properties.getProperty(propertyName);
- if (StringUtils.isEmpty(value)) {
+ return readListFromParam(value);
+ }
+ public static List readListFromParam(String param){
+ if (StringUtils.isEmpty(param)) {
return Collections.emptyList();
}
- return StringUtils.tokenizeToStringList(value, ",");
+ return StringUtils.tokenizeToStringList(param, ",");
}
@Override
@@ -876,7 +925,6 @@ public Map readPattern(String propertyNamePatternRegex) {
return result;
}
-
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("DefaultProfilerConfig{");
diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java
index 07d09c2185aa..f0d24e9397fd 100644
--- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java
+++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java
@@ -309,4 +309,10 @@ interface ValueResolver {
String resolve(String value, Properties properties);
}
+ boolean getRemoteEnable();
+ String getRemoteAddr();
+ String getRemoteType();
+ long getRemoteType1Gap();
+ long getRemoteType2Gap();
+ Properties getProperties();
}
diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java
index 3cbe8494a551..5a007d170679 100644
--- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java
+++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolver.java
@@ -27,10 +27,12 @@
public class AgentIdResolver {
public static final String APPLICATION_NAME = "applicationName";
public static final String AGENT_ID = "agentId";
+ public static final String AGENT_LICENCE = "licence";
public static final String SYSTEM_PROPERTY_PREFIX = "pinpoint.";
public static final String APPLICATION_NAME_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "applicationName";
public static final String AGENT_ID_SYSTEM_PROPERTY = SYSTEM_PROPERTY_PREFIX + "agentId";
+ public static final String LICENCE_PROPERTY = SYSTEM_PROPERTY_PREFIX + "licence";
private final BootLogger logger = BootLogger.getLogger(this.getClass().getName());
@@ -55,6 +57,8 @@ public AgentIds resolve() {
touch = true;
}
+ final String licenceName = agentProperty.getLicenceName();
+
if (touch) {
if (StringUtils.isEmpty(agentId)) {
String error = agentProperty.getType() + " agentId is missing";
@@ -66,7 +70,11 @@ public AgentIds resolve() {
logger.warn(error);
return null;
}
- return new AgentIds(agentProperty.getType(), agentId, applicationName);
+ if (StringUtils.isEmpty(licenceName)) {
+ String error = agentProperty.getType() + " licenceName is missing";
+ logger.warn(error);
+ }
+ return new AgentIds(agentProperty.getType(), agentId, applicationName, licenceName);
}
}
diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java
index 09bf72a80e9c..6d51b74f6600 100644
--- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java
+++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIdResolverBuilder.java
@@ -33,7 +33,7 @@ public void addSystemProperties(Properties system) {
Assert.requireNonNull(system, "system");
AgentProperties systemProperties = new AgentProperties(AgentIdSourceType.SYSTEM, system,
- AgentIdResolver.AGENT_ID_SYSTEM_PROPERTY, AgentIdResolver.APPLICATION_NAME_SYSTEM_PROPERTY);
+ AgentIdResolver.AGENT_ID_SYSTEM_PROPERTY, AgentIdResolver.APPLICATION_NAME_SYSTEM_PROPERTY, AgentIdResolver.LICENCE_PROPERTY);
this.agentProperties.add(systemProperties);
}
@@ -41,7 +41,7 @@ public void addAgentArgument(Map agentArguments) {
Assert.requireNonNull(agentArguments, "agentArguments");
AgentProperties agentArgument = new AgentProperties(AgentIdSourceType.AGENT_ARGUMENT, agentArguments,
- AgentIdResolver.AGENT_ID, AgentIdResolver.APPLICATION_NAME);
+ AgentIdResolver.AGENT_ID, AgentIdResolver.APPLICATION_NAME, AgentIdResolver.AGENT_LICENCE);
this.agentProperties.add(agentArgument);
}
diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java
index 91cb7af91630..430f3b101b99 100644
--- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java
+++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentIds.java
@@ -25,11 +25,13 @@ public class AgentIds {
private final String agentId;
private final String applicationName;
private final AgentIdSourceType type;
+ private final String agentLicence;
- public AgentIds(AgentIdSourceType type, String agentId, String applicationName) {
+ public AgentIds(AgentIdSourceType type, String agentId, String applicationName, String agentLicence) {
this.type = Assert.requireNonNull(type, "type");
this.agentId = Assert.requireNonNull(agentId, "agentId");
this.applicationName = Assert.requireNonNull(applicationName, "applicationName");
+ this.agentLicence = agentLicence;
}
public AgentIdSourceType getSourceType() {
@@ -43,4 +45,8 @@ public String getAgentId() {
public String getApplicationName() {
return applicationName;
}
+
+ public String getAgentLicence() {
+ return agentLicence;
+ }
}
diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java
index 77f12c909f6c..7383b549caa6 100644
--- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java
+++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentOption.java
@@ -28,6 +28,8 @@ public interface AgentOption {
Instrumentation getInstrumentation();
+ String getAgentLicence();
+
String getAgentId();
String getApplicationName();
diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java
index 8e42c84421b0..394ccfb1d160 100644
--- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java
+++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/AgentProperties.java
@@ -29,12 +29,20 @@ public class AgentProperties {
private final Properties properties;
private final String agentKey;
private final String applicationNameKey;
+ private final String licenceNameKey;
- public AgentProperties(AgentIdSourceType type, Properties properties, String agentKey, String applicationNameKey) {
+ public AgentProperties(AgentIdSourceType type, Properties properties, String agentKey, String applicationNameKey, String licenceNameKey) {
this.type = Assert.requireNonNull(type, "type");
this.properties = Assert.requireNonNull(properties, "properties");
this.agentKey = Assert.requireNonNull(agentKey, "agentKey");
this.applicationNameKey = Assert.requireNonNull(applicationNameKey, "applicationNameKey");
+ this.licenceNameKey = licenceNameKey;
+ }
+ public AgentProperties(AgentIdSourceType type, Map properties, String agentKey, String applicationNameKey, String licenceNameKey) {
+ this(type, toProperties(properties), agentKey, applicationNameKey, licenceNameKey);
+ }
+ public AgentProperties(AgentIdSourceType type, Properties properties, String agentKey, String applicationNameKey) {
+ this(type, properties, agentKey, applicationNameKey, "");
}
public AgentProperties(AgentIdSourceType type, Map properties, String agentKey, String applicationNameKey) {
@@ -69,6 +77,14 @@ public String getApplicationNameKey() {
return applicationNameKey;
}
+ public String getLicenceName() {
+ return trim(this.properties.getProperty(licenceNameKey));
+ }
+
+ public String getLicenceNameKey() {
+ return licenceNameKey;
+ }
+
private String trim(String string) {
if (string == null) {
return null;
diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java
index 491a25e79601..29d4871aad42 100644
--- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java
+++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/DefaultAgentOption.java
@@ -30,6 +30,7 @@ public class DefaultAgentOption implements AgentOption {
private final Instrumentation instrumentation;
+ private final String agentLicence;
private final String agentId;
private final String applicationName;
private final boolean isContainer;
@@ -38,8 +39,9 @@ public class DefaultAgentOption implements AgentOption {
private final List pluginJars;
private final List bootstrapJarPaths;
- public DefaultAgentOption(final Instrumentation instrumentation, String agentId, String applicationName, final boolean isContainer, final ProfilerConfig profilerConfig, final List pluginJars, final List bootstrapJarPaths) {
+ public DefaultAgentOption(final Instrumentation instrumentation, String agentLicence, String agentId, String applicationName, final boolean isContainer, final ProfilerConfig profilerConfig, final List pluginJars, final List bootstrapJarPaths) {
this.instrumentation = Assert.requireNonNull(instrumentation, "instrumentation");
+ this.agentLicence = agentLicence;
this.agentId = Assert.requireNonNull(agentId, "agentId");
this.applicationName = Assert.requireNonNull(applicationName, "applicationName");
this.isContainer = isContainer;
@@ -57,6 +59,11 @@ public Instrumentation getInstrumentation() {
return this.instrumentation;
}
+ @Override
+ public String getAgentLicence() {
+ return agentLicence;
+ }
+
@Override
public String getAgentId() {
return agentId;
diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java
index d0e4582added..347159c33e2c 100644
--- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java
+++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java
@@ -102,6 +102,7 @@ boolean start() {
if (applicationName == null) {
return false;
}
+ final String licenceName = agentIds.getAgentLicence();
final ContainerResolver containerResolver = new ContainerResolver();
final boolean isContainer = containerResolver.isContainer();
@@ -128,7 +129,7 @@ boolean start() {
logger.info(String.format("pinpoint agent [%s] starting...", bootClass));
final List pluginJars = agentDirectory.getPlugins();
- AgentOption option = createAgentOption(agentId, applicationName, isContainer, profilerConfig, instrumentation, pluginJars, agentDirectory);
+ AgentOption option = createAgentOption(licenceName, agentId, applicationName, isContainer, profilerConfig, instrumentation, pluginJars, agentDirectory);
Agent pinpointAgent = agentBootLoader.boot(option);
pinpointAgent.start();
pinpointAgent.registerStopHandler();
@@ -206,13 +207,13 @@ private String getAgentType() {
}
- private AgentOption createAgentOption(String agentId, String applicationName, boolean isContainer,
+ private AgentOption createAgentOption(String agentLicence, String agentId, String applicationName, boolean isContainer,
ProfilerConfig profilerConfig,
Instrumentation instrumentation,
List pluginJars,
AgentDirectory agentDirectory) {
List bootstrapJarPaths = agentDirectory.getBootDir().toList();
- return new DefaultAgentOption(instrumentation, agentId, applicationName, isContainer, profilerConfig, pluginJars, bootstrapJarPaths);
+ return new DefaultAgentOption(instrumentation, agentLicence, agentId, applicationName, isContainer, profilerConfig, pluginJars, bootstrapJarPaths);
}
// for test
diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java
index 2f8be060f418..bcbbd51caddd 100644
--- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java
+++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java
@@ -31,7 +31,7 @@
* @author yjqg6666
* @author Woonduk Kang(emeroad)
*/
-class ProfilePropertyLoader implements PropertyLoader {
+public class ProfilePropertyLoader implements PropertyLoader {
private static final String SEPARATOR = File.separator;
@@ -124,6 +124,14 @@ private void loadFileProperties(Properties properties, String filePath) {
throw new IllegalStateException(String.format("%s load fail Caused by:%s", filePath, e.getMessage()));
}
}
+ public static void loadFilePropertiesByProfileStr(Properties properties, String profileStr) {
+ try {
+ PropertyUtils.FileInputStreamFactory fileInputStreamFactory = new PropertyUtils.FileInputStreamFactory(profileStr, Boolean.TRUE);
+ PropertyUtils.loadProperty(properties, fileInputStreamFactory, PropertyUtils.DEFAULT_ENCODING);
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("remote properties load fail Caused by:%s", e.getMessage()));
+ }
+ }
private void loadSystemProperties(Properties dstProperties) {
Set stringPropertyNames = this.systemProperty.stringPropertyNames();
diff --git a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentBootLoaderTest.java b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentBootLoaderTest.java
index 5347f528e079..f38740e907a6 100644
--- a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentBootLoaderTest.java
+++ b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/AgentBootLoaderTest.java
@@ -42,7 +42,7 @@ public void boot() {
ClassLoader classLoader = AgentBootLoaderTest.class.getClassLoader();
AgentBootLoader agentBootLoader = new AgentBootLoader("com.navercorp.pinpoint.bootstrap.DummyAgent", classLoader);
Instrumentation instrumentation = mock(Instrumentation.class);
- AgentOption option = new DefaultAgentOption(instrumentation, "testCaseAgent", "testCaseAppName", false, new DefaultProfilerConfig(), Collections.emptyList(), null);
+ AgentOption option = new DefaultAgentOption(instrumentation, "licencen","testCaseAgent", "testCaseAppName", false, new DefaultProfilerConfig(), Collections.emptyList(), null);
Agent boot = agentBootLoader.boot(option);
boot.start();
boot.stop();
diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/HttpUtils.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/HttpUtils.java
index 489a7538e213..3c4bb05bbda3 100644
--- a/commons/src/main/java/com/navercorp/pinpoint/common/util/HttpUtils.java
+++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/HttpUtils.java
@@ -18,6 +18,14 @@
import com.navercorp.pinpoint.common.Charsets;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
/**
* @author emeroad
*/
@@ -54,4 +62,61 @@ public static String parseContentTypeCharset(String contentType, String defaultC
return contentType.trim();
}
+
+ public static String doGet(String httpUrl, int connectTimeout, int readTimeout) throws IOException {
+ //链接
+ HttpURLConnection connection=null;
+ InputStream is=null;
+ BufferedReader br = null;
+ StringBuffer result=new StringBuffer();
+ try {
+ //创建连接
+ URL url=new URL(httpUrl);
+ connection= (HttpURLConnection) url.openConnection();
+ //设置请求方式
+ connection.setRequestMethod("GET");
+ //设置连接超时时间
+ connection.setConnectTimeout(connectTimeout);
+ //设置读取超时时间
+ connection.setReadTimeout(readTimeout);
+ //开始连接
+ connection.connect();
+ //获取响应数据
+ if(connection.getResponseCode()==200){
+ //获取返回的数据
+ is=connection.getInputStream();
+ if(is!=null){
+ br=new BufferedReader(new InputStreamReader(is,"UTF-8"));
+ String temp = null;
+ while ((temp=br.readLine())!=null){
+ result.append(temp+"\r\n");
+ }
+ }
+ }
+ } catch (MalformedURLException e) {
+ throw e;
+ } catch (IOException e) {
+ throw e;
+ }finally {
+ if(br!=null){
+ try {
+ br.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ if(is!=null){
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ connection.disconnect();// 关闭远程连接
+ }
+ return result.toString();
+ }
+ public static String doGet(String httpUrl) throws IOException {
+ return doGet(httpUrl, 3000, 2000);
+ }
}
diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/util/PropertyUtils.java b/commons/src/main/java/com/navercorp/pinpoint/common/util/PropertyUtils.java
index e76cb498dae5..22c0e53d6187 100644
--- a/commons/src/main/java/com/navercorp/pinpoint/common/util/PropertyUtils.java
+++ b/commons/src/main/java/com/navercorp/pinpoint/common/util/PropertyUtils.java
@@ -102,16 +102,21 @@ public static Properties loadProperty(Properties properties, InputStreamFactory
public static class FileInputStreamFactory implements InputStreamFactory {
private final String filePath;
+ private final Boolean isPropertiesStr;
public FileInputStreamFactory(String filePath) {
- if (filePath == null) {
+ this(filePath, Boolean.FALSE);
+ }
+ public FileInputStreamFactory(String propertiesStr, Boolean isPropertiesStr) {
+ if (propertiesStr == null) {
throw new NullPointerException("filePath");
}
- this.filePath = filePath;
+ this.filePath = propertiesStr;
+ this.isPropertiesStr = isPropertiesStr;
}
@Override
public InputStream openInputStream() throws IOException {
- return new FileInputStream(filePath);
+ return isPropertiesStr ? new ByteArrayInputStream(filePath.getBytes()) : new FileInputStream(filePath);
}
}
diff --git a/pom.xml b/pom.xml
index 32034e7467e4..7d195b21d1eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -735,7 +735,11 @@
guice
4.1.0
-
+
+ com.alibaba.nacos
+ nacos-client
+ 2.2.0
+
diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApplicationContextFactory.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApplicationContextFactory.java
index 2ec65775c41c..e5f0b97370df 100644
--- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApplicationContextFactory.java
+++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/MockApplicationContextFactory.java
@@ -83,7 +83,7 @@ public DefaultApplicationContext build(ProfilerConfig config, ModuleFactory modu
String mockAgent = "mockAgent";
String mockApplicationName = "mockApplicationName";
- AgentOption agentOption = new DefaultAgentOption(instrumentation, mockAgent, mockApplicationName, false, config, Collections.emptyList(),
+ AgentOption agentOption = new DefaultAgentOption(instrumentation, "mockLicence", mockAgent, mockApplicationName, false, config, Collections.emptyList(),
null);
return new DefaultApplicationContext(agentOption, moduleFactory);
}
diff --git a/profiler-test/src/main/java/com/navercorp/pinpoint/test/OverrideModuleFactory.java b/profiler-test/src/main/java/com/navercorp/pinpoint/test/OverrideModuleFactory.java
index 46b35c13084c..0b67a3cb4906 100644
--- a/profiler-test/src/main/java/com/navercorp/pinpoint/test/OverrideModuleFactory.java
+++ b/profiler-test/src/main/java/com/navercorp/pinpoint/test/OverrideModuleFactory.java
@@ -22,6 +22,7 @@
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
import com.navercorp.pinpoint.bootstrap.config.TransportModule;
import com.navercorp.pinpoint.common.util.Assert;
+import com.navercorp.pinpoint.profiler.context.module.ApplicationContext;
import com.navercorp.pinpoint.profiler.context.module.ApplicationContextModuleFactory;
import com.navercorp.pinpoint.profiler.context.module.ModuleFactory;
import com.navercorp.pinpoint.test.rpc.MockRpcModule;
@@ -56,4 +57,8 @@ protected Module newRpcModule(AgentOption agentOption) {
Module module = moduleFactory.newModule(agentOption);
return Modules.override(module).with(overrideModule);
}
+ @Override
+ public Module newModule(AgentOption agentOption, ApplicationContext applicationContext) {
+ return newModule(agentOption);
+ }
}
diff --git a/profiler-test/src/test/java/com/navercorp/pinpoint/test/MockApplicationContextModuleTest.java b/profiler-test/src/test/java/com/navercorp/pinpoint/test/MockApplicationContextModuleTest.java
index 5e5fef02b921..e53a80892be1 100644
--- a/profiler-test/src/test/java/com/navercorp/pinpoint/test/MockApplicationContextModuleTest.java
+++ b/profiler-test/src/test/java/com/navercorp/pinpoint/test/MockApplicationContextModuleTest.java
@@ -49,7 +49,7 @@ public void test() {
Instrumentation instrumentation = Mockito.mock(Instrumentation.class);
AgentOption agentOption = new DefaultAgentOption(instrumentation,
- "mockAgent", "mockApplicationName", false, profilerConfig, Collections.emptyList(),
+ "mockLicence", "mockAgent", "mockApplicationName", false, profilerConfig, Collections.emptyList(),
null);
PluginTestAgent pluginTestAgent = new PluginTestAgent(agentOption);
@@ -67,7 +67,7 @@ public void testMockApplicationContext() {
Instrumentation instrumentation = Mockito.mock(Instrumentation.class);
AgentOption agentOption = new DefaultAgentOption(instrumentation,
- "mockAgent", "mockApplicationName", false, profilerConfig, Collections.emptyList(),
+ "mockLicence", "mockAgent", "mockApplicationName", false, profilerConfig, Collections.emptyList(),
null);
Module pluginModule = new PluginApplicationContextModule();
diff --git a/profiler-test/src/test/java/com/navercorp/pinpoint/test/monitor/AgentStatMonitorTest.java b/profiler-test/src/test/java/com/navercorp/pinpoint/test/monitor/AgentStatMonitorTest.java
index e76fc7f556a3..6484902e7acb 100644
--- a/profiler-test/src/test/java/com/navercorp/pinpoint/test/monitor/AgentStatMonitorTest.java
+++ b/profiler-test/src/test/java/com/navercorp/pinpoint/test/monitor/AgentStatMonitorTest.java
@@ -81,7 +81,7 @@ public void testAgentStatMonitor() throws InterruptedException {
// When
AgentStatMonitor monitor = new DefaultAgentStatMonitor(this.dataSender, "agentId", System.currentTimeMillis(),
- agentStatCollector, null, mockProfilerConfig);
+ agentStatCollector, null, mockProfilerConfig, null, null, null);
monitor.start();
Thread.sleep(totalTestDurationMs);
monitor.stop();
diff --git a/profiler/pom.xml b/profiler/pom.xml
index 5b33c14bbf7f..a11229de0068 100644
--- a/profiler/pom.xml
+++ b/profiler/pom.xml
@@ -212,6 +212,16 @@
junit
test
+
+ com.alibaba.nacos
+ nacos-client
+
+
+ slf4j-api
+ org.slf4j
+
+
+
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java
index 71d5ee619c5d..9c76e0e4d487 100644
--- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/AgentInfoSender.java
@@ -20,9 +20,11 @@
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;
+import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.common.util.Assert;
import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter;
import com.navercorp.pinpoint.profiler.metadata.AgentInfo;
+import com.navercorp.pinpoint.profiler.monitor.processor.ReSetConfigProcessorFactory;
import com.navercorp.pinpoint.profiler.sender.ResultResponse;
import com.navercorp.pinpoint.profiler.util.AgentInfoFactory;
import com.navercorp.pinpoint.rpc.DefaultFuture;
@@ -54,6 +56,7 @@ public class AgentInfoSender {
private final int maxTryPerAttempt;
private final Scheduler scheduler;
private final MessageConverter messageConverter;
+ private final ProfilerConfig profilerConfig;
private AgentInfoSender(Builder builder) {
this.dataSender = builder.dataSender;
@@ -63,6 +66,7 @@ private AgentInfoSender(Builder builder) {
this.maxTryPerAttempt = builder.maxTryPerAttempt;
this.scheduler = new Scheduler();
this.messageConverter = builder.messageConverter;
+ this.profilerConfig = builder.profilerConfig;
}
public void start() {
@@ -163,9 +167,15 @@ public void run() {
this.cancel();
return;
}
- boolean isSuccessful = sendAgentInfo();
- if (isSuccessful) {
- logger.info("AgentInfo sent.");
+ if(ReSetConfigProcessorFactory.isEnableCollect(profilerConfig)){
+ boolean isSuccessful = sendAgentInfo();
+ if (isSuccessful) {
+ logger.info("AgentInfo sent.");
+ this.cancel();
+ taskHandler.onSuccess();
+ }
+ }else{
+ logger.info("AgentInfo don't sent.");
this.cancel();
taskHandler.onSuccess();
}
@@ -211,6 +221,7 @@ public static class Builder {
private long sendIntervalMs = DEFAULT_AGENT_INFO_SEND_INTERVAL_MS;
private int maxTryPerAttempt = DEFAULT_MAX_TRY_COUNT_PER_ATTEMPT;
private MessageConverter messageConverter;
+ private ProfilerConfig profilerConfig;
public Builder(EnhancedDataSender dataSender, AgentInfoFactory agentInfoFactory) {
this.dataSender = Assert.requireNonNull(dataSender, "dataSender");
@@ -236,6 +247,10 @@ public Builder setMessageConverter(MessageConverter messageConve
this.messageConverter = messageConverter;
return this;
}
+ public Builder setProfilerConfig(ProfilerConfig profilerConfig) {
+ this.profilerConfig = profilerConfig;
+ return this;
+ }
public AgentInfoSender build() {
if (this.refreshIntervalMs <= 0) {
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentLicence.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentLicence.java
new file mode 100644
index 000000000000..a055ef4e93ed
--- /dev/null
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/AgentLicence.java
@@ -0,0 +1,15 @@
+package com.navercorp.pinpoint.profiler.context.module;
+
+import com.google.inject.BindingAnnotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@BindingAnnotation
+@Target(PARAMETER)
+@Retention(RUNTIME)
+public @interface AgentLicence {
+}
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModule.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModule.java
index ebd9b8e6d5e5..7dc54e6a2a47 100644
--- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModule.java
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModule.java
@@ -107,10 +107,7 @@
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService;
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataService;
-import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
-import com.navercorp.pinpoint.profiler.monitor.DeadlockMonitor;
-import com.navercorp.pinpoint.profiler.monitor.DeadlockThreadRegistry;
-import com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor;
+import com.navercorp.pinpoint.profiler.monitor.*;
import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeCollector;
import com.navercorp.pinpoint.profiler.monitor.metric.response.ReuseResponseTimeCollector;
import com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory;
@@ -137,6 +134,11 @@ public class ApplicationContextModule extends AbstractModule {
public ApplicationContextModule() {
}
+ private ApplicationContext applicationContext;
+
+ public ApplicationContextModule(ApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ }
@Override
protected void configure() {
@@ -146,6 +148,8 @@ protected void configure() {
binder().requireAtInjectOnConstructors();
binder().disableCircularProxies();
+ bind(ApplicationContext.class).toInstance(applicationContext);
+
bind(ServiceType.class).annotatedWith(ApplicationServerType.class).toProvider(ApplicationServerTypeProvider.class).in(Scopes.SINGLETON);
bind(ServerMetaDataRegistryService.class).toProvider(ServerMetaDataRegistryServiceProvider.class).in(Scopes.SINGLETON);
@@ -206,6 +210,7 @@ protected void configure() {
bind(DeadlockMonitor.class).toProvider(DeadlockMonitorProvider.class).in(Scopes.SINGLETON);
bind(AgentInfoSender.class).toProvider(AgentInfoSenderProvider.class).in(Scopes.SINGLETON);
bind(AgentStatMonitor.class).to(DefaultAgentStatMonitor.class).in(Scopes.SINGLETON);
+ bind(RemoteConfigMonitor.class).to(DefaultRemoteConfigMonitor.class).in(Scopes.SINGLETON);
}
private void bindTraceComponent() {
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModuleFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModuleFactory.java
index 946df71b200a..2b36ed565935 100644
--- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModuleFactory.java
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModuleFactory.java
@@ -30,19 +30,24 @@
*/
public class ApplicationContextModuleFactory implements ModuleFactory {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private ApplicationContext applicationContext;
@Override
public Module newModule(AgentOption agentOption) {
final Module config = new ConfigModule(agentOption);
final Module pluginModule = new PluginModule();
- final Module applicationContextModule = new ApplicationContextModule();
+ final Module applicationContextModule = new ApplicationContextModule(applicationContext);
final Module rpcModule = newRpcModule(agentOption);
final Module statsModule = new StatsModule();
final Module thriftStatsModule = new ThriftStatsModule();
return Modules.combine(config, pluginModule, applicationContextModule, rpcModule, statsModule, thriftStatsModule);
}
-
+ @Override
+ public Module newModule(AgentOption agentOption, ApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ return newModule(agentOption);
+ }
protected Module newRpcModule(AgentOption agentOption) {
ProfilerConfig profilerConfig = agentOption.getProfilerConfig();
final TransportModule transportModule = profilerConfig.getTransportModule();
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java
index 99157e62e50e..5e1d3d31351e 100644
--- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java
@@ -16,15 +16,17 @@
package com.navercorp.pinpoint.profiler.context.module;
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.config.ConfigService;
import com.navercorp.pinpoint.bootstrap.AgentOption;
+import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
+import com.navercorp.pinpoint.bootstrap.config.ProfilePropertyLoader;
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.instrument.DynamicTransformTrigger;
import com.navercorp.pinpoint.bootstrap.module.ClassFileTransformModuleAdaptor;
import com.navercorp.pinpoint.bootstrap.module.JavaModuleFactory;
-import com.navercorp.pinpoint.common.util.Assert;
-import com.navercorp.pinpoint.common.util.JvmUtils;
-import com.navercorp.pinpoint.common.util.JvmVersion;
+import com.navercorp.pinpoint.common.util.*;
import com.navercorp.pinpoint.profiler.AgentInfoSender;
import com.navercorp.pinpoint.profiler.AgentInformation;
import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService;
@@ -37,6 +39,9 @@
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
import com.navercorp.pinpoint.profiler.monitor.DeadlockMonitor;
+import com.navercorp.pinpoint.profiler.monitor.DefaultRemoteConfigMonitor;
+import com.navercorp.pinpoint.profiler.monitor.RemoteConfigMonitor;
+import com.navercorp.pinpoint.profiler.monitor.processor.ReSetConfigProcessorFactory;
import com.navercorp.pinpoint.profiler.sender.DataSender;
import com.google.inject.Guice;
@@ -51,6 +56,7 @@
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.Constructor;
+import java.util.Properties;
/**
* @author Woonduk Kang(emeroad)
@@ -64,6 +70,7 @@ public class DefaultApplicationContext implements ApplicationContext {
private final DeadlockMonitor deadlockMonitor;
private final AgentInfoSender agentInfoSender;
private final AgentStatMonitor agentStatMonitor;
+ private final RemoteConfigMonitor remoteConfigMonitor;
private final TraceContext traceContext;
@@ -80,6 +87,8 @@ public class DefaultApplicationContext implements ApplicationContext {
private final Injector injector;
+ private ConfigService configService;
+
public DefaultApplicationContext(AgentOption agentOption, ModuleFactory moduleFactory) {
Assert.requireNonNull(agentOption, "agentOption");
Assert.requireNonNull(moduleFactory, "moduleFactory");
@@ -90,7 +99,7 @@ public DefaultApplicationContext(AgentOption agentOption, ModuleFactory moduleFa
logger.info("DefaultAgent classLoader:{}", this.getClass().getClassLoader());
}
- final Module applicationContextModule = moduleFactory.newModule(agentOption);
+ final Module applicationContextModule = moduleFactory.newModule(agentOption, this);
this.injector = Guice.createInjector(Stage.PRODUCTION, applicationContextModule);
this.profilerConfig = injector.getInstance(ProfilerConfig.class);
@@ -129,6 +138,109 @@ public DefaultApplicationContext(AgentOption agentOption, ModuleFactory moduleFa
this.deadlockMonitor = injector.getInstance(DeadlockMonitor.class);
this.agentInfoSender = injector.getInstance(AgentInfoSender.class);
this.agentStatMonitor = injector.getInstance(AgentStatMonitor.class);
+ this.remoteConfigMonitor = injector.getInstance(RemoteConfigMonitor.class);
+ initRemoteConfig(agentOption);
+ initNacosConfigService();
+ }
+ private void initRemoteConfig(AgentOption agentOption){
+ try {
+ Properties propertiesOrigin = profilerConfig.getProperties();
+ Object remoteEnable = propertiesOrigin.get("profiler.remote.config.init.enable");
+ if(remoteEnable !=null && Boolean.parseBoolean(remoteEnable.toString())){
+ logger.info("activate the remote initialization configuration");
+ //get remote properties
+ String remoteConfigStr = loadAndSetRemoteProfile(propertiesOrigin, agentOption.getAgentLicence(), agentOption.getApplicationName());
+ if(null != remoteConfigStr && !"".equals(remoteConfigStr) && !"null".equals(remoteConfigStr)){
+ //reset profilerConfig
+ ((DefaultProfilerConfig)profilerConfig).resetDefaultProfilerConfig(propertiesOrigin);
+ //reinit some config
+ ReSetConfigProcessorFactory reSetConfigProcessorFactory = ((DefaultRemoteConfigMonitor) this.remoteConfigMonitor).getReSetConfigProcessorFactory();
+ reSetConfigProcessorFactory.dealConfigInfo(remoteConfigStr);
+ }
+ }else{
+ logger.info("skip the remote initialization configuration");
+ }
+ } catch (Exception e) {
+ logger.error("initRemoteConfig error:"+e.getMessage());
+ }
+ }
+ private void initNacosConfigService(){
+ try {
+ //init configService
+ if(DefaultRemoteConfigMonitor.startRemoteMonitorIsBeginNacos(this.profilerConfig)){
+ Properties nacosProperties = DefaultRemoteConfigMonitor.getNacosProperties(this.profilerConfig);
+ this.configService = NacosFactory.createConfigService(nacosProperties);
+ }else{
+ logger.info("Uninitialized nacos");
+ }
+ } catch (Exception e) {
+ logger.error("initNacosConfigService error:"+e.getMessage());
+ }
+ }
+ private static final String NACOS_USERNAME="username";
+ private static final String NACOS_PASSWORD="password";
+ private static final String NACOS_NAMESPANCE="namespaceCenter";
+
+ private String loadAndSetRemoteProfile(Properties defaultProperties, String licence, String appName){
+ String profileStr = null;
+ String nacosUrl = "http://%s/nacos/v1/cs/configs?username="+NACOS_USERNAME+"&password="+NACOS_PASSWORD+"&tenant="+NACOS_NAMESPANCE+"&dataId=%s&group=%s";
+
+ if(!StringUtils.isEmpty(licence)
+ && !StringUtils.isEmpty(appName)
+ && null!=defaultProperties
+ && !StringUtils.isEmpty(defaultProperties.getProperty("profiler.remote.config.addr"))
+ ){
+ String remoteAddrRoot = defaultProperties.getProperty("profiler.remote.config.addr");
+ int connectTimeout = 3000;
+ int readTimeout = 2000;
+ try {
+ connectTimeout = Integer.parseInt(defaultProperties.getProperty("profiler.remote.config.connectTimeout", "3000"));
+ readTimeout = Integer.parseInt(defaultProperties.getProperty("profiler.remote.config.readTimeout", "2000"));
+ } catch (Exception e) {
+ }
+ int forSize = remoteAddrRoot.contains(",") ? remoteAddrRoot.split(",").length : 1;
+ for(int i=0; i agentStats;
+ private ProfilerConfig profilerConfig;
+ private Properties properties;
+ private final Sampler sampler;
+ private final String licence;
+ private final String appName;
public CollectJob(DataSender dataSender,
- String agentId, long agentStartTimestamp,
- AgentStatMetricCollector agentStatCollector,
- int numCollectionsPerBatch) {
+ String agentId, long agentStartTimestamp,
+ AgentStatMetricCollector agentStatCollector,
+ int numCollectionsPerBatch, ProfilerConfig profilerConfig
+ , Sampler sampler, String licence, String appName) {
if (dataSender == null) {
throw new NullPointerException("dataSender");
}
@@ -57,10 +70,22 @@ public CollectJob(DataSender dataSender,
this.agentStatCollector = agentStatCollector;
this.numCollectionsPerBatch = numCollectionsPerBatch;
this.agentStats = new ArrayList(numCollectionsPerBatch);
+
+ this.profilerConfig=profilerConfig;
+ if(profilerConfig != null && profilerConfig instanceof DefaultProfilerConfig){
+ properties = ((DefaultProfilerConfig)profilerConfig).getProperties();
+ }
+ this.sampler=sampler;
+ this.licence=licence;
+ this.appName=appName;
}
@Override
public void run() {
+ if(!ReSetConfigProcessorFactory.isEnableCollect(profilerConfig)){
+ logger.info("CollectJob is disabled.");
+ return;
+ }
final long currentCollectionTimestamp = System.currentTimeMillis();
final long collectInterval = currentCollectionTimestamp - this.prevCollectionTimestamp;
try {
@@ -69,6 +94,7 @@ public void run() {
agentStat.setCollectInterval(collectInterval);
this.agentStats.add(agentStat);
if (++this.collectCount >= numCollectionsPerBatch) {
+ setMoreAgentInfos(agentStat);
sendAgentStats();
this.collectCount = 0;
}
@@ -78,6 +104,38 @@ public void run() {
this.prevCollectionTimestamp = currentCollectionTimestamp;
}
}
+ private static Boolean isFirst = Boolean.TRUE;
+ public void setMoreAgentInfos(AgentStatMetricSnapshot agentStat){
+ try {
+ if(isFirst){
+ LogLevelChangeProcessor logLevelChangeProcessor = new LogLevelChangeProcessor(properties);
+ logLevelChangeProcessor.resetConfig(properties);
+ LogLevelChangeProcessor.setLogLevel(properties);
+ isFirst = Boolean.FALSE;
+ }
+ Map propertiesMap = new HashMap(PropertiesKey.values().length+1);
+ for(PropertiesKey propertiesKey : PropertiesKey.values()) {
+ propertiesMap.put(propertiesKey.key, properties.get(propertiesKey.key));
+ }
+ //追加licence回去
+ propertiesMap.put("profiler.licence", this.licence);
+ propertiesMap.put("profiler.appName", this.appName);
+ propertiesMap.put("profiler.agentId", this.agentId);
+ propertiesMap.put("profiler.collectTime", agentStat.getTimestamp());
+ propertiesMap.put("profiler.remote.config.addr", profilerConfig.getRemoteAddr());
+
+ String reservedField = agentStat.getReservedField();
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map reservedFieldMap = new HashMap(2);
+ if(!StringUtils.isEmpty(reservedField)){
+ reservedFieldMap = objectMapper.readValue(reservedField, Map.class);
+ }
+ reservedFieldMap.put("properties", propertiesMap);
+ agentStat.setReservedField(objectMapper.writeValueAsString(reservedFieldMap));
+ } catch (Exception ex) {
+ logger.warn("setMoreAgentInfos failed. Caused:{}", ex.getMessage(), ex);
+ }
+ }
private void sendAgentStats() {
// prepare TAgentStat object.
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java
index aa8585b0e5b2..36b00639688c 100644
--- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java
@@ -18,10 +18,9 @@
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
+import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory;
-import com.navercorp.pinpoint.profiler.context.module.AgentId;
-import com.navercorp.pinpoint.profiler.context.module.AgentStartTime;
-import com.navercorp.pinpoint.profiler.context.module.StatDataSender;
+import com.navercorp.pinpoint.profiler.context.module.*;
import com.navercorp.pinpoint.profiler.context.monitor.metric.CustomMetricRegistryService;
import com.navercorp.pinpoint.profiler.monitor.collector.AgentCustomMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector;
@@ -60,12 +59,18 @@ public class DefaultAgentStatMonitor implements AgentStatMonitor {
private final StatMonitorJob statMonitorJob;
+ private final String licence;
+ private final String appName;
+
@Inject
public DefaultAgentStatMonitor(@StatDataSender DataSender dataSender,
@AgentId String agentId, @AgentStartTime long agentStartTimestamp,
@Named("AgentStatCollector") AgentStatMetricCollector agentStatCollector,
CustomMetricRegistryService customMetricRegistryService,
- ProfilerConfig profilerConfig) {
+ ProfilerConfig profilerConfig,
+ Sampler sampler,
+ @AgentLicence String licence,
+ @ApplicationName String appName) {
if (dataSender == null) {
throw new NullPointerException("dataSender");
}
@@ -89,10 +94,12 @@ public DefaultAgentStatMonitor(@StatDataSender DataSender dataSender,
numCollectionsPerBatch = DEFAULT_NUM_COLLECTIONS_PER_SEND;
}
this.collectionIntervalMs = collectionIntervalMs;
+ this.licence = licence;
+ this.appName = appName;
List runnableList = new ArrayList();
- Runnable statCollectingJob = new CollectJob(dataSender, agentId, agentStartTimestamp, agentStatCollector, numCollectionsPerBatch);
+ Runnable statCollectingJob = new CollectJob(dataSender, agentId, agentStartTimestamp, agentStatCollector, numCollectionsPerBatch, profilerConfig, sampler, licence, appName);
runnableList.add(statCollectingJob);
if (profilerConfig.isCustomMetricEnable() && customMetricRegistryService != null) {
@@ -102,7 +109,7 @@ public DefaultAgentStatMonitor(@StatDataSender DataSender dataSender,
this.statMonitorJob = new StatMonitorJob(runnableList);
- preLoadClass(agentId, agentStartTimestamp, agentStatCollector);
+ preLoadClass(agentId, agentStartTimestamp, agentStatCollector, profilerConfig, sampler);
}
// https://github.com/naver/pinpoint/issues/2881
@@ -110,9 +117,9 @@ public DefaultAgentStatMonitor(@StatDataSender DataSender dataSender,
// prevent deadlock for JDK6
// Single thread execution is more safe than multi thread execution.
// eg) executor.scheduleAtFixedRate(collectJob, 0(initialDelay is zero), this.collectionIntervalMs, TimeUnit.MILLISECONDS);
- private void preLoadClass(String agentId, long agentStartTimestamp, AgentStatMetricCollector agentStatCollector) {
+ private void preLoadClass(String agentId, long agentStartTimestamp, AgentStatMetricCollector agentStatCollector, ProfilerConfig profilerConfig, Sampler sampler) {
logger.debug("pre-load class start");
- CollectJob collectJob = new CollectJob(EmptyDataSender.INSTANCE, agentId, agentStartTimestamp, agentStatCollector, 1);
+ CollectJob collectJob = new CollectJob(EmptyDataSender.INSTANCE, agentId, agentStartTimestamp, agentStatCollector, 1, profilerConfig, sampler, licence, appName);
// It is called twice to initialize some fields.
collectJob.run();
diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultRemoteConfigMonitor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultRemoteConfigMonitor.java
new file mode 100644
index 000000000000..5dac0213305a
--- /dev/null
+++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultRemoteConfigMonitor.java
@@ -0,0 +1,357 @@
+package com.navercorp.pinpoint.profiler.monitor;
+
+import com.alibaba.nacos.api.config.ConfigService;
+import com.alibaba.nacos.api.config.listener.Listener;
+import com.alibaba.nacos.api.exception.NacosException;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
+import com.navercorp.pinpoint.bootstrap.context.TraceContext;
+import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
+import com.navercorp.pinpoint.common.util.Assert;
+import com.navercorp.pinpoint.common.util.HttpUtils;
+import com.navercorp.pinpoint.common.util.StringUtils;
+import com.navercorp.pinpoint.profiler.context.module.*;
+import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
+import com.navercorp.pinpoint.profiler.monitor.processor.ReSetConfigProcessorFactory;
+import com.navercorp.pinpoint.profiler.sender.DataSender;
+import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.*;
+import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author dongdd
+ * @description:
+ */
+public class DefaultRemoteConfigMonitor implements RemoteConfigMonitor{
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ private final ProfilerConfig profilerConfig;
+ private final Sampler sampler;
+ private ConfigService configService;
+ private final String dataId;
+ private final String group;
+ private final String GROUP_DEFAULT="default";
+ private final Set nacosConfigSet= new HashSet();
+ private ReSetConfigProcessorFactory reSetConfigProcessorFactory;
+ private final int retry = 2;
+ private final String REMOTETYPE_TIMEDTASK = "1";
+ private static final String REMOTETYPE_LONGCONNECTION = "2";
+
+ private Scheduler scheduler;
+ private final long refreshIntervalMs;
+ private final long sendIntervalMs;
+ private final int maxTryPerAttempt;
+
+ private final DataSender statDataSender;
+ private final DataSender spanDataSender;
+ private final DataSender tcpDataSender;
+
+ private static final String NACOS_USERNAME="username";
+ private static final String NACOS_PASSWORD="password";
+ private static final String NACOS_NAMESPANCE="namespace";
+
+ public ReSetConfigProcessorFactory getReSetConfigProcessorFactory(){
+ return this.reSetConfigProcessorFactory;
+ }
+
+ @Inject
+ public DefaultRemoteConfigMonitor(ProfilerConfig profilerConfig, Sampler sampler, @AgentLicence String agentLicence, @ApplicationName String applicationName
+ , @StatDataSender DataSender statDataSender , @SpanDataSender DataSender spanDataSender, @AgentDataSender EnhancedDataSender