diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java index 48514f2fed8c..0430056145cf 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/DefaultProfilerConfig.java @@ -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; @@ -258,18 +258,16 @@ public Map 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 + '\'' + + '}'; } } \ No newline at end of file diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/Profiles.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/Profiles.java index f4b15f1df95e..a262fa63e278 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/Profiles.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/config/Profiles.java @@ -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"; diff --git a/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java b/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java index ea6ddaf317c2..3ccb76f62946 100644 --- a/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java +++ b/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java @@ -60,14 +60,18 @@ public ProfilePropertyLoader(SimpleProperty javaSystemProperty, SimpleProperty o /** *
Configuration order
* - *

Same order as Spring-Boot - *

https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html + *

Same order as Spring-Boot

+ *

+ * + * boot-features-external-config + * + *

*
    - *
  1. Java System properties - *
  2. OS environment variables - *
  3. agent external configuration - *
  4. agent profile configuration /profiles/${profile}/pinpoint.config - *
  5. agent config /pinpoint-env.config + *
  6. Java System properties
  7. + *
  8. OS environment variables
  9. + *
  10. agent external configuration
  11. + *
  12. agent profile configuration /profiles/${profile}/pinpoint.config
  13. + *
  14. agent config /pinpoint-env.config
  15. *
*/ @Override @@ -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 + + "= to VM option. Valid profiles are \"" + profileCandidates + "\""); } // prevent directory traversal attack diff --git a/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/SimplePropertyLoader.java b/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/SimplePropertyLoader.java index 973f368c6b80..8eeded88d014 100644 --- a/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/SimplePropertyLoader.java +++ b/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/SimplePropertyLoader.java @@ -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(); diff --git a/tools/src/main/java/com/navercorp/pinpoint/tools/NetworkAvailabilityChecker.java b/tools/src/main/java/com/navercorp/pinpoint/tools/NetworkAvailabilityChecker.java index ff7e844e862a..3cbf42f54eb0 100644 --- a/tools/src/main/java/com/navercorp/pinpoint/tools/NetworkAvailabilityChecker.java +++ b/tools/src/main/java/com/navercorp/pinpoint/tools/NetworkAvailabilityChecker.java @@ -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; @@ -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; @@ -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) { @@ -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) {