class Fluent::ViaqDataModelFilter

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_viaq_data_model.rb, line 63
def configure(conf)
  super
  @keep_fields = {}
  @default_keep_fields.each{|xx| @keep_fields[xx] = true}
  @extra_keep_fields.each{|xx| @keep_fields[xx] = true}
  @keep_empty_fields_hash = {}
  @keep_empty_fields.each do |xx|
    @keep_empty_fields_hash[xx] = true
    @keep_fields[xx] = true
  end
  if @use_undefined && @keep_fields.key?(@undefined_name)
    raise Fluent::ConfigError, "Do not put [#{@undefined_name}] in default_keep_fields or extra_keep_fields"
  end
  if (@rename_time || @rename_time_if_not_exist) && @use_undefined && !@keep_fields.key?(@src_time_name)
    raise Fluent::ConfigError, "Field [#{@src_time_name}] must be listed in default_keep_fields or extra_keep_fields"
  end
end
delempty(thing) click to toggle source

recursively delete empty fields and empty lists/hashes from thing

# File lib/fluent/plugin/filter_viaq_data_model.rb, line 96
def delempty(thing)
  if thing.respond_to?(:delete_if)
    if thing.kind_of? Hash
      thing.delete_if{|k,v| v.nil? || isempty(delempty(v)) || isempty(v)}
    else # assume single element iterable
      thing.delete_if{|elem| elem.nil? || isempty(delempty(elem)) || isempty(elem)}
    end
  end
  thing
end
filter(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_viaq_data_model.rb, line 107
def filter(tag, time, record)
  if ENV['CDM_DEBUG']
    unless tag == ENV['CDM_DEBUG_IGNORE_TAG']
      log.error("input #{time} #{tag} #{record}")
    end
  end
  if @use_undefined
    # undefined contains all of the fields not in keep_fields
    undefined = record.reject{|k,v| @keep_fields.key?(k)}
    # only set the undefined field if there are undefined fields
    unless undefined.empty?
      record[@undefined_name] = undefined
      # remove the undefined fields from the record top level
      record.delete_if{|k,v| undefined.key?(k)}
    end
  end
  # remove the field from record if it is not in the list of fields to keep and
  # it is empty
  record.delete_if{|k,v| !@keep_empty_fields_hash.key?(k) && (v.nil? || isempty(delempty(v)) || isempty(v))}
  # probably shouldn't remove everything . . .
  log.warn("Empty record! tag [#{tag}] time [#{time}]") if record.empty?
  # rename the time field
  if (@rename_time || @rename_time_if_missing) && record.key?(@src_time_name)
    val = record.delete(@src_time_name)
    unless @rename_time_if_missing && record.key?(@dest_time_name)
      record[@dest_time_name] = val
    end
  end
  if ENV['CDM_DEBUG']
    unless tag == ENV['CDM_DEBUG_IGNORE_TAG']
      log.error("output #{time} #{tag} #{record}")
    end
  end
  record
end
isempty(thing) click to toggle source

if thing doesn't respond to empty? then assume it isn't empty e.g. 0.respond_to?(:empty?) == false - the FixNum 0 is not empty

# File lib/fluent/plugin/filter_viaq_data_model.rb, line 91
def isempty(thing)
  thing.respond_to?(:empty?) && thing.empty?
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_viaq_data_model.rb, line 85
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_viaq_data_model.rb, line 81
def start
  super
end