Skip to content

Commit

Permalink
[#11877] Improved Agent initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jan 3, 2025
1 parent f3b008d commit e2f51dc
Show file tree
Hide file tree
Showing 96 changed files with 1,187 additions and 1,081 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@

import com.navercorp.pinpoint.common.util.JvmUtils;
import com.navercorp.pinpoint.common.util.JvmVersion;
import com.navercorp.pinpoint.common.util.StringUtils;

import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;

/**
* @author Taejin Koo
Expand Down Expand Up @@ -80,9 +85,27 @@ private static ClassLoaderFactory newParallelClassLoaderFactory() {
}
}


public static ClassLoader createClassLoader(String name, URL[] urls, ClassLoader parent, List<String> libClass) {
return CLASS_LOADER_FACTORY.createClassLoader(name, urls, parent, libClass);
}


public static ClassLoader createClassLoader(String name, URL[] urls, ClassLoader parent, Properties properties) {
List<String> libClass = getAgentClassloaderLibs(properties);
return createClassLoader(name, urls, parent, libClass);

Check warning on line 95 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderFactory.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderFactory.java#L94-L95

Added lines #L94 - L95 were not covered by tests
}

public static final String AGENT_CLASSLOADER_ADDITIONAL_LIBS = "profiler.agent.classloader.additional-libs";

private static List<String> getAgentClassloaderLibs(Properties properties) {
Set<String> libs = new HashSet<>(ProfilerLibs.PINPOINT_PROFILER_CLASS);

Check warning on line 101 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderFactory.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderFactory.java#L101

Added line #L101 was not covered by tests

String libsString = properties.getProperty(AGENT_CLASSLOADER_ADDITIONAL_LIBS, "");
List<String> additionalLibs = StringUtils.tokenizeToStringList(libsString, ",");
libs.addAll(additionalLibs);

Check warning on line 105 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderFactory.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderFactory.java#L103-L105

Added lines #L103 - L105 were not covered by tests

List<String> copy = new ArrayList<>(libs);
copy.sort(String.CASE_INSENSITIVE_ORDER);
return copy;

Check warning on line 109 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderFactory.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderFactory.java#L107-L109

Added lines #L107 - L109 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcOption;
import com.navercorp.pinpoint.bootstrap.util.NumberUtils;
import com.navercorp.pinpoint.common.annotations.VisibleForTesting;
import com.navercorp.pinpoint.common.config.Value;
import com.navercorp.pinpoint.common.config.util.PlaceHolder;
import com.navercorp.pinpoint.common.config.util.spring.PropertyPlaceholderHelper;
import com.navercorp.pinpoint.common.util.StringUtils;
Expand All @@ -37,43 +35,17 @@
* @author netspider
*/
public class DefaultProfilerConfig implements ProfilerConfig {
public static final String PROFILER_INTERCEPTOR_EXCEPTION_PROPAGATE = "profiler.interceptor.exception.propagate";
public static final String AGENT_ROOT_PATH_KEY = "pinpoint.agent.root.path";

// TestAgent only
public static final String IMPORT_PLUGIN = "profiler.plugin.import-plugin";

public static final String AGENT_CLASSLOADER_ADDITIONAL_LIBS = "profiler.agent.classloader.additional-libs";

private final PropertyPlaceholderHelper placeholder;

private final Properties properties;

private final JdbcOption jdbcOption;

@Value("${pinpoint.disable:false}")
private String pinpointDisable = "false";

@Value("${profiler.logdir.maxbackupsize}")
private int logDirMaxBackupSize = 5;

@Value("${" + Profiles.ACTIVE_PROFILE_KEY + " }")
private String activeProfile = "";

@VisibleForTesting
private boolean staticResourceCleanup = false;

@Value("${profiler.transport.grpc.stats.logging.period}")
private String grpcStatLoggingPeriod = "PT1M";

@Value("${profiler.guice.module.factory}")
private String injectionModuleFactoryClazzName = null;
@Value("${profiler.application.namespace}")
private String applicationNamespace = "";

@Value("${" + AGENT_CLASSLOADER_ADDITIONAL_LIBS + "}")
private String agentClassloaderAdditionalLibs = "";


public DefaultProfilerConfig() {
this.properties = new Properties();
this.jdbcOption = JdbcOption.empty();
Expand All @@ -91,7 +63,6 @@ private PropertyPlaceholderHelper newPlaceholder(boolean ignoreUnresolvablePlace
return new PropertyPlaceholderHelper(PlaceHolder.START, PlaceHolder.END, PlaceHolder.DELIMITER, ignoreUnresolvablePlaceholders);
}

@Override
public Properties getProperties() {
return properties;
}
Expand All @@ -101,46 +72,67 @@ public JdbcOption getJdbcOption() {
return jdbcOption;
}

@Override
public String getActiveProfile() {
return activeProfile;
}

@Override
public String getPinpointDisable() {
return pinpointDisable;
}

@Override
public String getGrpcStatLoggingPeriod() {
return grpcStatLoggingPeriod;
}

@Override
public boolean getStaticResourceCleanup() {
return staticResourceCleanup;
}

@Override
public String getInjectionModuleFactoryClazzName() {
return injectionModuleFactoryClazzName;
}

@Override
public String getApplicationNamespace() {
return applicationNamespace;
}


@Override
public int getLogDirMaxBackupSize() {
return logDirMaxBackupSize;
}

@Override
public List<String> getAgentClassloaderAdditionalLibs() {
return StringUtils.tokenizeToStringList(agentClassloaderAdditionalLibs, ",");
}
//
// @Override
// public String getActiveProfile() {
// return activeProfile;
// }
//
// @Override
// public int getJdbcSqlCacheSize() {
// return jdbcSqlCacheSize;
// }
//
// @Override
// public boolean isTraceSqlBindValue() {
// return traceSqlBindValue;
// }
//
// @Override
// public int getMaxSqlBindValueSize() {
// return maxSqlBindValueSize;
// }
//
// @Override
// public int getMaxSqlCacheLength() {
// return maxSqlCacheLength;
// }
//
// @Override
// public int getMaxSqlLength() {
// return maxSqlLength;
// }
//
// @Override
// public String getGrpcStatLoggingPeriod() {
// return grpcStatLoggingPeriod;
// }
//
// @Override
// public HttpStatusCodeErrors getHttpStatusCodeErrors() {
// return httpStatusCodeErrors;
// }
//
// @Value("${profiler.http.status.code.errors}")
// void setHttpStatusCodeErrors(String httpStatusCodeErrors) {
// List<String> httpStatusCodeErrorList = StringUtils.tokenizeToStringList(httpStatusCodeErrors, ",");
// this.httpStatusCodeErrors = new HttpStatusCodeErrors(httpStatusCodeErrorList);
// }
//
// @Override
// public String getInjectionModuleFactoryClazzName() {
// return injectionModuleFactoryClazzName;
// }
//
// @Override
// public String getApplicationNamespace() {
// return applicationNamespace;
// }
//
// @Override
// public String getAgentRootPath() {
// return agentRootPath;
// }


@Override
Expand Down Expand Up @@ -223,14 +215,6 @@ public Map<String, String> readPattern(String propertyNamePatternRegex) {
public String toString() {
return "DefaultProfilerConfig{" +
"properties=" + properties +
", pinpointDisable='" + pinpointDisable + '\'' +
", logDirMaxBackupSize=" + logDirMaxBackupSize +
", activeProfile='" + activeProfile + '\'' +
", staticResourceCleanup=" + staticResourceCleanup +
", grpcStatLoggingPeriod='" + grpcStatLoggingPeriod + '\'' +
", injectionModuleFactoryClazzName='" + injectionModuleFactoryClazzName + '\'' +
", applicationNamespace='" + applicationNamespace + '\'' +
", agentClassloaderAdditionalLibs='" + agentClassloaderAdditionalLibs + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package com.navercorp.pinpoint.bootstrap.config;

import com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcOption;
import com.navercorp.pinpoint.common.annotations.InterfaceAudience;
import com.navercorp.pinpoint.common.annotations.VisibleForTesting;

import java.util.List;
import java.util.Map;
Expand All @@ -29,25 +27,9 @@
*/
public interface ProfilerConfig {

String getActiveProfile();

JdbcOption getJdbcOption();

Properties getProperties();

String getPinpointDisable();

String getGrpcStatLoggingPeriod();

@InterfaceAudience.Private
@VisibleForTesting
boolean getStaticResourceCleanup();

String getInjectionModuleFactoryClazzName();

String getApplicationNamespace();

List<String> getAgentClassloaderAdditionalLibs();
JdbcOption getJdbcOption();

String readString(String propertyName);

Expand All @@ -63,6 +45,4 @@ public interface ProfilerConfig {

Map<String, String> readPattern(String propertyNamePatternRegex);

int getLogDirMaxBackupSize();

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static ProfilerConfig load(InputStream inputStream) {
return load(properties);
}

private static Properties loadProperties(InputStream inputStream) {
public static Properties loadProperties(InputStream inputStream) {
try {
return PropertyUtils.loadProperty(inputStream);
} catch (IOException ex) {
Expand All @@ -51,5 +51,4 @@ public static ProfilerConfig load(Properties properties) {

return profilerConfig;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,9 @@ public final class Profiles {
private Profiles() {
}

/**
* see : ProfileConstants
*/
public static final String LOG_CONFIG_LOCATION_KEY = "pinpoint.profiler.log.config.location";

public static final String CONFIG_LOAD_MODE_KEY = "pinpoint.config.load.mode";

public enum CONFIG_LOAD_MODE {
PROFILE,
// for IT TEST
SIMPLE
}

public static final String ACTIVE_PROFILE_KEY = "pinpoint.profiler.profiles.active";

// 1. default config
public static final String CONFIG_FILE_NAME = "pinpoint-root.config";
// 2. profile config
public static final String PROFILE_CONFIG_FILE_NAME = "pinpoint.config";
// 3. external config
public static final String EXTERNAL_CONFIG_KEY = "pinpoint.config";
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ public interface TraceContext {

JdbcContext getJdbcContext();

String getClusterNamespace();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ public class DefaultRequestTraceWriter<T> implements RequestTraceWriter<T> {
private final ClientHeaderAdaptor<T> clientHeaderAdaptor;
private final String applicationName;
private final short serverTypeCode;
private final String applicationNamespace;
private final String clusterNamespace;

public DefaultRequestTraceWriter(ClientHeaderAdaptor<T> clientHeaderAdaptor, TraceContext traceContext) {
this(clientHeaderAdaptor, traceContext.getApplicationName(), traceContext.getServerTypeCode(), traceContext.getProfilerConfig().getApplicationNamespace());
this(clientHeaderAdaptor, traceContext.getApplicationName(), traceContext.getServerTypeCode(), traceContext.getClusterNamespace());

Check warning on line 44 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java#L44

Added line #L44 was not covered by tests
}

public DefaultRequestTraceWriter(ClientHeaderAdaptor<T> clientHeaderAdaptor, String applicationName, short serverTypeCode, String applicationNamespace) {
public DefaultRequestTraceWriter(ClientHeaderAdaptor<T> clientHeaderAdaptor, String applicationName, short serverTypeCode, String clusterNamespace) {

Check warning on line 47 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java#L47

Added line #L47 was not covered by tests
this.clientHeaderAdaptor = Objects.requireNonNull(clientHeaderAdaptor, "clientHeaderAdaptor");

this.applicationName = Objects.requireNonNull(applicationName, "applicationName");
this.serverTypeCode = serverTypeCode;
this.applicationNamespace = StringUtils.defaultIfEmpty(applicationNamespace, NOT_SET);
this.clusterNamespace = StringUtils.defaultIfEmpty(clusterNamespace, NOT_SET);

Check warning on line 52 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java#L52

Added line #L52 was not covered by tests
}

@Override
Expand All @@ -66,7 +66,7 @@ public void write(T header, final TraceId traceId, final String host) {
Objects.requireNonNull(traceId, "traceId");

if (isDebug) {
logger.debug("Set request header. traceId={}, applicationName={}, serverTypeCode={}, applicationNamespace={}", traceId, applicationName, serverTypeCode, applicationNamespace);
logger.debug("Set request header. traceId={}, applicationName={}, serverTypeCode={}, clusterNamespace={}", traceId, applicationName, serverTypeCode, clusterNamespace);

Check warning on line 69 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java#L69

Added line #L69 was not covered by tests
}
clientHeaderAdaptor.setHeader(header, Header.HTTP_TRACE_ID.toString(), traceId.getTransactionId());
clientHeaderAdaptor.setHeader(header, Header.HTTP_SPAN_ID.toString(), String.valueOf(traceId.getSpanId()));
Expand All @@ -75,8 +75,8 @@ public void write(T header, final TraceId traceId, final String host) {
clientHeaderAdaptor.setHeader(header, Header.HTTP_PARENT_APPLICATION_NAME.toString(), applicationName);
clientHeaderAdaptor.setHeader(header, Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(serverTypeCode));

if (applicationNamespace != NOT_SET) {
clientHeaderAdaptor.setHeader(header, Header.HTTP_PARENT_APPLICATION_NAMESPACE.toString(), applicationNamespace);
if (clusterNamespace != NOT_SET) {
clientHeaderAdaptor.setHeader(header, Header.HTTP_PARENT_APPLICATION_NAMESPACE.toString(), clusterNamespace);

Check warning on line 79 in agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java

View check run for this annotation

Codecov / codecov/patch

agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java#L79

Added line #L79 was not covered by tests
}

if (host != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public RequestTraceReader(final TraceContext traceContext, RequestAdaptor<T> req
this.requestAdaptor = Objects.requireNonNull(requestAdaptor, "requestAdaptor");
this.traceHeaderReader = new DefaultTraceHeaderReader<T>(requestAdaptor);
this.async = async;
String applicationNamespace = traceContext.getProfilerConfig().getApplicationNamespace();
this.nameSpaceChecker = NameSpaceCheckFactory.newNamespace(requestAdaptor, applicationNamespace);
String clusterNamespace = traceContext.getClusterNamespace();
this.nameSpaceChecker = NameSpaceCheckFactory.newNamespace(requestAdaptor, clusterNamespace);
}

// Read the transaction information from the request.
Expand Down
5 changes: 0 additions & 5 deletions agent-module/bootstraps/bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-bootstrap-core</artifactId>
</dependency>

<!-- Logging dependencies -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
Loading

0 comments on commit e2f51dc

Please sign in to comment.