fluent-plugin-elasticsearch 2.11.11 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac2845d66bafd01ff3ff4bcc297e962d005dabc4878b1d24fd85a9cc135c7a98
4
- data.tar.gz: b6649d2372541c3f6049baf5be3853a3e2a283422e268f03e9321ce50c2138a2
3
+ metadata.gz: daf714ffb7c731c2d2792efd8930165c2ca8baa3c387eae815f41d2ccfd89ead
4
+ data.tar.gz: df13ef1152b10bb2d63e7a870ab9afcbed6f040e6aee2a671f376690d0e616bb
5
5
  SHA512:
6
- metadata.gz: ab31cd71bc444c47246ea32878f5b65796175feeaa69dc301a87afd2ffe4a51dda014fbeb32e630bbc45763fdf5ff69b38974b12bdfec7afd36ab890942505a2
7
- data.tar.gz: 5bcec142ca65c7546139eae23bafddefb027d631c67b1e0062ff36c2f11fca746d5aa11310cb3646c6285017fd8bc26509e59fb1edd3fecfa95aa6bf3bff18fa
6
+ metadata.gz: b33818935a059b0e150bb5dcc0cbc1179a3b7179d4fd0b29c964d8238efcbaa68cc59b3232f3f326ba855914b2d54d1fd9bdf0eb107a75108a1c38dae8c305e0
7
+ data.tar.gz: 4d8d1cd2a3700e657c763caf5544344e6bfad1c185879539f48b52a65b84e5ba4dbc8bd524a1934e7d29348a20d7763a4c156519f71bb49c296b3192b2185069
data/History.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ### [Unreleased]
4
4
 
5
+ ### 2.12.0
6
+ - Decoupling the custom template and rollover index creation #485 (#486)
7
+
5
8
  ### 2.11.11
6
9
  - Handle error not to acquire version information (#479)
7
10
 
data/README.md CHANGED
@@ -37,6 +37,9 @@ Current maintainers: @cosmo0920
37
37
  + [template_file](#template_file)
38
38
  + [template_overwrite](#template_overwrite)
39
39
  + [customize_template](#customize_template)
40
+ + [rollover_index](#rollover_index)
41
+ + [deflector_alias](#deflector_alias)
42
+ + [application_name](#application_name)
40
43
  + [index_prefix](#index_prefix)
41
44
  + [templates](#templates)
42
45
  + [max_retry_putting_template](#max_retry_putting_template)
@@ -338,22 +341,52 @@ If `template_file` and `template_name` are set, then this parameter will be igno
338
341
 
339
342
  ### customize_template
340
343
 
341
- Specify the string and its value to be replaced in form of hash. Can contain multiple templates.
344
+ Specify the string and its value to be replaced in form of hash. Can contain multiple key value pair that would be replaced in the specified template_file.
345
+ This setting only creates template and to add rollover index please check the [rollover_index](#rollover_index) configuration.
342
346
 
343
347
  ```
344
348
  customize_template {"string_1": "subs_value_1", "string_2": "subs_value_2"}
345
349
  ```
346
350
 
347
- If `template_file` and `template_name` are set, then this parameter will be in effect otherwise ignored.
351
+ If [template_file](#template_file) and [template_name](#template_name) are set, then this parameter will be in effect otherwise ignored.
352
+
353
+ ### rollover_index
354
+
355
+ Specify this as true when an index with rollover capability needs to be created. It creates an index with the format <logstash-default-{now/d}-000001> where logstash denotes the index_prefix and default denotes the application_name which can be set.
356
+ 'deflector_alias' is a required field for rollover_index set to true.
357
+ 'index_prefix' and 'application_name' are optional and defaults to logstash and default respectively.
358
+ ```
359
+ rollover_index true # defaults to false
360
+ ```
361
+
362
+ If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
363
+
364
+ ### deflector_alias
365
+
366
+ Specify the deflector alias which would be assigned to the rollover index created. This is useful in case of using the Elasticsearch rollover API
367
+ ```
368
+ deflector_alias test-current
369
+ ```
370
+
371
+ If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
348
372
 
349
373
  ### index_prefix
350
374
 
375
+ Specify the index prefix for the rollover index to be created.
351
376
  ```
352
377
  index_prefix mylogs # defaults to "logstash"
353
378
  ```
354
379
 
355
- If `customize_template` is set, then this parameter will be in effect otherwise ignored.
380
+ If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
381
+
382
+ ### application_name
383
+
384
+ Specify the application name for the rollover index to be created.
385
+ ```
386
+ application_name default # defaults to "default"
387
+ ```
356
388
 
389
+ If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
357
390
 
358
391
  ### template_overwrite
359
392
 
@@ -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 = '2.11.11'
6
+ s.version = '2.12.0'
7
7
  s.authors = ['diogo', 'pitr']
8
8
  s.email = ['pitr.vern@gmail.com', 'me@diogoterror.com']
9
9
  s.description = %q{Elasticsearch output plugin for Fluent event collector}
@@ -68,9 +68,8 @@ module Fluent::ElasticsearchIndexTemplate
68
68
  end
69
69
  end
70
70
 
71
- def template_custom_install(name, template_file, overwrite, customize_template, index_prefix)
72
- template_custom_name=name.downcase+'_alias_template'
73
- alias_name=name.downcase+'-current'
71
+ def template_custom_install(template_name, template_file, overwrite, customize_template, index_prefix, rollover_index, deflector_alias_name, app_name)
72
+ template_custom_name=template_name.downcase
74
73
  if overwrite
75
74
  template_put(template_custom_name, get_custom_template(template_file, customize_template))
76
75
  log.info("Template '#{template_custom_name}' overwritten with #{template_file}.")
@@ -82,14 +81,17 @@ module Fluent::ElasticsearchIndexTemplate
82
81
  else
83
82
  log.info("Template configured and already installed.")
84
83
  end
85
-
86
- if !client.indices.exists_alias(:name => alias_name)
87
- index_name='<'+index_prefix.downcase+'-'+name.downcase+'-{now/d}-000001>'
88
- indexcreation(index_name)
89
- client.indices.put_alias(:index => index_name, :name => alias_name)
90
- log.info("The alias '#{alias_name}' is created for the index '#{index_name}'")
84
+ if rollover_index
85
+ if !client.indices.exists_alias(:name => deflector_alias_name)
86
+ index_name_temp='<'+index_prefix.downcase+'-'+app_name.downcase+'-{now/d}-000001>'
87
+ indexcreation(index_name_temp)
88
+ client.indices.put_alias(:index => index_name_temp, :name => deflector_alias_name)
89
+ log.info("The alias '#{deflector_alias_name}' is created for the index '#{index_name_temp}'")
90
+ else
91
+ log.info("The alias '#{deflector_alias_name}' is already present")
92
+ end
91
93
  else
92
- log.info("The alias '#{alias_name}' is already present")
94
+ log.info("No index and alias creation action performed because rollover_index is set to '#{rollover_index}'")
93
95
  end
94
96
  end
95
97
 
@@ -99,7 +99,10 @@ EOC
99
99
  config_param :template_file, :string, :default => nil
100
100
  config_param :template_overwrite, :bool, :default => false
101
101
  config_param :customize_template, :hash, :default => nil
102
+ config_param :rollover_index, :string, :default => false
103
+ config_param :deflector_alias, :string, :default => nil
102
104
  config_param :index_prefix, :string, :default => "logstash"
105
+ config_param :application_name, :string, :default => "default"
103
106
  config_param :templates, :hash, :default => nil
104
107
  config_param :max_retry_putting_template, :integer, :default => 10
105
108
  config_param :include_tag_key, :bool, :default => false
@@ -160,10 +163,14 @@ EOC
160
163
  end
161
164
 
162
165
  raise Fluent::ConfigError, "'max_retry_putting_template' must be positive number." if @max_retry_putting_template < 0
166
+
163
167
  if @template_name && @template_file
164
168
  retry_install(@max_retry_putting_template) do
165
169
  if @customize_template
166
- template_custom_install(@template_name, @template_file, @template_overwrite, @customize_template, @index_prefix)
170
+ if @rollover_index
171
+ raise Fluent::ConfigError, "'deflector_alias' must be provided if 'rollover_index' is set true ." if not @deflector_alias
172
+ end
173
+ template_custom_install(@template_name, @template_file, @template_overwrite, @customize_template, @index_prefix, @rollover_index, @deflector_alias, @application_name)
167
174
  else
168
175
  template_install(@template_name, @template_file, @template_overwrite)
169
176
  end
@@ -380,10 +380,44 @@ class ElasticsearchOutput < Test::Unit::TestCase
380
380
  path /es/
381
381
  user john
382
382
  password doe
383
- template_name myapp
383
+ template_name myapp_alias_template
384
384
  template_file #{template_file}
385
385
  customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
386
+ }
387
+
388
+ # connection start
389
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//").
390
+ to_return(:status => 200, :body => "", :headers => {})
391
+ # check if template exists
392
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/myapp_alias_template").
393
+ to_return(:status => 404, :body => "", :headers => {})
394
+ # creation
395
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/myapp_alias_template").
396
+ to_return(:status => 200, :body => "", :headers => {})
397
+
398
+ driver(config)
399
+
400
+ assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/myapp_alias_template", times: 1)
401
+ end
402
+
403
+ def test_custom_template_with_rollover_index_create
404
+ cwd = File.dirname(__FILE__)
405
+ template_file = File.join(cwd, 'test_alias_template.json')
406
+
407
+ config = %{
408
+ host logs.google.com
409
+ port 777
410
+ scheme https
411
+ path /es/
412
+ user john
413
+ password doe
414
+ template_name myapp_alias_template
415
+ template_file #{template_file}
416
+ customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
417
+ rollover_index true
418
+ deflector_alias myapp_deflector
386
419
  index_prefix mylogs
420
+ application_name myapp
387
421
  }
388
422
 
389
423
  # connection start
@@ -399,10 +433,10 @@ class ElasticsearchOutput < Test::Unit::TestCase
399
433
  stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E").
400
434
  to_return(:status => 200, :body => "", :headers => {})
401
435
  # check if alias exists
402
- stub_request(:head, "https://john:doe@logs.google.com:777/es//_alias/myapp-current").
436
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//_alias/myapp_deflector").
403
437
  to_return(:status => 404, :body => "", :headers => {})
404
438
  # put the alias for the index
405
- stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E/_alias/myapp-current").
439
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E/_alias/myapp_deflector").
406
440
  to_return(:status => 200, :body => "", :headers => {})
407
441
 
408
442
  driver(config)
@@ -410,6 +444,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
410
444
  assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/myapp_alias_template", times: 1)
411
445
  end
412
446
 
447
+
413
448
  def test_template_overwrite
414
449
  cwd = File.dirname(__FILE__)
415
450
  template_file = File.join(cwd, 'test_template.json')
@@ -452,11 +487,45 @@ class ElasticsearchOutput < Test::Unit::TestCase
452
487
  path /es/
453
488
  user john
454
489
  password doe
455
- template_name myapp
490
+ template_name myapp_alias_template
491
+ template_file #{template_file}
492
+ template_overwrite true
493
+ customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
494
+ }
495
+
496
+ # connection start
497
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//").
498
+ to_return(:status => 200, :body => "", :headers => {})
499
+ # check if template exists
500
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/myapp_alias_template").
501
+ to_return(:status => 200, :body => "", :headers => {})
502
+ # creation
503
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/myapp_alias_template").
504
+ to_return(:status => 200, :body => "", :headers => {})
505
+
506
+ driver(config)
507
+
508
+ assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/myapp_alias_template", times: 1)
509
+ end
510
+
511
+ def test_custom_template_with_rollover_index_overwrite
512
+ cwd = File.dirname(__FILE__)
513
+ template_file = File.join(cwd, 'test_template.json')
514
+
515
+ config = %{
516
+ host logs.google.com
517
+ port 777
518
+ scheme https
519
+ path /es/
520
+ user john
521
+ password doe
522
+ template_name myapp_alias_template
456
523
  template_file #{template_file}
457
524
  template_overwrite true
458
525
  customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
526
+ deflector_alias myapp_deflector
459
527
  index_prefix mylogs
528
+ application_name myapp
460
529
  }
461
530
 
462
531
  # connection start
@@ -472,10 +541,10 @@ class ElasticsearchOutput < Test::Unit::TestCase
472
541
  stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E").
473
542
  to_return(:status => 200, :body => "", :headers => {})
474
543
  # check if alias exists
475
- stub_request(:head, "https://john:doe@logs.google.com:777/es//_alias/myapp-current").
544
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//_alias/myapp_deflector").
476
545
  to_return(:status => 404, :body => "", :headers => {})
477
546
  # put the alias for the index
478
- stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E/_alias/myapp-current").
547
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E/_alias/myapp_deflector").
479
548
  to_return(:status => 200, :body => "", :headers => {})
480
549
 
481
550
  driver(config)
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: 2.11.11
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - diogo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-09 00:00:00.000000000 Z
12
+ date: 2018-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd