fluent-plugin-elasticsearch 4.0.0 → 4.0.1

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: 4e963cd715f4b07ec74b88df45a4b27bd28ea3d9a81a986720eb103baf1f4ab8
4
- data.tar.gz: 99adcede30be2bff2bce8eebdfb39e67a14028e46d073516411bfb81bcd623df
3
+ metadata.gz: 2d857451dc47373e32d9b2833fcb63a6afca5e45c1d131ee229ff8e29e408955
4
+ data.tar.gz: c0b7f154abe0b1e8288f72a7447c81a1c96ef3c7bb939af9f5964257e413a926
5
5
  SHA512:
6
- metadata.gz: a0fd61160246d393d0059737a2557ca595d943a5db15a554d12a7c20664b42972c2f466325a1c027cbddb1d3dcc0e6cb69fe3499f506aa95f17a47d809e6a7c9
7
- data.tar.gz: 7031ebb1c3fbfcd8bd23662c77ea34b44512297f780f7be632765a30753df7802e677a66bf6d468c6d3c33314938add162a26a16a484e587d1fae416e56ca8b1
6
+ metadata.gz: 1366c860429fe8da518a618f3651c839d5e151fbdf8025557433e323c84b718b7132fb27ad2c5c40d7d72980dcdb430a3398cb74aa1aafd99e4c4f701564c56d
7
+ data.tar.gz: caba8636b01815d08a00a81bf8159eaeafa0fce7824f2408d11f813f23504ab63b5ab1076c0a47ebc6f786f0228765a50f26b2076b5d1004710b1b448dace176
data/History.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ## Changelog [[tags]](https://github.com/uken/fluent-plugin-elasticsearch/tags)
2
2
 
3
3
  ### [Unreleased]
4
+ ### 4.0.1
5
+ - Placeholders for template name and customize template (#708)
6
+ - Add overwriting ilm policy config parameter (#707)
7
+ - Fix a failing ILM config testcase (#706)
4
8
 
5
9
  ### 4.0.0
6
10
  - Restructuring ILM related features (#701)
data/README.md CHANGED
@@ -91,6 +91,7 @@ Current maintainers: @cosmo0920
91
91
  + [enable_ilm](#enable_ilm)
92
92
  + [ilm_policy_id](#ilm_policy_id)
93
93
  + [ilm_policy](#ilm_policy)
94
+ + [ilm_policy_overwrite](#ilm_policy_overwrite)
94
95
  * [Configuration - Elasticsearch Input](#configuration---elasticsearch-input)
95
96
  * [Troubleshooting](#troubleshooting)
96
97
  + [Cannot send events to elasticsearch](#cannot-send-events-to-elasticsearch)
@@ -1162,6 +1163,14 @@ Default value is `{}`.
1162
1163
 
1163
1164
  **NOTE:** This parameter requests to install elasticsearch-xpack gem.
1164
1165
 
1166
+ ## ilm_policy_overwrite
1167
+
1168
+ Specify whether overwriting ilm policy or not.
1169
+
1170
+ Default value is `false`.
1171
+
1172
+ **NOTE:** This parameter requests to install elasticsearch-xpack gem.
1173
+
1165
1174
  ## Configuration - Elasticsearch Input
1166
1175
 
1167
1176
  See [Elasticsearch Input plugin document](README.ElasticsearchInput.md)
@@ -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.0'
6
+ s.version = '4.0.1'
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}
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.metadata["changelog_uri"] = "https://github.com/uken/fluent-plugin-elasticsearch/blob/master/History.md"
21
21
  end
22
22
 
23
- s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
23
+ s.required_ruby_version = Gem::Requirement.new(">= 2.3".freeze)
24
24
 
25
25
  s.add_runtime_dependency 'fluentd', '>= 0.14.22'
26
26
  s.add_runtime_dependency 'excon', '>= 0'
@@ -1,10 +1,10 @@
1
1
  module Fluent::Plugin::ElasticsearchIndexLifecycleManagement
2
2
  ILM_DEFAULT_POLICY_PATH = "default-ilm-policy.json"
3
3
 
4
- def setup_ilm(enable_ilm, policy_id, ilm_policy = default_policy_payload)
4
+ def setup_ilm(enable_ilm, policy_id, ilm_policy = default_policy_payload, overwrite = false)
5
5
  return unless enable_ilm
6
6
 
7
- create_ilm_policy(policy_id, ilm_policy)
7
+ create_ilm_policy(policy_id, ilm_policy, overwrite)
8
8
  end
9
9
 
10
10
  def verify_ilm_working
@@ -26,8 +26,8 @@ module Fluent::Plugin::ElasticsearchIndexLifecycleManagement
26
26
  end
27
27
  end
28
28
 
29
- def create_ilm_policy(policy_id, ilm_policy = default_policy_payload)
30
- if !ilm_policy_exists?(policy_id)
29
+ def create_ilm_policy(policy_id, ilm_policy = default_policy_payload, overwrite = false)
30
+ if overwrite || !ilm_policy_exists?(policy_id)
31
31
  ilm_policy_put(policy_id, ilm_policy)
32
32
  end
33
33
  end
@@ -127,7 +127,7 @@ module Fluent::ElasticsearchIndexTemplate
127
127
  template
128
128
  end
129
129
 
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, host)
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)
131
131
  # ILM request to create alias.
132
132
  if rollover_index || enable_ilm
133
133
  if !client.indices.exists_alias(:name => deflector_alias_name)
@@ -137,8 +137,7 @@ module Fluent::ElasticsearchIndexTemplate
137
137
  index_name_temp='<'+index_prefix.downcase+index_separator+app_name.downcase+'-{'+index_date_pattern+'}-000001>'
138
138
  end
139
139
  indexcreation(index_name_temp, host)
140
- body = {}
141
- body = rollover_alias_payload(deflector_alias_name) if enable_ilm
140
+ body = rollover_alias_payload(deflector_alias_name)
142
141
  client.indices.put_alias(:index => index_name_temp, :name => deflector_alias_name,
143
142
  :body => body)
144
143
  log.info("The alias '#{deflector_alias_name}' is created for the index '#{index_name_temp}'")
@@ -146,7 +145,7 @@ module Fluent::ElasticsearchIndexTemplate
146
145
  if ilm_policy.empty?
147
146
  setup_ilm(enable_ilm, ilm_policy_id)
148
147
  else
149
- setup_ilm(enable_ilm, ilm_policy_id, ilm_policy)
148
+ setup_ilm(enable_ilm, ilm_policy_id, ilm_policy, ilm_policy_overwrite)
150
149
  end
151
150
  end
152
151
  else
@@ -52,6 +52,7 @@ module Fluent::Plugin
52
52
  RequestInfo = Struct.new(:host, :index, :ilm_index)
53
53
 
54
54
  attr_reader :alias_indexes
55
+ attr_reader :template_names
55
56
 
56
57
  helpers :event_emitter, :compat_parameters, :record_accessor
57
58
 
@@ -155,6 +156,7 @@ EOC
155
156
  config_param :enable_ilm, :bool, :default => false
156
157
  config_param :ilm_policy_id, :string, :default => DEFAULT_POLICY_ID
157
158
  config_param :ilm_policy, :hash, :default => {}
159
+ config_param :ilm_policy_overwrite, :bool, :default => false
158
160
 
159
161
  config_section :buffer do
160
162
  config_set_default :@type, DEFAULT_BUFFER_TYPE
@@ -212,17 +214,21 @@ EOC
212
214
  end
213
215
 
214
216
  @alias_indexes = []
217
+ @template_names = []
215
218
  if !dry_run?
216
219
  if @template_name && @template_file
217
220
  if @enable_ilm
218
221
  raise Fluent::ConfigError, "deflector_alias is prohibited to use with 'logstash_format at same time." if @logstash_format and @deflector_alias
219
222
  end
223
+ if @ilm_policy.empty? && @ilm_policy_overwrite
224
+ raise Fluent::ConfigError, "ilm_policy_overwrite can work with non empty ilm_policy. Specify non-empty ilm policy into ilm_policy. "
225
+ end
220
226
  if @logstash_format || placeholder_substitution_needed_for_template?
221
227
  class << self
222
228
  alias_method :template_installation, :template_installation_actual
223
229
  end
224
230
  else
225
- template_installation_actual(@deflector_alias ? @deflector_alias : @index_name, @application_name, @index_name)
231
+ template_installation_actual(@deflector_alias ? @deflector_alias : @index_name, @template_name, @customize_template, @application_name, @index_name)
226
232
  end
227
233
  verify_ilm_working if @enable_ilm
228
234
  elsif @templates
@@ -358,13 +364,17 @@ EOC
358
364
  end
359
365
 
360
366
  def placeholder?(name, param)
361
- begin
362
- placeholder_validate!(name, param)
363
- true
364
- rescue Fluent::ConfigError => e
365
- log.debug("'#{name} #{param}' is tested built-in placeholder(s) but there is no valid placeholder(s). error: #{e}")
366
- false
367
+ placeholder_validities = []
368
+ placeholder_validators(name, param).each do |v|
369
+ begin
370
+ v.validate!
371
+ placeholder_validities << true
372
+ rescue Fluent::ConfigError => e
373
+ log.debug("'#{name} #{param}' is tested built-in placeholder(s) but there is no valid placeholder(s). error: #{e}")
374
+ placeholder_validities << false
375
+ end
367
376
  end
377
+ placeholder_validities.include?(true)
368
378
  end
369
379
 
370
380
  def compression
@@ -647,6 +657,16 @@ EOC
647
657
  else
648
658
  type_name = nil
649
659
  end
660
+ if @template_name
661
+ template_name = extract_placeholders(@template_name, chunk)
662
+ else
663
+ template_name = nil
664
+ end
665
+ if @customize_template
666
+ customize_template = @customize_template.each_with_object({}) { |(key, value), hash| hash[key] = extract_placeholders(value, chunk) }
667
+ else
668
+ customize_template = nil
669
+ end
650
670
  if @deflector_alias
651
671
  deflector_alias = extract_placeholders(@deflector_alias, chunk)
652
672
  else
@@ -662,7 +682,7 @@ EOC
662
682
  else
663
683
  pipeline = nil
664
684
  end
665
- return logstash_prefix, index_name, type_name, deflector_alias, application_name, pipeline
685
+ return logstash_prefix, index_name, type_name, template_name, customize_template, deflector_alias, application_name, pipeline
666
686
  end
667
687
 
668
688
  def multi_workers_ready?
@@ -736,7 +756,7 @@ EOC
736
756
  end
737
757
 
738
758
  def process_message(tag, meta, header, time, record, extracted_values)
739
- logstash_prefix, index_name, type_name, _deflector_alias, _application_name, pipeline = extracted_values
759
+ logstash_prefix, index_name, type_name, _template_name, _customize_template, _deflector_alias, _application_name, pipeline = extracted_values
740
760
 
741
761
  if @flatten_hashes
742
762
  record = flatten_record(record)
@@ -837,31 +857,38 @@ EOC
837
857
  end
838
858
 
839
859
  def placeholder_substitution_needed_for_template?
840
- placeholder?(:host, @host.to_s) ||
860
+ need_substitution = placeholder?(:host, @host.to_s) ||
841
861
  placeholder?(:index_name, @index_name.to_s) ||
862
+ placeholder?(:template_name, @template_name.to_s) ||
863
+ @customize_template&.values&.any? { |value| placeholder?(:customize_template, value.to_s) } ||
842
864
  placeholder?(:logstash_prefix, @logstash_prefix.to_s) ||
843
865
  placeholder?(:deflector_alias, @deflector_alias.to_s) ||
844
866
  placeholder?(:application_name, @application_name.to_s)
867
+ log.debug("Need substitution: #{need_substitution}")
868
+ need_substitution
845
869
  end
846
870
 
847
- def template_installation(deflector_alias, application_name, target_index, host)
871
+ def template_installation(deflector_alias, template_name, customize_template, application_name, target_index, host)
848
872
  # for safety.
849
873
  end
850
874
 
851
- def template_installation_actual(deflector_alias, application_name, target_index, host=nil)
852
- if @template_name && @template_file
875
+ def template_installation_actual(deflector_alias, template_name, customize_template, application_name, target_index, host=nil)
876
+ if template_name && @template_file
853
877
  if @alias_indexes.include? deflector_alias
854
878
  log.debug("Index alias #{deflector_alias} already exists (cached)")
879
+ elsif @template_names.include? template_name
880
+ log.debug("Template name #{template_name} already exists (cached)")
855
881
  else
856
882
  retry_operate(@max_retry_putting_template, @fail_on_putting_template_retry_exceed) do
857
- if @customize_template
858
- template_custom_install(@template_name, @template_file, @template_overwrite, @customize_template, @enable_ilm, deflector_alias, @ilm_policy_id, host)
883
+ if customize_template
884
+ template_custom_install(template_name, @template_file, @template_overwrite, customize_template, @enable_ilm, deflector_alias, @ilm_policy_id, host)
859
885
  else
860
- template_install(@template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, @ilm_policy_id, host)
886
+ template_install(template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, @ilm_policy_id, host)
861
887
  end
862
- create_rollover_alias(target_index, @rollover_index, deflector_alias, application_name, @index_date_pattern, @index_separator, @enable_ilm, @ilm_policy_id, @ilm_policy, host)
888
+ 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)
863
889
  end
864
890
  @alias_indexes << deflector_alias unless deflector_alias.nil?
891
+ @template_names << template_name unless template_name.nil?
865
892
  end
866
893
  end
867
894
  end
@@ -869,11 +896,11 @@ EOC
869
896
  # send_bulk given a specific bulk request, the original tag,
870
897
  # chunk, and bulk_message_count
871
898
  def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, info)
872
- logstash_prefix, index_name, _type_name, deflector_alias, application_name, _pipeline = extracted_values
899
+ logstash_prefix, index_name, _type_name, template_name, customize_template, deflector_alias, application_name, _pipeline = extracted_values
873
900
  if deflector_alias
874
- template_installation(deflector_alias, application_name, index_name, info.host)
901
+ template_installation(deflector_alias, template_name, customize_template, application_name, index_name, info.host)
875
902
  else
876
- template_installation(info.ilm_index, application_name, @logstash_format ? logstash_prefix : index_name, info.host)
903
+ template_installation(info.ilm_index, template_name, customize_template, application_name, @logstash_format ? logstash_prefix : index_name, info.host)
877
904
  end
878
905
 
879
906
  begin
@@ -307,36 +307,96 @@ class ElasticsearchOutput < Test::Unit::TestCase
307
307
  }
308
308
  end
309
309
 
310
- test 'valid configuration of index lifecycle management' do
311
- cwd = File.dirname(__FILE__)
312
- template_file = File.join(cwd, 'test_template.json')
310
+ sub_test_case 'ILM default config' do
311
+ setup do
312
+ begin
313
+ require "elasticsearch/xpack"
314
+ rescue LoadError
315
+ omit "ILM testcase needs elasticsearch-xpack gem."
316
+ end
317
+ end
313
318
 
314
- config = %{
315
- enable_ilm true
316
- template_name logstash
317
- template_file #{template_file}
318
- }
319
- stub_request(:get, "http://localhost:9200/_template/fluentd").
320
- to_return(status: 200, body: "", headers: {})
321
- stub_request(:head, "http://localhost:9200/_alias/fluentd").
322
- to_return(status: 404, body: "", headers: {})
323
- stub_request(:put, "http://localhost:9200/%3Cfluentd-default-%7Bnow%2Fd%7D-000001%3E/_alias/fluentd").
324
- with(body: "{\"aliases\":{\"fluentd\":{\"is_write_index\":true}}}").
325
- to_return(status: 200, body: "", headers: {})
326
- stub_request(:put, "http://localhost:9200/%3Cfluentd-default-%7Bnow%2Fd%7D-000001%3E").
327
- to_return(status: 200, body: "", headers: {})
328
- stub_request(:get, "http://localhost:9200/_xpack").
329
- to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}',
330
- :headers => {"Content-Type"=> "application/json"})
331
- stub_request(:get, "http://localhost:9200/_ilm/policy/logstash-policy").
332
- to_return(status: 404, body: "", headers: {})
333
- stub_request(:put, "http://localhost:9200/_ilm/policy/logstash-policy").
334
- with(body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
335
- to_return(status: 200, body: "", headers: {})
319
+ test 'valid configuration of index lifecycle management' do
320
+ cwd = File.dirname(__FILE__)
321
+ template_file = File.join(cwd, 'test_template.json')
336
322
 
337
- assert_nothing_raised {
338
- driver(config)
339
- }
323
+ config = %{
324
+ enable_ilm true
325
+ template_name logstash
326
+ template_file #{template_file}
327
+ }
328
+ stub_request(:get, "http://localhost:9200/_template/fluentd").
329
+ to_return(status: 200, body: "", headers: {})
330
+ stub_request(:head, "http://localhost:9200/_alias/fluentd").
331
+ to_return(status: 404, body: "", headers: {})
332
+ stub_request(:put, "http://localhost:9200/%3Cfluentd-default-%7Bnow%2Fd%7D-000001%3E/_alias/fluentd").
333
+ with(body: "{\"aliases\":{\"fluentd\":{\"is_write_index\":true}}}").
334
+ to_return(status: 200, body: "", headers: {})
335
+ stub_request(:put, "http://localhost:9200/%3Cfluentd-default-%7Bnow%2Fd%7D-000001%3E").
336
+ to_return(status: 200, body: "", headers: {})
337
+ stub_request(:get, "http://localhost:9200/_xpack").
338
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}',
339
+ :headers => {"Content-Type"=> "application/json"})
340
+ stub_request(:get, "http://localhost:9200/_ilm/policy/logstash-policy").
341
+ to_return(status: 404, body: "", headers: {})
342
+ stub_request(:put, "http://localhost:9200/_ilm/policy/logstash-policy").
343
+ with(body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
344
+ to_return(status: 200, body: "", headers: {})
345
+
346
+ assert_nothing_raised {
347
+ driver(config)
348
+ }
349
+ end
350
+
351
+ test 'valid configuration of overwriting ilm_policy' do
352
+ cwd = File.dirname(__FILE__)
353
+ template_file = File.join(cwd, 'test_template.json')
354
+
355
+ config = %{
356
+ enable_ilm true
357
+ template_name logstash
358
+ template_file #{template_file}
359
+ ilm_policy_overwrite true
360
+ ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"75gb","max_age": "50d"}}}}}}
361
+ }
362
+ stub_request(:get, "http://localhost:9200/_template/fluentd").
363
+ to_return(status: 200, body: "", headers: {})
364
+ stub_request(:head, "http://localhost:9200/_alias/fluentd").
365
+ to_return(status: 404, body: "", headers: {})
366
+ stub_request(:put, "http://localhost:9200/%3Cfluentd-default-%7Bnow%2Fd%7D-000001%3E/_alias/fluentd").
367
+ with(body: "{\"aliases\":{\"fluentd\":{\"is_write_index\":true}}}").
368
+ to_return(status: 200, body: "", headers: {})
369
+ stub_request(:put, "http://localhost:9200/%3Cfluentd-default-%7Bnow%2Fd%7D-000001%3E").
370
+ to_return(status: 200, body: "", headers: {})
371
+ stub_request(:get, "http://localhost:9200/_xpack").
372
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}',
373
+ :headers => {"Content-Type"=> "application/json"})
374
+ stub_request(:get, "http://localhost:9200/_ilm/policy/logstash-policy").
375
+ to_return(status: 200, body: "", headers: {})
376
+ stub_request(:put, "http://localhost:9200/_ilm/policy/logstash-policy").
377
+ with(body: "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"75gb\",\"max_age\":\"50d\"}}}}}}").
378
+ to_return(status: 200, body: "", headers: {})
379
+
380
+ assert_nothing_raised {
381
+ driver(config)
382
+ }
383
+ end
384
+
385
+ test 'invalid configuration of overwriting ilm_policy' do
386
+ cwd = File.dirname(__FILE__)
387
+ template_file = File.join(cwd, 'test_template.json')
388
+
389
+ config = %{
390
+ enable_ilm true
391
+ template_name logstash
392
+ template_file #{template_file}
393
+ ilm_policy_overwrite true
394
+ }
395
+
396
+ assert_raise(Fluent::ConfigError) {
397
+ driver(config)
398
+ }
399
+ end
340
400
  end
341
401
 
342
402
  test 'Detected Elasticsearch 7' do
@@ -399,6 +459,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
399
459
 
400
460
  sub_test_case "placeholder substitution needed?" do
401
461
  data("host placeholder" => ["host", "host-${tag}.google.com"],
462
+ "index_name_placeholder" => ["index_name", "logstash-${tag}"],
463
+ "template_name_placeholder" => ["template_name", "logstash-${tag}"],
464
+ "customize_template" => ["customize_template", '{"<<TAG>>":"${tag}"}'],
402
465
  "logstash_prefix_placeholder" => ["logstash_prefix", "fluentd-${tag}"],
403
466
  "deflector_alias_placeholder" => ["deflector_alias", "fluentd-${tag}"],
404
467
  "application_name_placeholder" => ["application_name", "fluentd-${tag}"],
@@ -419,6 +482,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
419
482
 
420
483
 
421
484
  data("host placeholder" => ["host", "host-%Y%m%d.google.com"],
485
+ "index_name_placeholder" => ["index_name", "logstash-%Y%m%d"],
486
+ "template_name_placeholder" => ["template_name", "logstash-%Y%m%d"],
487
+ "customize_template" => ["customize_template", '{"<<TAG>>":"fluentd-%Y%m%d"}'],
422
488
  "logstash_prefix_placeholder" => ["logstash_prefix", "fluentd-%Y%m%d"],
423
489
  "deflector_alias_placeholder" => ["deflector_alias", "fluentd-%Y%m%d"],
424
490
  "application_name_placeholder" => ["application_name", "fluentd-%Y%m%d"],
@@ -440,6 +506,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
440
506
  end
441
507
 
442
508
  data("host placeholder" => ["host", "host-${mykey}.google.com"],
509
+ "index_name_placeholder" => ["index_name", "logstash-${mykey}"],
510
+ "template_name_placeholder" => ["template_name", "logstash-${mykey}"],
511
+ "customize_template" => ["customize_template", '{"<<TAG>>":"${mykey}"}'],
443
512
  "logstash_prefix_placeholder" => ["logstash_prefix", "fluentd-${mykey}"],
444
513
  "deflector_alias_placeholder" => ["deflector_alias", "fluentd-${mykey}"],
445
514
  "application_name_placeholder" => ["application_name", "fluentd-${mykey}"],
@@ -460,6 +529,31 @@ class ElasticsearchOutput < Test::Unit::TestCase
460
529
 
461
530
  assert_true driver.instance.placeholder_substitution_needed_for_template?
462
531
  end
532
+
533
+ data("host placeholder" => ["host", "host-${tag}.google.com"],
534
+ "index_name_placeholder" => ["index_name", "logstash-${es_index}-%Y%m%d"],
535
+ "template_name_placeholder" => ["template_name", "logstash-${tag}-%Y%m%d"],
536
+ "customize_template" => ["customize_template", '{"<<TAG>>":"${es_index}"}'],
537
+ "logstash_prefix_placeholder" => ["logstash_prefix", "fluentd-${es_index}-%Y%m%d"],
538
+ "deflector_alias_placeholder" => ["deflector_alias", "fluentd-%Y%m%d"],
539
+ "application_name_placeholder" => ["application_name", "fluentd-${tag}-${es_index}-%Y%m%d"],
540
+ )
541
+ test 'mixed placeholder' do |data|
542
+ param, value = data
543
+ config = Fluent::Config::Element.new(
544
+ 'ROOT', '', {
545
+ '@type' => 'elasticsearch',
546
+ param => value
547
+ }, [
548
+ Fluent::Config::Element.new('buffer', 'tag,time,es_index', {
549
+ 'chunk_keys' => 'es_index',
550
+ 'timekey' => '1d',
551
+ }, [])
552
+ ])
553
+ driver(config)
554
+
555
+ assert_true driver.instance.placeholder_substitution_needed_for_template?
556
+ end
463
557
  end
464
558
 
465
559
  sub_test_case 'chunk_keys requirement' do
@@ -650,6 +744,63 @@ class ElasticsearchOutput < Test::Unit::TestCase
650
744
  assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
651
745
  end
652
746
 
747
+ def test_template_create_with_rollover_index_and_template_related_placeholders
748
+ cwd = File.dirname(__FILE__)
749
+ template_file = File.join(cwd, 'test_template.json')
750
+ config = %{
751
+ host logs.google.com
752
+ port 777
753
+ scheme https
754
+ path /es/
755
+ user john
756
+ password doe
757
+ template_name logstash-${tag}
758
+ template_file #{template_file}
759
+ rollover_index true
760
+ index_date_pattern ""
761
+ index_name fluentd-${tag}
762
+ deflector_alias myapp_deflector-${tag}
763
+ }
764
+
765
+ # connection start
766
+ stub_request(:head, "https://logs.google.com:777/es//").
767
+ with(basic_auth: ['john', 'doe']).
768
+ to_return(:status => 200, :body => "", :headers => {})
769
+ # check if template exists
770
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash-test.template").
771
+ with(basic_auth: ['john', 'doe']).
772
+ to_return(:status => 404, :body => "", :headers => {})
773
+ # create template
774
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash-test.template").
775
+ with(basic_auth: ['john', 'doe']).
776
+ to_return(:status => 200, :body => "", :headers => {})
777
+ # check if alias exists
778
+ stub_request(:head, "https://logs.google.com:777/es//_alias/myapp_deflector-test.template").
779
+ with(basic_auth: ['john', 'doe']).
780
+ to_return(:status => 404, :body => "", :headers => {})
781
+ # put the alias for the index
782
+ stub_request(:put, "https://logs.google.com:777/es//%3Cfluentd-test.template-default-000001%3E").
783
+ with(basic_auth: ['john', 'doe']).
784
+ to_return(status: 200, body: "", headers: {})
785
+ stub_request(:put, "https://logs.google.com:777/es//%3Cfluentd-test.template-default-000001%3E/_alias/myapp_deflector-test.template").
786
+ with(basic_auth: ['john', 'doe'],
787
+ body: "{\"aliases\":{\"myapp_deflector-test.template\":{\"is_write_index\":true}}}").
788
+ to_return(:status => 200, :body => "", :headers => {})
789
+
790
+ driver(config)
791
+
792
+ elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
793
+ driver.run(default_tag: 'test.template') do
794
+ driver.feed(sample_record)
795
+ end
796
+ assert_equal('fluentd-test.template', index_cmds.first['index']['_index'])
797
+
798
+ assert_equal ["myapp_deflector-test.template"], driver.instance.alias_indexes
799
+ assert_equal ["logstash-test.template"], driver.instance.template_names
800
+
801
+ assert_requested(elastic_request)
802
+ end
803
+
653
804
  class TemplateIndexLifecycleManagementTest < self
654
805
  def setup
655
806
  begin
@@ -724,6 +875,73 @@ class ElasticsearchOutput < Test::Unit::TestCase
724
875
  assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
725
876
  end
726
877
 
878
+ def test_template_create_with_rollover_index_and_default_ilm_and_ilm_policy_overwrite
879
+ cwd = File.dirname(__FILE__)
880
+ template_file = File.join(cwd, 'test_template.json')
881
+
882
+ config = %{
883
+ host logs.google.com
884
+ port 777
885
+ scheme https
886
+ path /es/
887
+ user john
888
+ password doe
889
+ template_name logstash
890
+ template_file #{template_file}
891
+ index_date_pattern now/w{xxxx.ww}
892
+ index_name logstash
893
+ enable_ilm true
894
+ ilm_policy_overwrite true
895
+ ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"60gb","max_age": "45d"}}}}}}
896
+ }
897
+
898
+ # connection start
899
+ stub_request(:head, "https://logs.google.com:777/es//").
900
+ with(basic_auth: ['john', 'doe']).
901
+ to_return(:status => 200, :body => "", :headers => {})
902
+ # check if template exists
903
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
904
+ with(basic_auth: ['john', 'doe']).
905
+ to_return(:status => 404, :body => "", :headers => {})
906
+ # creation
907
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash").
908
+ with(basic_auth: ['john', 'doe']).
909
+ to_return(:status => 200, :body => "", :headers => {})
910
+ # check if alias exists
911
+ stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
912
+ with(basic_auth: ['john', 'doe']).
913
+ to_return(:status => 404, :body => "", :headers => {})
914
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
915
+ with(basic_auth: ['john', 'doe']).
916
+ to_return(status: 404, body: "", headers: {})
917
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash").
918
+ with(basic_auth: ['john', 'doe'],
919
+ body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash\"},\"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-*\",\"order\":51}").
920
+ to_return(status: 200, body: "", headers: {})
921
+ # put the alias for the index
922
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
923
+ with(basic_auth: ['john', 'doe']).
924
+ to_return(:status => 200, :body => "", :headers => {})
925
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/logstash").
926
+ with(basic_auth: ['john', 'doe'],
927
+ :body => "{\"aliases\":{\"logstash\":{\"is_write_index\":true}}}").
928
+ to_return(:status => 200, :body => "", :headers => {})
929
+ stub_request(:get, "https://logs.google.com:777/es//_xpack").
930
+ with(basic_auth: ['john', 'doe']).
931
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
932
+ stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
933
+ with(basic_auth: ['john', 'doe']).
934
+ to_return(:status => 200, :body => "", :headers => {})
935
+ stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
936
+ with(basic_auth: ['john', 'doe'],
937
+ :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"60gb\",\"max_age\":\"45d\"}}}}}}").
938
+ to_return(:status => 200, :body => "", :headers => {})
939
+
940
+ driver(config)
941
+
942
+ assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
943
+ end
944
+
727
945
  def test_template_create_with_rollover_index_and_default_ilm_with_deflector_alias
728
946
  cwd = File.dirname(__FILE__)
729
947
  template_file = File.join(cwd, 'test_template.json')
@@ -1029,6 +1247,48 @@ class ElasticsearchOutput < Test::Unit::TestCase
1029
1247
  assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_alias_template", times: 1)
1030
1248
  end
1031
1249
 
1250
+ def test_custom_template_create_with_customize_template_related_placeholders
1251
+ cwd = File.dirname(__FILE__)
1252
+ template_file = File.join(cwd, 'test_alias_template.json')
1253
+
1254
+ config = %{
1255
+ host logs.google.com
1256
+ port 777
1257
+ scheme https
1258
+ path /es/
1259
+ user john
1260
+ password doe
1261
+ template_name myapp_alias_template-${tag}
1262
+ template_file #{template_file}
1263
+ customize_template {"--appid--": "${tag}-logs","--index_prefix--":"${tag}"}
1264
+ }
1265
+
1266
+ # connection start
1267
+ stub_request(:head, "https://logs.google.com:777/es//").
1268
+ with(basic_auth: ['john', 'doe']).
1269
+ to_return(:status => 200, :body => "", :headers => {})
1270
+ # check if template exists
1271
+ stub_request(:get, "https://logs.google.com:777/es//_template/myapp_alias_template-test.template").
1272
+ with(basic_auth: ['john', 'doe']).
1273
+ to_return(:status => 404, :body => "", :headers => {})
1274
+ # creation
1275
+ stub_request(:put, "https://logs.google.com:777/es//_template/myapp_alias_template-test.template").
1276
+ with(basic_auth: ['john', 'doe']).
1277
+ to_return(:status => 200, :body => "", :headers => {})
1278
+
1279
+ stub_request(:put, "https://logs.google.com:777/es//%3Cfluentd-test-default-000001%3E").
1280
+ to_return(status: 200, body: "", headers: {})
1281
+
1282
+ driver(config)
1283
+
1284
+ stub_elastic("https://logs.google.com:777/es//_bulk")
1285
+ driver.run(default_tag: 'test.template') do
1286
+ driver.feed(sample_record)
1287
+ end
1288
+
1289
+ assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_alias_template-test.template", times: 1)
1290
+ end
1291
+
1032
1292
  def test_custom_template_installation_for_host_placeholder
1033
1293
  cwd = File.dirname(__FILE__)
1034
1294
  template_file = File.join(cwd, 'test_template.json')
@@ -1302,6 +1562,77 @@ class ElasticsearchOutput < Test::Unit::TestCase
1302
1562
  assert_requested(:put, "https://logs.google.com:777/es//_template/mylogs", times: 1)
1303
1563
  end
1304
1564
 
1565
+ def test_custom_template_with_rollover_index_create_and_default_ilm_and_ilm_policy_overwrite
1566
+ cwd = File.dirname(__FILE__)
1567
+ template_file = File.join(cwd, 'test_alias_template.json')
1568
+
1569
+ config = %{
1570
+ host logs.google.com
1571
+ port 777
1572
+ scheme https
1573
+ path /es/
1574
+ user john
1575
+ password doe
1576
+ template_name myapp_alias_template
1577
+ template_file #{template_file}
1578
+ customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
1579
+ index_date_pattern now/w{xxxx.ww}
1580
+ index_name mylogs
1581
+ application_name myapp
1582
+ ilm_policy_id fluentd-policy
1583
+ enable_ilm true
1584
+ ilm_policy_overwrite true
1585
+ ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"60gb","max_age": "45d"}}}}}}
1586
+ }
1587
+
1588
+ # connection start
1589
+ stub_request(:head, "https://logs.google.com:777/es//").
1590
+ with(basic_auth: ['john', 'doe']).
1591
+ to_return(:status => 200, :body => "", :headers => {})
1592
+ # check if template exists
1593
+ stub_request(:get, "https://logs.google.com:777/es//_template/myapp_alias_template").
1594
+ with(basic_auth: ['john', 'doe']).
1595
+ to_return(:status => 404, :body => "", :headers => {})
1596
+ # creation
1597
+ stub_request(:put, "https://logs.google.com:777/es//_template/myapp_alias_template").
1598
+ with(basic_auth: ['john', 'doe']).
1599
+ to_return(:status => 200, :body => "", :headers => {})
1600
+ # creation of index which can rollover
1601
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1602
+ with(basic_auth: ['john', 'doe']).
1603
+ to_return(:status => 200, :body => "", :headers => {})
1604
+ # check if alias exists
1605
+ stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
1606
+ with(basic_auth: ['john', 'doe']).
1607
+ to_return(:status => 404, :body => "", :headers => {})
1608
+ stub_request(:get, "https://logs.google.com:777/es//_template/mylogs").
1609
+ with(basic_auth: ['john', 'doe']).
1610
+ to_return(status: 404, body: "", headers: {})
1611
+ stub_request(:put, "https://logs.google.com:777/es//_template/mylogs").
1612
+ with(basic_auth: ['john', 'doe'],
1613
+ body: "{\"order\":6,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-*\"}").
1614
+ to_return(status: 200, body: "", headers: {})
1615
+ # put the alias for the index
1616
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/mylogs").
1617
+ with(basic_auth: ['john', 'doe'],
1618
+ :body => "{\"aliases\":{\"mylogs\":{\"is_write_index\":true}}}").
1619
+ to_return(:status => 200, :body => "", :headers => {})
1620
+ stub_request(:get, "https://logs.google.com:777/es//_xpack").
1621
+ with(basic_auth: ['john', 'doe']).
1622
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1623
+ stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1624
+ with(basic_auth: ['john', 'doe']).
1625
+ to_return(:status => 200, :body => "", :headers => {})
1626
+ stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1627
+ with(basic_auth: ['john', 'doe'],
1628
+ :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"60gb\",\"max_age\":\"45d\"}}}}}}").
1629
+ to_return(:status => 200, :body => "", :headers => {})
1630
+
1631
+ driver(config)
1632
+
1633
+ assert_requested(:put, "https://logs.google.com:777/es//_template/mylogs", times: 1)
1634
+ end
1635
+
1305
1636
  def test_custom_template_with_rollover_index_create_and_default_ilm_with_deflector_alias
1306
1637
  cwd = File.dirname(__FILE__)
1307
1638
  template_file = File.join(cwd, 'test_alias_template.json')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - diogo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-01-27 00:00:00.000000000 Z
13
+ date: 2020-01-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluentd
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - ">="
187
187
  - !ruby/object:Gem::Version
188
- version: '2.0'
188
+ version: '2.3'
189
189
  required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - ">="