fix config yaml data type conversion bug (#8035)
Co-authored-by: yuzhongyu <yuzhongyu@cestc.cn>
This commit is contained in:
parent
32f9ab01f2
commit
149b359ca6
|
|
@ -42,6 +42,7 @@ Release Notes.
|
|||
* Fix TimeBucket missing in ElasticSearch and provide compatible `storage2Entity` for previous versions.
|
||||
* Fix ElasticSearch implementation of `queryMetricsValues` and `readLabeledMetricsValues` doesn't fill default values
|
||||
when no available data in the ElasticSearch server.
|
||||
* Fix config yaml data type conversion bug when meets special character like !.
|
||||
|
||||
#### UI
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.skywalking.oap.server.starter.config;
|
|||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
|
@ -111,7 +112,7 @@ public class ApplicationConfigLoader implements ConfigLoader<ApplicationConfigur
|
|||
log.info("Provider={} config={} has been set as an empty string", providerName, propertyName);
|
||||
} else {
|
||||
// Use YAML to do data type conversion.
|
||||
final Object replaceValue = yaml.load(valueString);
|
||||
final Object replaceValue = convertValueString(valueString);
|
||||
if (replaceValue != null) {
|
||||
target.replace(propertyName, replaceValue);
|
||||
log.info(
|
||||
|
|
@ -125,6 +126,20 @@ public class ApplicationConfigLoader implements ConfigLoader<ApplicationConfigur
|
|||
}
|
||||
}
|
||||
|
||||
private Object convertValueString(String valueString) {
|
||||
try {
|
||||
Object replaceValue = yaml.load(valueString);
|
||||
if (replaceValue instanceof String || replaceValue instanceof Integer || replaceValue instanceof Long || replaceValue instanceof Boolean || replaceValue instanceof ArrayList) {
|
||||
return replaceValue;
|
||||
} else {
|
||||
return valueString;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("yaml convert value type error, use origin values string. valueString={}", valueString, e);
|
||||
return valueString;
|
||||
}
|
||||
}
|
||||
|
||||
private void overrideConfigBySystemEnv(ApplicationConfiguration configuration) {
|
||||
for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
|
||||
overrideModuleSettings(configuration, prop.getKey().toString(), prop.getValue().toString());
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public class ApplicationConfigLoaderTestCase {
|
|||
public void setUp() throws ConfigFileNotFoundException {
|
||||
System.setProperty("SW_STORAGE", "mysql");
|
||||
System.setProperty("SW_RECEIVER_ZIPKIN", "default");
|
||||
System.setProperty("SW_DATA_SOURCE_PASSWORD", "!AI!3B");
|
||||
ApplicationConfigLoader configLoader = new ApplicationConfigLoader();
|
||||
applicationConfiguration = configLoader.load();
|
||||
}
|
||||
|
|
@ -60,4 +61,37 @@ public class ApplicationConfigLoaderTestCase {
|
|||
assertEquals(2, instanceNameRule.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadStringTypeConfig() {
|
||||
Properties providerConfig = applicationConfiguration.getModuleConfiguration("receiver_zipkin")
|
||||
.getProviderConfiguration("default");
|
||||
String host = (String) providerConfig.get("host");
|
||||
assertEquals("0.0.0.0", host);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadIntegerTypeConfig() {
|
||||
Properties providerConfig = applicationConfiguration.getModuleConfiguration("receiver_zipkin")
|
||||
.getProviderConfiguration("default");
|
||||
Integer port = (Integer) providerConfig.get("port");
|
||||
assertEquals(Integer.valueOf(9411), port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadBooleanTypeConfig() {
|
||||
Properties providerConfig = applicationConfiguration.getModuleConfiguration("core")
|
||||
.getProviderConfiguration("default");
|
||||
Boolean enableDataKeeperExecutor = (Boolean) providerConfig.get("enableDataKeeperExecutor");
|
||||
assertEquals(Boolean.TRUE, enableDataKeeperExecutor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSpecialStringTypeConfig() {
|
||||
Properties providerConfig = applicationConfiguration.getModuleConfiguration("storage")
|
||||
.getProviderConfiguration("mysql");
|
||||
Properties properties = (Properties) providerConfig.get("properties");
|
||||
String password = (String) properties.get("dataSource.password");
|
||||
assertEquals("!AI!3B", password);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue