Class: Fluent::Plugin::OpenSearchGenidFilter

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

Instance Method Summary collapse

Constructor Details

#initializeOpenSearchGenidFilter

Returns a new instance of OpenSearchGenidFilter.



44
45
46
# File 'lib/fluent/plugin/filter_opensearch_genid.rb', line 44

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fluent/plugin/filter_opensearch_genid.rb', line 48

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) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fluent/plugin/filter_opensearch_genid.rb', line 90

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) ⇒ Object



68
69
70
# File 'lib/fluent/plugin/filter_opensearch_genid.rb', line 68

def filter(tag, time, record)
  # for safety.
end

#filter_seed_as_record(tag, time, record) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fluent/plugin/filter_opensearch_genid.rb', line 77

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) ⇒ Object



72
73
74
75
# File 'lib/fluent/plugin/filter_opensearch_genid.rb', line 72

def filter_simple(tag, time, record)
  record[@hash_id_key] = Base64.strict_encode64(SecureRandom.uuid)
  record
end