From 81e53ca2ae031fc80056e3702224983dd690e92e Mon Sep 17 00:00:00 2001 From: Yongkoo Kang Date: Wed, 27 Mar 2024 14:50:19 -0700 Subject: [PATCH] Add getPropertiesUninstrumented endpoint for ConfigurationUtils --- .../config/util/ConfigurationUtils.java | 43 +++++++++++++------ .../config/util/InstrumentationAware.java | 6 +++ 2 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 archaius-core/src/main/java/com/netflix/config/util/InstrumentationAware.java diff --git a/archaius-core/src/main/java/com/netflix/config/util/ConfigurationUtils.java b/archaius-core/src/main/java/com/netflix/config/util/ConfigurationUtils.java index 03bb12613..70353c25f 100644 --- a/archaius-core/src/main/java/com/netflix/config/util/ConfigurationUtils.java +++ b/archaius-core/src/main/java/com/netflix/config/util/ConfigurationUtils.java @@ -123,19 +123,36 @@ public static Map getAllNamedConfiguration(Configuration * @return properties extracted from the configuration */ public static Properties getProperties(Configuration config) { - Properties p = new Properties(); - if (config != null){ - Iterator 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 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) { diff --git a/archaius-core/src/main/java/com/netflix/config/util/InstrumentationAware.java b/archaius-core/src/main/java/com/netflix/config/util/InstrumentationAware.java new file mode 100644 index 000000000..a5b42d89d --- /dev/null +++ b/archaius-core/src/main/java/com/netflix/config/util/InstrumentationAware.java @@ -0,0 +1,6 @@ +package com.netflix.config.util; + +// Interface which surfaces instrumentation-related endpoints for configurations +public interface InstrumentationAware { + Object getPropertyUninstrumented(String key); +}