Skip to content

Commit

Permalink
[#noissue] Removed hard-coded default agent profile
Browse files Browse the repository at this point in the history
  • Loading branch information
smilu97 committed May 16, 2023
1 parent 4ae8f24 commit 455c291
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class DefaultProfilerConfig implements ProfilerConfig {
private int logDirMaxBackupSize = 5;

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

@VisibleForTesting
private boolean staticResourceCleanup = false;
Expand Down Expand Up @@ -258,18 +258,16 @@ public Map<String, String> readPattern(String propertyNamePatternRegex) {

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("DefaultProfilerConfig{");
sb.append("profileEnable='").append(profileEnable).append('\'');
sb.append(", activeProfile=").append(activeProfile);
sb.append(", logDirMaxBackupSize=").append(logDirMaxBackupSize);
sb.append(", staticResourceCleanup=").append(staticResourceCleanup);
sb.append(", jdbcSqlCacheSize=").append(jdbcSqlCacheSize);
sb.append(", traceSqlBindValue=").append(traceSqlBindValue);
sb.append(", maxSqlBindValueSize=").append(maxSqlBindValueSize);
sb.append(", httpStatusCodeErrors=").append(httpStatusCodeErrors);
sb.append(", injectionModuleFactoryClazzName='").append(injectionModuleFactoryClazzName).append('\'');
sb.append(", applicationNamespace='").append(applicationNamespace).append('\'');
sb.append('}');
return sb.toString();
return "DefaultProfilerConfig{" + "profileEnable='" + profileEnable + '\'' +
", activeProfile=" + activeProfile +
", logDirMaxBackupSize=" + logDirMaxBackupSize +
", staticResourceCleanup=" + staticResourceCleanup +
", jdbcSqlCacheSize=" + jdbcSqlCacheSize +
", traceSqlBindValue=" + traceSqlBindValue +
", maxSqlBindValueSize=" + maxSqlBindValueSize +
", httpStatusCodeErrors=" + httpStatusCodeErrors +
", injectionModuleFactoryClazzName='" + injectionModuleFactoryClazzName + '\'' +
", applicationNamespace='" + applicationNamespace + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public enum CONFIG_LOAD_MODE {
}

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

public static final String ACTIVE_PROFILE_CANDIDATES_KEY = "pinpoint.profiler.profiles.candidates";
public static final String DEFAULT_ACTIVE_PROFILE_CANDIDATES = "local | release";

// 1. default config
public static final String CONFIG_FILE_NAME = "pinpoint-root.config";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ public ProfilePropertyLoader(SimpleProperty javaSystemProperty, SimpleProperty o
/**
* <pre>Configuration order</pre>
*
* <p> Same order as Spring-Boot
* <p> https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html
* <p> Same order as Spring-Boot </p>
* <p>
* <a href="https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html">
* boot-features-external-config
* </a>
* </p>
* <ol>
* <li>Java System properties
* <li>OS environment variables
* <li>agent external configuration
* <li>agent profile configuration /profiles/${profile}/pinpoint.config
* <li>agent config /pinpoint-env.config
* <li>Java System properties</li>
* <li>OS environment variables</li>
* <li>agent external configuration</li>
* <li>agent profile configuration /profiles/${profile}/pinpoint.config</li>
* <li>agent config /pinpoint-env.config</li>
* </ol>
*/
@Override
Expand Down Expand Up @@ -135,8 +139,16 @@ private String getActiveProfile(Properties defaultProperties) {
profile = defaultProperties.getProperty(Profiles.ACTIVE_PROFILE_KEY);
}
if (profile == null) {
// default profile
profile = Profiles.DEFAULT_ACTIVE_PROFILE;
final String profileCandidates = javaSystemProperty.getProperty(
Profiles.ACTIVE_PROFILE_CANDIDATES_KEY,
defaultProperties.getProperty(
Profiles.ACTIVE_PROFILE_CANDIDATES_KEY,
Profiles.DEFAULT_ACTIVE_PROFILE_CANDIDATES
)
);
throw new RuntimeException("Failed to detect pinpoint profile. Please add -D" +
Profiles.ACTIVE_PROFILE_KEY +
"=<profile> to VM option. Valid profiles are \"" + profileCandidates + "\"");
}

// prevent directory traversal attack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ public Properties load() {


private void saveLogConfigLocation(Properties properties) {
String activeProfile = systemProperty.getProperty(Profiles.ACTIVE_PROFILE_KEY, Profiles.DEFAULT_ACTIVE_PROFILE);
String activeProfile = systemProperty.getProperty(Profiles.ACTIVE_PROFILE_KEY);
if (activeProfile == null) {
throw new RuntimeException("Failed to read " + Profiles.ACTIVE_PROFILE_KEY + " from systemProperty");
}

LogConfigResolver logConfigResolver = new ProfileLogConfigResolver(profilesPath, activeProfile);
final Path log4jLocation = logConfigResolver.getLogPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfigLoader;
import com.navercorp.pinpoint.bootstrap.config.Profiles;
import com.navercorp.pinpoint.common.util.PropertyUtils;

import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory;
import com.navercorp.pinpoint.thrift.io.NetworkAvailabilityCheckPacket;
Expand All @@ -30,8 +29,6 @@
import com.navercorp.pinpoint.tools.network.grpc.GrpcTransportConfig;
import com.navercorp.pinpoint.tools.network.thrift.ThriftTransportConfig;
import org.apache.thrift.TException;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import java.io.File;
import java.io.IOException;
Expand All @@ -44,8 +41,6 @@
*/
public class NetworkAvailabilityChecker {

private static final Logger LOGGER = LogManager.getLogger(NetworkAvailabilityChecker.class);

private static final String SEPARATOR = File.separator;

public static void main(String[] args) {
Expand Down Expand Up @@ -134,8 +129,7 @@ public static void main(String[] args) {
}

private static String getActiveProfile(Properties defaultProperties) {
String profile = defaultProperties.getProperty(Profiles.ACTIVE_PROFILE_KEY, Profiles.DEFAULT_ACTIVE_PROFILE);
return profile;
return defaultProperties.getProperty(Profiles.ACTIVE_PROFILE_KEY, "release");
}

private static void loadFileProperties(Properties properties, String filePath) {
Expand Down

0 comments on commit 455c291

Please # to comment.