-
Notifications
You must be signed in to change notification settings - Fork 311
Stable Config improvements #9259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
370e894
df4da2f
7049d36
e730cbe
5b639aa
85d11cf
6ab4b6c
007f58a
ac69f2d
473c59b
feb1ba0
f93546a
780aee3
ac5e05a
bcebbcb
0baccfd
957d9c9
b9870bd
5019584
e8d6e8f
1fefb17
058cbda
5460c8a
37da711
5dac7f8
5104ac5
13bef8d
2706bca
4dde216
bfd5d7b
16d5f36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,34 @@ public Rule(List<Selector> selectors, Map<String, Object> configuration) { | |
} | ||
|
||
public Rule(Object yaml) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know if this constructor is too hard to read and if you recommend I move the "require fields" logic into helper functions (in a utils class to be used by both Rule and Selector?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, I would rather try to bring type safety to the Java API as soon as possible even if SnakeYaml is returning loose An idiomatic Java would be to have a static builder like So far example, I would check the type ahead in this.apmConfigurationRules = parseRules(yaml);
// with some helper methods in StableConfig
private List<Rule> parseRules(Map<?, ?> yaml) {
Object apmConfigurationDefaultObject = map.get("apm_configuration_default");
if (apmConfigurationDefaultObject instanceof List) {
return ((List<?>) apmConfigurationDefaultObject).stream()
.filter(r -> r instanceof Map)
.map(r -> (Map<?, ?>) r)
.map(Rule::fromMap)
.collect(toList());
} else {
return emptyList();
}
} |
||
if (!(yaml instanceof Map)) { | ||
throw new StableConfigMappingException( | ||
"Rule must be a map, but got: " + yaml.getClass().getSimpleName()); | ||
} | ||
Map map = (Map) yaml; | ||
|
||
Object selectorsObj = map.get("selectors"); | ||
if (selectorsObj == null) { | ||
throw new StableConfigMappingException("Missing 'selectors' in rule: " + map); | ||
AlexeyKuznetsov-DD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (!(selectorsObj instanceof List)) { | ||
mtoffl01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new StableConfigMappingException( | ||
"'selectors' must be a list, but got: " + selectorsObj.getClass().getSimpleName()); | ||
} | ||
selectors = | ||
unmodifiableList( | ||
((List<Object>) map.get("selectors")) | ||
((List<Object>) selectorsObj) | ||
.stream().filter(Objects::nonNull).map(Selector::new).collect(toList())); | ||
configuration = unmodifiableMap((Map<String, Object>) map.get("configuration")); | ||
|
||
Object configObj = map.get("configuration"); | ||
if (configObj == null) { | ||
throw new StableConfigMappingException("Missing 'configuration' in rule: " + map); | ||
} | ||
if (!(configObj instanceof Map)) { | ||
throw new StableConfigMappingException( | ||
"'configuration' must be a map, but got: " + configObj.getClass().getSimpleName()); | ||
} | ||
configuration = unmodifiableMap((Map<String, Object>) configObj); | ||
} | ||
|
||
public List<Selector> getSelectors() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package datadog.trace.bootstrap.config.provider.stableconfig; | ||
|
||
public class StableConfigMappingException extends RuntimeException { | ||
public StableConfigMappingException(String message) { | ||
super(message); | ||
} | ||
|
||
public StableConfigMappingException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍