From 710a42e98703f8f3973ab97a0c403a6b617549c5 Mon Sep 17 00:00:00 2001 From: Ravi Kancherla Date: Wed, 28 Mar 2018 09:51:17 -0500 Subject: [PATCH] getting indiv props instead of reading all props (#444) Secured applications may not have access to all system properties on a server. Making this change to prevent reading all the system properties and just read the properties that are required for creating the DefaultMonitorRegistry instance. Fixes #443. --- .../servo/tag/aws/AwsInjectableTag.java | 2 +- .../netflix/servo/DefaultMonitorRegistry.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/servo-aws/src/main/java/com/netflix/servo/tag/aws/AwsInjectableTag.java b/servo-aws/src/main/java/com/netflix/servo/tag/aws/AwsInjectableTag.java index bec05db3..cb0f9f1b 100644 --- a/servo-aws/src/main/java/com/netflix/servo/tag/aws/AwsInjectableTag.java +++ b/servo-aws/src/main/java/com/netflix/servo/tag/aws/AwsInjectableTag.java @@ -89,7 +89,7 @@ public String tagString() { static String getAutoScaleGroup() { try { - String credFileProperty = System.getProperties().getProperty( + String credFileProperty = System.getProperty( AwsPropertyKeys.AWS_CREDENTIALS_FILE.getBundle()); AWSCredentials credentials; diff --git a/servo-core/src/main/java/com/netflix/servo/DefaultMonitorRegistry.java b/servo-core/src/main/java/com/netflix/servo/DefaultMonitorRegistry.java index fe7c0990..60c4ec49 100644 --- a/servo-core/src/main/java/com/netflix/servo/DefaultMonitorRegistry.java +++ b/servo-core/src/main/java/com/netflix/servo/DefaultMonitorRegistry.java @@ -61,7 +61,7 @@ public static MonitorRegistry getInstance() { * Creates a new instance based on system properties. */ DefaultMonitorRegistry() { - this(System.getProperties()); + this(loadProps()); } /** @@ -118,6 +118,24 @@ private static ObjectNameMapper getObjectNameMapper(Properties props) { return mapper; } + + private static Properties loadProps() { + String registryClassProp = System.getProperty(REGISTRY_CLASS_PROP); + String registryNameProp = System.getProperty(REGISTRY_NAME_PROP); + String registryJmxNameProp = System.getProperty(REGISTRY_JMX_NAME_PROP); + + Properties props = new Properties(); + if (registryClassProp != null) { + props.setProperty(REGISTRY_CLASS_PROP, registryClassProp); + } + if (registryNameProp != null) { + props.setProperty(REGISTRY_NAME_PROP, registryNameProp); + } + if (registryJmxNameProp != null) { + props.setProperty(REGISTRY_JMX_NAME_PROP, registryJmxNameProp); + } + return props; + } /** * The set of registered Monitor objects.