Class: Fluent::Plugin::KubEventsTimestampFilter

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (Fluent::ConfigError)


19
20
21
22
23
24
25
# File 'lib/fluent/plugin/filter_kube_events_timestamp.rb', line 19

def configure(conf)
  super
  require 'date'
  @strftime_format = "%Y-%m-%dT%H:%M:%S.%3N%z".freeze
  raise Fluent::ConfigError, "mapped_time_key can not be empty" if mapped_time_key.to_s.empty?
  raise Fluent::ConfigError, "timestamp_fields must have 3 items" if timestamp_fields.length != 3
end

#filter(tag, time, record) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fluent/plugin/filter_kube_events_timestamp.rb', line 35

def filter(tag, time, record)

  vals=@timestamp_fields.map do |field|; getin(record, field); end

  record[@mapped_time_key] = (vals[0].to_s.empty?) ? (vals[1].to_s.empty?) ? vals[2] : vals[1] : vals[0]

  # record[@mapped_time_key] = (getin(record,@timestamp_fields[0]).to_s.empty?) ? (getin(record,@timestamp_fields[1]).to_s.empty?) ? getin(record,@timestamp_fields[2]) : getin(record,@timestamp_fields[1]) : getin(record,@timestamp_fields[0])

  if record[@mapped_time_key].to_s.empty?
    record[@mapped_time_key] = Time.at(time.is_a?(Fluent::EventTime) ? time.to_int : time).strftime(@strftime_format)
  end
  $log.debug("Timestamp added: #{@mapped_time_key}:#{record[@mapped_time_key]}")
  
  record
end

#shutdownObject



31
32
33
# File 'lib/fluent/plugin/filter_kube_events_timestamp.rb', line 31

def shutdown
  super
end

#startObject



27
28
29
# File 'lib/fluent/plugin/filter_kube_events_timestamp.rb', line 27

def start
  super
end