diff --git a/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/PropertyPlaceholderHelper.java b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/PropertyPlaceholderHelper.java index 41957f4de1ec61e6419ce311a62bd6e9a5a276b1..10de12200c8e7afd210051cc37c055708e11c965 100644 --- a/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/PropertyPlaceholderHelper.java +++ b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/PropertyPlaceholderHelper.java @@ -29,14 +29,11 @@ import java.util.Set; * ${name}}. Using {@code PropertyPlaceholderHelper} these placeholders can be substituted for user-supplied values.
* Values for substitution can be supplied using a {@link Properties} instance or using a {@link PlaceholderResolver}.
*/
-public class PropertyPlaceholderHelper {
- private static final Map
* Also try to override the config by system.env and system.properties. All the keys in these two places should
* start with {@link #ENV_KEY_PREFIX}. e.g. in env `skywalking.agent.application_code=yourAppName` to override
@@ -67,14 +67,10 @@ public class SnifferConfigInitializer {
configFileStream = loadConfig();
Properties properties = new Properties();
properties.load(configFileStream);
- PropertyPlaceholderHelper helper =
- new PropertyPlaceholderHelper(PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX,
- PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX,
- PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR, true);
for (String key : properties.stringPropertyNames()) {
String value = (String)properties.get(key);
//replace the key's value. properties.replace(key,value) in jdk8+
- properties.put(key, helper.replacePlaceholders(value, properties));
+ properties.put(key, PropertyPlaceholderHelper.INSTANCE.replacePlaceholders(value, properties));
}
ConfigInitializer.initialize(properties, Config.class);
} catch (Exception e) {
@@ -153,11 +149,10 @@ public class SnifferConfigInitializer {
}
/**
- * Override the config by system properties. The env key must start with `skywalking`, the reuslt should be as same as in
- * `agent.config`
+ * Override the config by system properties. The env key must start with `skywalking`, the reuslt should be as same
+ * as in `agent.config`
*
- * such as:
- * Env key of `agent.application_code` shoule be `skywalking.agent.application_code`
+ * such as: Env key of `agent.application_code` shoule be `skywalking.agent.application_code`
*
* @return the config file {@link InputStream}, or null if not needEnhance.
*/
diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java
index 305466ef2ce9a71dc00f0a8cd9db278e4a166659..0ed5d4e5279d0643897ae68f1354ab7a1e66a98b 100644
--- a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java
+++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java
@@ -24,7 +24,6 @@ import java.util.Properties;
import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.apache.skywalking.apm.agent.core.logging.core.LogLevel;
import org.apache.skywalking.apm.util.ConfigInitializer;
-import org.apache.skywalking.apm.util.PlaceholderConfigurerSupport;
import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.junit.After;
import org.junit.Rule;
@@ -81,11 +80,7 @@ public class SnifferConfigInitializerTest {
properties.put("agent.service_name", "${AGENT_SERVICE_NAME:testAppFromSystem}");
properties.put("collector.backend_service", "${AGENT_COLLECTOR_SERVER:127.0.0.1:8090}");
properties.put("logging.level", "INFO");
-
- PropertyPlaceholderHelper placeholderHelper =
- new PropertyPlaceholderHelper(PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX,
- PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX,
- PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR, true);
+ PropertyPlaceholderHelper placeholderHelper = PropertyPlaceholderHelper.INSTANCE;
properties.put("agent.service_name", placeholderHelper.replacePlaceholders((String)properties.get("agent.service_name"), properties));
properties.put("collector.backend_service", placeholderHelper.replacePlaceholders((String)properties.get("collector.backend_service"), properties));
ConfigInitializer.initialize(properties, Config.class);
diff --git a/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/PropertyPlaceholderHelperTest.java b/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/PropertyPlaceholderHelperTest.java
index 6c72092f60404eb50ca3b2ccc24bd64cb68de23f..bd88be2d1af4e7a2f5c4ac4bcd6d8064a72343bd 100644
--- a/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/PropertyPlaceholderHelperTest.java
+++ b/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/PropertyPlaceholderHelperTest.java
@@ -22,7 +22,6 @@ import java.io.FileNotFoundException;
import java.io.Reader;
import java.util.Map;
import java.util.Properties;
-import org.apache.skywalking.apm.util.PlaceholderConfigurerSupport;
import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.junit.After;
import org.junit.Assert;
@@ -63,10 +62,7 @@ public class PropertyPlaceholderHelperTest {
}
});
}
- placeholderHelper =
- new PropertyPlaceholderHelper(PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX,
- PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX,
- PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR, true);
+ placeholderHelper = PropertyPlaceholderHelper.INSTANCE;
}
@Test
diff --git a/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoader.java b/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoader.java
index 80e965902a1167ed7d097974188a71fdfd598f48..fdc2e7fe616ce1ba46a0652d7f1f1f4e0525de8d 100644
--- a/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoader.java
+++ b/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoader.java
@@ -22,10 +22,9 @@ import java.io.FileNotFoundException;
import java.io.Reader;
import java.util.Map;
import java.util.Properties;
+import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.apache.skywalking.oap.server.library.module.ApplicationConfiguration;
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
-import org.apache.skywalking.apm.util.PlaceholderConfigurerSupport;
-import org.apache.skywalking.apm.util.PropertyPlaceholderHelper;
import org.apache.skywalking.oap.server.library.util.ResourceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,11 +67,8 @@ public class ApplicationConfigLoader implements ConfigLoader