-
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
Changes from 7 commits
6a8587e
4200740
6b6fb93
03da2b3
668273b
66ac4a3
9b898c1
44f206a
44b67c9
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 |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Can't we use 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. Oh.... We can use it. 44f206a |
||
available_worker_ids << id | ||
end | ||
# initialize <worker> elements | ||
conf.elements(name: 'worker').each do |e| | ||
target_worker_id_str = e.arg | ||
if target_worker_id_str.empty? | ||
raise ConfigError, "Missing worker id on <worker> directive" | ||
raise Fluent::ConfigError, "Missing worker id on <worker> directive" | ||
end | ||
|
||
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)}" | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Could you add duplication check to avoid following case?
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've added a collisions checker in d900a73. 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. And I added more concreate error message commit: 03da2b3. |
||
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 Fluent::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>" | ||
end | ||
target_worker_ids = [] | ||
first_worker_id.step(last_worker_id, 1) do |worker_id| | ||
target_worker_id = worker_id.to_i | ||
target_worker_ids << target_worker_id | ||
|
||
if target_worker_id < 0 || target_worker_id > (Fluent::Engine.system_config.workers - 1) | ||
raise Fluent::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 | ||
available_worker_ids.delete(target_worker_id) if available_worker_ids.include?(target_worker_id) | ||
if used_worker_ids.include?(target_worker_id) && !Fluent::Engine.dry_run_mode | ||
raise Fluent::ConfigError, "specified worker_id<#{worker_id}> collisions is detected on <worker> directive. Available worker id(s): #{available_worker_ids}" | ||
end | ||
used_worker_ids << target_worker_id | ||
|
||
e.elements.each do |elem| | ||
unless ['source', 'match', 'filter', 'label'].include?(elem.name) | ||
raise Fluent::ConfigError, "<worker> section cannot have <#{elem.name}> directive" | ||
end | ||
end | ||
|
||
# On dry_run mode, all worker sections have to be configured on supervisor (recognized as worker_id = 0). | ||
target_worker_ids = [0] if Fluent::Engine.dry_run_mode | ||
|
||
unless target_worker_ids.empty? | ||
e.set_target_worker_ids(target_worker_ids.uniq) | ||
end | ||
end | ||
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 Fluent::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 | ||
|
||
## On dry_run mode, all worker sections have to be configured on supervisor (recognized as worker_id = 0). | ||
target_worker_id = 0 if Fluent::Engine.dry_run_mode | ||
## On dry_run mode, all worker sections have to be configured on supervisor (recognized as worker_id = 0). | ||
target_worker_id = 0 if Fluent::Engine.dry_run_mode | ||
|
||
e.elements.each do |elem| | ||
unless ['source', 'match', 'filter', 'label'].include?(elem.name) | ||
raise ConfigError, "<worker> section cannot have <#{elem.name}> directive" | ||
e.elements.each do |elem| | ||
unless ['source', 'match', 'filter', 'label'].include?(elem.name) | ||
raise Fluent::ConfigError, "<worker> section cannot have <#{elem.name}> directive" | ||
end | ||
elem.set_target_worker_id(target_worker_id) | ||
end | ||
elem.set_target_worker_id(target_worker_id) | ||
end | ||
conf += e | ||
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.
When
conf.target_worker_ids.size
returnnil
orfalse
?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.