fluent-plugin-elasticsearch 4.0.11 → 4.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c90e0b347a5c90ec23231df927384dadcc4b91b813a4e2c11df23539dfe05628
4
- data.tar.gz: d6e296c8006870a5f85bd0b97294c69d797fc3f40b574ede7645fcd808ae6356
3
+ metadata.gz: c7923225803a37c0076c7cb4c4d6e94c1ec9ccf120ce4067b45db8c0fc19f17f
4
+ data.tar.gz: f1ce4098fb1e4e563e00aae9fe8d30b2bc9cfcb08100616f0ff00b3dfa210667
5
5
  SHA512:
6
- metadata.gz: 8466c4e3a13ef5c5ca1bda536a0baf7044fdaa0bc3ae1e1c7e6d0e6cf3dc7596d2b68e3f61ed2fb788f8ef2d8392939b8f63fd6aedc53e5818725bc6e0910aa6
7
- data.tar.gz: b0572e50952ce49e44b280e94764d0d204d482e8e89cc2124e9a3025c1bd4cf7debe5625ad141337e5f81e6b6816286ee81f931f6b782f0a8cffcbfa0ed12dc3
6
+ metadata.gz: '0579350a7eba583c7c4784f5500d9faa6df4e398b4b0d0e4aacf230502751a39fb9591d189217c869a82f6da689ffb435445aea7bd5920332787e787170b37d7'
7
+ data.tar.gz: 8d150716862d82b313a31b104842b368aac3f945bece0a11074bf43a25830c91e6b5ee0556a23e93fdc2159ab20185e08847b4c94bb10033fe7b259741b332b6
data/History.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ### [Unreleased]
4
4
 
5
+ ### 4.1.4
6
+ - ElasticsearchGenID update docs for hash_type (#809)
7
+ - Handle api key header (#808)
8
+ - index_template: Handle error object entirely on index creation failure (#807)
9
+
10
+ ### 4.1.3
11
+ - Load multiple templates even if template_name and template_file given (#799)
12
+ - Handle elasticsearch-ruby 7.9.0 using HTTP method changes (#795)
13
+
14
+ ### 4.1.2
15
+ - Use Hash#dig instead of Hash#[] on retrieving version information from Elasticsearch info API (#793)
16
+
17
+ ### 4.1.1
18
+ - Correct ILM explain on logstash_format case (#786)
19
+
20
+ ### 4.1.0
21
+ - Implement Fallback selector and configurable selector class (#782)
22
+
5
23
  ### 4.0.11
6
24
  - Add custom and time placeholders combination testcase for ILM (#781)
7
25
  - Really support ILM on `logstash_format` enabled environment (#779)
@@ -26,7 +26,7 @@ In your Fluentd configuration, use `@type elasticsearch_genid`. Additional confi
26
26
  use_entire_record false
27
27
  record_keys []
28
28
  separator _
29
- hash_type md5
29
+ hash_type sha1
30
30
  </match>
31
31
  ```
32
32
 
@@ -95,7 +95,7 @@ You can specify separator charactor to creating seed for hash generation.
95
95
  hash_type sha1
96
96
  ```
97
97
 
98
- You can specify hash algorithm.
98
+ You can specify hash algorithm. Support algorithms `md5`, `sha1`, `sha256`, `sha512`. Default: `sha1`
99
99
 
100
100
  ## Advanced Usage
101
101
 
data/README.md CHANGED
@@ -78,12 +78,14 @@ Current maintainers: @cosmo0920
78
78
  + [Hash flattening](#hash-flattening)
79
79
  + [Generate Hash ID](#generate-hash-id)
80
80
  + [sniffer_class_name](#sniffer-class-name)
81
+ + [selector_class_name](#selector-class-name)
81
82
  + [reload_after](#reload-after)
82
83
  + [validate_client_version](#validate-client-version)
83
84
  + [unrecoverable_error_types](#unrecoverable-error-types)
84
85
  + [verify_es version at startup](#verify_es_version_at_startup)
85
86
  + [default_elasticsearch_version](#default_elasticsearch_version)
86
87
  + [custom_headers](#custom_headers)
88
+ + [api_key](#api_key)
87
89
  + [Not seeing a config you need?](#not-seeing-a-config-you-need)
88
90
  + [Dynamic configuration](#dynamic-configuration)
89
91
  + [Placeholders](#placeholders)
@@ -120,10 +122,12 @@ Current maintainers: @cosmo0920
120
122
 
121
123
  ## Requirements
122
124
 
123
- | fluent-plugin-elasticsearch | fluentd | ruby |
124
- |-------------------|---------|------|
125
- | >= 2.0.0 | >= v0.14.20 | >= 2.1 |
126
- | < 2.0.0 | >= v0.12.0 | >= 1.9 |
125
+ | fluent-plugin-elasticsearch | fluentd | ruby |
126
+ |:----------------------------:|:-----------:|:------:|
127
+ | >= 4.0.1 | >= v0.14.22 | >= 2.3 |
128
+ | >= 3.2.4 && < 4.0.1 | >= v0.14.22 | >= 2.1 |
129
+ | >= 2.0.0 && < 3.2.3 | >= v0.14.20 | >= 2.1 |
130
+ | < 2.0.0 | >= v0.12.0 | >= 1.9 |
127
131
 
128
132
  NOTE: For v0.12 version, you should use 1.x.y version. Please send patch into v0.12 branch if you encountered 1.x version's bug.
129
133
 
@@ -428,7 +432,7 @@ Specify index templates in form of hash. Can contain multiple templates.
428
432
  templates { "template_name_1": "path_to_template_1_file", "template_name_2": "path_to_template_2_file"}
429
433
  ```
430
434
 
431
- If `template_file` and `template_name` are set, then this parameter will be ignored.
435
+ **Note:** Before ES plugin v4.1.2, if `template_file` and `template_name` are set, then this parameter will be ignored. In 4.1.3 or later, `template_file` and `template_name` can work with `templates`.
432
436
 
433
437
  ### customize_template
434
438
 
@@ -478,6 +482,8 @@ deflector_alias test-current
478
482
 
479
483
  If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
480
484
 
485
+ **NOTE:** Since 4.1.1, `deflector_alias` is prohibited to use with `enable_ilm`.
486
+
481
487
  ### index_prefix
482
488
 
483
489
  This parameter is marked as obsoleted.
@@ -989,7 +995,7 @@ reload_after 100
989
995
 
990
996
  #### Tips
991
997
 
992
- The included sniffer class does not required `out_elasticsearch`.
998
+ The included sniffer class is not required `out_elasticsearch`.
993
999
  You should tell Fluentd where the sniffer class exists.
994
1000
 
995
1001
  If you use td-agent, you must put the following lines into `TD_AGENT_DEFAULT` file:
@@ -1006,6 +1012,38 @@ sniffer=$(td-agent-gem contents fluent-plugin-elasticsearch|grep elasticsearch_s
1006
1012
  $ fluentd -r $sniffer [AND YOUR OTHER OPTIONS]
1007
1013
  ```
1008
1014
 
1015
+ ### Selector Class Name
1016
+
1017
+ The default selector used by the `Elasticsearch::Transport` class works well when Fluentd should behave round robin and random selector cases. This doesn't work well when Fluentd should behave fallbacking from exhausted ES cluster to normal ES cluster.
1018
+ The parameter `selector_class_name` gives you the ability to provide your own Selector class to implement whatever selection nodes logic you require.
1019
+
1020
+ The below configuration is using plugin built-in `ElasticseatchFallbackSelector`:
1021
+
1022
+ ```
1023
+ hosts exhausted-host:9201,normal-host:9200
1024
+ selector_class_name "Fluent::Plugin::ElasticseatchFallbackSelector"
1025
+ ```
1026
+
1027
+ #### Tips
1028
+
1029
+ The included selector class is required in `out_elasticsearch` by default.
1030
+ But, your custom selector class is not required in `out_elasticsearch`.
1031
+ You should tell Fluentd where the selector class exists.
1032
+
1033
+ If you use td-agent, you must put the following lines into `TD_AGENT_DEFAULT` file:
1034
+
1035
+ ```
1036
+ selector=/path/to/your_awesome_selector.rb
1037
+ TD_AGENT_OPTIONS="--use-v1-config -r $selector"
1038
+ ```
1039
+
1040
+ If you use Fluentd directly, you must pass the following lines as Fluentd command line option:
1041
+
1042
+ ```
1043
+ selector=/path/to/your_awesome_selector.rb
1044
+ $ fluentd -r $selector [AND YOUR OTHER OPTIONS]
1045
+ ```
1046
+
1009
1047
  ### Reload After
1010
1048
 
1011
1049
  When `reload_connections true`, this is the integer number of operations after which the plugin will
@@ -1069,6 +1107,14 @@ This parameter adds additional headers to request. The default value is `{}`.
1069
1107
  custom_headers {"token":"secret"}
1070
1108
  ```
1071
1109
 
1110
+ ### api_key
1111
+
1112
+ This parameter adds authentication header. The default value is `nil`.
1113
+
1114
+ ```
1115
+ api_key "ElasticsearchAPIKEY"
1116
+ ```
1117
+
1072
1118
  ### Not seeing a config you need?
1073
1119
 
1074
1120
  We try to keep the scope of this plugin small and not add too many configuration options. If you think an option would be useful to others, feel free to open an issue or contribute a Pull Request.
@@ -1720,7 +1766,7 @@ ILM target index alias is created with `index_name` or an index which is calcula
1720
1766
 
1721
1767
  From Elasticsearch plugin v4.0.0, ILM target index will be calculated from `index_name` (normal mode) or `logstash_prefix` (using with `logstash_format`as true).
1722
1768
 
1723
- When using `deflector_alias` parameter, Elasticsearch plugin will create ILM target indices alias with `deflector_alias` instead of `index_name` or an index which is calculated from `logstash_prefix`. This behavior should be kept due to backward ILM feature compatibility.
1769
+ **NOTE:** Before Elasticsearch plugin v4.1.0, using `deflector_alias` parameter when ILM is enabled is permitted and handled, but, in the later releases such that 4.1.1 or later, it cannot use with when ILM is enabled.
1724
1770
 
1725
1771
  And also, ILM feature users should specify their Elasticsearch template for ILM enabled indices.
1726
1772
  Because ILM settings are injected into their Elasticsearch templates.
@@ -1733,7 +1779,13 @@ It usually should be used with default value which is `default`.
1733
1779
 
1734
1780
  Then, ILM parameters are used in alias index like as:
1735
1781
 
1736
- `<index_name/logstash_prefix><index_separator><application_name>-000001`.
1782
+ ##### Simple `index_name` case:
1783
+
1784
+ `<index_name><index_separator><application_name>-000001`.
1785
+
1786
+ ##### `logstash_format` as `true` case:
1787
+
1788
+ `<logstash_prefix><logstash_prefix_separator><application_name><logstash_prefix_separator><logstash_dateformat>-000001`.
1737
1789
 
1738
1790
  #### Example ILM settings
1739
1791
 
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'fluent-plugin-elasticsearch'
6
- s.version = '4.0.11'
6
+ s.version = '4.1.4'
7
7
  s.authors = ['diogo', 'pitr', 'Hiroshi Hatake']
8
8
  s.email = ['pitr.vern@gmail.com', 'me@diogoterror.com', 'cosmo0920.wp@gmail.com']
9
9
  s.description = %q{Elasticsearch output plugin for Fluent event collector}
@@ -0,0 +1,9 @@
1
+ require 'elasticsearch/transport/transport/connections/selector'
2
+
3
+ class Fluent::Plugin::ElasticseatchFallbackSelector
4
+ include Elasticsearch::Transport::Transport::Connections::Selector::Base
5
+
6
+ def select(options={})
7
+ connections.first
8
+ end
9
+ end
@@ -61,15 +61,16 @@ module Fluent::ElasticsearchIndexTemplate
61
61
  if e.message =~ /"already exists"/ || e.message =~ /resource_already_exists_exception/
62
62
  log.debug("Index #{index_name} already exists")
63
63
  else
64
- log.error("Error while index creation - #{index_name}: #{e.inspect}")
64
+ log.error("Error while index creation - #{index_name}", error: e)
65
65
  end
66
66
  end
67
67
 
68
- def template_install(name, template_file, overwrite, enable_ilm = false, deflector_alias_name = nil, ilm_policy_id = nil, host = nil)
68
+ def template_install(name, template_file, overwrite, enable_ilm = false, deflector_alias_name = nil, ilm_policy_id = nil, host = nil, target_index = nil)
69
69
  inject_template_name = get_template_name(enable_ilm, name, deflector_alias_name)
70
70
  if overwrite
71
71
  template_put(inject_template_name,
72
72
  enable_ilm ? inject_ilm_settings_to_template(deflector_alias_name,
73
+ target_index,
73
74
  ilm_policy_id,
74
75
  get_template(template_file)) :
75
76
  get_template(template_file), host)
@@ -80,6 +81,7 @@ module Fluent::ElasticsearchIndexTemplate
80
81
  if !template_exists?(inject_template_name, host)
81
82
  template_put(inject_template_name,
82
83
  enable_ilm ? inject_ilm_settings_to_template(deflector_alias_name,
84
+ target_index,
83
85
  ilm_policy_id,
84
86
  get_template(template_file)) :
85
87
  get_template(template_file), host)
@@ -89,10 +91,12 @@ module Fluent::ElasticsearchIndexTemplate
89
91
  end
90
92
  end
91
93
 
92
- def template_custom_install(template_name, template_file, overwrite, customize_template, enable_ilm, deflector_alias_name, ilm_policy_id, host)
94
+ def template_custom_install(template_name, template_file, overwrite, customize_template, enable_ilm, deflector_alias_name, ilm_policy_id, host, target_index)
93
95
  template_custom_name = get_template_name(enable_ilm, template_name, deflector_alias_name)
94
96
  custom_template = if enable_ilm
95
- inject_ilm_settings_to_template(deflector_alias_name, ilm_policy_id,
97
+ inject_ilm_settings_to_template(deflector_alias_name,
98
+ target_index,
99
+ ilm_policy_id,
96
100
  get_custom_template(template_file,
97
101
  customize_template))
98
102
  else
@@ -115,26 +119,30 @@ module Fluent::ElasticsearchIndexTemplate
115
119
  enable_ilm ? deflector_alias_name : template_name
116
120
  end
117
121
 
118
- def inject_ilm_settings_to_template(deflector_alias_name, ilm_policy_id, template)
122
+ def inject_ilm_settings_to_template(deflector_alias, target_index, ilm_policy_id, template)
119
123
  log.debug("Overwriting index patterns when Index Lifecycle Management is enabled.")
120
124
  template.delete('template') if template.include?('template')
121
- template['index_patterns'] = "#{deflector_alias_name}-*"
122
- template['order'] = template['order'] ? template['order'] + deflector_alias_name.split('-').length : 50 + deflector_alias_name.split('-').length
125
+ template['index_patterns'] = "#{target_index}-*"
126
+ template['order'] = template['order'] ? template['order'] + target_index.split('-').length : 50 + target_index.split('-').length
123
127
  if template['settings'] && (template['settings']['index.lifecycle.name'] || template['settings']['index.lifecycle.rollover_alias'])
124
128
  log.debug("Overwriting index lifecycle name and rollover alias when Index Lifecycle Management is enabled.")
125
129
  end
126
- template['settings'].update({ 'index.lifecycle.name' => ilm_policy_id, 'index.lifecycle.rollover_alias' => deflector_alias_name})
130
+ template['settings'].update({ 'index.lifecycle.name' => ilm_policy_id, 'index.lifecycle.rollover_alias' => deflector_alias})
127
131
  template
128
132
  end
129
133
 
130
- def create_rollover_alias(index_prefix, rollover_index, deflector_alias_name, app_name, index_date_pattern, index_separator, enable_ilm, ilm_policy_id, ilm_policy, ilm_policy_overwrite, host)
134
+ def create_rollover_alias(target_index, rollover_index, deflector_alias_name, app_name, index_date_pattern, index_separator, enable_ilm, ilm_policy_id, ilm_policy, ilm_policy_overwrite, host)
131
135
  # ILM request to create alias.
132
136
  if rollover_index || enable_ilm
133
137
  if !client.indices.exists_alias(:name => deflector_alias_name)
134
- if index_date_pattern.empty?
135
- index_name_temp='<'+index_prefix.downcase+index_separator+app_name.downcase+'-000001>'
138
+ if @logstash_format
139
+ index_name_temp = '<'+target_index+'-000001>'
136
140
  else
137
- index_name_temp='<'+index_prefix.downcase+index_separator+app_name.downcase+'-{'+index_date_pattern+'}-000001>'
141
+ if index_date_pattern.empty?
142
+ index_name_temp = '<'+target_index.downcase+index_separator+app_name.downcase+'-000001>'
143
+ else
144
+ index_name_temp = '<'+target_index.downcase+index_separator+app_name.downcase+'-{'+index_date_pattern+'}-000001>'
145
+ end
138
146
  end
139
147
  indexcreation(index_name_temp, host)
140
148
  body = rollover_alias_payload(deflector_alias_name)
@@ -8,6 +8,7 @@ rescue LoadError
8
8
  end
9
9
  require 'json'
10
10
  require 'uri'
11
+ require 'base64'
11
12
  begin
12
13
  require 'strptime'
13
14
  rescue LoadError
@@ -25,6 +26,7 @@ require_relative 'elasticsearch_error_handler'
25
26
  require_relative 'elasticsearch_index_template'
26
27
  require_relative 'elasticsearch_index_lifecycle_management'
27
28
  require_relative 'elasticsearch_tls'
29
+ require_relative 'elasticsearch_fallback_selector'
28
30
  begin
29
31
  require_relative 'oj_serializer'
30
32
  rescue LoadError
@@ -50,12 +52,13 @@ module Fluent::Plugin
50
52
  end
51
53
  end
52
54
 
53
- RequestInfo = Struct.new(:host, :index, :ilm_index)
55
+ RequestInfo = Struct.new(:host, :index, :ilm_index, :ilm_alias)
54
56
 
55
57
  attr_reader :alias_indexes
56
58
  attr_reader :template_names
57
59
  attr_reader :ssl_version_options
58
60
  attr_reader :compressable_connection
61
+ attr_reader :api_key_header
59
62
 
60
63
  helpers :event_emitter, :compat_parameters, :record_accessor, :timer
61
64
 
@@ -137,6 +140,7 @@ EOC
137
140
  config_param :with_transporter_log, :bool, :default => false
138
141
  config_param :emit_error_for_missing_id, :bool, :default => false
139
142
  config_param :sniffer_class_name, :string, :default => nil
143
+ config_param :selector_class_name, :string, :default => nil
140
144
  config_param :reload_after, :integer, :default => DEFAULT_RELOAD_AFTER
141
145
  config_param :content_type, :enum, list: [:"application/json", :"application/x-ndjson"], :default => :"application/json",
142
146
  :deprecated => <<EOC
@@ -153,6 +157,7 @@ EOC
153
157
  config_param :default_elasticsearch_version, :integer, :default => DEFAULT_ELASTICSEARCH_VERSION
154
158
  config_param :log_es_400_reason, :bool, :default => false
155
159
  config_param :custom_headers, :hash, :default => {}
160
+ config_param :api_key, :string, :default => nil, :secret => true
156
161
  config_param :suppress_doc_wrap, :bool, :default => false
157
162
  config_param :ignore_exceptions, :array, :default => [], value_type: :string, :desc => "Ignorable exception list"
158
163
  config_param :exception_backup, :bool, :default => true, :desc => "Chunk backup flag when ignore exception occured"
@@ -210,6 +215,8 @@ EOC
210
215
  @remove_keys_on_update = @remove_keys_on_update.split ','
211
216
  end
212
217
 
218
+ @api_key_header = setup_api_key
219
+
213
220
  raise Fluent::ConfigError, "'max_retry_putting_template' must be greater than or equal to zero." if @max_retry_putting_template < 0
214
221
  raise Fluent::ConfigError, "'max_retry_get_es_version' must be greater than or equal to zero." if @max_retry_get_es_version < 0
215
222
 
@@ -232,7 +239,7 @@ EOC
232
239
  if !dry_run?
233
240
  if @template_name && @template_file
234
241
  if @enable_ilm
235
- raise Fluent::ConfigError, "deflector_alias is prohibited to use with 'logstash_format at same time." if @logstash_format and @deflector_alias
242
+ raise Fluent::ConfigError, "deflector_alias is prohibited to use with enable_ilm at same time." if @deflector_alias
236
243
  end
237
244
  if @ilm_policy.empty? && @ilm_policy_overwrite
238
245
  raise Fluent::ConfigError, "ilm_policy_overwrite requires a non empty ilm_policy."
@@ -245,7 +252,8 @@ EOC
245
252
  template_installation_actual(@deflector_alias ? @deflector_alias : @index_name, @template_name, @customize_template, @application_name, @index_name, @ilm_policy_id)
246
253
  end
247
254
  verify_ilm_working if @enable_ilm
248
- elsif @templates
255
+ end
256
+ if @templates
249
257
  retry_operate(@max_retry_putting_template, @fail_on_putting_template_retry_exceed) do
250
258
  templates_hash_install(@templates, @template_overwrite)
251
259
  end
@@ -300,6 +308,13 @@ EOC
300
308
  raise Fluent::ConfigError, "Could not load sniffer class #{@sniffer_class_name}: #{ex}"
301
309
  end
302
310
 
311
+ @selector_class = nil
312
+ begin
313
+ @selector_class = Object.const_get(@selector_class_name) if @selector_class_name
314
+ rescue Exception => ex
315
+ raise Fluent::ConfigError, "Could not load selector class #{@selector_class_name}: #{ex}"
316
+ end
317
+
303
318
  @last_seen_major_version = if major_version = handle_last_seen_es_major_version
304
319
  major_version
305
320
  else
@@ -388,6 +403,12 @@ EOC
388
403
  end
389
404
  end
390
405
 
406
+ def setup_api_key
407
+ return {} unless @api_key
408
+
409
+ { "Authorization" => "ApiKey " + Base64.strict_encode64(@api_key) }
410
+ end
411
+
391
412
  def dry_run?
392
413
  if Fluent::Engine.respond_to?(:dry_run_mode)
393
414
  Fluent::Engine.dry_run_mode
@@ -452,7 +473,10 @@ EOC
452
473
 
453
474
  def detect_es_major_version
454
475
  @_es_info ||= client.info
455
- @_es_info["version"]["number"].to_i
476
+ unless version = @_es_info.dig("version", "number")
477
+ version = @default_elasticsearch_version
478
+ end
479
+ version.to_i
456
480
  end
457
481
 
458
482
  def client_library_version
@@ -545,7 +569,10 @@ EOC
545
569
  else
546
570
  {}
547
571
  end
548
- headers = { 'Content-Type' => @content_type.to_s }.merge(@custom_headers).merge(gzip_headers)
572
+ headers = { 'Content-Type' => @content_type.to_s }
573
+ .merge(@custom_headers)
574
+ .merge(@api_key_header)
575
+ .merge(gzip_headers)
549
576
  ssl_options = { verify: @ssl_verify, ca_file: @ca_file}.merge(@ssl_version_options)
550
577
 
551
578
  transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(connection_options.merge(
@@ -566,6 +593,7 @@ EOC
566
593
  },
567
594
  sniffer_class: @sniffer_class,
568
595
  serializer_class: @serializer_class,
596
+ selector_class: @selector_class,
569
597
  compression: compress_connection,
570
598
  }), &adapter_conf)
571
599
  Elasticsearch::Client.new transport: transport
@@ -761,9 +789,9 @@ EOC
761
789
  begin
762
790
  meta, header, record = process_message(tag, meta, header, time, record, extracted_values)
763
791
  info = if @include_index_in_url
764
- RequestInfo.new(host, meta.delete("_index".freeze), meta.delete("_alias".freeze))
792
+ RequestInfo.new(host, meta.delete("_index".freeze), meta["_index".freeze], meta.delete("_alias".freeze))
765
793
  else
766
- RequestInfo.new(host, nil, meta.delete("_alias".freeze))
794
+ RequestInfo.new(host, nil, meta["_index".freeze], meta.delete("_alias".freeze))
767
795
  end
768
796
 
769
797
  if split_request?(bulk_message, info)
@@ -934,16 +962,16 @@ EOC
934
962
 
935
963
  def template_installation_actual(deflector_alias, template_name, customize_template, application_name, target_index, ilm_policy_id, host=nil)
936
964
  if template_name && @template_file
937
- if @alias_indexes.include? deflector_alias
965
+ if !@logstash_format && @alias_indexes.include?(deflector_alias)
938
966
  log.debug("Index alias #{deflector_alias} already exists (cached)")
939
- elsif @template_names.include? template_name
967
+ elsif !@logstash_format && @template_names.include?(template_name)
940
968
  log.debug("Template name #{template_name} already exists (cached)")
941
969
  else
942
970
  retry_operate(@max_retry_putting_template, @fail_on_putting_template_retry_exceed) do
943
971
  if customize_template
944
- template_custom_install(template_name, @template_file, @template_overwrite, customize_template, @enable_ilm, deflector_alias, ilm_policy_id, host)
972
+ template_custom_install(template_name, @template_file, @template_overwrite, customize_template, @enable_ilm, deflector_alias, ilm_policy_id, host, target_index)
945
973
  else
946
- template_install(template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, ilm_policy_id, host)
974
+ template_install(template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, ilm_policy_id, host, target_index)
947
975
  end
948
976
  ilm_policy = @ilm_policies[ilm_policy_id] || {}
949
977
  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)
@@ -957,11 +985,11 @@ EOC
957
985
  # send_bulk given a specific bulk request, the original tag,
958
986
  # chunk, and bulk_message_count
959
987
  def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, info)
960
- logstash_prefix, _logstash_dateformat, index_name, _type_name, template_name, customize_template, deflector_alias, application_name, _pipeline, ilm_policy_id = extracted_values
988
+ _logstash_prefix, _logstash_dateformat, index_name, _type_name, template_name, customize_template, deflector_alias, application_name, _pipeline, ilm_policy_id = extracted_values
961
989
  if deflector_alias
962
990
  template_installation(deflector_alias, template_name, customize_template, application_name, index_name, ilm_policy_id, info.host)
963
991
  else
964
- template_installation(info.ilm_index, template_name, customize_template, application_name, @logstash_format ? logstash_prefix : index_name, ilm_policy_id, info.host)
992
+ template_installation(info.ilm_index, template_name, customize_template, application_name, @logstash_format ? info.ilm_alias : index_name, ilm_policy_id, info.host)
965
993
  end
966
994
 
967
995
  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
@@ -20,6 +20,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
20
20
  @driver = nil
21
21
  log = Fluent::Engine.log
22
22
  log.out.logs.slice!(0, log.out.logs.length)
23
+ @http_method = if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("7.9.0")
24
+ :post
25
+ else
26
+ :get
27
+ end
23
28
  end
24
29
 
25
30
  def driver(conf='')
@@ -313,7 +318,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
313
318
  end
314
319
 
315
320
  def test_emit
316
- stub_request(:get, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
321
+ stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
317
322
  with(body: "{\"sort\":[\"_doc\"]}").
318
323
  to_return(status: 200, body: sample_response.to_s,
319
324
  headers: {'Content-Type' => 'application/json'})
@@ -328,7 +333,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
328
333
 
329
334
  def test_emit_with_custom_index_name
330
335
  index_name = "logstash"
331
- stub_request(:get, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
336
+ stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
332
337
  with(body: "{\"sort\":[\"_doc\"]}").
333
338
  to_return(status: 200, body: sample_response(index_name).to_s,
334
339
  headers: {'Content-Type' => 'application/json'})
@@ -343,7 +348,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
343
348
 
344
349
  def test_emit_with_parse_timestamp
345
350
  index_name = "fluentd"
346
- stub_request(:get, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
351
+ stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
347
352
  with(body: "{\"sort\":[\"_doc\"]}").
348
353
  to_return(status: 200, body: sample_response(index_name).to_s,
349
354
  headers: {'Content-Type' => 'application/json'})
@@ -361,7 +366,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
361
366
 
362
367
  def test_emit_with_parse_timestamp_and_timstamp_format
363
368
  index_name = "fluentd"
364
- stub_request(:get, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
369
+ stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
365
370
  with(body: "{\"sort\":[\"_doc\"]}").
366
371
  to_return(status: 200, body: sample_response(index_name).to_s,
367
372
  headers: {'Content-Type' => 'application/json'})
@@ -380,7 +385,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
380
385
  end
381
386
 
382
387
  def test_emit_with_docinfo
383
- stub_request(:get, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
388
+ stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
384
389
  with(body: "{\"sort\":[\"_doc\"]}").
385
390
  to_return(status: 200, body: sample_response.to_s,
386
391
  headers: {'Content-Type' => 'application/json'})
@@ -399,11 +404,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
399
404
  end
400
405
 
401
406
  def test_emit_with_slices
402
- stub_request(:get, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
407
+ stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
403
408
  with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":0,\"max\":2}}").
404
409
  to_return(status: 200, body: sample_response.to_s,
405
410
  headers: {'Content-Type' => 'application/json'})
406
- stub_request(:get, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
411
+ stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
407
412
  with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":1,\"max\":2}}").
408
413
  to_return(status: 200, body: sample_response.to_s,
409
414
  headers: {'Content-Type' => 'application/json'})
@@ -419,12 +424,12 @@ class ElasticsearchInputTest < Test::Unit::TestCase
419
424
  end
420
425
 
421
426
  def test_emit_with_size
422
- stub_request(:get, "http://localhost:9200/fluentd/_search?scroll=1m&size=1").
427
+ stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1").
423
428
  with(body: "{\"sort\":[\"_doc\"]}").
424
429
  to_return(status: 200, body: sample_scroll_response.to_s,
425
430
  headers: {'Content-Type' => 'application/json'})
426
431
  connection = 0
427
- scroll_request = stub_request(:get, "http://localhost:9200/_search/scroll?scroll=1m").
432
+ scroll_request = stub_request(@http_method, "http://localhost:9200/_search/scroll?scroll=1m").
428
433
  with(
429
434
  body: "{\"scroll_id\":\"WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz\"}") do
430
435
  connection += 1
@@ -252,6 +252,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
252
252
  assert_false instance.compression
253
253
  assert_equal :no_compression, instance.compression_level
254
254
  assert_true instance.http_backend_excon_nonblock
255
+ assert_equal({}, instance.api_key_header)
255
256
  end
256
257
 
257
258
  test 'configure compression' do
@@ -707,7 +708,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
707
708
  Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
708
709
  def detect_es_major_version
709
710
  @_es_info ||= client.info
710
- @_es_info["version"]["number"].to_i
711
+ unless version = @_es_info.dig("version", "number")
712
+ version = @default_elasticsearch_version
713
+ end
714
+ version.to_i
711
715
  end
712
716
  CODE
713
717
  Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
@@ -753,7 +757,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
753
757
  Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
754
758
  def detect_es_major_version
755
759
  @_es_info ||= client.info
756
- @_es_info["version"]["number"].to_i
760
+ unless version = @_es_info.dig("version", "number")
761
+ version = @default_elasticsearch_version
762
+ end
763
+ version.to_i
757
764
  end
758
765
  CODE
759
766
  Fluent::Plugin::ElasticsearchOutput.module_eval(<<-CODE)
@@ -1078,32 +1085,32 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1078
1085
  with(basic_auth: ['john', 'doe']).
1079
1086
  to_return(:status => 200, :body => "", :headers => {})
1080
1087
  # check if template exists
1081
- stub_request(:get, "https://logs.google.com:777/es//_template/logstash-log-#{date_str}").
1088
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash-#{date_str}").
1082
1089
  with(basic_auth: ['john', 'doe']).
1083
1090
  to_return(:status => 404, :body => "", :headers => {})
1084
1091
  # creation
1085
- stub_request(:put, "https://logs.google.com:777/es//_template/logstash-log-#{date_str}").
1092
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash-#{date_str}").
1086
1093
  with(basic_auth: ['john', 'doe']).
1087
1094
  to_return(:status => 200, :body => "", :headers => {})
1088
1095
  # check if alias exists
1089
- stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-log-#{date_str}").
1096
+ stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-#{date_str}").
1090
1097
  with(basic_auth: ['john', 'doe']).
1091
1098
  to_return(:status => 404, :body => "", :headers => {})
1092
- stub_request(:get, "https://logs.google.com:777/es//_template/logstash-log-#{date_str}").
1099
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash-#{date_str}").
1093
1100
  with(basic_auth: ['john', 'doe']).
1094
1101
  to_return(status: 404, body: "", headers: {})
1095
- stub_request(:put, "https://logs.google.com:777/es//_template/logstash-log-#{date_str}").
1102
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash-#{date_str}").
1096
1103
  with(basic_auth: ['john', 'doe'],
1097
1104
  body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-log-#{date_str}\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}},\"index_patterns\":\"logstash-log-#{date_str}-*\",\"order\":53}").
1098
1105
  to_return(status: 200, body: "", headers: {})
1099
1106
  # put the alias for the index
1100
- stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-log-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1107
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-log-#{date_str}-000001%3E").
1101
1108
  with(basic_auth: ['john', 'doe']).
1102
1109
  to_return(:status => 200, :body => "", :headers => {})
1103
1110
 
1104
- stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-log-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/logstash-log-#{date_str}").
1111
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-log-#{date_str}-000001%3E/#{alias_endpoint}/logstash-#{date_str}").
1105
1112
  with(basic_auth: ['john', 'doe'],
1106
- body: "{\"aliases\":{\"logstash-log-#{date_str}\":{\"is_write_index\":true}}}").
1113
+ body: "{\"aliases\":{\"logstash-#{date_str}\":{\"is_write_index\":true}}}").
1107
1114
  to_return(status: 200, body: "", headers: {})
1108
1115
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1109
1116
  with(basic_auth: ['john', 'doe']).
@@ -1122,7 +1129,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1122
1129
  driver.run(default_tag: 'test') do
1123
1130
  driver.feed(sample_record)
1124
1131
  end
1125
- assert_requested(:put, "https://logs.google.com:777/es//_template/logstash-log-#{date_str}", times: 1)
1132
+ assert_requested(:put, "https://logs.google.com:777/es//_template/logstash-#{date_str}", times: 1)
1126
1133
 
1127
1134
  assert_requested(elastic_request)
1128
1135
  end
@@ -1213,51 +1220,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1213
1220
  enable_ilm true
1214
1221
  }
1215
1222
 
1216
- # connection start
1217
- stub_request(:head, "https://logs.google.com:777/es//").
1218
- with(basic_auth: ['john', 'doe']).
1219
- to_return(:status => 200, :body => "", :headers => {})
1220
- # check if template exists
1221
- stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
1222
- with(basic_auth: ['john', 'doe']).
1223
- to_return(:status => 404, :body => "", :headers => {})
1224
- # creation
1225
- stub_request(:put, "https://logs.google.com:777/es//_template/logstash").
1226
- with(basic_auth: ['john', 'doe']).
1227
- to_return(:status => 200, :body => "", :headers => {})
1228
- # check if alias exists
1229
- stub_request(:head, "https://logs.google.com:777/es//_alias/myapp_deflector").
1230
- with(basic_auth: ['john', 'doe']).
1231
- to_return(:status => 404, :body => "", :headers => {})
1232
- stub_request(:get, "https://logs.google.com:777/es//_template/myapp_deflector").
1233
- with(basic_auth: ['john', 'doe']).
1234
- to_return(status: 404, body: "", headers: {})
1235
- stub_request(:put, "https://logs.google.com:777/es//_template/myapp_deflector").
1236
- with(basic_auth: ['john', 'doe'],
1237
- body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"myapp_deflector\"},\"mappings\":{\"type1\":{\"_source\":{\"enabled\":false},\"properties\":{\"host_name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"created_at\":{\"type\":\"date\",\"format\":\"EEE MMM dd HH:mm:ss Z YYYY\"}}}},\"index_patterns\":\"myapp_deflector-*\",\"order\":51}").
1238
- to_return(status: 200, body: "", headers: {})
1239
- # put the alias for the index
1240
- stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1241
- with(basic_auth: ['john', 'doe']).
1242
- to_return(:status => 200, :body => "", :headers => {})
1243
- stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/myapp_deflector").
1244
- with(basic_auth: ['john', 'doe'],
1245
- :body => "{\"aliases\":{\"myapp_deflector\":{\"is_write_index\":true}}}").
1246
- to_return(:status => 200, :body => "", :headers => {})
1247
- stub_request(:get, "https://logs.google.com:777/es//_xpack").
1248
- with(basic_auth: ['john', 'doe']).
1249
- to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1250
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1251
- with(basic_auth: ['john', 'doe']).
1252
- to_return(:status => 404, :body => "", :headers => {})
1253
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
1254
- with(basic_auth: ['john', 'doe'],
1255
- :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1256
- to_return(:status => 200, :body => "", :headers => {})
1257
-
1258
- driver(config)
1259
-
1260
- assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_deflector", times: 1)
1223
+ # Should raise error because multiple alias indices IllegalArgument Error on executing ILM feature
1224
+ assert_raise(Fluent::ConfigError) do
1225
+ driver(config)
1226
+ end
1261
1227
  end
1262
1228
 
1263
1229
  def test_template_create_with_rollover_index_and_default_ilm_with_empty_index_date_pattern
@@ -1996,6 +1962,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
1996
1962
  application_name myapp
1997
1963
  }
1998
1964
 
1965
+ timestr = Time.now.strftime("%Y.%m.%d")
1999
1966
  # connection start
2000
1967
  stub_request(:head, "https://logs.google.com:777/es//").
2001
1968
  with(basic_auth: ['john', 'doe']).
@@ -2009,17 +1976,17 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2009
1976
  with(basic_auth: ['john', 'doe']).
2010
1977
  to_return(:status => 200, :body => "", :headers => {})
2011
1978
  # creation of index which can rollover
2012
- stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1979
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-#{timestr}-000001%3E").
2013
1980
  with(basic_auth: ['john', 'doe']).
2014
1981
  to_return(:status => 200, :body => "", :headers => {})
2015
1982
  # check if alias exists
2016
- timestr = Time.now.strftime("%Y.%m.%d")
2017
- stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-myapp-#{timestr}").
1983
+ stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-#{timestr}").
2018
1984
  with(basic_auth: ['john', 'doe']).
2019
1985
  to_return(:status => 404, :body => "", :headers => {})
2020
1986
  # put the alias for the index
2021
- stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/mylogs-myapp-#{timestr}").
2022
- with(basic_auth: ['john', 'doe']).
1987
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-#{timestr}-000001%3E/#{alias_endpoint}/mylogs-#{timestr}").
1988
+ with(basic_auth: ['john', 'doe'],
1989
+ body: "{\"aliases\":{\"mylogs-#{timestr}\":{\"is_write_index\":true}}}").
2023
1990
  to_return(:status => 200, :body => "", :headers => {})
2024
1991
 
2025
1992
  driver(config)
@@ -2202,52 +2169,10 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2202
2169
  enable_ilm true
2203
2170
  }
2204
2171
 
2205
- # connection start
2206
- stub_request(:head, "https://logs.google.com:777/es//").
2207
- with(basic_auth: ['john', 'doe']).
2208
- to_return(:status => 200, :body => "", :headers => {})
2209
- # check if template exists
2210
- stub_request(:get, "https://logs.google.com:777/es//_template/myapp_alias_template").
2211
- with(basic_auth: ['john', 'doe']).
2212
- to_return(:status => 404, :body => "", :headers => {})
2213
- # creation
2214
- stub_request(:put, "https://logs.google.com:777/es//_template/myapp_alias_template").
2215
- with(basic_auth: ['john', 'doe']).
2216
- to_return(:status => 200, :body => "", :headers => {})
2217
- # creation of index which can rollover
2218
- stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
2219
- with(basic_auth: ['john', 'doe']).
2220
- to_return(:status => 200, :body => "", :headers => {})
2221
- # check if alias exists
2222
- stub_request(:head, "https://logs.google.com:777/es//_alias/myapp_deflector").
2223
- with(basic_auth: ['john', 'doe']).
2224
- to_return(:status => 404, :body => "", :headers => {})
2225
- stub_request(:get, "https://logs.google.com:777/es//_template/myapp_deflector").
2226
- with(basic_auth: ['john', 'doe']).
2227
- to_return(status: 404, body: "", headers: {})
2228
- stub_request(:put, "https://logs.google.com:777/es//_template/myapp_deflector").
2229
- with(basic_auth: ['john', 'doe'],
2230
- body: "{\"order\":6,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"myapp_deflector\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"myapp_deflector-*\"}").
2231
- to_return(status: 200, body: "", headers: {})
2232
- # put the alias for the index
2233
- stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/#{alias_endpoint}/myapp_deflector").
2234
- with(basic_auth: ['john', 'doe'],
2235
- :body => "{\"aliases\":{\"myapp_deflector\":{\"is_write_index\":true}}}").
2236
- to_return(:status => 200, :body => "", :headers => {})
2237
- stub_request(:get, "https://logs.google.com:777/es//_xpack").
2238
- with(basic_auth: ['john', 'doe']).
2239
- to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
2240
- stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
2241
- with(basic_auth: ['john', 'doe']).
2242
- to_return(:status => 404, :body => "", :headers => {})
2243
- stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
2244
- with(basic_auth: ['john', 'doe'],
2245
- :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
2246
- to_return(:status => 200, :body => "", :headers => {})
2247
-
2248
- driver(config)
2249
-
2250
- assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_deflector", times: 1)
2172
+ # Should raise error because multiple alias indices IllegalArgument Error on executing ILM feature
2173
+ assert_raise(Fluent::ConfigError) do
2174
+ driver(config)
2175
+ end
2251
2176
  end
2252
2177
 
2253
2178
  def test_custom_template_with_rollover_index_create_and_default_ilm_and_placeholders
@@ -2735,7 +2660,7 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2735
2660
  assert_requested(:put, "https://logs.google.com:777/es//_template/logstash3", times: 1)
2736
2661
  end
2737
2662
 
2738
- def test_templates_not_used
2663
+ def test_templates_are_also_used
2739
2664
  cwd = File.dirname(__FILE__)
2740
2665
  template_file = File.join(cwd, 'test_template.json')
2741
2666
 
@@ -2779,8 +2704,8 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2779
2704
 
2780
2705
  assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
2781
2706
 
2782
- assert_not_requested(:put, "https://logs.google.com:777/es//_template/logstash1")
2783
- assert_not_requested(:put, "https://logs.google.com:777/es//_template/logstash2")
2707
+ assert_requested(:put, "https://logs.google.com:777/es//_template/logstash1")
2708
+ assert_requested(:put, "https://logs.google.com:777/es//_template/logstash2")
2784
2709
  end
2785
2710
 
2786
2711
  def test_templates_can_be_partially_created_if_error_occurs
@@ -2986,6 +2911,18 @@ class ElasticsearchOutputTest < Test::Unit::TestCase
2986
2911
  assert_requested(elastic_request)
2987
2912
  end
2988
2913
 
2914
+ def test_api_key_header
2915
+ stub_request(:head, "http://localhost:9200/").
2916
+ to_return(:status => 200, :body => "", :headers => {})
2917
+ elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
2918
+ with(headers: {'Authorization'=>'ApiKey dGVzdGF1dGhoZWFkZXI='})
2919
+ driver.configure(%[api_key testauthheader])
2920
+ driver.run(default_tag: 'test') do
2921
+ driver.feed(sample_record)
2922
+ end
2923
+ assert_requested(elastic_request)
2924
+ end
2925
+
2989
2926
  def test_write_message_with_bad_chunk
2990
2927
  driver.configure("target_index_key bad_value\n@log_level debug\n")
2991
2928
  stub_elastic
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.11
4
+ version: 4.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - diogo
8
8
  - pitr
9
9
  - Hiroshi Hatake
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-07-09 00:00:00.000000000 Z
13
+ date: 2020-09-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluentd
@@ -160,6 +160,7 @@ files:
160
160
  - lib/fluent/plugin/elasticsearch_constants.rb
161
161
  - lib/fluent/plugin/elasticsearch_error.rb
162
162
  - lib/fluent/plugin/elasticsearch_error_handler.rb
163
+ - lib/fluent/plugin/elasticsearch_fallback_selector.rb
163
164
  - lib/fluent/plugin/elasticsearch_index_lifecycle_management.rb
164
165
  - lib/fluent/plugin/elasticsearch_index_template.rb
165
166
  - lib/fluent/plugin/elasticsearch_simple_sniffer.rb
@@ -172,6 +173,7 @@ files:
172
173
  - test/helper.rb
173
174
  - test/plugin/test_alias_template.json
174
175
  - test/plugin/test_elasticsearch_error_handler.rb
176
+ - test/plugin/test_elasticsearch_fallback_selector.rb
175
177
  - test/plugin/test_elasticsearch_index_lifecycle_management.rb
176
178
  - test/plugin/test_elasticsearch_tls.rb
177
179
  - test/plugin/test_filter_elasticsearch_genid.rb
@@ -186,7 +188,7 @@ licenses:
186
188
  - Apache-2.0
187
189
  metadata:
188
190
  changelog_uri: https://github.com/uken/fluent-plugin-elasticsearch/blob/master/History.md
189
- post_install_message:
191
+ post_install_message:
190
192
  rdoc_options: []
191
193
  require_paths:
192
194
  - lib
@@ -202,13 +204,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
204
  version: '0'
203
205
  requirements: []
204
206
  rubygems_version: 3.1.2
205
- signing_key:
207
+ signing_key:
206
208
  specification_version: 4
207
209
  summary: Elasticsearch output plugin for Fluent event collector
208
210
  test_files:
209
211
  - test/helper.rb
210
212
  - test/plugin/test_alias_template.json
211
213
  - test/plugin/test_elasticsearch_error_handler.rb
214
+ - test/plugin/test_elasticsearch_fallback_selector.rb
212
215
  - test/plugin/test_elasticsearch_index_lifecycle_management.rb
213
216
  - test/plugin/test_elasticsearch_tls.rb
214
217
  - test/plugin/test_filter_elasticsearch_genid.rb