cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasobr...@apache.org
Subject [04/16] cassandra git commit: Only log yaml config once, at startup
Date Wed, 02 Mar 2016 21:04:05 GMT
Only log yaml config once, at startup

patch by jasobrown, reviewed by Paulo Motta for CASSANDRA-11217


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/09345420
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/09345420
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/09345420

Branch: refs/heads/trunk
Commit: 093454205498bad7094cb8fb362d60e95296b092
Parents: d1f6a1d
Author: Jason Brown <jasedbrown@gmail.com>
Authored: Fri Feb 12 14:55:27 2016 -0800
Committer: Jason Brown <jasedbrown@gmail.com>
Committed: Wed Mar 2 12:57:06 2016 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../org/apache/cassandra/config/Config.java     | 51 ++++++++++++++++++++
 .../cassandra/config/DatabaseDescriptor.java    | 12 ++++-
 .../config/YamlConfigurationLoader.java         | 18 +------
 4 files changed, 63 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/09345420/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 481916b..db6d79d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.6
+ * Only log yaml config once, at startup (CASSANDRA-11217)
  * Preserve order for preferred SSL cipher suites (CASSANDRA-11164)
  * Reference leak with parallel repairs on the same table (CASSANDRA-11215)
  * Range.compareTo() violates the contract of Comparable (CASSANDRA-11216)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/09345420/src/java/org/apache/cassandra/config/Config.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/Config.java b/src/java/org/apache/cassandra/config/Config.java
index e7ac0c0..c7ad837 100644
--- a/src/java/org/apache/cassandra/config/Config.java
+++ b/src/java/org/apache/cassandra/config/Config.java
@@ -17,14 +17,27 @@
  */
 package org.apache.cassandra.config;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.StringReader;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.concurrent.TimeUnit;
 
+import com.google.common.base.Joiner;
 import com.google.common.collect.Sets;
 
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.cassandra.config.EncryptionOptions.ClientEncryptionOptions;
 import org.apache.cassandra.config.EncryptionOptions.ServerEncryptionOptions;
 import org.apache.cassandra.exceptions.ConfigurationException;
@@ -38,6 +51,8 @@ import org.supercsv.prefs.CsvPreference;
  */
 public class Config
 {
+    private static final Logger logger = LoggerFactory.getLogger(Config.class);
+
     /*
      * Prefix for Java properties for internal Cassandra configuration options
      */
@@ -368,4 +383,40 @@ public class Config
     {
         keyspace
     }
+
+    private static final List<String> SENSITIVE_KEYS = new ArrayList<String>()
{{
+        add("client_encryption_options");
+        add("server_encryption_options");
+    }};
+    public void log()
+    {
+        Map<String, String> configMap = new TreeMap<>();
+        for (Field field : getClass().getFields())
+        {
+            // ignore the constants
+            if (Modifier.isFinal(field.getModifiers()))
+                continue;
+
+            String name = field.getName();
+            if (SENSITIVE_KEYS.contains(name))
+            {
+                configMap.put(name, "<REDACTED>");
+                continue;
+            }
+
+            String value;
+            try
+            {
+                // Field.get() can throw NPE if the value of the field is null
+                value = field.get(this).toString();
+            }
+            catch (NullPointerException | IllegalAccessException npe)
+            {
+                value = "null";
+            }
+            configMap.put(name, value);
+        }
+
+        logger.info("Node configuration:[" + Joiner.on("; ").join(configMap.entrySet()) +
"]");
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/09345420/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
index af0595d..cbea2ff 100644
--- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
+++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
@@ -53,7 +53,6 @@ import org.apache.cassandra.scheduler.IRequestScheduler;
 import org.apache.cassandra.scheduler.NoScheduler;
 import org.apache.cassandra.service.CacheService;
 import org.apache.cassandra.thrift.ThriftServer;
-import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.memory.*;
 
@@ -101,6 +100,7 @@ public class DatabaseDescriptor
 
     private static String localDC;
     private static Comparator<InetAddress> localComparator;
+    private static boolean hasLoggedConfig;
 
     public static void forceStaticInitialization() {}
     static
@@ -132,7 +132,15 @@ public class DatabaseDescriptor
         ConfigurationLoader loader = loaderClass == null
                                    ? new YamlConfigurationLoader()
                                    : FBUtilities.<ConfigurationLoader>construct(loaderClass,
"configuration loading");
-        return loader.loadConfig();
+        Config config = loader.loadConfig();
+
+        if (!hasLoggedConfig)
+        {
+            hasLoggedConfig = true;
+            config.log();
+        }
+
+        return config;
     }
 
     private static InetAddress getNetworkInterfaceAddress(String intf, String configName,
boolean preferIPv6) throws ConfigurationException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/09345420/src/java/org/apache/cassandra/config/YamlConfigurationLoader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/YamlConfigurationLoader.java b/src/java/org/apache/cassandra/config/YamlConfigurationLoader.java
index 8331f85..dc691c4 100644
--- a/src/java/org/apache/cassandra/config/YamlConfigurationLoader.java
+++ b/src/java/org/apache/cassandra/config/YamlConfigurationLoader.java
@@ -89,7 +89,7 @@ public class YamlConfigurationLoader implements ConfigurationLoader
     {
         try
         {
-            logger.info("Loading settings from {}", url);
+            logger.debug("Loading settings from {}", url);
             byte[] configBytes;
             try (InputStream is = url.openStream())
             {
@@ -101,8 +101,6 @@ public class YamlConfigurationLoader implements ConfigurationLoader
                 throw new AssertionError(e);
             }
 
-            logConfig(configBytes);
-
             org.yaml.snakeyaml.constructor.Constructor constructor = new org.yaml.snakeyaml.constructor.Constructor(Config.class);
             TypeDescription seedDesc = new TypeDescription(ParameterizedClass.class);
             seedDesc.putMapPropertyType("parameters", String.class, String.class);
@@ -121,20 +119,6 @@ public class YamlConfigurationLoader implements ConfigurationLoader
         }
     }
 
-    private void logConfig(byte[] configBytes)
-    {
-        Map<Object, Object> configMap = new TreeMap<>((Map<?, ?>) new Yaml().load(new
ByteArrayInputStream(configBytes)));
-        // these keys contain passwords, don't log them
-        for (String sensitiveKey : new String[] { "client_encryption_options", "server_encryption_options"
})
-        {
-            if (configMap.containsKey(sensitiveKey))
-            {
-                configMap.put(sensitiveKey, "<REDACTED>");
-            }
-        }
-        logger.info("Node configuration:[{}]", Joiner.on("; ").join(configMap.entrySet()));
-    }
-
     private static class MissingPropertiesChecker extends PropertyUtils
     {
         private final Set<String> missingProperties = new HashSet<>();


Mime
View raw message