Skip to content
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

Minor performance improvements #4302

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fluent/command/binlog_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def initialize(argv = ARGV)
private

def configure_option_parser
@options.merge!(config_params: {})
@options[:config_params] = {}

@opt_parser.banner = "Usage: fluent-binlog-reader #{self.class.to_s.split('::').last.downcase} [options] file"

Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/config/configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def merge_for_finalized(other)

def overwrite_defaults(other) # other is owner plugin's corresponding proxy
self.defaults = self.defaults.merge(other.defaults)
self.sections.keys.each do |section_key|
self.sections.each_key do |section_key|
if other.sections.has_key?(section_key)
self.sections[section_key].overwrite_defaults(other.sections[section_key])
end
Expand Down Expand Up @@ -274,7 +274,7 @@ def parameter_configuration(name, type = nil, **kwargs, &block)
option_value_type!(name, opts, :deprecated, String)
option_value_type!(name, opts, :obsoleted, String)
if type == :enum
if !opts.has_key?(:list) || !opts[:list].is_a?(Array) || opts[:list].empty? || !opts[:list].all?{|v| v.is_a?(Symbol) }
if !opts.has_key?(:list) || !opts[:list].is_a?(Array) || opts[:list].empty? || !opts[:list].all?(Symbol)
raise ArgumentError, "#{name}: enum parameter requires :list of Symbols"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/config/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def self.enum_value(val, opts = {}, name = nil)

s = val.to_sym
list = opts[:list]
raise "Plugin BUG: config type 'enum' requires :list of symbols" unless list.is_a?(Array) && list.all?{|v| v.is_a? Symbol }
raise "Plugin BUG: config type 'enum' requires :list of symbols" unless list.is_a?(Array) && list.all?(Symbol)
unless list.include?(s)
raise ConfigError, "valid options are #{list.join(',')} but got #{val}"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def initialize
super
# to simulate implicit 'attr_accessor' by config_param / config_section and its value by config_set_default
proxy = self.class.merged_configure_proxy
proxy.params.keys.each do |name|
proxy.params.each_key do |name|
next if name.to_s.start_with?('@')
if proxy.defaults.has_key?(name)
instance_variable_set("@#{name}".to_sym, proxy.defaults[name])
end
end
proxy.sections.keys.each do |name|
proxy.sections.each_key do |name|
next if name.to_s.start_with?('@')
subproxy = proxy.sections[name]
if subproxy.multi?
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/counter/mutex_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def synchronize(*keys)
if mutex.try_lock
locks[key] = mutex
else
locks.values.each(&:unlock)
locks.each_value(&:unlock)
locks = {} # flush locked keys
break
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/buf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def configure(conf)

@variable_store = Fluent::VariableStore.fetch_or_build(:buf_file)

multi_workers_configured = owner.system_config.workers > 1 ? true : false
multi_workers_configured = owner.system_config.workers > 1

using_plugin_root_dir = false
unless @path
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/plugin_helper/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def metrics_create(namespace: "fluentd", subsystem: "metrics", name:, help_text:
metrics.configure(config)
# For multi workers environment, cmetrics should be distinguish with static labels.
if Fluent::Engine.system_config.workers > 1
labels.merge!(worker_id: fluentd_worker_id.to_s)
labels[:worker_id] = fluentd_worker_id.to_s
end
labels.merge!(plugin: @plugin_type_or_id)
labels[:plugin] = @plugin_type_or_id
metrics.create(namespace: namespace, subsystem: subsystem, name: name, help_text: help_text, labels: labels)

@_metrics["#{@plugin_type_or_id}_#{namespace}_#{subsystem}_#{name}"] = metrics
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/test/output_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def run(&block)
assert_equal(@expected_buffer, buffer)
end

lines.keys.each do |meta|
lines.each_key do |meta|
chunk = @instance.buffer.generate_chunk(meta).staged!
chunk.append(lines[meta])
begin
Expand Down
Loading