fluent-plugin-elasticsearch 4.0.8 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/issue-auto-closer.yml +12 -0
- data/History.md +23 -0
- data/README.ElasticsearchGenID.md +116 -0
- data/README.md +104 -5
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_fallback_selector.rb +9 -0
- data/lib/fluent/plugin/elasticsearch_index_template.rb +19 -11
- data/lib/fluent/plugin/filter_elasticsearch_genid.rb +52 -0
- data/lib/fluent/plugin/out_elasticsearch.rb +64 -31
- data/test/plugin/test_elasticsearch_fallback_selector.rb +73 -0
- data/test/plugin/test_filter_elasticsearch_genid.rb +171 -0
- data/test/plugin/test_out_elasticsearch.rb +375 -72
- metadata +7 -2
@@ -7,6 +7,13 @@ module Fluent::Plugin
|
|
7
7
|
Fluent::Plugin.register_filter('elasticsearch_genid', self)
|
8
8
|
|
9
9
|
config_param :hash_id_key, :string, :default => '_hash'
|
10
|
+
config_param :include_tag_in_seed, :bool, :default => false
|
11
|
+
config_param :include_time_in_seed, :bool, :default => false
|
12
|
+
config_param :use_record_as_seed, :bool, :default => false
|
13
|
+
config_param :use_entire_record, :bool, :default => false
|
14
|
+
config_param :record_keys, :array, :default => []
|
15
|
+
config_param :separator, :string, :default => '_'
|
16
|
+
config_param :hash_type, :enum, list: [:md5, :sha1, :sha256, :sha512], :default => :sha1
|
10
17
|
|
11
18
|
def initialize
|
12
19
|
super
|
@@ -14,12 +21,57 @@ module Fluent::Plugin
|
|
14
21
|
|
15
22
|
def configure(conf)
|
16
23
|
super
|
24
|
+
|
25
|
+
if !@use_entire_record
|
26
|
+
if @record_keys.empty? && @use_record_as_seed
|
27
|
+
raise Fluent::ConfigError, "When using record as hash seed, users must specify `record_keys`."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if @use_record_as_seed
|
32
|
+
class << self
|
33
|
+
alias_method :filter, :filter_seed_as_record
|
34
|
+
end
|
35
|
+
else
|
36
|
+
class << self
|
37
|
+
alias_method :filter, :filter_simple
|
38
|
+
end
|
39
|
+
end
|
17
40
|
end
|
18
41
|
|
19
42
|
def filter(tag, time, record)
|
43
|
+
# for safety.
|
44
|
+
end
|
45
|
+
|
46
|
+
def filter_simple(tag, time, record)
|
20
47
|
record[@hash_id_key] = Base64.strict_encode64(SecureRandom.uuid)
|
21
48
|
record
|
22
49
|
end
|
23
50
|
|
51
|
+
def filter_seed_as_record(tag, time, record)
|
52
|
+
seed = ""
|
53
|
+
seed += tag + separator if @include_tag_in_seed
|
54
|
+
seed += time.to_s + separator if @include_time_in_seed
|
55
|
+
if @use_entire_record
|
56
|
+
record.each {|k,v| seed += "|#{k}|#{v}"}
|
57
|
+
else
|
58
|
+
seed += record_keys.map {|k| record[k]}.join(separator)
|
59
|
+
end
|
60
|
+
record[@hash_id_key] = Base64.strict_encode64(encode_hash(@hash_type, seed))
|
61
|
+
record
|
62
|
+
end
|
63
|
+
|
64
|
+
def encode_hash(type, seed)
|
65
|
+
case type
|
66
|
+
when :md5
|
67
|
+
Digest::MD5.digest(seed)
|
68
|
+
when :sha1
|
69
|
+
Digest::SHA1.digest(seed)
|
70
|
+
when :sha256
|
71
|
+
Digest::SHA256.digest(seed)
|
72
|
+
when :sha512
|
73
|
+
Digest::SHA512.digest(seed)
|
74
|
+
end
|
75
|
+
end
|
24
76
|
end
|
25
77
|
end
|
@@ -25,6 +25,7 @@ require_relative 'elasticsearch_error_handler'
|
|
25
25
|
require_relative 'elasticsearch_index_template'
|
26
26
|
require_relative 'elasticsearch_index_lifecycle_management'
|
27
27
|
require_relative 'elasticsearch_tls'
|
28
|
+
require_relative 'elasticsearch_fallback_selector'
|
28
29
|
begin
|
29
30
|
require_relative 'oj_serializer'
|
30
31
|
rescue LoadError
|
@@ -50,7 +51,7 @@ module Fluent::Plugin
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
RequestInfo = Struct.new(:host, :index, :ilm_index)
|
54
|
+
RequestInfo = Struct.new(:host, :index, :ilm_index, :ilm_alias)
|
54
55
|
|
55
56
|
attr_reader :alias_indexes
|
56
57
|
attr_reader :template_names
|
@@ -90,6 +91,7 @@ EOC
|
|
90
91
|
config_param :logstash_dateformat, :string, :default => "%Y.%m.%d"
|
91
92
|
config_param :utc_index, :bool, :default => true
|
92
93
|
config_param :type_name, :string, :default => DEFAULT_TYPE_NAME
|
94
|
+
config_param :suppress_type_name, :bool, :default => false
|
93
95
|
config_param :index_name, :string, :default => "fluentd"
|
94
96
|
config_param :id_key, :string, :default => nil
|
95
97
|
config_param :write_operation, :string, :default => "index"
|
@@ -136,6 +138,7 @@ EOC
|
|
136
138
|
config_param :with_transporter_log, :bool, :default => false
|
137
139
|
config_param :emit_error_for_missing_id, :bool, :default => false
|
138
140
|
config_param :sniffer_class_name, :string, :default => nil
|
141
|
+
config_param :selector_class_name, :string, :default => nil
|
139
142
|
config_param :reload_after, :integer, :default => DEFAULT_RELOAD_AFTER
|
140
143
|
config_param :content_type, :enum, list: [:"application/json", :"application/x-ndjson"], :default => :"application/json",
|
141
144
|
:deprecated => <<EOC
|
@@ -160,6 +163,7 @@ EOC
|
|
160
163
|
config_param :enable_ilm, :bool, :default => false
|
161
164
|
config_param :ilm_policy_id, :string, :default => DEFAULT_POLICY_ID
|
162
165
|
config_param :ilm_policy, :hash, :default => {}
|
166
|
+
config_param :ilm_policies, :hash, :default => {}
|
163
167
|
config_param :ilm_policy_overwrite, :bool, :default => false
|
164
168
|
config_param :truncate_caches_interval, :time, :default => nil
|
165
169
|
|
@@ -220,22 +224,27 @@ EOC
|
|
220
224
|
log.info "host placeholder and template installation makes your Elasticsearch cluster a bit slow down(beta)."
|
221
225
|
end
|
222
226
|
|
227
|
+
raise Fluent::ConfigError, "You can't specify ilm_policy and ilm_policies at the same time" unless @ilm_policy.empty? or @ilm_policies.empty?
|
228
|
+
|
229
|
+
unless @ilm_policy.empty?
|
230
|
+
@ilm_policies = { @ilm_policy_id => @ilm_policy }
|
231
|
+
end
|
223
232
|
@alias_indexes = []
|
224
233
|
@template_names = []
|
225
234
|
if !dry_run?
|
226
235
|
if @template_name && @template_file
|
227
236
|
if @enable_ilm
|
228
|
-
raise Fluent::ConfigError, "deflector_alias is prohibited to use with
|
237
|
+
raise Fluent::ConfigError, "deflector_alias is prohibited to use with enable_ilm at same time." if @deflector_alias
|
229
238
|
end
|
230
239
|
if @ilm_policy.empty? && @ilm_policy_overwrite
|
231
|
-
raise Fluent::ConfigError, "ilm_policy_overwrite
|
240
|
+
raise Fluent::ConfigError, "ilm_policy_overwrite requires a non empty ilm_policy."
|
232
241
|
end
|
233
242
|
if @logstash_format || placeholder_substitution_needed_for_template?
|
234
243
|
class << self
|
235
244
|
alias_method :template_installation, :template_installation_actual
|
236
245
|
end
|
237
246
|
else
|
238
|
-
template_installation_actual(@deflector_alias ? @deflector_alias : @index_name, @template_name, @customize_template, @application_name, @index_name)
|
247
|
+
template_installation_actual(@deflector_alias ? @deflector_alias : @index_name, @template_name, @customize_template, @application_name, @index_name, @ilm_policy_id)
|
239
248
|
end
|
240
249
|
verify_ilm_working if @enable_ilm
|
241
250
|
elsif @templates
|
@@ -293,21 +302,32 @@ EOC
|
|
293
302
|
raise Fluent::ConfigError, "Could not load sniffer class #{@sniffer_class_name}: #{ex}"
|
294
303
|
end
|
295
304
|
|
305
|
+
@selector_class = nil
|
306
|
+
begin
|
307
|
+
@selector_class = Object.const_get(@selector_class_name) if @selector_class_name
|
308
|
+
rescue Exception => ex
|
309
|
+
raise Fluent::ConfigError, "Could not load selector class #{@selector_class_name}: #{ex}"
|
310
|
+
end
|
311
|
+
|
296
312
|
@last_seen_major_version = if major_version = handle_last_seen_es_major_version
|
297
313
|
major_version
|
298
314
|
else
|
299
315
|
@default_elasticsearch_version
|
300
316
|
end
|
301
|
-
if @
|
302
|
-
log.info "Detected ES 6.x: ES 7.x will only accept `_doc` in type_name."
|
303
|
-
end
|
304
|
-
if @last_seen_major_version == 7 && @type_name != DEFAULT_TYPE_NAME_ES_7x
|
305
|
-
log.warn "Detected ES 7.x: `_doc` will be used as the document `_type`."
|
306
|
-
@type_name = '_doc'.freeze
|
307
|
-
end
|
308
|
-
if @last_seen_major_version >= 8 && @type_name != DEFAULT_TYPE_NAME_ES_7x
|
309
|
-
log.info "Detected ES 8.x or above: This parameter has no effect."
|
317
|
+
if @suppress_type_name && @last_seen_major_version >= 7
|
310
318
|
@type_name = nil
|
319
|
+
else
|
320
|
+
if @last_seen_major_version == 6 && @type_name != DEFAULT_TYPE_NAME_ES_7x
|
321
|
+
log.info "Detected ES 6.x: ES 7.x will only accept `_doc` in type_name."
|
322
|
+
end
|
323
|
+
if @last_seen_major_version == 7 && @type_name != DEFAULT_TYPE_NAME_ES_7x
|
324
|
+
log.warn "Detected ES 7.x: `_doc` will be used as the document `_type`."
|
325
|
+
@type_name = '_doc'.freeze
|
326
|
+
end
|
327
|
+
if @last_seen_major_version >= 8 && @type_name != DEFAULT_TYPE_NAME_ES_7x
|
328
|
+
log.info "Detected ES 8.x or above: This parameter has no effect."
|
329
|
+
@type_name = nil
|
330
|
+
end
|
311
331
|
end
|
312
332
|
|
313
333
|
if @validate_client_version && !dry_run?
|
@@ -555,6 +575,7 @@ EOC
|
|
555
575
|
},
|
556
576
|
sniffer_class: @sniffer_class,
|
557
577
|
serializer_class: @serializer_class,
|
578
|
+
selector_class: @selector_class,
|
558
579
|
compression: compress_connection,
|
559
580
|
}), &adapter_conf)
|
560
581
|
Elasticsearch::Client.new transport: transport
|
@@ -719,7 +740,12 @@ EOC
|
|
719
740
|
else
|
720
741
|
pipeline = nil
|
721
742
|
end
|
722
|
-
|
743
|
+
if @ilm_policy_id
|
744
|
+
ilm_policy_id = extract_placeholders(@ilm_policy_id, chunk)
|
745
|
+
else
|
746
|
+
ilm_policy_id = nil
|
747
|
+
end
|
748
|
+
return logstash_prefix, logstash_dateformat, index_name, type_name, template_name, customize_template, deflector_alias, application_name, pipeline, ilm_policy_id
|
723
749
|
end
|
724
750
|
|
725
751
|
def multi_workers_ready?
|
@@ -745,9 +771,9 @@ EOC
|
|
745
771
|
begin
|
746
772
|
meta, header, record = process_message(tag, meta, header, time, record, extracted_values)
|
747
773
|
info = if @include_index_in_url
|
748
|
-
RequestInfo.new(host, meta.delete("_index".freeze), meta["_index".freeze])
|
774
|
+
RequestInfo.new(host, meta.delete("_index".freeze), meta["_index".freeze], meta.delete("_alias".freeze))
|
749
775
|
else
|
750
|
-
RequestInfo.new(host, nil, meta["_index".freeze])
|
776
|
+
RequestInfo.new(host, nil, meta["_index".freeze], meta.delete("_alias".freeze))
|
751
777
|
end
|
752
778
|
|
753
779
|
if split_request?(bulk_message, info)
|
@@ -793,7 +819,7 @@ EOC
|
|
793
819
|
end
|
794
820
|
|
795
821
|
def process_message(tag, meta, header, time, record, extracted_values)
|
796
|
-
logstash_prefix, logstash_dateformat, index_name, type_name, _template_name, _customize_template, _deflector_alias,
|
822
|
+
logstash_prefix, logstash_dateformat, index_name, type_name, _template_name, _customize_template, _deflector_alias, application_name, pipeline, _ilm_policy_id = extracted_values
|
797
823
|
|
798
824
|
if @flatten_hashes
|
799
825
|
record = flatten_record(record)
|
@@ -816,17 +842,19 @@ EOC
|
|
816
842
|
|
817
843
|
target_index_parent, target_index_child_key = @target_index_key ? get_parent_of(record, @target_index_key) : nil
|
818
844
|
if target_index_parent && target_index_parent[target_index_child_key]
|
819
|
-
target_index = target_index_parent.delete(target_index_child_key)
|
845
|
+
target_index_alias = target_index = target_index_parent.delete(target_index_child_key)
|
820
846
|
elsif @logstash_format
|
821
847
|
dt = dt.new_offset(0) if @utc_index
|
822
848
|
target_index = "#{logstash_prefix}#{@logstash_prefix_separator}#{dt.strftime(logstash_dateformat)}"
|
849
|
+
target_index_alias = "#{logstash_prefix}#{@logstash_prefix_separator}#{application_name}#{@logstash_prefix_separator}#{dt.strftime(logstash_dateformat)}"
|
823
850
|
else
|
824
|
-
target_index = index_name
|
851
|
+
target_index_alias = target_index = index_name
|
825
852
|
end
|
826
853
|
|
827
854
|
# Change target_index to lower-case since Elasticsearch doesn't
|
828
855
|
# allow upper-case characters in index names.
|
829
856
|
target_index = target_index.downcase
|
857
|
+
target_index_alias = target_index_alias.downcase
|
830
858
|
if @include_tag_key
|
831
859
|
record[@tag_key] = tag
|
832
860
|
end
|
@@ -845,7 +873,9 @@ EOC
|
|
845
873
|
target_type = nil
|
846
874
|
end
|
847
875
|
else
|
848
|
-
if @
|
876
|
+
if @suppress_type_name && @last_seen_major_version >= 7
|
877
|
+
target_type = nil
|
878
|
+
elsif @last_seen_major_version == 7 && @type_name != DEFAULT_TYPE_NAME_ES_7x
|
849
879
|
log.warn "Detected ES 7.x: `_doc` will be used as the document `_type`."
|
850
880
|
target_type = '_doc'.freeze
|
851
881
|
elsif @last_seen_major_version >= 8
|
@@ -859,6 +889,7 @@ EOC
|
|
859
889
|
meta.clear
|
860
890
|
meta["_index".freeze] = target_index
|
861
891
|
meta["_type".freeze] = target_type unless @last_seen_major_version >= 8
|
892
|
+
meta["_alias".freeze] = target_index_alias
|
862
893
|
|
863
894
|
if @pipeline
|
864
895
|
meta["pipeline".freeze] = pipeline
|
@@ -901,29 +932,31 @@ EOC
|
|
901
932
|
placeholder?(:logstash_prefix, @logstash_prefix.to_s) ||
|
902
933
|
placeholder?(:logstash_dateformat, @logstash_dateformat.to_s) ||
|
903
934
|
placeholder?(:deflector_alias, @deflector_alias.to_s) ||
|
904
|
-
placeholder?(:application_name, @application_name.to_s)
|
935
|
+
placeholder?(:application_name, @application_name.to_s) ||
|
936
|
+
placeholder?(:ilm_policy_id, @ilm_policy_id.to_s)
|
905
937
|
log.debug("Need substitution: #{need_substitution}")
|
906
938
|
need_substitution
|
907
939
|
end
|
908
940
|
|
909
|
-
def template_installation(deflector_alias, template_name, customize_template, application_name, target_index, host)
|
941
|
+
def template_installation(deflector_alias, template_name, customize_template, application_name, ilm_policy_id, target_index, host)
|
910
942
|
# for safety.
|
911
943
|
end
|
912
944
|
|
913
|
-
def template_installation_actual(deflector_alias, template_name, customize_template, application_name, target_index, host=nil)
|
945
|
+
def template_installation_actual(deflector_alias, template_name, customize_template, application_name, target_index, ilm_policy_id, host=nil)
|
914
946
|
if template_name && @template_file
|
915
|
-
if @alias_indexes.include?
|
947
|
+
if !@logstash_format && @alias_indexes.include?(deflector_alias)
|
916
948
|
log.debug("Index alias #{deflector_alias} already exists (cached)")
|
917
|
-
elsif @template_names.include?
|
949
|
+
elsif !@logstash_format && @template_names.include?(template_name)
|
918
950
|
log.debug("Template name #{template_name} already exists (cached)")
|
919
951
|
else
|
920
952
|
retry_operate(@max_retry_putting_template, @fail_on_putting_template_retry_exceed) do
|
921
953
|
if customize_template
|
922
|
-
template_custom_install(template_name, @template_file, @template_overwrite, customize_template, @enable_ilm, deflector_alias,
|
954
|
+
template_custom_install(template_name, @template_file, @template_overwrite, customize_template, @enable_ilm, deflector_alias, ilm_policy_id, host, target_index)
|
923
955
|
else
|
924
|
-
template_install(template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias,
|
956
|
+
template_install(template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, ilm_policy_id, host, target_index)
|
925
957
|
end
|
926
|
-
|
958
|
+
ilm_policy = @ilm_policies[ilm_policy_id] || {}
|
959
|
+
create_rollover_alias(target_index, @rollover_index, deflector_alias, application_name, @index_date_pattern, @index_separator, @enable_ilm, ilm_policy_id, ilm_policy, @ilm_policy_overwrite, host)
|
927
960
|
end
|
928
961
|
@alias_indexes << deflector_alias unless deflector_alias.nil?
|
929
962
|
@template_names << template_name unless template_name.nil?
|
@@ -934,11 +967,11 @@ EOC
|
|
934
967
|
# send_bulk given a specific bulk request, the original tag,
|
935
968
|
# chunk, and bulk_message_count
|
936
969
|
def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, info)
|
937
|
-
|
970
|
+
_logstash_prefix, _logstash_dateformat, index_name, _type_name, template_name, customize_template, deflector_alias, application_name, _pipeline, ilm_policy_id = extracted_values
|
938
971
|
if deflector_alias
|
939
|
-
template_installation(deflector_alias, template_name, customize_template, application_name, index_name, info.host)
|
972
|
+
template_installation(deflector_alias, template_name, customize_template, application_name, index_name, ilm_policy_id, info.host)
|
940
973
|
else
|
941
|
-
template_installation(info.ilm_index, template_name, customize_template, application_name, @logstash_format ?
|
974
|
+
template_installation(info.ilm_index, template_name, customize_template, application_name, @logstash_format ? info.ilm_alias : index_name, ilm_policy_id, info.host)
|
942
975
|
end
|
943
976
|
|
944
977
|
begin
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/test/driver/output'
|
3
|
+
require 'fluent/plugin/out_elasticsearch'
|
4
|
+
|
5
|
+
class ElasticsearchFallbackSelectorTest < Test::Unit::TestCase
|
6
|
+
attr_accessor :index_cmds
|
7
|
+
|
8
|
+
def setup
|
9
|
+
Fluent::Test.setup
|
10
|
+
@driver = nil
|
11
|
+
log = Fluent::Engine.log
|
12
|
+
log.out.logs.slice!(0, log.out.logs.length)
|
13
|
+
end
|
14
|
+
|
15
|
+
def stub_elastic(url="http://localhost:9200/_bulk")
|
16
|
+
stub_request(:post, url).with do |req|
|
17
|
+
@index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_elastic_info(url="http://localhost:9200/", version="6.4.2")
|
22
|
+
body ="{\"version\":{\"number\":\"#{version}\"}}"
|
23
|
+
stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
|
24
|
+
end
|
25
|
+
|
26
|
+
def stub_elastic_info_not_found(url="http://localhost:9200/", version="6.4.2")
|
27
|
+
stub_request(:get, url).to_return(:status => [404, "Not Found"])
|
28
|
+
end
|
29
|
+
|
30
|
+
def stub_elastic_info_unavailable(url="http://localhost:9200/", version="6.4.2")
|
31
|
+
stub_request(:get, url).to_return(:status => [503, "Service Unavailable"])
|
32
|
+
end
|
33
|
+
|
34
|
+
def sample_record(content={})
|
35
|
+
{'age' => 26, 'request_id' => '42', 'parent_id' => 'parent', 'routing_id' => 'routing'}.merge(content)
|
36
|
+
end
|
37
|
+
|
38
|
+
def driver(conf='')
|
39
|
+
@driver ||= Fluent::Test::Driver::Output.new(Fluent::Plugin::ElasticsearchOutput) {
|
40
|
+
# v0.12's test driver assume format definition. This simulates ObjectBufferedOutput format
|
41
|
+
if !defined?(Fluent::Plugin::Output)
|
42
|
+
def format(tag, time, record)
|
43
|
+
[time, record].to_msgpack
|
44
|
+
end
|
45
|
+
end
|
46
|
+
}.configure(conf)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_fallback_on_info
|
50
|
+
stub_elastic_info_not_found("http://localhost:9202/")
|
51
|
+
stub_elastic_info_unavailable("http://localhost:9201/")
|
52
|
+
stub_elastic_info
|
53
|
+
stub_elastic
|
54
|
+
config = %[
|
55
|
+
hosts localhost:9202,localhost:9201,localhost:9200
|
56
|
+
selector_class_name Fluent::Plugin::ElasticseatchFallbackSelector
|
57
|
+
@log_level debug
|
58
|
+
with_transporter_log true
|
59
|
+
reload_connections true
|
60
|
+
reload_after 10
|
61
|
+
]
|
62
|
+
assert_raise(Elasticsearch::Transport::Transport::Errors::NotFound) do
|
63
|
+
driver(config)
|
64
|
+
end
|
65
|
+
driver.run(default_tag: 'test') do
|
66
|
+
driver.feed(sample_record)
|
67
|
+
end
|
68
|
+
assert_equal(2, index_cmds.length)
|
69
|
+
assert_equal("fluentd", index_cmds.first['index']['_index'])
|
70
|
+
end
|
71
|
+
|
72
|
+
# TODO: on feed phase test case
|
73
|
+
end
|
@@ -18,6 +18,12 @@ class ElasticsearchGenidFilterTest < Test::Unit::TestCase
|
|
18
18
|
Fluent::Test::Driver::Filter.new(Fluent::Plugin::ElasticsearchGenidFilter).configure(conf)
|
19
19
|
end
|
20
20
|
|
21
|
+
test "invalid configuration" do
|
22
|
+
assert_raise(Fluent::ConfigError) do
|
23
|
+
create_driver("use_record_as_seed true")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
21
27
|
def sample_record
|
22
28
|
{'age' => 26, 'request_id' => '42', 'parent_id' => 'parent', 'routing_id' => 'routing'}
|
23
29
|
end
|
@@ -41,4 +47,169 @@ class ElasticsearchGenidFilterTest < Test::Unit::TestCase
|
|
41
47
|
assert_equal(Base64.strict_encode64(SecureRandom.uuid),
|
42
48
|
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
43
49
|
end
|
50
|
+
|
51
|
+
class UseRecordAsSeedTest < self
|
52
|
+
data("md5" => ["md5", "PPg+zmH1ASUCpNzMUcTzqw=="],
|
53
|
+
"sha1" => ["sha1", "JKfCrEAxeAyRSdcKqkw4unC9xZ8="],
|
54
|
+
"sha256" => ["sha256", "9Z9i+897bGivSItD/6i0vye9uRwq/sLwWkxOwydtTJY="],
|
55
|
+
"sha512" => ["sha512", "KWI5OdZPaCFW9/CEY3NoGrvueMtjZJdmGdqIVGJP8vgI4uW+0gHExZVaHerw+RhbtIdLCtVZ43xBgMKH+KliQg=="],
|
56
|
+
)
|
57
|
+
def test_simple(data)
|
58
|
+
hash_type, expected = data
|
59
|
+
d = create_driver(%[
|
60
|
+
use_record_as_seed true
|
61
|
+
record_keys age,parent_id,routing_id,custom_key
|
62
|
+
hash_type #{hash_type}
|
63
|
+
])
|
64
|
+
time = event_time("2017-10-15 15:00:23.34567890 UTC")
|
65
|
+
d.run(default_tag: 'test') do
|
66
|
+
d.feed(time, sample_record.merge("custom_key" => "This is also encoded value."))
|
67
|
+
end
|
68
|
+
assert_equal(expected,
|
69
|
+
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
70
|
+
end
|
71
|
+
|
72
|
+
data("md5" => ["md5", "qUO/xqWiOJq4D0ApdoHVEQ=="],
|
73
|
+
"sha1" => ["sha1", "v3UWYr90zIH2veGQBVwUH586TuI="],
|
74
|
+
"sha256" => ["sha256", "4hwh10qfw9B24NtNFoEFF8wCiImvgIy1Vk4gzcKt5Pw="],
|
75
|
+
"sha512" => ["sha512", "TY3arcmC8mhYClDIjQxH8ePRLnHK01Cj5QQL8FxbwNtPQBY3IZ4qJY9CpOusmdWBYwm1golRVQCmURiAhlnWIQ=="],)
|
76
|
+
def test_record_with_tag(data)
|
77
|
+
hash_type, expected = data
|
78
|
+
d = create_driver(%[
|
79
|
+
use_record_as_seed true
|
80
|
+
record_keys age,parent_id,routing_id,custom_key
|
81
|
+
hash_type #{hash_type}
|
82
|
+
include_tag_in_seed true
|
83
|
+
])
|
84
|
+
time = event_time("2017-10-15 15:00:23.34567890 UTC")
|
85
|
+
d.run(default_tag: 'test.fluentd') do
|
86
|
+
d.feed(time, sample_record.merge("custom_key" => "This is also encoded value."))
|
87
|
+
end
|
88
|
+
assert_equal(expected,
|
89
|
+
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
90
|
+
end
|
91
|
+
|
92
|
+
data("md5" => ["md5", "oHo+PoC5I4KC+XCfXvyf9w=="],
|
93
|
+
"sha1" => ["sha1", "50Nwarm2225gLy1ka8d9i+W6cKA="],
|
94
|
+
"sha256" => ["sha256", "ReX1XgizcrHjBc0sQwx9Sjuf2QBFll2njYf4ee+XSIc="],
|
95
|
+
"sha512" => ["sha512", "8bcpZrqNUQIz6opdoVZz0MwxP8r9SCqOEPkWF6xGLlFwPCJVqk2SQp99m8rPufr0xPIgvZyOMejA5slBV9xrdg=="],)
|
96
|
+
def test_record_with_time(data)
|
97
|
+
hash_type, expected = data
|
98
|
+
d = create_driver(%[
|
99
|
+
use_record_as_seed true
|
100
|
+
record_keys age,parent_id,routing_id,custom_key
|
101
|
+
hash_type #{hash_type}
|
102
|
+
include_time_in_seed true
|
103
|
+
])
|
104
|
+
time = event_time("2017-10-15 15:00:23.34567890 UTC")
|
105
|
+
d.run(default_tag: 'test.fluentd') do
|
106
|
+
d.feed(time, sample_record.merge("custom_key" => "This is also encoded value."))
|
107
|
+
end
|
108
|
+
assert_equal(expected,
|
109
|
+
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
110
|
+
end
|
111
|
+
|
112
|
+
data("md5" => ["md5", "u7/hr09gDC9CM5DI7tLc2Q=="],
|
113
|
+
"sha1" => ["sha1", "1WgptcTnVSHtTAlNUwNcoiaY3oM="],
|
114
|
+
"sha256" => ["sha256", "1iWZHI19m/A1VH8iFK7H2KFoyLdszpJRiVeKBv1Ndis="],
|
115
|
+
"sha512" => ["sha512", "NM+ui0lUmeDaEJsT7c9EyTc+lQBbRf1x6MQXXYdxp21CX3jZvHy3IT8Xp9ZdIKevZwhoo3Suo/tIBlfyLFXJXw=="],)
|
116
|
+
def test_record_with_tag_and_time
|
117
|
+
hash_type, expected = data
|
118
|
+
d = create_driver(%[
|
119
|
+
use_record_as_seed true
|
120
|
+
record_keys age,parent_id,routing_id,custom_key
|
121
|
+
hash_type #{hash_type}
|
122
|
+
include_tag_in_seed true
|
123
|
+
include_time_in_seed true
|
124
|
+
])
|
125
|
+
time = event_time("2017-10-15 15:00:23.34567890 UTC")
|
126
|
+
d.run(default_tag: 'test.fluentd') do
|
127
|
+
d.feed(time, sample_record.merge("custom_key" => "This is also encoded value."))
|
128
|
+
end
|
129
|
+
assert_equal(expected,
|
130
|
+
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class UseEntireRecordAsSeedTest < self
|
135
|
+
data("md5" => ["md5", "MuMU0gHOP1cWvvg/J4aEFg=="],
|
136
|
+
"sha1" => ["sha1", "GZ6Iup9Ywyk5spCWtPQbtZnfK0U="],
|
137
|
+
"sha256" => ["sha256", "O4YN0RiXCUAYeaR97UUULRLxgra/R2dvTV47viir5l4="],
|
138
|
+
"sha512" => ["sha512", "FtbwO1xsLUq0KcO0mj0l80rbwFH5rGE3vL+Vgh90+4R/9j+/Ni/ipwhiOoUcetDxj1r5Vf/92B54La+QTu3eMA=="],)
|
139
|
+
def test_record
|
140
|
+
hash_type, expected = data
|
141
|
+
d = create_driver(%[
|
142
|
+
use_record_as_seed true
|
143
|
+
use_entire_record true
|
144
|
+
hash_type #{hash_type}
|
145
|
+
])
|
146
|
+
time = event_time("2017-10-15 15:00:23.34567890 UTC")
|
147
|
+
d.run(default_tag: 'test.fluentd') do
|
148
|
+
d.feed(time, sample_record.merge("custom_key" => "This is also encoded value."))
|
149
|
+
end
|
150
|
+
assert_equal(expected,
|
151
|
+
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
152
|
+
end
|
153
|
+
|
154
|
+
data("md5" => ["md5", "GJfpWe8ofiGzn97bc9Gh0Q=="],
|
155
|
+
"sha1" => ["sha1", "AVaK67Tz0bEJ8xNEzjOQ6r9fAu4="],
|
156
|
+
"sha256" => ["sha256", "WIXWAuf/Z94Uw95mudloo2bgjhSsSduQIwkKTQsNFgU="],
|
157
|
+
"sha512" => ["sha512", "yjMGGxy8uc7gCrPgm8W6MzJGLFk0GtUwJ6w/91laf6WNywuvG/7T6kNHLagAV8rSW8xzxmtEfyValBO5scuoKw=="],)
|
158
|
+
def test_record_with_tag
|
159
|
+
hash_type, expected = data
|
160
|
+
d = create_driver(%[
|
161
|
+
use_record_as_seed true
|
162
|
+
use_entire_record true
|
163
|
+
hash_type #{hash_type}
|
164
|
+
include_tag_in_seed true
|
165
|
+
])
|
166
|
+
time = event_time("2017-10-15 15:00:23.34567890 UTC")
|
167
|
+
d.run(default_tag: 'test.fluentd') do
|
168
|
+
d.feed(time, sample_record.merge("custom_key" => "This is also encoded value."))
|
169
|
+
end
|
170
|
+
assert_equal(expected,
|
171
|
+
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
172
|
+
end
|
173
|
+
|
174
|
+
data("md5" => ["md5", "5nQSaJ4F1p9rDFign13Lfg=="],
|
175
|
+
"sha1" => ["sha1", "hyo9+0ZFBpizKl2NShs3C8yQcGw="],
|
176
|
+
"sha256" => ["sha256", "romVsZSIksbqYsOSnUzolZQw76ankcy0DgvDZ3CayTo="],
|
177
|
+
"sha512" => ["sha512", "RPU7K2Pt0iVyvV7p5usqcUIIOmfTajD1aa7pkR9qZ89UARH/lpm6ESY9iwuYJj92lxOUuF5OxlEwvV7uXJ07iA=="],)
|
178
|
+
def test_record_with_time
|
179
|
+
hash_type, expected = data
|
180
|
+
d = create_driver(%[
|
181
|
+
use_record_as_seed true
|
182
|
+
use_entire_record true
|
183
|
+
hash_type #{hash_type}
|
184
|
+
include_time_in_seed true
|
185
|
+
])
|
186
|
+
time = event_time("2017-10-15 15:00:23.34567890 UTC")
|
187
|
+
d.run(default_tag: 'test.fluentd') do
|
188
|
+
d.feed(time, sample_record.merge("custom_key" => "This is also encoded value."))
|
189
|
+
end
|
190
|
+
assert_equal(expected,
|
191
|
+
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
192
|
+
end
|
193
|
+
|
194
|
+
data("md5" => ["md5", "zGQF35KlMUibJAcgkgQDtw=="],
|
195
|
+
"sha1" => ["sha1", "1x9RZO1xEuWps090qq4DUIsU9x8="],
|
196
|
+
"sha256" => ["sha256", "eulMz0eF56lBEf31aIs0OG2TGCH/aoPfZbRqfEOkAwk="],
|
197
|
+
"sha512" => ["sha512", "mIiYATtpdUFEFCIZg1FdKssIs7oWY0gJjhSSbet0ddUmqB+CiQAcAMTmrXO6AVSH0vsMvao/8vtC8AsIPfF1fA=="],)
|
198
|
+
def test_record_with_tag_and_time
|
199
|
+
hash_type, expected = data
|
200
|
+
d = create_driver(%[
|
201
|
+
use_record_as_seed true
|
202
|
+
use_entire_record true
|
203
|
+
hash_type #{hash_type}
|
204
|
+
include_tag_in_seed true
|
205
|
+
include_time_in_seed true
|
206
|
+
])
|
207
|
+
time = event_time("2017-10-15 15:00:23.34567890 UTC")
|
208
|
+
d.run(default_tag: 'test.fluentd') do
|
209
|
+
d.feed(time, sample_record.merge("custom_key" => "This is also encoded value."))
|
210
|
+
end
|
211
|
+
assert_equal(expected,
|
212
|
+
d.filtered.map {|e| e.last}.first[d.instance.hash_id_key])
|
213
|
+
end
|
214
|
+
end
|
44
215
|
end
|