class Fluent::Plugin::ElasticsearchGenidFilter

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_elasticsearch_genid.rb, line 18
def initialize
  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_elasticsearch_genid.rb, line 22
def configure(conf)
  super

  if !@use_entire_record
    if @record_keys.empty? && @use_record_as_seed
      raise Fluent::ConfigError, "When using record as hash seed, users must specify `record_keys`."
    end
  end

  if @use_record_as_seed
    class << self
      alias_method :filter, :filter_seed_as_record
    end
  else
    class << self
      alias_method :filter, :filter_simple
    end
  end
end
encode_hash(type, seed) click to toggle source
# File lib/fluent/plugin/filter_elasticsearch_genid.rb, line 64
def encode_hash(type, seed)
  case type
  when :md5
    Digest::MD5.digest(seed)
  when :sha1
    Digest::SHA1.digest(seed)
  when :sha256
    Digest::SHA256.digest(seed)
  when :sha512
    Digest::SHA512.digest(seed)
  end
end
filter(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_elasticsearch_genid.rb, line 42
def filter(tag, time, record)
  # for safety.
end
filter_seed_as_record(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_elasticsearch_genid.rb, line 51
def filter_seed_as_record(tag, time, record)
  seed = ""
  seed += tag + separator if @include_tag_in_seed
  seed += time.to_s + separator if @include_time_in_seed
  if @use_entire_record
    record.each {|k,v| seed += "|#{k}|#{v}"}
  else
    seed += record_keys.map {|k| record[k]}.join(separator)
  end
  record[@hash_id_key] = Base64.strict_encode64(encode_hash(@hash_type, seed))
  record
end
filter_simple(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_elasticsearch_genid.rb, line 46
def filter_simple(tag, time, record)
  record[@hash_id_key] = Base64.strict_encode64(SecureRandom.uuid)
  record
end