class Fluent::Plugin::ComparisonFilter
Constants
- DEFAULT_STORAGE_TYPE
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_comparison.rb, line 23 def initialize super @column_key = nil @column_key_type = nil @time_type = nil end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_comparison.rb, line 30 def configure(conf) super @column_key = @comparison_config.column_key @column_key_type = @comparison_config.column_key_type @time_type = @comparison_config.time_type if compare_by_time? @time_parser = case @time_type when :float then Fluent::NumericTimeParser.new(:float) when :unixtime then Fluent::NumericTimeParser.new(:unixtime) else localtime = @comparison_config.localtime && !@comparison_config.utc Fluent::TimeParser.new(@comparison_config.time_format, localtime, @comparison_config.timezone) end else end @storage = storage_create(usage: 'comparison', conf: nil, type: DEFAULT_STORAGE_TYPE) end
filter(tag, time, record)
click to toggle source
# File lib/fluent/plugin/filter_comparison.rb, line 50 def filter(tag, time, record) result = nil last_recorded = fetch_comparison_key begin comparison_key = extract_comparison_column_from_record(record) if last_recorded.nil? || last_recorded < comparison_key set_comparison_key(comparison_key) result = record end rescue => e log.warn "failed to filter records", error: e log.warn_backtrace end result end
Private Instance Methods
compare_by_time?()
click to toggle source
# File lib/fluent/plugin/filter_comparison.rb, line 76 def compare_by_time? @comparison_config.column_key_type == :time end
extract_comparison_column_from_record(record)
click to toggle source
# File lib/fluent/plugin/filter_comparison.rb, line 80 def extract_comparison_column_from_record(record) if compare_by_time? if @column_key && record.has_key?(@column_key) return @time_parser.call(record[@column_key]).to_i # treats time as unixtime end nil else record[@column_key] end end
fetch_comparison_key()
click to toggle source
# File lib/fluent/plugin/filter_comparison.rb, line 68 def fetch_comparison_key @storage.get(:last_recorded) end
set_comparison_key(key)
click to toggle source
# File lib/fluent/plugin/filter_comparison.rb, line 72 def set_comparison_key(key) @storage.put(:last_recorded, key) end