-
Notifications
You must be signed in to change notification settings - Fork 2k
[Feature][Config] Support nested references to external files in configuration files #8984
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
base: dev
Are you sure you want to change the base?
Changes from 4 commits
9d0a299
8294c05
ed29abf
8aefcf6
9c0fd04
73b4e0a
5ebd068
55972ae
580ecd7
e4b41f7
ccc1d22
6b1ad30
7ab6ec7
2973521
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 |
---|---|---|
|
@@ -107,4 +107,10 @@ public class EnvCommonOptions { | |
.mapType() | ||
.noDefaultValue() | ||
.withDescription("Define the worker where the job runs by tag"); | ||
|
||
public static Option<String> REF_PATH = | ||
Options.key("__st_config_ref_path__") | ||
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.
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. Not surprising, he cannot conflict with normal attributes |
||
.stringType() | ||
.defaultValue(null) | ||
.withDescription("Define the ref config file path"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,29 +173,51 @@ private static Config processConfig( | |
String jsonString = config.root().render(ConfigRenderOptions.concise()); | ||
ObjectNode jsonNodes = JsonUtils.parseObject(jsonString); | ||
Map<String, Object> configMap = JsonUtils.toMap(jsonNodes); | ||
List<Map<String, Object>> sources = | ||
(ArrayList<Map<String, Object>>) configMap.get(Constants.SOURCE); | ||
List<Map<String, Object>> sinks = | ||
(ArrayList<Map<String, Object>>) configMap.get(Constants.SINK); | ||
Preconditions.checkArgument( | ||
!sources.isEmpty(), "Miss <Source> config! Please check the config file."); | ||
Preconditions.checkArgument( | ||
!sinks.isEmpty(), "Miss <Sink> config! Please check the config file."); | ||
sources.forEach( | ||
source -> { | ||
for (String sensitiveOption : sensitiveOptions) { | ||
source.computeIfPresent(sensitiveOption, processFunction); | ||
} | ||
}); | ||
sinks.forEach( | ||
sink -> { | ||
for (String sensitiveOption : sensitiveOptions) { | ||
sink.computeIfPresent(sensitiveOption, processFunction); | ||
} | ||
}); | ||
configMap.put(Constants.SOURCE, sources); | ||
configMap.put(Constants.SINK, sinks); | ||
return ConfigFactory.parseMap(configMap); | ||
if (configMap.containsKey(Constants.SOURCE)) { | ||
thirsd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
List<Map<String, Object>> sources = | ||
(ArrayList<Map<String, Object>>) configMap.get(Constants.SOURCE); | ||
List<Map<String, Object>> sinks = | ||
(ArrayList<Map<String, Object>>) configMap.get(Constants.SINK); | ||
Preconditions.checkArgument( | ||
!sources.isEmpty(), "Miss <Source> config! Please check the config file."); | ||
Preconditions.checkArgument( | ||
!sinks.isEmpty(), "Miss <Sink> config! Please check the config file."); | ||
sources.forEach( | ||
source -> { | ||
for (String sensitiveOption : sensitiveOptions) { | ||
source.computeIfPresent(sensitiveOption, processFunction); | ||
} | ||
}); | ||
sinks.forEach( | ||
sink -> { | ||
for (String sensitiveOption : sensitiveOptions) { | ||
sink.computeIfPresent(sensitiveOption, processFunction); | ||
} | ||
}); | ||
configMap.put(Constants.SOURCE, sources); | ||
configMap.put(Constants.SINK, sinks); | ||
return ConfigFactory.parseMap(configMap); | ||
} else { | ||
Map<String, Map<String, Object>> refMap = new HashMap<>(); | ||
// get map element in ref | ||
for (String key : configMap.keySet()) { | ||
Object ref_config = configMap.get(key); | ||
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. we should name the variables in the camelcase style. |
||
if (ref_config instanceof Map) { | ||
// 2. 安全转换为 Map(泛型擦除后需处理警告) | ||
Map<String, Object> refDict = (Map<String, Object>) ref_config; | ||
refMap.put(key, refDict); | ||
} | ||
} | ||
refMap.forEach( | ||
(refId, RefConfig) -> { | ||
Map<String, Object> ref_dit = new HashMap<>(RefConfig.size()); | ||
for (String sensitiveOption : sensitiveOptions) { | ||
ref_dit.computeIfPresent(sensitiveOption, processFunction); | ||
} | ||
}); | ||
return ConfigFactory.parseMap(refMap); | ||
} | ||
} | ||
|
||
public static Set<String> getSensitiveOptions(Config config) { | ||
|
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.
From the code, looks if the
mysql_prod
ref config also containsquery
parameter, it will overwrite the existedquery
parameter.Please add the priority for replacements when there are duplicate parameters.
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.
got it
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.
We can just describe it in the document to let use know this thing. Replace behavior is good to me.
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.
已经补充了配置优先级。