Module: Fluent::RecordReformerOutputCore
- Included in:
- RecordReformerOutput, Plugin::RecordReformerOutput
- Defined in:
- lib/fluent/plugin/out_record_reformer/core.rb
Defined Under Namespace
Classes: PlaceholderExpander, RubyPlaceholderExpander
Constant Summary collapse
- BUILTIN_CONFIGURATIONS =
%W(@id @type @label type tag output_tag remove_keys renew_record keep_keys enable_ruby renew_time_key auto_typecast)
Class Method Summary collapse
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #initialize ⇒ Object
- #multi_workers_ready? ⇒ Boolean
- #process(tag, es) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fluent/plugin/out_record_reformer/core.rb', line 10 def self.included(klass) klass.config_param :output_tag, :string, :default => nil, # obsolete :desc => 'The output tag name. This option is deprecated. Use `tag` option instead.' klass.config_param :tag, :string, :default => nil, :desc => 'The output tag name.' klass.config_param :remove_keys, :string, :default => nil, :desc => 'Specify record keys to be removed by a string separated by , (comma).' klass.config_param :keep_keys, :string, :default => nil, :desc => 'Specify record keys to be kept by a string separated by , (comma).' klass.config_param :renew_record, :bool, :default => false, :desc => 'Creates an output record newly without extending (merging) the input record fields.' klass.config_param :renew_time_key, :string, :default => nil, :desc => 'Overwrites the time of events with a value of the record field.' klass.config_param :enable_ruby, :bool, :default => true, # true for lower version compatibility :desc => 'Enable to use ruby codes in placeholders.' klass.config_param :auto_typecast, :bool, :default => false, # false for lower version compatibility :desc => 'Automatically cast the field types.' end |
Instance Method Details
#configure(conf) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fluent/plugin/out_record_reformer/core.rb', line 31 def configure(conf) super map = {} conf.each_pair { |k, v| next if BUILTIN_CONFIGURATIONS.include?(k) conf.has_key?(k) # to suppress unread configuration warning map[k] = parse_value(v) } # <record></record> directive conf.elements.select { |element| element.name == 'record' }.each { |element| element.each_pair { |k, v| element.has_key?(k) # to suppress unread configuration warning map[k] = parse_value(v) } } if @remove_keys @remove_keys = @remove_keys.split(',') end if @keep_keys raise Fluent::ConfigError, "out_record_reformer: `renew_record` must be true to use `keep_keys`" unless @renew_record @keep_keys = @keep_keys.split(',') end if @output_tag and @tag.nil? # for lower version compatibility log.warn "out_record_reformer: `output_tag` is deprecated. Use `tag` option instead." @tag = @output_tag end if @tag.nil? raise Fluent::ConfigError, "out_record_reformer: `tag` must be specified" end = { :log => log, :auto_typecast => @auto_typecast, } @placeholder_expander = if @enable_ruby # require utilities which would be used in ruby placeholders require 'pathname' require 'uri' require 'cgi' RubyPlaceholderExpander.new() else PlaceholderExpander.new() end @map = @placeholder_expander.preprocess_map(map) @tag = @placeholder_expander.preprocess_map(@tag) @hostname = Socket.gethostname end |
#initialize ⇒ Object
6 7 8 |
# File 'lib/fluent/plugin/out_record_reformer/core.rb', line 6 def initialize super end |
#multi_workers_ready? ⇒ Boolean
85 86 87 |
# File 'lib/fluent/plugin/out_record_reformer/core.rb', line 85 def multi_workers_ready? true end |
#process(tag, es) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fluent/plugin/out_record_reformer/core.rb', line 89 def process(tag, es) tag_parts = tag.split('.') tag_prefix = tag_prefix(tag_parts) tag_suffix = tag_suffix(tag_parts) placeholder_values = { 'tag' => tag, 'tags' => tag_parts, # for old version compatibility 'tag_parts' => tag_parts, 'tag_prefix' => tag_prefix, 'tag_suffix' => tag_suffix, 'hostname' => @hostname, } last_record = nil es.each {|time, record| last_record = record # for debug log placeholder_values.merge!({ 'time' => @placeholder_expander.time_value(time), 'record' => record, }) new_tag, new_record = reform(@tag, record, placeholder_values) if new_tag if @renew_time_key && new_record.has_key?(@renew_time_key) time = new_record[@renew_time_key].to_i end @remove_keys.each {|k| new_record.delete(k) } if @remove_keys router.emit(new_tag, time, new_record) end } rescue => e log.warn "record_reformer: #{e.class} #{e.} #{e.backtrace.first}" log.debug "record_reformer: tag:#{@tag} map:#{@map} record:#{last_record} placeholder_values:#{placeholder_values}" end |