-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
config: Add hostname and worker_id short-cut. fix #1473 #1814
Conversation
lib/fluent/config/literal_parser.rb
Outdated
@@ -162,6 +163,8 @@ def eval_embedded_code(code) | |||
if @eval_context.nil? | |||
parse_error! "embedded code is not allowed in this file" | |||
end | |||
hostname = Socket.gethostname | |||
worker_id = ENV['SERVERENGINE_WORKER_ID'] || '' |
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.
This approach shows warnings with verbose mode but I'm not sure how to avoid 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.
I can't see any warnings on my environment. Could you share the detail?
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.
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.
Ah, I see. How about using Binding#local_variable_set
?
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.
With instance_eval
, local_variable_set
doesn't work. Try this:
context = Kernel.binding
context.local_variable_set(:worker_id, 1)
p context.instance_eval('"foo#{worker_id}"')
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.
Can't we use #eval
instead of #instance_eval
here?
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.
I'm not sure it doesn't break existing behaviour or not.
@nurse Do you see any problem for using eval
here?
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.
Just add to code
seems simple.
code = <<eom + code
hostname = Socket.gethostname
worker_id = ENV['SERVERENGINE_WORKER_ID'] || ''
eom
@eval_context.instance_eval(code)
With this conf
dumped config is like this:
but I think |
Yeah. The problem is |
Makes sense. |
Applied reviews. Will merge after test passed. |
No description provided.