Module: Fluent::Compat::AddTimeSliceKeyToChunkMixin

Defined in:
lib/fluent/compat/output.rb

Instance Method Summary collapse

Instance Method Details

#assume_timekey!Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fluent/compat/output.rb', line 85

def assume_timekey!
  @_formatter = Fluent::TimeFormatter.new(@_time_slice_format, nil, @_timezone)

  return if self..timekey
  if self.respond_to?(:path) && self.path =~ /\.(\d+)\.(?:b|q)(?:[a-z0-9]+)/
    begin
      self..timekey = Time.parse($1, @_time_slice_format).to_i
    rescue ArgumentError
      # unknown format / value as timekey
    end
  end
  unless self..timekey
    # file creation time is assumed in the time range of that time slice
    # because the first record should be in that range.
    time_int = self.created_at.to_i
    self..timekey = time_int - (time_int % @_timekey)
  end
end

#keyObject



104
105
106
# File 'lib/fluent/compat/output.rb', line 104

def key
  @_formatter.call(self..timekey)
end

#time_slice_format=(format) ⇒ Object



73
74
75
# File 'lib/fluent/compat/output.rb', line 73

def time_slice_format=(format)
  @_time_slice_format = format
end

#timekey=(unit) ⇒ Object



77
78
79
# File 'lib/fluent/compat/output.rb', line 77

def timekey=(unit)
  @_timekey = unit
end

#timezone=(tz) ⇒ Object



81
82
83
# File 'lib/fluent/compat/output.rb', line 81

def timezone=(tz)
  @_timezone = tz
end