From eb1478d5dead8cc036a2cf3970b7c3b138ce6e3f Mon Sep 17 00:00:00 2001 From: "Satoshi \"Moris\" Tagomori" Date: Tue, 9 Feb 2016 18:28:18 +0900 Subject: [PATCH] Merge pull request #795 from fluent/hash-syntax enforce new hash syntax by `rubocop --only HashSyntax --auto-correct` --- Rakefile | 4 +- lib/fluent/agent.rb | 12 +- lib/fluent/buffer.rb | 6 +- lib/fluent/engine.rb | 4 +- lib/fluent/formatter.rb | 46 ++++---- lib/fluent/log.rb | 2 +- lib/fluent/output.rb | 45 ++++---- lib/fluent/parser.rb | 46 ++++---- lib/fluent/plugin/buf_file.rb | 4 +- lib/fluent/plugin/buf_memory.rb | 2 +- lib/fluent/plugin/filter_grep.rb | 6 +- .../plugin/filter_record_transformer.rb | 22 ++-- lib/fluent/plugin/filter_stdout.rb | 2 +- lib/fluent/plugin/in_debug_agent.rb | 10 +- lib/fluent/plugin/in_dummy.rb | 6 +- lib/fluent/plugin/in_exec.rb | 18 +-- lib/fluent/plugin/in_forward.rb | 22 ++-- lib/fluent/plugin/in_gc_stat.rb | 4 +- lib/fluent/plugin/in_http.rb | 26 ++--- lib/fluent/plugin/in_monitor_agent.rb | 20 ++-- lib/fluent/plugin/in_object_space.rb | 8 +- lib/fluent/plugin/in_stream.rb | 12 +- lib/fluent/plugin/in_syslog.rb | 22 ++-- lib/fluent/plugin/in_tail.rb | 18 +-- lib/fluent/plugin/in_tcp.rb | 2 +- lib/fluent/plugin/in_udp.rb | 2 +- lib/fluent/plugin/out_copy.rb | 2 +- lib/fluent/plugin/out_exec.rb | 10 +- lib/fluent/plugin/out_exec_filter.rb | 50 ++++---- lib/fluent/plugin/out_file.rb | 10 +- lib/fluent/plugin/out_forward.rb | 42 +++---- lib/fluent/plugin/out_stdout.rb | 2 +- lib/fluent/plugin/out_stream.rb | 4 +- lib/fluent/plugin/socket_util.rb | 16 +-- lib/fluent/process.rb | 16 +-- lib/fluent/root_agent.rb | 10 +- lib/fluent/rpc.rb | 10 +- lib/fluent/supervisor.rb | 58 +++++----- test/config/test_configurable.rb | 22 ++-- test/config/test_configure_proxy.rb | 2 +- test/plugin/test_filter_record_transformer.rb | 108 +++++++++--------- test/test_config.rb | 4 +- 42 files changed, 368 insertions(+), 369 deletions(-) diff --git a/Rakefile b/Rakefile index 9c968f3a6c..8b0184e462 100755 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require 'fileutils' require 'rake/testtask' require 'rake/clean' -task :test => [:base_test] +task test: [:base_test] desc 'Run test_unit based test' Rake::TestTask.new(:base_test) do |t| @@ -30,4 +30,4 @@ task :coverage do |t| Rake::Task["test"].invoke end -task :default => [:test, :build] +task default: [:test, :build] diff --git a/lib/fluent/agent.rb b/lib/fluent/agent.rb index 5080f2377c..1c766fe197 100644 --- a/lib/fluent/agent.rb +++ b/lib/fluent/agent.rb @@ -81,7 +81,7 @@ def shutdown log.info "shutting down filter#{@context.nil? ? '' : " in #{@context}"}", type: Plugin.lookup_name_from_class(f.class), plugin_id: f.plugin_id f.shutdown rescue => e - log.warn "unexpected error while shutting down filter plugins", :plugin => f.class, :plugin_id => f.plugin_id, :error_class => e.class, :error => e + log.warn "unexpected error while shutting down filter plugins", plugin: f.class, plugin_id: f.plugin_id, error_class: e.class, error: e log.warn_backtrace end end @@ -95,7 +95,7 @@ def shutdown log.info "shutting down output#{@context.nil? ? '' : " in #{@context}"}", type: Plugin.lookup_name_from_class(o.class), plugin_id: o.plugin_id o.shutdown rescue => e - log.warn "unexpected error while shutting down output plugins", :plugin => o.class, :plugin_id => o.plugin_id, :error_class => e.class, :error => e + log.warn "unexpected error while shutting down output plugins", plugin: o.class, plugin_id: o.plugin_id, error_class: e.class, error: e log.warn_backtrace end end @@ -115,7 +115,7 @@ def flush_recursive(array) flush_recursive(o.outputs) end rescue => e - log.debug "error while force flushing", :error_class => e.class, :error => e + log.debug "error while force flushing", error_class: e.class, error: e log.debug_backtrace end } @@ -163,16 +163,16 @@ def emit(tag, es, chain) c = (@count += 1) if c < 512 if Math.log(c) / Math.log(2) % 1.0 == 0 - @log.warn "no patterns matched", :tag => tag + @log.warn "no patterns matched", tag: tag return end else if c % 512 == 0 - @log.warn "no patterns matched", :tag => tag + @log.warn "no patterns matched", tag: tag return end end - @log.on_trace { @log.trace "no patterns matched", :tag => tag } + @log.on_trace { @log.trace "no patterns matched", tag: tag } end def start diff --git a/lib/fluent/buffer.rb b/lib/fluent/buffer.rb index 97f10d2ad0..2187d835f1 100644 --- a/lib/fluent/buffer.rb +++ b/lib/fluent/buffer.rb @@ -140,11 +140,11 @@ def enable_parallel(b=true) # Local file based plugins which should provide more reliability and efficiency # should override buffer_chunk_limit with a larger size. desc 'The size of each buffer chunk.' - config_param :buffer_chunk_limit, :size, :default => 8*1024*1024 + config_param :buffer_chunk_limit, :size, default: 8*1024*1024 desc 'The length limit of the chunk queue.' - config_param :buffer_queue_limit, :integer, :default => 256 + config_param :buffer_queue_limit, :integer, default: 256 desc 'The action when the size of buffer queue exceeds the buffer_queue_limit.' - config_param :buffer_queue_full_action, :enum, :list => [:exception, :block], :default => :exception + config_param :buffer_queue_full_action, :enum, list: [:exception, :block], default: :exception alias chunk_limit buffer_chunk_limit alias chunk_limit= buffer_chunk_limit= diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index 48acb7c4df..4bb8927a61 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -164,7 +164,7 @@ def log_event_loop begin @event_router.emit(tag, time, record) rescue => e - $log.error "failed to emit fluentd's log event", :tag => tag, :event => record, :error_class => e.class, :error => e + $log.error "failed to emit fluentd's log event", tag: tag, event: record, error_class: e.class, error: e end } end @@ -193,7 +193,7 @@ def run end rescue => e - $log.error "unexpected error", :error_class=>e.class, :error=>e + $log.error "unexpected error", error_class: e.class, error: e $log.error_backtrace ensure $log.info "shutting down fluentd" diff --git a/lib/fluent/formatter.rb b/lib/fluent/formatter.rb index 5b14892f3a..dbc4c86b4b 100644 --- a/lib/fluent/formatter.rb +++ b/lib/fluent/formatter.rb @@ -33,13 +33,13 @@ module TextFormatter module HandleTagAndTimeMixin def self.included(klass) klass.instance_eval { - config_param :include_time_key, :bool, :default => false - config_param :time_key, :string, :default => 'time' - config_param :time_format, :string, :default => nil - config_param :include_tag_key, :bool, :default => false - config_param :tag_key, :string, :default => 'tag' - config_param :localtime, :bool, :default => true - config_param :timezone, :string, :default => nil + config_param :include_time_key, :bool, default: false + config_param :time_key, :string, default: 'time' + config_param :time_format, :string, default: nil + config_param :include_tag_key, :bool, default: false + config_param :tag_key, :string, default: 'tag' + config_param :localtime, :bool, default: true + config_param :timezone, :string, default: nil } end @@ -65,9 +65,9 @@ def filter_record(tag, time, record) class OutFileFormatter < Formatter include HandleTagAndTimeMixin - config_param :output_time, :bool, :default => true - config_param :output_tag, :bool, :default => true - config_param :delimiter, :default => "\t" do |val| + config_param :output_time, :bool, default: true + config_param :output_tag, :bool, default: true + config_param :delimiter, default: "\t" do |val| case val when /SPACE/i then ' ' when /COMMA/i then ',' @@ -85,7 +85,7 @@ def format(tag, time, record) end class StdoutFormatter < Formatter - config_param :output_type, :string, :default => 'json' + config_param :output_type, :string, default: 'json' def configure(conf) super @@ -103,7 +103,7 @@ def format(tag, time, record) module StructuredFormatMixin def self.included(klass) klass.instance_eval { - config_param :time_as_epoch, :bool, :default => false + config_param :time_as_epoch, :bool, default: false } end @@ -131,7 +131,7 @@ class JSONFormatter < Formatter include HandleTagAndTimeMixin include StructuredFormatMixin - config_param :json_parser, :string, :default => 'oj' + config_param :json_parser, :string, default: 'oj' def configure(conf) super @@ -139,7 +139,7 @@ def configure(conf) begin raise LoadError unless @json_parser == 'oj' require 'oj' - Oj.default_options = {:mode => :compat} + Oj.default_options = {mode: :compat} @dump_proc = Oj.method(:dump) rescue LoadError @dump_proc = Yajl.method(:dump) @@ -172,8 +172,8 @@ def format_record(record) class LabeledTSVFormatter < Formatter include HandleTagAndTimeMixin - config_param :delimiter, :string, :default => "\t" - config_param :label_delimiter, :string, :default => ":" + config_param :delimiter, :string, default: "\t" + config_param :label_delimiter, :string, default: ":" def format(tag, time, record) filter_record(tag, time, record) @@ -189,11 +189,11 @@ def format(tag, time, record) class CsvFormatter < Formatter include HandleTagAndTimeMixin - config_param :delimiter, :default => ',' do |val| + config_param :delimiter, default: ',' do |val| ['\t', 'TAB'].include?(val) ? "\t" : val end - config_param :force_quotes, :bool, :default => true - config_param :fields, :default => [] do |val| + config_param :force_quotes, :bool, default: true + config_param :fields, default: [] do |val| val.split(',').map do |f| f.strip! f.size > 0 ? f : nil @@ -211,14 +211,14 @@ def format(tag, time, record) memo << record[key] memo end - CSV.generate_line(row, :col_sep => @delimiter, - :force_quotes => @force_quotes) + CSV.generate_line(row, col_sep: @delimiter, + force_quotes: @force_quotes) end end class SingleValueFormatter < Formatter - config_param :message_key, :string, :default => 'message' - config_param :add_newline, :bool, :default => true + config_param :message_key, :string, default: 'message' + config_param :add_newline, :bool, default: true def format(tag, time, record) text = record[@message_key].to_s.dup diff --git a/lib/fluent/log.rb b/lib/fluent/log.rb index f14f27c32f..978da489d1 100644 --- a/lib/fluent/log.rb +++ b/lib/fluent/log.rb @@ -344,7 +344,7 @@ module PluginLoggerMixin def self.included(klass) klass.instance_eval { desc 'Allows the user to set different levels of logging for each plugin.' - config_param :log_level, :string, :default => nil, :alias => :@log_level + config_param :log_level, :string, default: nil, alias: :@log_level } end diff --git a/lib/fluent/output.rb b/lib/fluent/output.rb index 2b8523b283..ebeea00c34 100644 --- a/lib/fluent/output.rb +++ b/lib/fluent/output.rb @@ -88,7 +88,7 @@ def shutdown def secondary_init(primary) if primary.class != self.class - $log.warn "type of secondary output should be same as primary output", :primary=>primary.class.to_s, :secondary=>self.class.to_s + $log.warn "type of secondary output should be same as primary output", primary: primary.class.to_s, secondary: self.class.to_s end end end @@ -152,7 +152,7 @@ def run @mutex.unlock end rescue - $log.error "error on output thread", :error=>$!.to_s + $log.error "error on output thread", error: $!.to_s $log.error_backtrace raise ensure @@ -180,22 +180,22 @@ def initialize end desc 'The buffer type (memory, file)' - config_param :buffer_type, :string, :default => 'memory' + config_param :buffer_type, :string, default: 'memory' desc 'The interval between data flushes.' - config_param :flush_interval, :time, :default => 60 - config_param :try_flush_interval, :float, :default => 1 + config_param :flush_interval, :time, default: 60 + config_param :try_flush_interval, :float, default: 1 desc 'If true, the value of `retry_value` is ignored and there is no limit' - config_param :disable_retry_limit, :bool, :default => false + config_param :disable_retry_limit, :bool, default: false desc 'The limit on the number of retries before buffered data is discarded' - config_param :retry_limit, :integer, :default => 17 + config_param :retry_limit, :integer, default: 17 desc 'The initial intervals between write retries.' - config_param :retry_wait, :time, :default => 1.0 + config_param :retry_wait, :time, default: 1.0 desc 'The maximum intervals between write retries.' - config_param :max_retry_wait, :time, :default => nil + config_param :max_retry_wait, :time, default: nil desc 'The number of threads to flush the buffer.' - config_param :num_threads, :integer, :default => 1 + config_param :num_threads, :integer, default: 1 desc 'The interval between data flushes for queued chunk.' - config_param :queued_chunk_flush_interval, :time, :default => 1 + config_param :queued_chunk_flush_interval, :time, default: 1 def configure(conf) super @@ -334,7 +334,7 @@ def try_flush @num_errors = 0 # Note: don't notify to other threads to prevent # burst to recovered server - $log.warn "retry succeeded.", :plugin_id=>plugin_id + $log.warn "retry succeeded.", plugin_id: plugin_id end if has_next @@ -359,20 +359,20 @@ def try_flush end if @disable_retry_limit || error_count < @retry_limit - $log.warn "temporarily failed to flush the buffer.", :next_retry=>Time.at(@next_retry_time), :error_class=>e.class.to_s, :error=>e.to_s, :plugin_id=>plugin_id + $log.warn "temporarily failed to flush the buffer.", next_retry: Time.at(@next_retry_time), error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id $log.warn_backtrace e.backtrace elsif @secondary if error_count == @retry_limit - $log.warn "failed to flush the buffer.", :error_class=>e.class.to_s, :error=>e.to_s, :plugin_id=>plugin_id + $log.warn "failed to flush the buffer.", error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id $log.warn "retry count exceededs limit. falling back to secondary output." $log.warn_backtrace e.backtrace retry # retry immediately elsif error_count <= @retry_limit + @secondary_limit - $log.warn "failed to flush the buffer, next retry will be with secondary output.", :next_retry=>Time.at(@next_retry_time), :error_class=>e.class.to_s, :error=>e.to_s, :plugin_id=>plugin_id + $log.warn "failed to flush the buffer, next retry will be with secondary output.", next_retry: Time.at(@next_retry_time), error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id $log.warn_backtrace e.backtrace else - $log.warn "failed to flush the buffer.", :error_class=>e.class, :error=>e.to_s, :plugin_id=>plugin_id + $log.warn "failed to flush the buffer.", error_class: e.class, error: e.to_s, plugin_id: plugin_id $log.warn "secondary retry count exceededs limit." $log.warn_backtrace e.backtrace write_abort @@ -380,7 +380,7 @@ def try_flush end else - $log.warn "failed to flush the buffer.", :error_class=>e.class.to_s, :error=>e.to_s, :plugin_id=>plugin_id + $log.warn "failed to flush the buffer.", error_class: e.class.to_s, error: e.to_s, plugin_id: plugin_id $log.warn "retry count exceededs limit." $log.warn_backtrace e.backtrace write_abort @@ -403,7 +403,7 @@ def before_shutdown begin @buffer.before_shutdown(self) rescue - $log.warn "before_shutdown failed", :error=>$!.to_s + $log.warn "before_shutdown failed", error: $!.to_s $log.warn_backtrace end end @@ -425,7 +425,7 @@ def write_abort begin @buffer.clear! rescue - $log.error "unexpected error while aborting", :error=>$!.to_s + $log.error "unexpected error while aborting", error: $!.to_s $log.error_backtrace end end @@ -483,11 +483,11 @@ def initialize end desc 'The time format used as part of the file name.' - config_param :time_slice_format, :string, :default => '%Y%m%d' + config_param :time_slice_format, :string, default: '%Y%m%d' desc 'The amount of time Fluentd will wait for old logs to arrive.' - config_param :time_slice_wait, :time, :default => 10*60 + config_param :time_slice_wait, :time, default: 10*60 desc 'Parse the time value in the specified timezone' - config_param :timezone, :string, :default => nil + config_param :timezone, :string, default: nil config_set_default :buffer_type, 'file' # overwrite default buffer_type config_set_default :buffer_chunk_limit, 256*1024*1024 # overwrite default buffer_chunk_limit config_set_default :flush_interval, nil @@ -609,4 +609,3 @@ class MultiOutput < Output #end end end - diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index bd6674b8d6..ef14b46a09 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -27,7 +27,7 @@ class Parser # 'configure()' may raise errors for unexpected configurations attr_accessor :estimate_current_event - config_param :keep_time_key, :bool, :default => false + config_param :keep_time_key, :bool, default: false def initialize super @@ -113,9 +113,9 @@ module TypeConverter def self.included(klass) klass.instance_eval { - config_param :types, :string, :default => nil - config_param :types_delimiter, :string, :default => ',' - config_param :types_label_delimiter, :string, :default => ':' + config_param :types, :string, default: nil + config_param :types_delimiter, :string, default: ',' + config_param :types_label_delimiter, :string, default: ':' } end @@ -162,8 +162,8 @@ def parse_types_parameter class RegexpParser < Parser include TypeConverter - config_param :time_key, :string, :default => 'time' - config_param :time_format, :string, :default => nil + config_param :time_key, :string, default: 'time' + config_param :time_format, :string, default: nil def initialize(regexp, conf={}) super() @@ -235,9 +235,9 @@ def parse(text) end class JSONParser < Parser - config_param :time_key, :string, :default => 'time' - config_param :time_format, :string, :default => nil - config_param :json_parser, :string, :default => 'oj' + config_param :time_key, :string, default: 'time' + config_param :time_format, :string, default: nil + config_param :json_parser, :string, default: 'oj' def configure(conf) super @@ -250,7 +250,7 @@ def configure(conf) begin raise LoadError unless @json_parser == 'oj' require 'oj' - Oj.default_options = {:bigdecimal_load => :float} + Oj.default_options = {bigdecimal_load: :float} @load_proc = Oj.method(:load) @error_class = Oj::ParseError rescue LoadError @@ -298,17 +298,17 @@ def parse(text) class ValuesParser < Parser include TypeConverter - config_param :keys, :default => [] do |val| + config_param :keys, default: [] do |val| if val.start_with?('[') # This check is enough because keys parameter is simple. No '[' started column name. JSON.load(val) else val.split(",") end end - config_param :time_key, :string, :default => nil - config_param :time_format, :string, :default => nil - config_param :null_value_pattern, :string, :default => nil - config_param :null_empty_string, :bool, :default => false + config_param :time_key, :string, default: nil + config_param :time_format, :string, default: nil + config_param :null_value_pattern, :string, default: nil + config_param :null_empty_string, :bool, default: false def configure(conf) super @@ -377,7 +377,7 @@ def convert_value_to_nil(value) end class TSVParser < ValuesParser - config_param :delimiter, :string, :default => "\t" + config_param :delimiter, :string, default: "\t" def configure(conf) super @@ -394,9 +394,9 @@ def parse(text) end class LabeledTSVParser < ValuesParser - config_param :delimiter, :string, :default => "\t" - config_param :label_delimiter, :string, :default => ":" - config_param :time_key, :string, :default => "time" + config_param :delimiter, :string, default: "\t" + config_param :label_delimiter, :string, default: ":" + config_param :time_key, :string, default: "time" def configure(conf) conf['keys'] = conf['time_key'] || 'time' @@ -437,7 +437,7 @@ def parse(text) end class NoneParser < Parser - config_param :message_key, :string, :default => 'message' + config_param :message_key, :string, default: 'message' def parse(text) record = {} @@ -526,8 +526,8 @@ class SyslogParser < Parser # From in_syslog default pattern REGEXP_WITH_PRI = /^\<(?[0-9]+)\>(?