Class: Fluent::ViaqDataModelFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_viaq_data_model.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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) ⇒ Object

recursively delete empty fields and empty lists/hashes from thing



96
97
98
99
100
101
# File 'lib/fluent/plugin/filter_viaq_data_model.rb', line 96

def delempty(thing)
  if thing.respond_to?(:delete_if)
    thing.delete_if{|k,v| v.nil? || isempty(delempty(v)) || isempty(v)}
  end
  thing
end

#filter(tag, time, record) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/fluent/plugin/filter_viaq_data_model.rb', line 103

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) ⇒ Object

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



91
92
93
# File 'lib/fluent/plugin/filter_viaq_data_model.rb', line 91

def isempty(thing)
  thing.respond_to?(:empty?) && thing.empty?
end

#shutdownObject



85
86
87
# File 'lib/fluent/plugin/filter_viaq_data_model.rb', line 85

def shutdown
  super
end

#startObject



81
82
83
# File 'lib/fluent/plugin/filter_viaq_data_model.rb', line 81

def start
  super
end