-
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
Support multi workers assign syntax on <worker>
section. Fix #2289
#2292
Conversation
Any advice and feedback are appreciated. |
raise ConfigError, "worker id #{target_worker_id} specified by <worker> directive is not allowed. Available worker id is between 0 and #{(Fluent::Engine.system_config.workers - 1)}" | ||
end | ||
target_worker_ids = target_worker_id_str.split("-") | ||
if target_worker_ids.size == 2 |
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.
Could you add duplication check to avoid following case?
<worker 0-3>
</worker>
<worker 3-7> # should be 4-7
</worker>
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've added a collisions checker in d900a73.
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.
And I added more concreate error message commit: 03da2b3.
lib/fluent/root_agent.rb
Outdated
first_worker_id = target_worker_ids.first.to_i | ||
last_worker_id = target_worker_ids.last.to_i | ||
if first_worker_id > last_worker_id | ||
raise ConfigError, "greater first_worker_id<#{first_worker_id}> than last_worker_id<#{last_worker_id}> specified by <worker> directive is not allowed. Available multi worker assign syntax is <smaller_worker_id>-<greater_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.
Fluent::ConfigError
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 used full-qualified name: 4200740.
lib/fluent/root_agent.rb
Outdated
first_worker_id.step(last_worker_id, 1) do |worker_id| | ||
target_worker_id = worker_id.to_i | ||
if target_worker_id < 0 || target_worker_id > (Fluent::Engine.system_config.workers - 1) | ||
raise ConfigError, "worker id #{target_worker_id} specified by <worker> directive is not allowed. Available worker id is between 0 and #{(Fluent::Engine.system_config.workers - 1)}" |
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.
ditto
lib/fluent/root_agent.rb
Outdated
|
||
e.elements.each do |elem| | ||
unless ['source', 'match', 'filter', 'label'].include?(elem.name) | ||
raise ConfigError, "<worker> section cannot have <#{elem.name}> directive" |
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.
ditto
lib/fluent/root_agent.rb
Outdated
else | ||
target_worker_id = target_worker_id_str.to_i | ||
if target_worker_id < 0 || target_worker_id > (Fluent::Engine.system_config.workers - 1) | ||
raise ConfigError, "worker id #{target_worker_id} specified by <worker> directive is not allowed. Available worker id is between 0 and #{(Fluent::Engine.system_config.workers - 1)}" |
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.
ditto
lib/fluent/root_agent.rb
Outdated
raise ConfigError, "<worker> section cannot have <#{elem.name}> directive" | ||
e.elements.each do |elem| | ||
unless ['source', 'match', 'filter', 'label'].include?(elem.name) | ||
raise ConfigError, "<worker> section cannot have <#{elem.name}> directive" |
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.
ditto
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
d900a73
to
6b6fb93
Compare
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
297cabb
to
03da2b3
Compare
This patch something wrong.
The result should show two worker ids for each input plugin but it always shows fixed number, e.g. |
Oh, |
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
c7e1885
to
9b898c1
Compare
I've confirmed that the above configuration works correctly with Fluentd LogBoot Log
Running Log
Another Terminal Log
|
lib/fluent/root_agent.rb
Outdated
@@ -64,26 +64,67 @@ def initialize(log:, system_config: SystemConfig.new) | |||
attr_reader :labels | |||
|
|||
def configure(conf) | |||
used_worker_ids = [] | |||
available_worker_ids = [] | |||
0.step(Fluent::Engine.system_config.workers - 1, 1).each do |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 available_worker_ids = (0..Fluent::Engine.system_config.workers - 1).to_a
like code?
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.
Oh.... We can use it. 44f206a
lib/fluent/plugin/base.rb
Outdated
@@ -52,7 +52,8 @@ def fluentd_worker_id | |||
|
|||
def configure(conf) | |||
if conf.respond_to?(:for_this_worker?) && conf.for_this_worker? | |||
system_config_override(workers: 1) | |||
workers = conf.target_worker_ids.size || 1 |
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.
When conf.target_worker_ids.size
return nil
or false
?
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've added a checking code on 44b67c9.
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
@cosmo0920 On your environment, does |
In my environment, sometimes IOError error="stream closed in another thread" occurred during shutdown.
|
I've tested the above configuration with the following code: require 'socket'
u = UDPSocket.new
u.connect('localhost', 5160)
threads = []
threads << Thread.new {
loop do
u.send "uuuu", 0
sleep 0.5
end
}
threads << Thread.new {
loop do
u.send "aaaa", 0
sleep 0.3
end
}
threads << Thread.new {
loop do
u.send "waaa", 0
sleep 0.1
end
}
threads.each { |thr| thr.join } Nothing |
Yeah. Maybe, multiprocess or others trigger it. |
Basic behabiour works as expected so merged. |
This PR contains a naive
<worker N-M>
syntax implementation.Signed-off-by: Hiroshi Hatake hatake@clear-code.com