-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Remove comments of config.string
.
#16625
Changes from 1 commit
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 |
---|---|---|
|
@@ -23,14 +23,17 @@ class MultiLocal < Local | |
include LogStash::Util::SubstitutionVariables | ||
include LogStash::Util::Loggable | ||
|
||
REMOVE_COMMENTS_CONFIG_KEYS = %w(config.string) | ||
|
||
def initialize(settings) | ||
@original_settings = settings | ||
super(settings) | ||
@match_warning_done = false | ||
end | ||
|
||
def pipeline_configs | ||
pipelines = deep_replace(retrieve_yaml_pipelines) | ||
yaml_config_without_comments = wipeout_comments(retrieve_yaml_pipelines) | ||
pipelines = deep_replace(yaml_config_without_comments) | ||
pipelines_settings = pipelines.map do |pipeline_settings| | ||
clone = @original_settings.clone | ||
clone.merge_pipeline_settings(pipeline_settings) | ||
|
@@ -134,5 +137,28 @@ def do_warning? | |
end | ||
!done | ||
end | ||
|
||
# @param [Object] `yaml_config` the input object | ||
# @return [Object] Updated object where its key etries which match the `CONFIG_KEYS_TO_WIPE_OUT_COMMENTS` do not contain comments | ||
def wipeout_comments(yaml_config) | ||
case yaml_config | ||
when Hash | ||
yaml_config.each do |key, val| | ||
yaml_config[key.to_s] = wipeout_comments(val) if REMOVE_COMMENTS_CONFIG_KEYS.include?(key) | ||
end | ||
when Array | ||
yaml_config.map { |val| wipeout_comments(val) } | ||
when String | ||
yaml_config.lines.map do |line| | ||
if line.strip.start_with?("#") | ||
"" | ||
else | ||
line.match?(/(?<!['"]) #/) ? line.gsub(/ (?<!['"])#.*/, '') : line | ||
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. I'm still learning what is acceptable under these pipeline definitions.... Would it be possible to have string literals with a
In that case, would we mangle this using this regex? 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. it would:
same with ruby code that may have a #:
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. Wow! This is more than I initially thought. I have revised a logic but honestly I would avoid adding such complex art which touches user's config. Maybe we document that commenting env ${VAR} is not allowed for Example
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. Agreed, it's a very high hanging fruit for very little return in terms of user experience. +1 on documenting this limitation and closing the PR 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. I agree, i was looking back at the discussion around this issue trying to get the context. It seemed to me at first glance that the behavior of doing interpolation here is correct. Specifically the flow seemed to be that variables would be interpolated before generating the config. At that point there would be no concept of what is a comment vs config in the template input. I do see how this may be a frustrating edge case, but it is one that is probably not worth introducing magic around. 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. Thanks for the feedback! I have added doc changes with the PR-16689 and that closes both current PR and upstream issue. |
||
end | ||
end.join("\n") | ||
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. review note: we keep new lines even though they are empty because when something goes wrong in config, error displays the line with specific error position. |
||
else | ||
yaml_config | ||
end | ||
end | ||
end | ||
end end end |
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.
review note: currently only
config.string
may contain the comments.YAML::safe_load
removes the comments from other keys such aspipeline.id
.