You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/10/29 13:36:44 UTC

[skywalking] branch master updated: fix config yaml data type conversion bug (#8035)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 149b359  fix config yaml data type conversion bug (#8035)
149b359 is described below

commit 149b359ca62b9ead2a9fc73b094e8501d45fc276
Author: zhyyu <zh...@gmail.com>
AuthorDate: Fri Oct 29 21:35:17 2021 +0800

    fix config yaml data type conversion bug (#8035)
    
    Co-authored-by: yuzhongyu <yu...@cestc.cn>
---
 CHANGES.md                                         |  1 +
 .../starter/config/ApplicationConfigLoader.java    | 17 ++++++++++-
 .../config/ApplicationConfigLoaderTestCase.java    | 34 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index 27c28a7..b0d4f85 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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
 
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 7fcf620..3bccd30 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
@@ -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());
diff --git a/oap-server/server-starter/src/test/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoaderTestCase.java b/oap-server/server-starter/src/test/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoaderTestCase.java
index 52b61c5..09f7871 100644
--- a/oap-server/server-starter/src/test/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoaderTestCase.java
+++ b/oap-server/server-starter/src/test/java/org/apache/skywalking/oap/server/starter/config/ApplicationConfigLoaderTestCase.java
@@ -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);
+    }
+
 }