From a40c403716e5ea958fc29dbe6e341dbbbb82930a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Wed, 13 Sep 2023 22:13:49 +0200 Subject: [PATCH 1/4] Remove redundant ternary operator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- lib/fluent/plugin/buf_file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fluent/plugin/buf_file.rb b/lib/fluent/plugin/buf_file.rb index d75f789830..7f11478a01 100644 --- a/lib/fluent/plugin/buf_file.rb +++ b/lib/fluent/plugin/buf_file.rb @@ -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 From 1b2ef896b68c07efd9a73631510e5d83e4d6542b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Mon, 18 Sep 2023 11:44:29 +0200 Subject: [PATCH 2/4] perf: avoid using merge for a single key/val tuple MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- lib/fluent/command/binlog_reader.rb | 2 +- lib/fluent/plugin_helper/metrics.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fluent/command/binlog_reader.rb b/lib/fluent/command/binlog_reader.rb index f77c47c4ff..ba7adf430e 100644 --- a/lib/fluent/command/binlog_reader.rb +++ b/lib/fluent/command/binlog_reader.rb @@ -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" diff --git a/lib/fluent/plugin_helper/metrics.rb b/lib/fluent/plugin_helper/metrics.rb index 7489732918..452610ab75 100644 --- a/lib/fluent/plugin_helper/metrics.rb +++ b/lib/fluent/plugin_helper/metrics.rb @@ -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 From 8555bbe1b5c5ec60a40d3c9304ea0f6de7e78d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Mon, 18 Sep 2023 11:47:36 +0200 Subject: [PATCH 3/4] perf: redundant equality check in a block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- lib/fluent/config/configure_proxy.rb | 2 +- lib/fluent/config/types.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fluent/config/configure_proxy.rb b/lib/fluent/config/configure_proxy.rb index 4db4fd4ef0..fbb6b63af8 100644 --- a/lib/fluent/config/configure_proxy.rb +++ b/lib/fluent/config/configure_proxy.rb @@ -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 diff --git a/lib/fluent/config/types.rb b/lib/fluent/config/types.rb index 98e7d0d9d8..9c9ba89c8d 100644 --- a/lib/fluent/config/types.rb +++ b/lib/fluent/config/types.rb @@ -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 From 8dce70320f674853c2fc68e94d03734f27c63df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Tue, 26 Sep 2023 18:30:33 +0200 Subject: [PATCH 4/4] perf: avoid creating an extra list when iterating through values or keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- lib/fluent/config/configure_proxy.rb | 2 +- lib/fluent/configurable.rb | 4 ++-- lib/fluent/counter/mutex_hash.rb | 2 +- lib/fluent/test/output_test.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/fluent/config/configure_proxy.rb b/lib/fluent/config/configure_proxy.rb index fbb6b63af8..ec2ce42040 100644 --- a/lib/fluent/config/configure_proxy.rb +++ b/lib/fluent/config/configure_proxy.rb @@ -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 diff --git a/lib/fluent/configurable.rb b/lib/fluent/configurable.rb index aa3ece1752..9131738c11 100644 --- a/lib/fluent/configurable.rb +++ b/lib/fluent/configurable.rb @@ -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? diff --git a/lib/fluent/counter/mutex_hash.rb b/lib/fluent/counter/mutex_hash.rb index 9c66286458..22868fcdda 100644 --- a/lib/fluent/counter/mutex_hash.rb +++ b/lib/fluent/counter/mutex_hash.rb @@ -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 diff --git a/lib/fluent/test/output_test.rb b/lib/fluent/test/output_test.rb index b7ff3fd37a..bb18884dc2 100644 --- a/lib/fluent/test/output_test.rb +++ b/lib/fluent/test/output_test.rb @@ -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