Module: KubernetesMetadata::Util

Included in:
Fluent::Plugin::KubernetesMetadataFilter
Defined in:
lib/fluent/plugin/kubernetes_metadata_util.rb

Instance Method Summary collapse

Instance Method Details

#create_time_from_record(record, internal_time) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fluent/plugin/kubernetes_metadata_util.rb', line 23

def create_time_from_record(record, internal_time)
  time_key = @time_fields.detect { |ii| record.key?(ii) }
  time = record[time_key]
  if time.nil? || time.is_a?(String) && time.chop.empty?
    # `internal_time` is a Fluent::EventTime, it can't compare with Time.
    return Time.at(internal_time.to_f)
  end

  if ['_SOURCE_REALTIME_TIMESTAMP', '__REALTIME_TIMESTAMP'].include?(time_key)
    timei = time.to_i
    return Time.at(timei / 1_000_000, timei % 1_000_000)
  end
  return Time.at(time) if time.is_a?(Numeric)

  Time.parse(time)
end