class Fluent::Plugin::AmplifierFilter
Public Instance Methods
amp_with_floor(value)
click to toggle source
# File lib/fluent/plugin/filter_amplifier.rb, line 38 def amp_with_floor(value) (value.to_f * @ratio).floor end
amp_without_floor(value)
click to toggle source
# File lib/fluent/plugin/filter_amplifier.rb, line 34 def amp_without_floor(value) value.to_f * @ratio end
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_amplifier.rb, line 14 def configure(conf) super if @key_names.nil? && @key_pattern.nil? raise Fluent::ConfigError, "missing both of key_names and key_pattern" end if @key_names && @key_pattern raise Fluent::ConfigError, "cannot specify both of key_names and key_pattern" end if @key_pattern @key_pattern = Regexp.new(@key_pattern) end amp = @floor ? :amp_with_floor : :amp_without_floor self.define_singleton_method(:amp, method(amp)) filter_method = @key_names ? :filter_with_names : :filter_with_patterns self.define_singleton_method(:filter, method(filter_method)) end
filter(tag, time, record)
click to toggle source
# File lib/fluent/plugin/filter_amplifier.rb, line 42 def filter(tag, time, record) if @key_names filter_with_names(tag, time, record) else filter_with_patterns(tag, time, record) end end
filter_with_names(tag, time, record)
click to toggle source
# File lib/fluent/plugin/filter_amplifier.rb, line 50 def filter_with_names(tag, time, record) updated = {} @key_names.each do |key| val = record[key] next unless val updated[key] = amp(val) end log.trace "amplifier", tag: tag, floor: @floor, ratio: @ratio, updated: updated, original: record if updated.size > 0 record.merge(updated) else record end end
filter_with_patterns(tag, time, record)
click to toggle source
# File lib/fluent/plugin/filter_amplifier.rb, line 65 def filter_with_patterns(tag, time, record) updated = {} record.each_pair do |key, val| next unless val next unless @key_pattern.match(key) updated[key] = amp(val) end log.trace "amplifier", tag: tag, floor: @floor, ratio: @ratio, updated: updated, original: record if updated.size > 0 record.merge(updated) else record end end