fluent-plugin-elasticsearch 3.8.0 → 4.0.0

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: 28cfb80e32dd25c9d67c582d4d39672515bbc9e0acb6a7b940ee1e36edd35de1
4
- data.tar.gz: 6c2440335c4a1ebc03939dee6204cbd9fc6265797c9658d728df70fc63e9ba9d
3
+ metadata.gz: 4e963cd715f4b07ec74b88df45a4b27bd28ea3d9a81a986720eb103baf1f4ab8
4
+ data.tar.gz: 99adcede30be2bff2bce8eebdfb39e67a14028e46d073516411bfb81bcd623df
5
5
  SHA512:
6
- metadata.gz: 7f67a2f892890ff80e34f6cd8aa14c5a61fc04095512f095d05554772eb384ddf54ec222006cf2b021ed08355d0af8575f0020671cd74de422c8b4c1e14989a0
7
- data.tar.gz: 0d1919231ba8c8a88391a54d1853d992ba531f39c33826ff12ffd7258f9b3087ae5e18e1497edb0b6dac40998641a9ed79e28449cb90e2c9339a7a4e34406e4b
6
+ metadata.gz: a0fd61160246d393d0059737a2557ca595d943a5db15a554d12a7c20664b42972c2f466325a1c027cbddb1d3dcc0e6cb69fe3499f506aa95f17a47d809e6a7c9
7
+ data.tar.gz: 7031ebb1c3fbfcd8bd23662c77ea34b44512297f780f7be632765a30753df7802e677a66bf6d468c6d3c33314938add162a26a16a484e587d1fae416e56ca8b1
@@ -2,12 +2,6 @@ language: ruby
2
2
 
3
3
  matrix:
4
4
  include:
5
- - rvm: 2.1
6
- gemfile: Gemfile
7
- - rvm: 2.2
8
- gemfile: Gemfile
9
- - rvm: 2.3
10
- gemfile: Gemfile
11
5
  - rvm: 2.4.6
12
6
  gemfile: Gemfile
13
7
  - rvm: 2.5.5
@@ -16,6 +10,8 @@ matrix:
16
10
  gemfile: gemfiles/Gemfile.ilm
17
11
  - rvm: 2.6.3
18
12
  gemfile: Gemfile
13
+ - rvm: 2.7.0
14
+ gemfile: Gemfile
19
15
 
20
16
  gemfile:
21
17
  - Gemfile
data/History.md CHANGED
@@ -1,6 +1,13 @@
1
1
  ## Changelog [[tags]](https://github.com/uken/fluent-plugin-elasticsearch/tags)
2
2
 
3
3
  ### [Unreleased]
4
+
5
+ ### 4.0.0
6
+ - Restructuring ILM related features (#701)
7
+ - Extract placeholders in pipeline parameter (#695)
8
+ - fix typo in `README.md` (#698)
9
+ - Reduce log noise when not using rollover_index (#692)
10
+
4
11
  ### 3.8.0
5
12
  - Add FAQ for specifying index.codec (#679)
6
13
  - Add FAQ for connect_write timeout reached error (#687)
data/README.md CHANGED
@@ -435,15 +435,14 @@ Specify this to override the index date pattern for creating a rollover index. T
435
435
  for example: <logstash-default-{now/d}-000001>. Overriding this changes the rollover time period. Setting
436
436
  "now/w{xxxx.ww}" would create weekly rollover indexes instead of daily.
437
437
 
438
- This setting only takes effect when combined with the [rollover_index](#rollover_index) setting.
438
+ This setting only takes effect when combined with the [enable_ilm](#enable_ilm) setting.
439
439
 
440
- And rollover\_index is also used in Lifecycle Index Management(ILM) feature.
441
440
  ```
442
441
  index_date_pattern "now/w{xxxx.ww}" # defaults to "now/d"
443
442
  ```
444
443
 
445
- If empty string(`""`) is specified in `index_date_patter`, index date pattern is not used.
446
- Elasticsearch plugin just creates <`index_prefix`-`application_name`-000001> rollover index instead of <`index_prefix`-`application_name`-`{index_date_pattern}`-000001>.
444
+ If empty string(`""`) is specified in `index_date_pattern`, index date pattern is not used.
445
+ Elasticsearch plugin just creates <`target_index`-`application_name`-000001> rollover index instead of <`target_index`-`application_name`-`{index_date_pattern}`-000001>.
447
446
 
448
447
  If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
449
448
 
@@ -458,12 +457,9 @@ If [rollover_index](#rollover_index) is set, then this parameter will be in effe
458
457
 
459
458
  ### index_prefix
460
459
 
461
- Specify the index prefix for the rollover index to be created.
462
- ```
463
- index_prefix mylogs # defaults to "logstash"
464
- ```
465
-
466
- If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
460
+ This parameter is marked as obsoleted.
461
+ Consider to use [index_name](#index_name) for specify ILM target index when not using with logstash_format.
462
+ When specifying `logstash_format` as true, consider to use [logstash_prefix](#logstash_prefix) to specify ILM target index prefix.
467
463
 
468
464
  ### application_name
469
465
 
@@ -472,7 +468,7 @@ Specify the application name for the rollover index to be created.
472
468
  application_name default # defaults to "default"
473
469
  ```
474
470
 
475
- If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
471
+ If [enable_ilm](#enable_ilm is set, then this parameter will be in effect otherwise ignored.
476
472
 
477
473
  ### template_overwrite
478
474
 
@@ -1593,23 +1589,27 @@ Index lifecycle management is template based index management feature.
1593
1589
 
1594
1590
  Main ILM feature parameters are:
1595
1591
 
1596
- * `rollover_index`
1597
- * `deflector_alias`
1592
+ * `index_name` (when logstash_format as false)
1593
+ * `logstash_prefix` (when logstash_format as true)
1598
1594
  * `enable_ilm`
1599
1595
  * `ilm_policy_id`
1600
1596
  * `ilm_policy`
1601
1597
 
1602
1598
  They are not all mandatory parameters but they are used for ILM feature in effect.
1603
1599
 
1600
+ ILM target index alias is created with `index_name` or an index which is calculated from `logstash_prefix`.
1601
+
1602
+ 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).
1603
+
1604
+ When using `deflectoe_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.
1605
+
1604
1606
  And also, ILM feature users should specify their Elasticsearch template for ILM enabled indices.
1605
1607
  Because ILM settings are injected into their Elasticsearch templates.
1606
1608
 
1609
+ #### Example ILM settings
1610
+
1607
1611
  ```aconf
1608
1612
  index_name fluentd-${tag}
1609
- # Should specify rollover_index as true
1610
- rollover_index true
1611
- deflector_alias fluentd-${tag} # Should specify as same index_name
1612
- index_prefix fluentd
1613
1613
  application_name ${tag}
1614
1614
  index_date_pattern "now/d"
1615
1615
  enable_ilm true
@@ -1618,11 +1618,44 @@ ilm_policy_id fluentd-policy
1618
1618
  # ilm_policy {} # Use default policy
1619
1619
  template_name your-fluentd-template
1620
1620
  template_file /path/to/fluentd-template.json
1621
- customize_template {"<<index_prefix>>": "fluentd"}
1621
+ # customize_template {"<<index_prefix>>": "fluentd"}
1622
1622
  ```
1623
1623
 
1624
1624
  Note: This plugin only creates rollover-enabled indices, which are aliases pointing to them and index templates, and creates an ILM policy if enabled.
1625
1625
 
1626
+ #### Create ILM indices in each day
1627
+
1628
+ If you want to create new index in each day, you should use `logstash_format` style configuration:
1629
+
1630
+ ```aconf
1631
+ logstash_prefix fluentd
1632
+ application_name default
1633
+ index_date_pattern "now/d"
1634
+ enable_ilm true
1635
+ # Policy configurations
1636
+ ilm_policy_id fluentd-policy
1637
+ # ilm_policy {} # Use default policy
1638
+ template_name your-fluentd-template
1639
+ template_file /path/to/fluentd-template.json
1640
+ ```
1641
+
1642
+ #### Fixed ILM indices
1643
+
1644
+ Also, users can use fixed ILM indices configuration.
1645
+ If `index_date_pattern` is set as `""`(empty string), Elasticsearch plugin won't attach date pattern in ILM indices:
1646
+
1647
+ ```aconf
1648
+ index_name fluentd
1649
+ application_name default
1650
+ index_date_pattern ""
1651
+ enable_ilm true
1652
+ # Policy configurations
1653
+ ilm_policy_id fluentd-policy
1654
+ # ilm_policy {} # Use default policy
1655
+ template_name your-fluentd-template
1656
+ template_file /path/to/fluentd-template.json
1657
+ ```
1658
+
1626
1659
  ### How to specify index codec
1627
1660
 
1628
1661
  Elasticsearch can handle compression methods for stored data such as LZ4 and best_compression.
@@ -1,8 +1,7 @@
1
1
  version: '{build}'
2
2
  install:
3
3
  - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - "%devkit%\\devkitvars.bat"
5
- - IF EXIST "%devkit%\\bin\\ridk.cmd" ridk.cmd enable
4
+ - ridk.cmd enable
6
5
  - ruby --version
7
6
  - gem --version
8
7
  - bundle install
@@ -13,18 +12,9 @@ test_script:
13
12
  # https://www.appveyor.com/docs/installed-software/#ruby
14
13
  environment:
15
14
  matrix:
15
+ - ruby_version: "26-x64"
16
+ - ruby_version: "26"
16
17
  - ruby_version: "25-x64"
17
- devkit: C:\Ruby23-x64\DevKit
18
18
  - ruby_version: "25"
19
- devkit: C:\Ruby23\DevKit
20
19
  - ruby_version: "24-x64"
21
- devkit: C:\Ruby23-x64\DevKit
22
20
  - ruby_version: "24"
23
- devkit: C:\Ruby23\DevKit
24
- - ruby_version: "23-x64"
25
- devkit: C:\Ruby23-x64\DevKit
26
- - ruby_version: "22-x64"
27
- devkit: C:\Ruby23-x64\DevKit
28
- matrix:
29
- allow_failures:
30
- - ruby_version: "21"
@@ -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 = '3.8.0'
6
+ s.version = '4.0.0'
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}
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
 
30
30
  s.add_development_dependency 'rake', '>= 0'
31
31
  s.add_development_dependency 'webmock', '~> 3'
32
- s.add_development_dependency 'test-unit', '~> 3.1.0'
32
+ s.add_development_dependency 'test-unit', '~> 3.3.0'
33
33
  s.add_development_dependency 'minitest', '~> 5.8'
34
34
  s.add_development_dependency 'flexmock', '~> 2.0'
35
35
  end
@@ -74,7 +74,7 @@ module Fluent::ElasticsearchIndexTemplate
74
74
  get_template(template_file)) :
75
75
  get_template(template_file), host)
76
76
 
77
- log.info("Template '#{inject_template_name}' overwritten with #{template_file}.")
77
+ log.debug("Template '#{inject_template_name}' overwritten with #{template_file}.")
78
78
  return
79
79
  end
80
80
  if !template_exists?(inject_template_name, host)
@@ -128,7 +128,8 @@ module Fluent::ElasticsearchIndexTemplate
128
128
  end
129
129
 
130
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)
131
- if rollover_index
131
+ # ILM request to create alias.
132
+ if rollover_index || enable_ilm
132
133
  if !client.indices.exists_alias(:name => deflector_alias_name)
133
134
  if index_date_pattern.empty?
134
135
  index_name_temp='<'+index_prefix.downcase+index_separator+app_name.downcase+'-000001>'
@@ -152,7 +153,7 @@ module Fluent::ElasticsearchIndexTemplate
152
153
  log.debug("The alias '#{deflector_alias_name}' is already present")
153
154
  end
154
155
  else
155
- log.info("No index and alias creation action performed because rollover_index is set to '#{rollover_index}'")
156
+ log.debug("No index and alias creation action performed because rollover_index or enable_ilm is set to: '#{rollover_index}', '#{enable_ilm}'")
156
157
  end
157
158
  end
158
159
 
@@ -49,7 +49,7 @@ module Fluent::Plugin
49
49
  end
50
50
  end
51
51
 
52
- RequestInfo = Struct.new(:host, :index)
52
+ RequestInfo = Struct.new(:host, :index, :ilm_index)
53
53
 
54
54
  attr_reader :alias_indexes
55
55
 
@@ -117,7 +117,8 @@ EOC
117
117
  config_param :index_date_pattern, :string, :default => "now/d"
118
118
  config_param :index_separator, :string, :default => "-"
119
119
  config_param :deflector_alias, :string, :default => nil
120
- config_param :index_prefix, :string, :default => "logstash"
120
+ config_param :index_prefix, :string, :default => "logstash",
121
+ obsoleted: "This parameter shouldn't be used in 4.0.0 or later. Specify ILM target index with using `index_name' w/o `logstash_format' or 'logstash_prefix' w/ `logstash_format' instead."
121
122
  config_param :application_name, :string, :default => "default"
122
123
  config_param :templates, :hash, :default => nil
123
124
  config_param :max_retry_putting_template, :integer, :default => 10
@@ -150,7 +151,7 @@ EOC
150
151
  config_param :ignore_exceptions, :array, :default => [], value_type: :string, :desc => "Ignorable exception list"
151
152
  config_param :exception_backup, :bool, :default => true, :desc => "Chunk backup flag when ignore exception occured"
152
153
  config_param :bulk_message_request_threshold, :size, :default => TARGET_BULK_BYTES
153
- config_param :compression_level, :enum, {list: [:no_compression, :best_speed, :best_compression, :default_compression], :default => :no_compression}
154
+ config_param :compression_level, :enum, list: [:no_compression, :best_speed, :best_compression, :default_compression], :default => :no_compression
154
155
  config_param :enable_ilm, :bool, :default => false
155
156
  config_param :ilm_policy_id, :string, :default => DEFAULT_POLICY_ID
156
157
  config_param :ilm_policy, :hash, :default => {}
@@ -173,8 +174,12 @@ EOC
173
174
  compat_parameters_convert(conf, :buffer)
174
175
 
175
176
  super
176
- raise Fluent::ConfigError, "'tag' or '_index' in chunk_keys is required." if not @buffer_config.chunk_keys.include? "tag" and not @buffer_config.chunk_keys.include? "_index"
177
-
177
+ if placeholder_substitution_needed_for_template?
178
+ # nop.
179
+ elsif not @buffer_config.chunk_keys.include? "tag" and
180
+ not @buffer_config.chunk_keys.include? "_index"
181
+ raise Fluent::ConfigError, "'tag' or '_index' in chunk_keys is required."
182
+ end
178
183
  @time_parser = create_time_parser
179
184
  @backend_options = backend_options
180
185
 
@@ -209,11 +214,15 @@ EOC
209
214
  @alias_indexes = []
210
215
  if !dry_run?
211
216
  if @template_name && @template_file
212
- if @rollover_index
213
- raise Fluent::ConfigError, "'deflector_alias' must be provided if 'rollover_index' is set true ." if not @deflector_alias
214
- end
215
217
  if @enable_ilm
216
- raise Fluent::ConfigError, "'rollover_index' and 'deflector_alias' must be provided if 'enable_ilm' is set true ." if !@deflector_alias &&!@deflector_alias
218
+ raise Fluent::ConfigError, "deflector_alias is prohibited to use with 'logstash_format at same time." if @logstash_format and @deflector_alias
219
+ end
220
+ if @logstash_format || placeholder_substitution_needed_for_template?
221
+ class << self
222
+ alias_method :template_installation, :template_installation_actual
223
+ end
224
+ else
225
+ template_installation_actual(@deflector_alias ? @deflector_alias : @index_name, @application_name, @index_name)
217
226
  end
218
227
  verify_ilm_working if @enable_ilm
219
228
  elsif @templates
@@ -298,10 +307,6 @@ EOC
298
307
  end
299
308
  end
300
309
 
301
- if @buffer_config.flush_thread_count < 2
302
- log.warn "To prevent events traffic jam, you should specify 2 or more 'flush_thread_count'."
303
- end
304
-
305
310
  # Consider missing the prefix of "$." in nested key specifiers.
306
311
  @id_key = convert_compat_id_key(@id_key) if @id_key
307
312
  @parent_key = convert_compat_id_key(@parent_key) if @parent_key
@@ -356,7 +361,8 @@ EOC
356
361
  begin
357
362
  placeholder_validate!(name, param)
358
363
  true
359
- rescue Fluent::ConfigError
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}")
360
366
  false
361
367
  end
362
368
  end
@@ -651,7 +657,12 @@ EOC
651
657
  else
652
658
  application_name = nil
653
659
  end
654
- return logstash_prefix, index_name, type_name, deflector_alias, application_name
660
+ if @pipeline
661
+ pipeline = extract_placeholders(@pipeline, chunk)
662
+ else
663
+ pipeline = nil
664
+ end
665
+ return logstash_prefix, index_name, type_name, deflector_alias, application_name, pipeline
655
666
  end
656
667
 
657
668
  def multi_workers_ready?
@@ -677,9 +688,9 @@ EOC
677
688
  begin
678
689
  meta, header, record = process_message(tag, meta, header, time, record, extracted_values)
679
690
  info = if @include_index_in_url
680
- RequestInfo.new(host, meta.delete("_index".freeze))
691
+ RequestInfo.new(host, meta.delete("_index".freeze), meta["_index".freeze])
681
692
  else
682
- RequestInfo.new(host, nil)
693
+ RequestInfo.new(host, nil, meta["_index".freeze])
683
694
  end
684
695
 
685
696
  if split_request?(bulk_message, info)
@@ -725,7 +736,7 @@ EOC
725
736
  end
726
737
 
727
738
  def process_message(tag, meta, header, time, record, extracted_values)
728
- logstash_prefix, index_name, type_name, deflector_alias, application_name = extracted_values
739
+ logstash_prefix, index_name, type_name, _deflector_alias, _application_name, pipeline = extracted_values
729
740
 
730
741
  if @flatten_hashes
731
742
  record = flatten_record(record)
@@ -793,7 +804,7 @@ EOC
793
804
  meta["_type".freeze] = target_type unless @last_seen_major_version >= 8
794
805
 
795
806
  if @pipeline
796
- meta["pipeline".freeze] = @pipeline
807
+ meta["pipeline".freeze] = pipeline
797
808
  end
798
809
 
799
810
  @meta_config_map.each do |record_accessor, meta_key|
@@ -825,25 +836,45 @@ EOC
825
836
  wio.string
826
837
  end
827
838
 
828
- # send_bulk given a specific bulk request, the original tag,
829
- # chunk, and bulk_message_count
830
- def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, info)
831
- logstash_prefix, index_name, type_name, deflector_alias, application_name = extracted_values
839
+ def placeholder_substitution_needed_for_template?
840
+ placeholder?(:host, @host.to_s) ||
841
+ placeholder?(:index_name, @index_name.to_s) ||
842
+ placeholder?(:logstash_prefix, @logstash_prefix.to_s) ||
843
+ placeholder?(:deflector_alias, @deflector_alias.to_s) ||
844
+ placeholder?(:application_name, @application_name.to_s)
845
+ end
846
+
847
+ def template_installation(deflector_alias, application_name, target_index, host)
848
+ # for safety.
849
+ end
850
+
851
+ def template_installation_actual(deflector_alias, application_name, target_index, host=nil)
832
852
  if @template_name && @template_file
833
853
  if @alias_indexes.include? deflector_alias
834
854
  log.debug("Index alias #{deflector_alias} already exists (cached)")
835
855
  else
836
856
  retry_operate(@max_retry_putting_template, @fail_on_putting_template_retry_exceed) do
837
857
  if @customize_template
838
- template_custom_install(@template_name, @template_file, @template_overwrite, @customize_template, @enable_ilm, deflector_alias, @ilm_policy_id, info.host)
858
+ template_custom_install(@template_name, @template_file, @template_overwrite, @customize_template, @enable_ilm, deflector_alias, @ilm_policy_id, host)
839
859
  else
840
- template_install(@template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, @ilm_policy_id, info.host)
860
+ template_install(@template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, @ilm_policy_id, host)
841
861
  end
842
- create_rollover_alias(@index_prefix, @rollover_index, deflector_alias, application_name, @index_date_pattern, @index_separator, @enable_ilm, @ilm_policy_id, @ilm_policy, info.host)
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)
843
863
  end
844
864
  @alias_indexes << deflector_alias unless deflector_alias.nil?
845
865
  end
846
866
  end
867
+ end
868
+
869
+ # send_bulk given a specific bulk request, the original tag,
870
+ # chunk, and bulk_message_count
871
+ 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
873
+ if deflector_alias
874
+ template_installation(deflector_alias, application_name, index_name, info.host)
875
+ else
876
+ template_installation(info.ilm_index, application_name, @logstash_format ? logstash_prefix : index_name, info.host)
877
+ end
847
878
 
848
879
  begin
849
880
 
@@ -246,7 +246,7 @@ module Fluent::Plugin
246
246
  # check for '${ ... }'
247
247
  # yes => `eval`
248
248
  # no => return param
249
- return param if (param =~ /\${.+}/).nil?
249
+ return param if (param.to_s =~ /\${.+}/).nil?
250
250
 
251
251
  # check for 'tag_parts[]'
252
252
  # separated by a delimiter (default '.')
@@ -307,7 +307,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
307
307
  }
308
308
  end
309
309
 
310
- test 'invalid configuration of index lifecycle management' do
310
+ test 'valid configuration of index lifecycle management' do
311
311
  cwd = File.dirname(__FILE__)
312
312
  template_file = File.join(cwd, 'test_template.json')
313
313
 
@@ -316,7 +316,25 @@ class ElasticsearchOutput < Test::Unit::TestCase
316
316
  template_name logstash
317
317
  template_file #{template_file}
318
318
  }
319
- assert_raise(Fluent::ConfigError) {
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: {})
336
+
337
+ assert_nothing_raised {
320
338
  driver(config)
321
339
  }
322
340
  end
@@ -379,6 +397,71 @@ class ElasticsearchOutput < Test::Unit::TestCase
379
397
  end
380
398
  end
381
399
 
400
+ sub_test_case "placeholder substitution needed?" do
401
+ data("host placeholder" => ["host", "host-${tag}.google.com"],
402
+ "logstash_prefix_placeholder" => ["logstash_prefix", "fluentd-${tag}"],
403
+ "deflector_alias_placeholder" => ["deflector_alias", "fluentd-${tag}"],
404
+ "application_name_placeholder" => ["application_name", "fluentd-${tag}"],
405
+ )
406
+ test 'tag placeholder' do |data|
407
+ param, value = data
408
+ config = Fluent::Config::Element.new(
409
+ 'ROOT', '', {
410
+ '@type' => 'elasticsearch',
411
+ param => value
412
+ }, [
413
+ Fluent::Config::Element.new('buffer', 'tag', {}, [])
414
+ ])
415
+ driver(config)
416
+
417
+ assert_true driver.instance.placeholder_substitution_needed_for_template?
418
+ end
419
+
420
+
421
+ data("host placeholder" => ["host", "host-%Y%m%d.google.com"],
422
+ "logstash_prefix_placeholder" => ["logstash_prefix", "fluentd-%Y%m%d"],
423
+ "deflector_alias_placeholder" => ["deflector_alias", "fluentd-%Y%m%d"],
424
+ "application_name_placeholder" => ["application_name", "fluentd-%Y%m%d"],
425
+ )
426
+ test 'time placeholder' do |data|
427
+ param, value = data
428
+ config = Fluent::Config::Element.new(
429
+ 'ROOT', '', {
430
+ '@type' => 'elasticsearch',
431
+ param => value
432
+ }, [
433
+ Fluent::Config::Element.new('buffer', 'time', {
434
+ 'timekey' => '1d'
435
+ }, [])
436
+ ])
437
+ driver(config)
438
+
439
+ assert_true driver.instance.placeholder_substitution_needed_for_template?
440
+ end
441
+
442
+ data("host placeholder" => ["host", "host-${mykey}.google.com"],
443
+ "logstash_prefix_placeholder" => ["logstash_prefix", "fluentd-${mykey}"],
444
+ "deflector_alias_placeholder" => ["deflector_alias", "fluentd-${mykey}"],
445
+ "application_name_placeholder" => ["application_name", "fluentd-${mykey}"],
446
+ )
447
+ test 'custom placeholder' do |data|
448
+ param, value = data
449
+ config = Fluent::Config::Element.new(
450
+ 'ROOT', '', {
451
+ '@type' => 'elasticsearch',
452
+ param => value
453
+ }, [
454
+ Fluent::Config::Element.new('buffer', 'mykey', {
455
+ 'chunk_keys' => 'mykey',
456
+ 'timekey' => '1d',
457
+ }, [])
458
+ ])
459
+ driver(config)
460
+
461
+ assert_true driver.instance.placeholder_substitution_needed_for_template?
462
+ end
463
+ end
464
+
382
465
  sub_test_case 'chunk_keys requirement' do
383
466
  test 'tag in chunk_keys' do
384
467
  assert_nothing_raised do
@@ -462,27 +545,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
462
545
  end
463
546
  end
464
547
 
465
- sub_test_case 'connection exceptions' do
466
- test 'default connection exception' do
467
- driver(Fluent::Config::Element.new(
468
- 'ROOT', '', {
469
- '@type' => 'elasticsearch',
470
- 'host' => 'log.google.com',
471
- 'port' => 777,
472
- 'scheme' => 'https',
473
- 'path' => '/es/',
474
- 'user' => 'john',
475
- 'password' => 'doe',
476
- }, [
477
- Fluent::Config::Element.new('buffer', 'tag', {
478
- }, [])
479
- ]
480
- ))
481
- logs = driver.logs
482
- assert_logs_include(logs, /you should specify 2 or more 'flush_thread_count'/, 1)
483
- end
484
- end
485
-
486
548
  class GetElasticsearchVersionTest < self
487
549
  def create_driver(conf='', client_version="\"5.0\"")
488
550
  # For request stub to detect compatibility.
@@ -584,10 +646,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
584
646
  to_return(:status => 200, :body => "", :headers => {})
585
647
 
586
648
  driver(config)
587
- stub_elastic("https://logs.google.com:777/es//_bulk")
588
- driver.run(default_tag: 'test') do
589
- driver.feed(sample_record)
590
- end
649
+
591
650
  assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
592
651
  end
593
652
 
@@ -600,7 +659,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
600
659
  end
601
660
  end
602
661
 
603
-
604
662
  def test_template_create_with_rollover_index_and_default_ilm
605
663
  cwd = File.dirname(__FILE__)
606
664
  template_file = File.join(cwd, 'test_template.json')
@@ -614,9 +672,74 @@ class ElasticsearchOutput < Test::Unit::TestCase
614
672
  password doe
615
673
  template_name logstash
616
674
  template_file #{template_file}
617
- rollover_index true
675
+ index_date_pattern now/w{xxxx.ww}
676
+ index_name logstash
677
+ enable_ilm true
678
+ }
679
+
680
+ # connection start
681
+ stub_request(:head, "https://logs.google.com:777/es//").
682
+ with(basic_auth: ['john', 'doe']).
683
+ to_return(:status => 200, :body => "", :headers => {})
684
+ # check if template exists
685
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
686
+ with(basic_auth: ['john', 'doe']).
687
+ to_return(:status => 404, :body => "", :headers => {})
688
+ # creation
689
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash").
690
+ with(basic_auth: ['john', 'doe']).
691
+ to_return(:status => 200, :body => "", :headers => {})
692
+ # check if alias exists
693
+ stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
694
+ with(basic_auth: ['john', 'doe']).
695
+ to_return(:status => 404, :body => "", :headers => {})
696
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
697
+ with(basic_auth: ['john', 'doe']).
698
+ to_return(status: 404, body: "", headers: {})
699
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash").
700
+ with(basic_auth: ['john', 'doe'],
701
+ 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}").
702
+ to_return(status: 200, body: "", headers: {})
703
+ # put the alias for the index
704
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
705
+ with(basic_auth: ['john', 'doe']).
706
+ to_return(:status => 200, :body => "", :headers => {})
707
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/logstash").
708
+ with(basic_auth: ['john', 'doe'],
709
+ :body => "{\"aliases\":{\"logstash\":{\"is_write_index\":true}}}").
710
+ to_return(:status => 200, :body => "", :headers => {})
711
+ stub_request(:get, "https://logs.google.com:777/es//_xpack").
712
+ with(basic_auth: ['john', 'doe']).
713
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
714
+ stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
715
+ with(basic_auth: ['john', 'doe']).
716
+ to_return(:status => 404, :body => "", :headers => {})
717
+ stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/logstash-policy").
718
+ with(basic_auth: ['john', 'doe'],
719
+ :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
720
+ to_return(:status => 200, :body => "", :headers => {})
721
+
722
+ driver(config)
723
+
724
+ assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
725
+ end
726
+
727
+ def test_template_create_with_rollover_index_and_default_ilm_with_deflector_alias
728
+ cwd = File.dirname(__FILE__)
729
+ template_file = File.join(cwd, 'test_template.json')
730
+
731
+ config = %{
732
+ host logs.google.com
733
+ port 777
734
+ scheme https
735
+ path /es/
736
+ user john
737
+ password doe
738
+ template_name logstash
739
+ template_file #{template_file}
618
740
  index_date_pattern now/w{xxxx.ww}
619
741
  deflector_alias myapp_deflector
742
+ index_name logstash
620
743
  enable_ilm true
621
744
  }
622
745
 
@@ -664,12 +787,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
664
787
 
665
788
  driver(config)
666
789
 
667
- elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
668
- driver.run(default_tag: 'test') do
669
- driver.feed(sample_record)
670
- end
671
-
672
- assert_requested(elastic_request)
790
+ assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_deflector", times: 1)
673
791
  end
674
792
 
675
793
  def test_template_create_with_rollover_index_and_default_ilm_with_empty_index_date_pattern
@@ -685,9 +803,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
685
803
  password doe
686
804
  template_name logstash
687
805
  template_file #{template_file}
688
- rollover_index true
689
806
  index_date_pattern ""
690
- deflector_alias myapp_deflector
807
+ index_name logstash
691
808
  enable_ilm true
692
809
  }
693
810
 
@@ -704,23 +821,23 @@ class ElasticsearchOutput < Test::Unit::TestCase
704
821
  with(basic_auth: ['john', 'doe']).
705
822
  to_return(:status => 200, :body => "", :headers => {})
706
823
  # check if alias exists
707
- stub_request(:head, "https://logs.google.com:777/es//_alias/myapp_deflector").
824
+ stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
708
825
  with(basic_auth: ['john', 'doe']).
709
826
  to_return(:status => 404, :body => "", :headers => {})
710
- stub_request(:get, "https://logs.google.com:777/es//_template/myapp_deflector").
827
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
711
828
  with(basic_auth: ['john', 'doe']).
712
829
  to_return(status: 404, body: "", headers: {})
713
830
  stub_request(:put, "https://logs.google.com:777/es//_template/myapp_deflector").
714
831
  with(basic_auth: ['john', 'doe'],
715
- 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}").
832
+ 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}").
716
833
  to_return(status: 200, body: "", headers: {})
717
834
  # put the alias for the index
718
835
  stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-000001%3E").
719
836
  with(basic_auth: ['john', 'doe']).
720
837
  to_return(:status => 200, :body => "", :headers => {})
721
- stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-000001%3E/_alias/myapp_deflector").
838
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-000001%3E/_alias/logstash").
722
839
  with(basic_auth: ['john', 'doe'],
723
- :body => "{\"aliases\":{\"myapp_deflector\":{\"is_write_index\":true}}}").
840
+ :body => "{\"aliases\":{\"logstash\":{\"is_write_index\":true}}}").
724
841
  to_return(:status => 200, :body => "", :headers => {})
725
842
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
726
843
  with(basic_auth: ['john', 'doe']).
@@ -735,12 +852,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
735
852
 
736
853
  driver(config)
737
854
 
738
- elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
739
- driver.run(default_tag: 'test') do
740
- driver.feed(sample_record)
741
- end
742
-
743
- assert_requested(elastic_request)
855
+ assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
744
856
  end
745
857
 
746
858
  def test_template_create_with_rollover_index_and_custom_ilm
@@ -756,11 +868,10 @@ class ElasticsearchOutput < Test::Unit::TestCase
756
868
  password doe
757
869
  template_name logstash
758
870
  template_file #{template_file}
759
- rollover_index true
760
871
  index_date_pattern now/w{xxxx.ww}
761
- deflector_alias myapp_deflector
762
872
  ilm_policy_id fluentd-policy
763
873
  enable_ilm true
874
+ index_name logstash
764
875
  ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_size":"70gb", "max_age":"30d"}}}}}}
765
876
  }
766
877
 
@@ -777,24 +888,23 @@ class ElasticsearchOutput < Test::Unit::TestCase
777
888
  with(basic_auth: ['john', 'doe']).
778
889
  to_return(:status => 200, :body => "", :headers => {})
779
890
  # check if alias exists
780
- stub_request(:head, "https://logs.google.com:777/es//_alias/myapp_deflector").
891
+ stub_request(:head, "https://logs.google.com:777/es//_alias/logstash").
781
892
  with(basic_auth: ['john', 'doe']).
782
893
  to_return(:status => 404, :body => "", :headers => {})
783
- stub_request(:get, "https://logs.google.com:777/es//_template/myapp_deflector").
894
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash").
784
895
  with(basic_auth: ['john', 'doe']).
785
896
  to_return(status: 404, body: "", headers: {})
786
- stub_request(:put, "https://logs.google.com:777/es//_template/myapp_deflector").
897
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash").
787
898
  with(basic_auth: ['john', 'doe'],
788
- body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-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}").
899
+ body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"myalogs\"},\"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\":\"mylogs-*\",\"order\":51}").
789
900
  to_return(status: 200, body: "", headers: {})
790
901
  # put the alias for the index
791
902
  stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
792
903
  with(basic_auth: ['john', 'doe']).
793
904
  to_return(:status => 200, :body => "", :headers => {})
794
- stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/myapp_deflector").
795
- with(basic_auth: ['john', 'doe'],
796
- :body => "{\"aliases\":{\"myapp_deflector\":{\"is_write_index\":true}}}").
797
- to_return(:status => 200, :body => "", :headers => {})
905
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/logstash").
906
+ with(body: "{\"aliases\":{\"logstash\":{\"is_write_index\":true}}}").
907
+ to_return(status: 200, body: "", headers: {})
798
908
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
799
909
  with(basic_auth: ['john', 'doe']).
800
910
  to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
@@ -808,12 +918,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
808
918
 
809
919
  driver(config)
810
920
 
811
- elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
812
- driver.run(default_tag: 'test') do
813
- driver.feed(sample_record)
814
- end
815
-
816
- assert_requested(elastic_request)
921
+ assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
817
922
  end
818
923
 
819
924
  def test_template_create_with_rollover_index_and_default_ilm_and_placeholders
@@ -829,10 +934,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
829
934
  password doe
830
935
  template_name logstash
831
936
  template_file #{template_file}
832
- rollover_index true
833
937
  index_date_pattern now/w{xxxx.ww}
834
- index_name fluentd-${tag}
835
- deflector_alias myapp_deflector-${tag}
938
+ index_name logstash-${tag}
836
939
  enable_ilm true
837
940
  }
838
941
 
@@ -849,23 +952,23 @@ class ElasticsearchOutput < Test::Unit::TestCase
849
952
  with(basic_auth: ['john', 'doe']).
850
953
  to_return(:status => 200, :body => "", :headers => {})
851
954
  # check if alias exists
852
- stub_request(:head, "https://logs.google.com:777/es//_alias/myapp_deflector-test").
955
+ stub_request(:head, "https://logs.google.com:777/es//_alias/logstash-test").
853
956
  with(basic_auth: ['john', 'doe']).
854
957
  to_return(:status => 404, :body => "", :headers => {})
855
- stub_request(:get, "https://logs.google.com:777/es//_template/myapp_deflector-test").
958
+ stub_request(:get, "https://logs.google.com:777/es//_template/logstash-test").
856
959
  with(basic_auth: ['john', 'doe']).
857
960
  to_return(status: 404, body: "", headers: {})
858
- stub_request(:put, "https://logs.google.com:777/es//_template/myapp_deflector-test").
961
+ stub_request(:put, "https://logs.google.com:777/es//_template/logstash-test").
859
962
  with(basic_auth: ['john', 'doe'],
860
- body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"myapp_deflector-test\"},\"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-test-*\",\"order\":52}").
963
+ body: "{\"settings\":{\"number_of_shards\":1,\"index.lifecycle.name\":\"logstash-policy\",\"index.lifecycle.rollover_alias\":\"logstash-test\"},\"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-test-*\",\"order\":52}").
861
964
  to_return(status: 200, body: "", headers: {})
862
965
  # put the alias for the index
863
- stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
966
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-test-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
864
967
  with(basic_auth: ['john', 'doe']).
865
968
  to_return(:status => 200, :body => "", :headers => {})
866
- stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/myapp_deflector-test").
969
+ stub_request(:put, "https://logs.google.com:777/es//%3Clogstash-test-default-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/logstash-test").
867
970
  with(basic_auth: ['john', 'doe'],
868
- :body => "{\"aliases\":{\"myapp_deflector-test\":{\"is_write_index\":true}}}").
971
+ :body => "{\"aliases\":{\"logstash-test\":{\"is_write_index\":true}}}").
869
972
  to_return(:status => 200, :body => "", :headers => {})
870
973
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
871
974
  with(basic_auth: ['john', 'doe']).
@@ -884,9 +987,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
884
987
  driver.run(default_tag: 'test') do
885
988
  driver.feed(sample_record)
886
989
  end
887
- assert_equal('fluentd-test', index_cmds.first['index']['_index'])
990
+ assert_equal('logstash-test', index_cmds.first['index']['_index'])
888
991
 
889
- assert_equal ["myapp_deflector-test"], driver.instance.alias_indexes
992
+ assert_equal ["logstash-test"], driver.instance.alias_indexes
890
993
 
891
994
  assert_requested(elastic_request)
892
995
  end
@@ -923,11 +1026,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
923
1026
 
924
1027
  driver(config)
925
1028
 
926
- stub_elastic("https://logs.google.com:777/es//_bulk")
927
- driver.run(default_tag: 'test') do
928
- driver.feed(sample_record)
929
- end
930
-
931
1029
  assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_alias_template", times: 1)
932
1030
  end
933
1031
 
@@ -973,6 +1071,56 @@ class ElasticsearchOutput < Test::Unit::TestCase
973
1071
  cwd = File.dirname(__FILE__)
974
1072
  template_file = File.join(cwd, 'test_alias_template.json')
975
1073
 
1074
+ config = %{
1075
+ host logs.google.com
1076
+ port 777
1077
+ scheme https
1078
+ path /es/
1079
+ user john
1080
+ password doe
1081
+ template_name myapp_alias_template
1082
+ template_file #{template_file}
1083
+ customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
1084
+ rollover_index true
1085
+ index_date_pattern now/w{xxxx.ww}
1086
+ index_name mylogs
1087
+ application_name myapp
1088
+ }
1089
+
1090
+ # connection start
1091
+ stub_request(:head, "https://logs.google.com:777/es//").
1092
+ with(basic_auth: ['john', 'doe']).
1093
+ to_return(:status => 200, :body => "", :headers => {})
1094
+ # check if template exists
1095
+ stub_request(:get, "https://logs.google.com:777/es//_template/myapp_alias_template").
1096
+ with(basic_auth: ['john', 'doe']).
1097
+ to_return(:status => 404, :body => "", :headers => {})
1098
+ # creation
1099
+ stub_request(:put, "https://logs.google.com:777/es//_template/myapp_alias_template").
1100
+ with(basic_auth: ['john', 'doe']).
1101
+ to_return(:status => 200, :body => "", :headers => {})
1102
+ # creation of index which can rollover
1103
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1104
+ with(basic_auth: ['john', 'doe']).
1105
+ to_return(:status => 200, :body => "", :headers => {})
1106
+ # check if alias exists
1107
+ stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
1108
+ with(basic_auth: ['john', 'doe']).
1109
+ to_return(:status => 404, :body => "", :headers => {})
1110
+ # put the alias for the index
1111
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/mylogs").
1112
+ with(basic_auth: ['john', 'doe']).
1113
+ to_return(:status => 200, :body => "", :headers => {})
1114
+
1115
+ driver(config)
1116
+
1117
+ assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_alias_template", times: 1)
1118
+ end
1119
+
1120
+ def test_custom_template_with_rollover_index_create_and_deflector_alias
1121
+ cwd = File.dirname(__FILE__)
1122
+ template_file = File.join(cwd, 'test_alias_template.json')
1123
+
976
1124
  config = %{
977
1125
  host logs.google.com
978
1126
  port 777
@@ -986,7 +1134,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
986
1134
  rollover_index true
987
1135
  index_date_pattern now/w{xxxx.ww}
988
1136
  deflector_alias myapp_deflector
989
- index_prefix mylogs
1137
+ index_name mylogs
990
1138
  application_name myapp
991
1139
  }
992
1140
 
@@ -1017,12 +1165,63 @@ class ElasticsearchOutput < Test::Unit::TestCase
1017
1165
 
1018
1166
  driver(config)
1019
1167
 
1020
- stub_elastic("https://logs.google.com:777/es//_bulk")
1021
- driver.run(default_tag: 'test') do
1168
+ assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_alias_template", times: 1)
1169
+ end
1170
+
1171
+ def test_custom_template_with_rollover_index_create_with_logstash_format
1172
+ cwd = File.dirname(__FILE__)
1173
+ template_file = File.join(cwd, 'test_alias_template.json')
1174
+
1175
+ config = %{
1176
+ host logs.google.com
1177
+ port 777
1178
+ scheme https
1179
+ path /es/
1180
+ user john
1181
+ password doe
1182
+ template_name myapp_alias_template
1183
+ template_file #{template_file}
1184
+ customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
1185
+ rollover_index true
1186
+ index_date_pattern now/w{xxxx.ww}
1187
+ logstash_format true
1188
+ logstash_prefix mylogs
1189
+ application_name myapp
1190
+ }
1191
+
1192
+ # connection start
1193
+ stub_request(:head, "https://logs.google.com:777/es//").
1194
+ with(basic_auth: ['john', 'doe']).
1195
+ to_return(:status => 200, :body => "", :headers => {})
1196
+ # check if template exists
1197
+ stub_request(:get, "https://logs.google.com:777/es//_template/myapp_alias_template").
1198
+ with(basic_auth: ['john', 'doe']).
1199
+ to_return(:status => 404, :body => "", :headers => {})
1200
+ # creation
1201
+ stub_request(:put, "https://logs.google.com:777/es//_template/myapp_alias_template").
1202
+ with(basic_auth: ['john', 'doe']).
1203
+ to_return(:status => 200, :body => "", :headers => {})
1204
+ # creation of index which can rollover
1205
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1206
+ with(basic_auth: ['john', 'doe']).
1207
+ to_return(:status => 200, :body => "", :headers => {})
1208
+ # check if alias exists
1209
+ timestr = Time.now.strftime("%Y.%m.%d")
1210
+ stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-#{timestr}").
1211
+ with(basic_auth: ['john', 'doe']).
1212
+ to_return(:status => 404, :body => "", :headers => {})
1213
+ # put the alias for the index
1214
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/mylogs-#{timestr}").
1215
+ with(basic_auth: ['john', 'doe']).
1216
+ to_return(:status => 200, :body => "", :headers => {})
1217
+
1218
+ driver(config)
1219
+
1220
+ elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
1221
+ driver.run(default_tag: 'custom-test') do
1022
1222
  driver.feed(sample_record)
1023
1223
  end
1024
-
1025
- assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_alias_template", times: 1)
1224
+ assert_requested(elastic_request)
1026
1225
  end
1027
1226
 
1028
1227
  class CustomTemplateIndexLifecycleManagementTest < self
@@ -1048,10 +1247,78 @@ class ElasticsearchOutput < Test::Unit::TestCase
1048
1247
  template_name myapp_alias_template
1049
1248
  template_file #{template_file}
1050
1249
  customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
1051
- rollover_index true
1250
+ index_date_pattern now/w{xxxx.ww}
1251
+ index_name mylogs
1252
+ application_name myapp
1253
+ ilm_policy_id fluentd-policy
1254
+ enable_ilm true
1255
+ }
1256
+
1257
+ # connection start
1258
+ stub_request(:head, "https://logs.google.com:777/es//").
1259
+ with(basic_auth: ['john', 'doe']).
1260
+ to_return(:status => 200, :body => "", :headers => {})
1261
+ # check if template exists
1262
+ stub_request(:get, "https://logs.google.com:777/es//_template/myapp_alias_template").
1263
+ with(basic_auth: ['john', 'doe']).
1264
+ to_return(:status => 404, :body => "", :headers => {})
1265
+ # creation
1266
+ stub_request(:put, "https://logs.google.com:777/es//_template/myapp_alias_template").
1267
+ with(basic_auth: ['john', 'doe']).
1268
+ to_return(:status => 200, :body => "", :headers => {})
1269
+ # creation of index which can rollover
1270
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1271
+ with(basic_auth: ['john', 'doe']).
1272
+ to_return(:status => 200, :body => "", :headers => {})
1273
+ # check if alias exists
1274
+ stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
1275
+ with(basic_auth: ['john', 'doe']).
1276
+ to_return(:status => 404, :body => "", :headers => {})
1277
+ stub_request(:get, "https://logs.google.com:777/es//_template/mylogs").
1278
+ with(basic_auth: ['john', 'doe']).
1279
+ to_return(status: 404, body: "", headers: {})
1280
+ stub_request(:put, "https://logs.google.com:777/es//_template/mylogs").
1281
+ with(basic_auth: ['john', 'doe'],
1282
+ body: "{\"order\":6,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-*\"}").
1283
+ to_return(status: 200, body: "", headers: {})
1284
+ # put the alias for the index
1285
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/mylogs").
1286
+ with(basic_auth: ['john', 'doe'],
1287
+ :body => "{\"aliases\":{\"mylogs\":{\"is_write_index\":true}}}").
1288
+ to_return(:status => 200, :body => "", :headers => {})
1289
+ stub_request(:get, "https://logs.google.com:777/es//_xpack").
1290
+ with(basic_auth: ['john', 'doe']).
1291
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json"})
1292
+ stub_request(:get, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1293
+ with(basic_auth: ['john', 'doe']).
1294
+ to_return(:status => 404, :body => "", :headers => {})
1295
+ stub_request(:put, "https://logs.google.com:777/es//_ilm/policy/fluentd-policy").
1296
+ with(basic_auth: ['john', 'doe'],
1297
+ :body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}").
1298
+ to_return(:status => 200, :body => "", :headers => {})
1299
+
1300
+ driver(config)
1301
+
1302
+ assert_requested(:put, "https://logs.google.com:777/es//_template/mylogs", times: 1)
1303
+ end
1304
+
1305
+ def test_custom_template_with_rollover_index_create_and_default_ilm_with_deflector_alias
1306
+ cwd = File.dirname(__FILE__)
1307
+ template_file = File.join(cwd, 'test_alias_template.json')
1308
+
1309
+ config = %{
1310
+ host logs.google.com
1311
+ port 777
1312
+ scheme https
1313
+ path /es/
1314
+ user john
1315
+ password doe
1316
+ template_name myapp_alias_template
1317
+ template_file #{template_file}
1318
+ customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
1052
1319
  index_date_pattern now/w{xxxx.ww}
1053
1320
  deflector_alias myapp_deflector
1054
- index_prefix mylogs
1321
+ index_name mylogs
1055
1322
  application_name myapp
1056
1323
  ilm_policy_id fluentd-policy
1057
1324
  enable_ilm true
@@ -1102,12 +1369,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
1102
1369
 
1103
1370
  driver(config)
1104
1371
 
1105
- elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
1106
- driver.run(default_tag: 'test') do
1107
- driver.feed(sample_record)
1108
- end
1109
-
1110
- assert_requested(elastic_request)
1372
+ assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_deflector", times: 1)
1111
1373
  end
1112
1374
 
1113
1375
  def test_custom_template_with_rollover_index_create_and_default_ilm_and_placeholders
@@ -1124,11 +1386,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
1124
1386
  template_name myapp_alias_template
1125
1387
  template_file #{template_file}
1126
1388
  customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
1127
- rollover_index true
1128
1389
  index_date_pattern now/w{xxxx.ww}
1129
- index_name fluentd-${tag}
1130
- deflector_alias myapp_deflector-${tag}
1131
- index_prefix mylogs
1390
+ index_name mylogs-${tag}
1132
1391
  application_name myapp
1133
1392
  ilm_policy_id fluentd-policy
1134
1393
  enable_ilm true
@@ -1147,24 +1406,24 @@ class ElasticsearchOutput < Test::Unit::TestCase
1147
1406
  with(basic_auth: ['john', 'doe']).
1148
1407
  to_return(:status => 200, :body => "", :headers => {})
1149
1408
  # creation of index which can rollover
1150
- stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1409
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-custom-test-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
1151
1410
  with(basic_auth: ['john', 'doe']).
1152
1411
  to_return(:status => 200, :body => "", :headers => {})
1153
1412
  # check if alias exists
1154
- stub_request(:head, "https://logs.google.com:777/es//_alias/myapp_deflector-custom-test").
1413
+ stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs-custom-test").
1155
1414
  with(basic_auth: ['john', 'doe']).
1156
1415
  to_return(:status => 404, :body => "", :headers => {})
1157
- stub_request(:get, "https://logs.google.com:777/es//_template/myapp_deflector-custom-test").
1416
+ stub_request(:get, "https://logs.google.com:777/es//_template/mylogs-custom-test").
1158
1417
  with(basic_auth: ['john', 'doe']).
1159
1418
  to_return(status: 404, body: "", headers: {})
1160
- stub_request(:put, "https://logs.google.com:777/es//_template/myapp_deflector-custom-test").
1419
+ stub_request(:put, "https://logs.google.com:777/es//_template/mylogs-custom-test").
1161
1420
  with(basic_auth: ['john', 'doe'],
1162
- body: "{\"order\":8,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"myapp_deflector-custom-test\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"myapp_deflector-custom-test-*\"}").
1421
+ body: "{\"order\":8,\"settings\":{\"index.lifecycle.name\":\"fluentd-policy\",\"index.lifecycle.rollover_alias\":\"mylogs-custom-test\"},\"mappings\":{},\"aliases\":{\"myapp-logs-alias\":{}},\"index_patterns\":\"mylogs-custom-test-*\"}").
1163
1422
  to_return(status: 200, body: "", headers: {})
1164
1423
  # put the alias for the index
1165
- stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/myapp_deflector-custom-test").
1424
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-custom-test-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/mylogs-custom-test").
1166
1425
  with(basic_auth: ['john', 'doe'],
1167
- :body => "{\"aliases\":{\"myapp_deflector-custom-test\":{\"is_write_index\":true}}}").
1426
+ :body => "{\"aliases\":{\"mylogs-custom-test\":{\"is_write_index\":true}}}").
1168
1427
  to_return(:status => 200, :body => "", :headers => {})
1169
1428
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1170
1429
  with(basic_auth: ['john', 'doe']).
@@ -1183,9 +1442,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
1183
1442
  driver.run(default_tag: 'custom-test') do
1184
1443
  driver.feed(sample_record)
1185
1444
  end
1186
- assert_equal('fluentd-custom-test', index_cmds.first['index']['_index'])
1445
+ assert_equal('mylogs-custom-test', index_cmds.first['index']['_index'])
1187
1446
 
1188
- assert_equal ["myapp_deflector-custom-test"], driver.instance.alias_indexes
1447
+ assert_equal ["mylogs-custom-test"], driver.instance.alias_indexes
1189
1448
 
1190
1449
  assert_requested(elastic_request)
1191
1450
  end
@@ -1204,10 +1463,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
1204
1463
  template_name myapp_alias_template
1205
1464
  template_file #{template_file}
1206
1465
  customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
1207
- rollover_index true
1208
1466
  index_date_pattern now/w{xxxx.ww}
1209
- deflector_alias myapp_deflector
1210
- index_prefix mylogs
1467
+ index_name mylogs
1211
1468
  application_name myapp
1212
1469
  ilm_policy_id fluentd-policy
1213
1470
  enable_ilm true
@@ -1231,19 +1488,19 @@ class ElasticsearchOutput < Test::Unit::TestCase
1231
1488
  with(basic_auth: ['john', 'doe']).
1232
1489
  to_return(:status => 200, :body => "", :headers => {})
1233
1490
  # check if alias exists
1234
- stub_request(:head, "https://logs.google.com:777/es//_alias/myapp_deflector").
1491
+ stub_request(:head, "https://logs.google.com:777/es//_alias/mylogs").
1235
1492
  with(basic_auth: ['john', 'doe']).
1236
1493
  to_return(:status => 404, :body => "", :headers => {})
1237
- stub_request(:get, "https://logs.google.com:777/es//_template/myapp_deflector").
1494
+ stub_request(:get, "https://logs.google.com:777/es//_template/mylogs").
1238
1495
  with(basic_auth: ['john', 'doe']).
1239
1496
  to_return(status: 404, body: "", headers: {})
1240
- stub_request(:put, "https://logs.google.com:777/es//_template/myapp_deflector").
1497
+ stub_request(:put, "https://logs.google.com:777/es//_template/mylogs").
1241
1498
  with(basic_auth: ['john', 'doe']).
1242
1499
  to_return(status: 200, body: "", headers: {})
1243
1500
  # put the alias for the index
1244
- stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/myapp_deflector").
1501
+ stub_request(:put, "https://logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/mylogs").
1245
1502
  with(basic_auth: ['john', 'doe'],
1246
- :body => "{\"aliases\":{\"myapp_deflector\":{\"is_write_index\":true}}}").
1503
+ :body => "{\"aliases\":{\"mylogs\":{\"is_write_index\":true}}}").
1247
1504
  to_return(:status => 200, :body => "", :headers => {})
1248
1505
  stub_request(:get, "https://logs.google.com:777/es//_xpack").
1249
1506
  with(basic_auth: ['john', 'doe']).
@@ -1258,12 +1515,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
1258
1515
 
1259
1516
  driver(config)
1260
1517
 
1261
- elastic_request = stub_elastic("https://logs.google.com:777/es//_bulk")
1262
- driver.run(default_tag: 'test') do
1263
- driver.feed(sample_record)
1264
- end
1265
-
1266
- assert_requested(elastic_request)
1518
+ assert_requested(:put, "https://logs.google.com:777/es//_template/mylogs", times: 1)
1267
1519
  end
1268
1520
  end
1269
1521
 
@@ -1298,11 +1550,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1298
1550
 
1299
1551
  driver(config)
1300
1552
 
1301
- stub_elastic("https://logs.google.com:777/es//_bulk")
1302
- driver.run(default_tag: 'test') do
1303
- driver.feed(sample_record)
1304
- end
1305
-
1306
1553
  assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
1307
1554
  end
1308
1555
 
@@ -1338,11 +1585,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1338
1585
 
1339
1586
  driver(config)
1340
1587
 
1341
- stub_elastic("https://logs.google.com:777/es//_bulk")
1342
- driver.run(default_tag: 'test') do
1343
- driver.feed(sample_record)
1344
- end
1345
-
1346
1588
  assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_alias_template", times: 1)
1347
1589
  end
1348
1590
 
@@ -1363,7 +1605,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
1363
1605
  customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
1364
1606
  deflector_alias myapp_deflector
1365
1607
  rollover_index true
1366
- index_prefix mylogs
1608
+ index_name mylogs
1367
1609
  application_name myapp
1368
1610
  }
1369
1611
 
@@ -1394,11 +1636,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1394
1636
 
1395
1637
  driver(config)
1396
1638
 
1397
- stub_elastic("https://logs.google.com:777/es//_bulk")
1398
- driver.run(default_tag: 'test') do
1399
- driver.feed(sample_record)
1400
- end
1401
-
1402
1639
  assert_requested(:put, "https://logs.google.com:777/es//_template/myapp_alias_template", times: 1)
1403
1640
  end
1404
1641
 
@@ -1423,13 +1660,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
1423
1660
  with(basic_auth: ['john', 'doe']).
1424
1661
  to_return(:status => 404, :body => "", :headers => {})
1425
1662
 
1426
- driver(config)
1427
1663
 
1428
- stub_elastic("https://logs.google.com:777/es//_bulk")
1429
1664
  assert_raise(RuntimeError) {
1430
- driver.run(default_tag: 'test') do
1431
- driver.feed(sample_record)
1432
- end
1665
+ driver(config)
1433
1666
  }
1434
1667
  end
1435
1668
 
@@ -1497,11 +1730,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
1497
1730
  raise Faraday::ConnectionFailed, "Test message"
1498
1731
  end
1499
1732
 
1500
- driver(config)
1501
-
1502
- stub_elastic("https://logs.google.com:777/es//_bulk")
1503
- driver.run(default_tag: 'test') do
1504
- driver.feed(sample_record)
1733
+ assert_raise(Fluent::Plugin::ElasticsearchError::RetryableOperationExhaustedFailure) do
1734
+ driver(config)
1505
1735
  end
1506
1736
 
1507
1737
  assert_equal(4, connection_resets)
@@ -1534,11 +1764,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1534
1764
 
1535
1765
  driver(config)
1536
1766
 
1537
- stub_elastic("https://logs.google.com:778/es//_bulk")
1538
- driver.run(default_tag: 'test') do
1539
- driver.feed(sample_record)
1540
- end
1541
-
1542
1767
  assert_equal(4, connection_resets)
1543
1768
  end
1544
1769
 
@@ -1674,11 +1899,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1674
1899
 
1675
1900
  driver(config)
1676
1901
 
1677
- stub_elastic("https://logs.google.com:777/es//_bulk")
1678
- driver.run(default_tag: 'test') do
1679
- driver.feed(sample_record)
1680
- end
1681
-
1682
1902
  assert_requested(:put, "https://logs.google.com:777/es//_template/logstash", times: 1)
1683
1903
 
1684
1904
  assert_not_requested(:put, "https://logs.google.com:777/es//_template/logstash1")
@@ -2123,6 +2343,58 @@ class ElasticsearchOutput < Test::Unit::TestCase
2123
2343
  assert_equal(pipeline, index_cmds.first['index']['pipeline'])
2124
2344
  end
2125
2345
 
2346
+ class PipelinePlaceholdersTest < self
2347
+ def test_writes_to_default_index_with_pipeline_tag_placeholder
2348
+ pipeline = "fluentd-${tag}"
2349
+ driver.configure("pipeline #{pipeline}")
2350
+ stub_elastic
2351
+ driver.run(default_tag: 'test.builtin.placeholder') do
2352
+ driver.feed(sample_record)
2353
+ end
2354
+ assert_equal("fluentd-test.builtin.placeholder", index_cmds.first['index']['pipeline'])
2355
+ end
2356
+
2357
+ def test_writes_to_default_index_with_pipeline_time_placeholder
2358
+ driver.configure(Fluent::Config::Element.new(
2359
+ 'ROOT', '', {
2360
+ '@type' => 'elasticsearch',
2361
+ 'pipeline' => 'fluentd-%Y%m%d',
2362
+ }, [
2363
+ Fluent::Config::Element.new('buffer', 'tag,time', {
2364
+ 'chunk_keys' => ['tag', 'time'],
2365
+ 'timekey' => 3600,
2366
+ }, [])
2367
+ ]
2368
+ ))
2369
+ time = Time.parse Date.today.iso8601
2370
+ pipeline = "fluentd-#{time.getutc.strftime("%Y%m%d")}"
2371
+ stub_elastic
2372
+ driver.run(default_tag: 'test') do
2373
+ driver.feed(time.to_i, sample_record)
2374
+ end
2375
+ assert_equal(pipeline, index_cmds.first['index']['pipeline'])
2376
+ end
2377
+
2378
+ def test_writes_to_default_index_with_pipeline_custom_key_placeholder
2379
+ driver.configure(Fluent::Config::Element.new(
2380
+ 'ROOT', '', {
2381
+ '@type' => 'elasticsearch',
2382
+ 'pipeline' => 'fluentd-${pipeline_id}',
2383
+ }, [
2384
+ Fluent::Config::Element.new('buffer', 'tag,pipeline_id', {}, [])
2385
+ ]
2386
+ ))
2387
+ time = Time.parse Date.today.iso8601
2388
+ pipeline_id = "mypipeline"
2389
+ logstash_index = "fluentd-#{pipeline_id}"
2390
+ stub_elastic
2391
+ driver.run(default_tag: 'test') do
2392
+ driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
2393
+ end
2394
+ assert_equal(logstash_index, index_cmds.first['index']['pipeline'])
2395
+ end
2396
+ end
2397
+
2126
2398
  def test_writes_to_target_index_key_fallack
2127
2399
  driver.configure("target_index_key @target_index\n")
2128
2400
  stub_elastic