-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #651 from Netflix/instrumentation
Property usage instrumentation initial framework
- Loading branch information
Showing
27 changed files
with
1,134 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
archaius2-api/src/main/java/com/netflix/archaius/api/PropertyDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.netflix.archaius.api; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Container class for any information about the property at usage time that is relevant for instrumentation purposes. | ||
*/ | ||
public class PropertyDetails { | ||
private final String key; | ||
private final String id; | ||
private final Object value; | ||
public PropertyDetails(String key, String id, Object value) { | ||
this.key = key; | ||
this.id = id; | ||
this.value = value; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public Object getValue() { | ||
return value; | ||
} | ||
|
||
public boolean equals(Object o) { | ||
if (!(o instanceof PropertyDetails)) { | ||
return false; | ||
} | ||
PropertyDetails pd = (PropertyDetails) o; | ||
return Objects.equals(key, pd.key) | ||
&& Objects.equals(id, pd.id) | ||
&& Objects.equals(value, pd.value); | ||
} | ||
|
||
public String toString() { | ||
return "[key: " + key + ", id: " + id + ", value: " + value + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
archaius2-core/src/main/java/com/netflix/archaius/config/AbstractDependentConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.netflix.archaius.config; | ||
|
||
import com.netflix.archaius.api.PropertyDetails; | ||
|
||
import java.util.Iterator; | ||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* Extendable base class for the dependent config paradigm. Dependent configs are assumed to be configs which inherit | ||
* values from some number (1+) of parent configs. Dependent configs hold onto caches of the property data and operate | ||
* independently of the parent configs except in cases of propagation of instrumentation data and property value | ||
* changes. | ||
* | ||
* TODO: Move DependentConfigListener logic here as well? | ||
*/ | ||
public abstract class AbstractDependentConfig extends AbstractConfig { | ||
|
||
public AbstractDependentConfig(String name) { | ||
super(name); | ||
} | ||
|
||
public AbstractDependentConfig() { | ||
super(); | ||
} | ||
|
||
abstract CachedState getState(); | ||
|
||
@Override | ||
public Object getRawProperty(String key) { | ||
Object value = getState().getData().get(key); | ||
if (getState().getInstrumentedKeys().containsKey(key)) { | ||
getState().getInstrumentedKeys().get(key).recordUsage(createPropertyDetails(key, value)); | ||
} | ||
return value; | ||
} | ||
|
||
@Override | ||
public Object getRawPropertyUninstrumented(String key) { | ||
return getState().getData().get(key); | ||
} | ||
|
||
/** Return a set of all unique keys tracked by any child of this composite. */ | ||
@Override | ||
public Iterator<String> getKeys() { | ||
return getState().getData().keySet().iterator(); | ||
} | ||
|
||
@Override | ||
public Iterable<String> keys() { | ||
return getState().getData().keySet(); | ||
} | ||
|
||
@Override | ||
public void forEachProperty(BiConsumer<String, Object> consumer) { | ||
getState().getData().forEach((k, v) -> { | ||
if (getState().getInstrumentedKeys().containsKey(k)) { | ||
getState().getInstrumentedKeys().get(k).recordUsage(createPropertyDetails(k, v)); | ||
} | ||
consumer.accept(k, v); | ||
}); | ||
} | ||
|
||
@Override | ||
public void forEachPropertyUninstrumented(BiConsumer<String, Object> consumer) { | ||
getState().getData().forEach(consumer); | ||
} | ||
|
||
@Override | ||
public boolean containsKey(String key) { | ||
return getState().getData().containsKey(key); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return getState().getData().isEmpty(); | ||
} | ||
|
||
@Override | ||
public void recordUsage(PropertyDetails propertyDetails) { | ||
if (getState().getInstrumentedKeys().containsKey(propertyDetails.getKey())) { | ||
getState().getInstrumentedKeys().get(propertyDetails.getKey()).recordUsage(propertyDetails); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean instrumentationEnabled() { | ||
// In the case of dependent configs, instrumentation needs to be propagated. | ||
// So, if any of the parent configs are instrumented, we mark this config as instrumented as well. | ||
return !getState().getInstrumentedKeys().isEmpty(); | ||
} | ||
|
||
protected PropertyDetails createPropertyDetails(String key, Object value) { | ||
return new PropertyDetails(key, null, value); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
archaius2-core/src/main/java/com/netflix/archaius/config/CachedState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.netflix.archaius.config; | ||
|
||
import com.netflix.archaius.api.Config; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** Represents an immutable, current view of a dependent config over its parent configs. */ | ||
class CachedState { | ||
private final Map<String, Object> data; | ||
private final Map<String, Config> instrumentedKeys; | ||
|
||
CachedState(Map<String, Object> data, Map<String, Config> instrumentedKeys) { | ||
this.data = Collections.unmodifiableMap(data); | ||
this.instrumentedKeys = Collections.unmodifiableMap(instrumentedKeys); | ||
} | ||
|
||
Map<String, Object> getData() { | ||
return data; | ||
} | ||
|
||
Map<String, Config> getInstrumentedKeys() { | ||
return instrumentedKeys; | ||
} | ||
} |
Oops, something went wrong.