Class: Plugin::RecordModifierOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_record_modifier.rb

Defined Under Namespace

Classes: DynamicExpander

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fluent/plugin/out_record_modifier.rb', line 55

def configure(conf)
  super

  @map = {}
  @to_enc = nil
  if @char_encoding
    from, to = @char_encoding.split(':', 2)
    @from_enc = Encoding.find(from)
    @to_enc = Encoding.find(to) if to

    m = if @to_enc
          method(:convert_encoding)
        else
          method(:set_encoding)
        end

    (class << self; self; end).module_eval do
      define_method(:change_encoding, m)
    end
  end

  @has_tag_parts = false
  conf.elements.select { |element| element.name == 'record' }.each do |element|
    element.each_pair do |k, v|
      element.has_key?(k) # to suppress unread configuration warning
      @has_tag_parts = true if v.include?('tag_parts')
      @map[k] = DynamicExpander.new(k, v, @prepare_value)
    end
  end

  if @remove_keys and @whitelist_keys
    raise Fluent::ConfigError, "remove_keys and whitelist_keys are exclusive with each other."
  elsif @remove_keys
    @remove_keys = @remove_keys.split(',').map(&:strip)
  elsif @whitelist_keys
    @whitelist_keys = @whitelist_keys.split(',').map(&:strip)
    @whitelist_keys.concat(@map.keys).uniq!
  end

  @has_tag_parts = true if @tag.include?('tag_parts')
  @tag_ex = DynamicExpander.new('tag', @tag, @prepare_value)

    # Collect DynamicExpander related garbage instructions
  GC.start
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/fluent/plugin/out_record_modifier.rb', line 101

def multi_workers_ready?
  true
end

#process(tag, es) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fluent/plugin/out_record_modifier.rb', line 105

def process(tag, es)
  tag_parts = @has_tag_parts ? tag.split('.') : nil
  if @tag_ex.param_value.nil?
    result = {}
    es.each { |time, record|
      new_record = modify_record(tag, time, record, tag_parts)
      new_tag = @tag_ex.expand(tag, time, new_record, tag_parts)
      result[new_tag] ||= MultiEventStream.new
      result[new_tag].add(time, new_record)
    }
    result.each { |tag, stream|
      router.emit_stream(tag, stream)
    }
  else
    stream = MultiEventStream.new
    es.each { |time, record|
      new_record = modify_record(tag, time, record, tag_parts)
      stream.add(time, new_record)
    }
    router.emit_stream(@tag, stream)
  end
end