Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] The dynamic control pinpoint(Master switch, sampling rate,… #10013

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions agent/src/main/resources/profiles/local/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<appender-ref ref="console"/>
<appender-ref ref="rollingFile"/>
</logger>
<logger name="com.alibaba.nacos" additivity="false">
<level value="off"/>
<appender-ref ref="console"/>
<appender-ref ref="rollingFile"/>
</logger>

<root>
<level value="DEBUG"/>
Expand Down
5 changes: 5 additions & 0 deletions agent/src/main/resources/profiles/release/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<appender-ref ref="console"/>
<appender-ref ref="rollingFile"/>
</logger>
<logger name="com.alibaba.nacos" additivity="false">
<level value="off"/>
<appender-ref ref="console"/>
<appender-ref ref="rollingFile"/>
</logger>

<root>
<level value="INFO"/>
Expand Down
10 changes: 9 additions & 1 deletion agent/src/main/resources/profiles/release/pinpoint-env.config
Original file line number Diff line number Diff line change
Expand Up @@ -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=
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
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -166,13 +166,21 @@ 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();
this.thriftTransportConfig = new DefaultThriftTransportConfig();
}

public DefaultProfilerConfig(Properties properties) {
resetDefaultProfilerConfig(properties);
}
public void resetDefaultProfilerConfig(Properties properties) {
if (properties == null) {
throw new NullPointerException("properties");
}
Expand Down Expand Up @@ -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() {

Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -840,10 +886,13 @@ public long readLong(String propertyName, long defaultValue) {
@Override
public List<String> readList(String propertyName) {
String value = properties.getProperty(propertyName);
if (StringUtils.isEmpty(value)) {
return readListFromParam(value);
}
public static List<String> readListFromParam(String param){
if (StringUtils.isEmpty(param)) {
return Collections.emptyList();
}
return StringUtils.tokenizeToStringList(value, ",");
return StringUtils.tokenizeToStringList(param, ",");
}

@Override
Expand Down Expand Up @@ -876,7 +925,6 @@ public Map<String, String> readPattern(String propertyNamePatternRegex) {

return result;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("DefaultProfilerConfig{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,10 @@ interface ValueResolver {
String resolve(String value, Properties properties);
}

boolean getRemoteEnable();
String getRemoteAddr();
String getRemoteType();
long getRemoteType1Gap();
long getRemoteType2Gap();
Properties getProperties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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";
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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);
}

public void addAgentArgument(Map<String, String> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -43,4 +45,8 @@ public String getAgentId() {
public String getApplicationName() {
return applicationName;
}

public String getAgentLicence() {
return agentLicence;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface AgentOption {

Instrumentation getInstrumentation();

String getAgentLicence();

String getAgentId();

String getApplicationName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, String> properties, String agentKey, String applicationNameKey) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,8 +39,9 @@ public class DefaultAgentOption implements AgentOption {
private final List<String> pluginJars;
private final List<String> bootstrapJarPaths;

public DefaultAgentOption(final Instrumentation instrumentation, String agentId, String applicationName, final boolean isContainer, final ProfilerConfig profilerConfig, final List<String> pluginJars, final List<String> bootstrapJarPaths) {
public DefaultAgentOption(final Instrumentation instrumentation, String agentLicence, String agentId, String applicationName, final boolean isContainer, final ProfilerConfig profilerConfig, final List<String> pluginJars, final List<String> 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;
Expand All @@ -57,6 +59,11 @@ public Instrumentation getInstrumentation() {
return this.instrumentation;
}

@Override
public String getAgentLicence() {
return agentLicence;
}

@Override
public String getAgentId() {
return agentId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -128,7 +129,7 @@ boolean start() {
logger.info(String.format("pinpoint agent [%s] starting...", bootClass));

final List<String> 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();
Expand Down Expand Up @@ -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<String> pluginJars,
AgentDirectory agentDirectory) {
List<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> stringPropertyNames = this.systemProperty.stringPropertyNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<String>emptyList(), null);
AgentOption option = new DefaultAgentOption(instrumentation, "licencen","testCaseAgent", "testCaseAppName", false, new DefaultProfilerConfig(), Collections.<String>emptyList(), null);
Agent boot = agentBootLoader.boot(option);
boot.start();
boot.stop();
Expand Down
Loading