Skip to content

Commit

Permalink
Merge pull request #717 from Netflix/1.x-bridge-uninstrumented
Browse files Browse the repository at this point in the history
Add getPropertiesUninstrumented endpoint for ConfigurationUtils
  • Loading branch information
akang31 authored Mar 28, 2024
2 parents b74bd03 + 81e53ca commit 2c98773
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,36 @@ public static Map<String, Configuration> getAllNamedConfiguration(Configuration
* @return properties extracted from the configuration
*/
public static Properties getProperties(Configuration config) {
Properties p = new Properties();
if (config != null){
Iterator<String> it = config.getKeys();
while (it.hasNext()){
String key = it.next();
if (key != null) {
Object value = config.getProperty(key);
if (value != null) {
p.put(key, value);
} }
}
}
return p;
return getPropertiesInternal(config, true);
}

/**
* If possible, returns the Properties while avoiding instrumented fast property usage endpoints.
* @param config Configuration to get the properties
* @return properties extracted from the configuration
*/
public static Properties getPropertiesUninstrumented(Configuration config) {
return getPropertiesInternal(config, false);
}

private static Properties getPropertiesInternal(Configuration config, boolean instrumented) {
Properties p = new Properties();
if (config != null){
Iterator<String> it = config.getKeys();
while (it.hasNext()){
String key = it.next();
if (key != null) {
Object value =
!instrumented && config instanceof InstrumentationAware
? ((InstrumentationAware) config).getPropertyUninstrumented(key)
: config.getProperty(key);
if (value != null) {
p.put(key, value);
}
}
}
}
return p;
}

public static void loadProperties(Properties props, Configuration config) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.netflix.config.util;

// Interface which surfaces instrumentation-related endpoints for configurations
public interface InstrumentationAware {
Object getPropertyUninstrumented(String key);
}

0 comments on commit 2c98773

Please sign in to comment.