class Fluent::Plugin::InsertIdFilter

Attributes

insert_id_key[R]

Expose attr_readers for testing.

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_insert_id.rb, line 53
def configure(conf)
  super
end
filter(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_insert_id.rb, line 69
def filter(tag, time, record)
  # Only generate and add an insertId field if the record is a hash and
  # the insert ID field is not already set (or set to an empty string).
  if record.is_a?(Hash) && record[@insert_id_key].to_s.empty?
    record[@insert_id_key] = increment_insert_id
  end
  record
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_insert_id.rb, line 65
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_insert_id.rb, line 57
def start
  super
  # Initialize the ID
  log.info "Started the insert-id plugin with #{@insert_id_key} as the insert ID key."
  @insert_id = generate_initial_insert_id
  log.info "Initialized the insert ID key to #{@insert_id}."
end

Private Instance Methods

generate_initial_insert_id() click to toggle source

Generate a random string as the initial insertId.

# File lib/fluent/plugin/filter_insert_id.rb, line 82
def generate_initial_insert_id
  Array.new(INSERT_ID_SIZE) { ALLOWED_CHARS.sample }.join
end
increment_insert_id() click to toggle source

Increment the insertId and return the new value.

# File lib/fluent/plugin/filter_insert_id.rb, line 87
def increment_insert_id
  @insert_id = @insert_id.next.slice(-INSERT_ID_SIZE,INSERT_ID_SIZE) # slice is required to make sure ID has fixed length.
end