fluent-plugin-elasticsearch 5.1.1 → 5.1.5

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: 27d74e7048671def02b98e337c052c395152021a4a3f4c2138d1780c725d09bd
4
- data.tar.gz: eb5282b8e688b091700a549c711af2f1959bc9b1b2c4f6fd1b49e3119c62ddb7
3
+ metadata.gz: 0ae6214f54783c402097e26276b9247f1d58866b08cdc80be47d3b4638516d54
4
+ data.tar.gz: b69af374d04f84b2b1137189916c2b78f25eae71c2294d9a0cc196c30c09db29
5
5
  SHA512:
6
- metadata.gz: 3a3ad9fa5259fcd1e80a85bdf7d1acd11cd26675d4f47f326100db242f0f9320232530099eb5346e5ea11aba76c4cc66cfc2e97f6393ca95d1227281217283ea
7
- data.tar.gz: f97182a9487be71d34ddcd8ec2dd046eca9c6de1cae55d3842feeeaef627f23a05862be4783aee37fe38c84cba3bf984a51fb7fb3e8bad50f1bf0f57c956803e
6
+ metadata.gz: 29173c2331bc0e533aa1d3aa66aa555bad7802e5fbb4207641b11aebc0a18c0d4e44ebed0b167c8fe4bddf403d2dd5a61349afeffecfc28a65359c3bb4cce26b
7
+ data.tar.gz: 7fdf58624182bdd4e354cad2d4f9ba001cff5a8c8c0ba02ac043607a87e2372311deb85bc0306d3aa167e98170a6049f33f3203b202ebcf25eac75e65dc23a17
data/History.md CHANGED
@@ -2,8 +2,23 @@
2
2
 
3
3
  ### [Unreleased]
4
4
 
5
+ ### 5.1.5
6
+ - Make retryable DataStreams creation at configure phase (#943)
7
+ - Handle @hosts parameter on data_stream plugin (#942)
8
+ - allow specifying custom ILM policies for data streams (#933)
9
+
10
+ ### 5.1.4
11
+ - Handle ES8 or above more strictly (#931)
12
+ - fixing double "\_policy" in index lifecycle management policy for elasticsearch\_data\_stream output (#930)
13
+
14
+ ### 5.1.3
15
+ - fixing execution order for dynamic data stream creation (#928)
16
+
17
+ ### 5.1.2
18
+ - Fix default values of datastream parameters (#926)
19
+
5
20
  ### 5.1.1
6
- - Report appropriate error for data_stream parameters (#922)
21
+ - Report appropriate error for data_stream parameters (#922)
7
22
  - Add ILM and template parameters for data streams (#920)
8
23
  - Support Buffer in Data Stream Output (#917)
9
24
 
data/README.md CHANGED
@@ -1521,7 +1521,7 @@ You can enable this feature by specifying `@type elasticsearch_data_stream`.
1521
1521
  data_stream_name test
1522
1522
  ```
1523
1523
 
1524
- When `@type elasticsearch_data_stream` is used, unless specified with `data_stream_ilm_name` and `data_stream_template_name`, ILM default policy is set to the specified data stream.
1524
+ When `@type elasticsearch_data_stream` is used, unless specified with `data_stream_ilm_name` and `data_stream_template_name` or `data_stream_ilm_policy`, ILM default policy is set to the specified data stream.
1525
1525
  Then, the matching index template is also created automatically.
1526
1526
 
1527
1527
  ### data_stream_name
@@ -1545,6 +1545,21 @@ There are some limitations about naming rule.
1545
1545
 
1546
1546
  In more detail, please refer to the [Path parameters](https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-data-stream.html#indices-create-data-stream-api-path-params).
1547
1547
 
1548
+
1549
+ ### data_stream_ilm_policy
1550
+
1551
+ You can specify the ILM policy contents as hash. If not present, it will apply the ILM default policy.
1552
+
1553
+ **NOTE:** This parameter requests to install elasticsearch-xpack gem.
1554
+
1555
+ ### data_stream_ilm_policy_overwrite
1556
+
1557
+ Specify whether the data stream ILM policy should be overwritten.
1558
+
1559
+ Default value is `false`.
1560
+
1561
+ **NOTE:** This parameter requests to install elasticsearch-xpack gem.
1562
+
1548
1563
  ## Troubleshooting
1549
1564
 
1550
1565
  See [Troubleshooting document](README.Troubleshooting.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 = '5.1.1'
6
+ s.version = '5.1.5'
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}
@@ -987,12 +987,12 @@ EOC
987
987
  elsif @last_seen_major_version == 7
988
988
  log.warn "Detected ES 7.x: `_doc` will be used as the document `_type`."
989
989
  target_type = '_doc'.freeze
990
- elsif @last_seen_major_version >=8
990
+ elsif @last_seen_major_version >= 8
991
991
  log.debug "Detected ES 8.x or above: document type will not be used."
992
992
  target_type = nil
993
993
  end
994
994
  else
995
- if @suppress_type_name && @last_seen_major_version >= 7
995
+ if @suppress_type_name && @last_seen_major_version == 7
996
996
  target_type = nil
997
997
  elsif @last_seen_major_version == 7 && @type_name != DEFAULT_TYPE_NAME_ES_7x
998
998
  log.warn "Detected ES 7.x: `_doc` will be used as the document `_type`."
@@ -9,8 +9,11 @@ module Fluent::Plugin
9
9
  helpers :event_emitter
10
10
 
11
11
  config_param :data_stream_name, :string
12
- config_param :data_stream_ilm_name, :string, :default => :data_stream_name
13
- config_param :data_stream_template_name, :string, :default => :data_stream_name
12
+ config_param :data_stream_ilm_name, :string, :default => nil
13
+ config_param :data_stream_template_name, :string, :default => nil
14
+ config_param :data_stream_ilm_policy, :string, :default => nil
15
+ config_param :data_stream_ilm_policy_overwrite, :bool, :default => false
16
+
14
17
  # Elasticsearch 7.9 or later always support new style of index template.
15
18
  config_set_default :use_legacy_template, false
16
19
 
@@ -27,6 +30,10 @@ module Fluent::Plugin
27
30
  raise Fluent::ConfigError, "'elasticsearch/api', 'elasticsearch/xpack' are required for <@elasticsearch_data_stream>."
28
31
  end
29
32
 
33
+ @data_stream_ilm_name = "#{@data_stream_name}_policy" if @data_stream_ilm_name.nil?
34
+ @data_stream_template_name = "#{@data_stream_name}_template" if @data_stream_template_name.nil?
35
+ @data_stream_ilm_policy = File.read(File.join(File.dirname(__FILE__), "default-ilm-policy.json")) if @data_stream_ilm_policy.nil?
36
+
30
37
  # ref. https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-data-stream.html
31
38
  unless placeholder?(:data_stream_name_placeholder, @data_stream_name)
32
39
  validate_data_stream_parameters
@@ -35,13 +42,16 @@ module Fluent::Plugin
35
42
  @data_stream_names = []
36
43
  end
37
44
 
38
- @client = client
39
45
  unless @use_placeholder
40
46
  begin
41
47
  @data_stream_names = [@data_stream_name]
42
- create_ilm_policy(@data_stream_name, @data_stream_template_name, @data_stream_ilm_name, @host)
43
- create_index_template(@data_stream_name, @data_stream_template_name, @data_stream_ilm_name, @host)
44
- create_data_stream(@data_stream_name)
48
+ retry_operate(@max_retry_putting_template,
49
+ @fail_on_putting_template_retry_exceed,
50
+ @catch_transport_exception_on_retry) do
51
+ create_ilm_policy(@data_stream_name, @data_stream_template_name, @data_stream_ilm_name)
52
+ create_index_template(@data_stream_name, @data_stream_template_name, @data_stream_ilm_name)
53
+ create_data_stream(@data_stream_name)
54
+ end
45
55
  rescue => e
46
56
  raise Fluent::ConfigError, "Failed to create data stream: <#{@data_stream_name}> #{e.message}"
47
57
  end
@@ -73,27 +83,30 @@ module Fluent::Plugin
73
83
  end
74
84
  end
75
85
 
76
- def create_ilm_policy(datastream_name, template_name, ilm_name, host)
77
- return if data_stream_exist?(datastream_name) or template_exists?(template_name, host) or ilm_policy_exists?(ilm_name)
86
+ def create_ilm_policy(datastream_name, template_name, ilm_name, host = nil)
87
+ unless @data_stream_ilm_policy_overwrite
88
+ return if data_stream_exist?(datastream_name, host) or template_exists?(template_name, host) or ilm_policy_exists?(ilm_name, host)
89
+ end
90
+
78
91
  params = {
79
- policy_id: "#{ilm_name}_policy",
80
- body: File.read(File.join(File.dirname(__FILE__), "default-ilm-policy.json"))
92
+ policy_id: ilm_name,
93
+ body: @data_stream_ilm_policy
81
94
  }
82
95
  retry_operate(@max_retry_putting_template,
83
96
  @fail_on_putting_template_retry_exceed,
84
97
  @catch_transport_exception_on_retry) do
85
- @client.xpack.ilm.put_policy(params)
98
+ client(host).xpack.ilm.put_policy(params)
86
99
  end
87
100
  end
88
101
 
89
- def create_index_template(datastream_name, template_name, ilm_name, host)
90
- return if data_stream_exist?(datastream_name) or template_exists?(template_name, host)
102
+ def create_index_template(datastream_name, template_name, ilm_name, host = nil)
103
+ return if data_stream_exist?(datastream_name, host) or template_exists?(template_name, host)
91
104
  body = {
92
105
  "index_patterns" => ["#{datastream_name}*"],
93
106
  "data_stream" => {},
94
107
  "template" => {
95
108
  "settings" => {
96
- "index.lifecycle.name" => "#{ilm_name}_policy"
109
+ "index.lifecycle.name" => "#{ilm_name}"
97
110
  }
98
111
  }
99
112
  }
@@ -104,16 +117,16 @@ module Fluent::Plugin
104
117
  retry_operate(@max_retry_putting_template,
105
118
  @fail_on_putting_template_retry_exceed,
106
119
  @catch_transport_exception_on_retry) do
107
- @client.indices.put_index_template(params)
120
+ client(host).indices.put_index_template(params)
108
121
  end
109
122
  end
110
123
 
111
- def data_stream_exist?(datastream_name)
124
+ def data_stream_exist?(datastream_name, host = nil)
112
125
  params = {
113
126
  name: datastream_name
114
127
  }
115
128
  begin
116
- response = @client.indices.get_data_stream(params)
129
+ response = client(host).indices.get_data_stream(params)
117
130
  return (not response.is_a?(Elasticsearch::Transport::Transport::Errors::NotFound))
118
131
  rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
119
132
  log.info "Specified data stream does not exist. Will be created: <#{e}>"
@@ -121,21 +134,21 @@ module Fluent::Plugin
121
134
  end
122
135
  end
123
136
 
124
- def create_data_stream(datastream_name)
125
- return if data_stream_exist?(datastream_name)
137
+ def create_data_stream(datastream_name, host = nil)
138
+ return if data_stream_exist?(datastream_name, host)
126
139
  params = {
127
140
  name: datastream_name
128
141
  }
129
142
  retry_operate(@max_retry_putting_template,
130
143
  @fail_on_putting_template_retry_exceed,
131
144
  @catch_transport_exception_on_retry) do
132
- @client.indices.create_data_stream(params)
145
+ client(host).indices.create_data_stream(params)
133
146
  end
134
147
  end
135
148
 
136
- def ilm_policy_exists?(policy_id)
149
+ def ilm_policy_exists?(policy_id, host = nil)
137
150
  begin
138
- @client.ilm.get_policy(policy_id: policy_id)
151
+ client(host).ilm.get_policy(policy_id: policy_id)
139
152
  true
140
153
  rescue
141
154
  false
@@ -189,16 +202,17 @@ module Fluent::Plugin
189
202
  data_stream_name = @data_stream_name
190
203
  data_stream_template_name = @data_stream_template_name
191
204
  data_stream_ilm_name = @data_stream_ilm_name
192
- host = @host
205
+ host = nil
193
206
  if @use_placeholder
207
+ host = extract_placeholders(@host, chunk)
194
208
  data_stream_name = extract_placeholders(@data_stream_name, chunk)
195
209
  data_stream_template_name = extract_placeholders(@data_stream_template_name, chunk)
196
210
  data_stream_ilm_name = extract_placeholders(@data_stream_ilm_name, chunk)
197
211
  unless @data_stream_names.include?(data_stream_name)
198
212
  begin
199
- create_data_stream(data_stream_name)
200
213
  create_ilm_policy(data_stream_name, data_stream_template_name, data_stream_ilm_name, host)
201
214
  create_index_template(data_stream_name, data_stream_template_name, data_stream_ilm_name, host)
215
+ create_data_stream(data_stream_name)
202
216
  @data_stream_names << data_stream_name
203
217
  rescue => e
204
218
  raise Fluent::ConfigError, "Failed to create data stream: <#{data_stream_name}> #{e.message}"
@@ -227,7 +241,7 @@ module Fluent::Plugin
227
241
  body: bulk_message
228
242
  }
229
243
  begin
230
- response = @client.bulk(params)
244
+ response = client(host).bulk(params)
231
245
  if response['errors']
232
246
  log.error "Could not bulk insert to Data Stream: #{data_stream_name} #{response}"
233
247
  end
@@ -62,56 +62,61 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
62
62
  DUPLICATED_DATA_STREAM_EXCEPTION = {"error": {}, "status": 400}
63
63
  NONEXISTENT_DATA_STREAM_EXCEPTION = {"error": {}, "status": 404}
64
64
 
65
- def stub_ilm_policy(name="foo_ilm")
66
- stub_request(:put, "http://localhost:9200/_ilm/policy/#{name}_policy").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
65
+ def stub_ilm_policy(name="foo_ilm_policy", url="http://localhost:9200")
66
+ stub_request(:put, "#{url}/_ilm/policy/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
67
67
  end
68
68
 
69
- def stub_index_template(name="foo_tpl")
70
- stub_request(:put, "http://localhost:9200/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
69
+ def stub_index_template(name="foo_tpl", url="http://localhost:9200")
70
+ stub_request(:put, "#{url}/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
71
71
  end
72
72
 
73
- def stub_data_stream(name="foo")
74
- stub_request(:put, "http://localhost:9200/_data_stream/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
73
+ def stub_data_stream(name="foo", url="http://localhost:9200")
74
+ stub_request(:put, "#{url}/_data_stream/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
75
75
  end
76
76
 
77
- def stub_existent_data_stream?(name="foo")
78
- stub_request(:get, "http://localhost:9200/_data_stream/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
77
+ def stub_existent_data_stream?(name="foo", url="http://localhost:9200")
78
+ stub_request(:get, "#{url}/_data_stream/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
79
79
  end
80
80
 
81
- def stub_existent_ilm?(name="foo_ilm")
82
- stub_request(:get, "http://localhost:9200/_ilm/policy/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
81
+ def stub_existent_ilm?(name="foo_ilm_policy", url="http://localhost:9200")
82
+ stub_request(:get, "#{url}/_ilm/policy/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
83
83
  end
84
84
 
85
- def stub_existent_template?(name="foo_tpl")
86
- stub_request(:get, "http://localhost:9200/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
85
+ def stub_existent_template?(name="foo_tpl", url="http://localhost:9200")
86
+ stub_request(:get, "#{url}/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
87
87
  end
88
88
 
89
- def stub_nonexistent_data_stream?(name="foo")
90
- stub_request(:get, "http://localhost:9200/_data_stream/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
89
+ def stub_nonexistent_data_stream?(name="foo", url="http://localhost:9200")
90
+ stub_request(:get, "#{url}/_data_stream/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
91
91
  end
92
92
 
93
- def stub_nonexistent_ilm?(name="foo_ilm")
94
- stub_request(:get, "http://localhost:9200/_ilm/policy/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
93
+ def stub_nonexistent_ilm?(name="foo_ilm_policy", url="http://localhost:9200")
94
+ stub_request(:get, "#{url}/_ilm/policy/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
95
95
  end
96
96
 
97
- def stub_nonexistent_template?(name="foo_tpl")
98
- stub_request(:get, "http://localhost:9200/_index_template/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
97
+ def stub_nonexistent_template?(name="foo_tpl", url="http://localhost:9200")
98
+ stub_request(:get, "#{url}/_index_template/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
99
99
  end
100
100
 
101
- def stub_bulk_feed(datastream_name="foo", ilm_name="foo_ilm", template_name="foo_tpl")
102
- stub_request(:post, "http://localhost:9200/#{datastream_name}/_bulk").with do |req|
101
+ def stub_nonexistent_template_retry?(name="foo_tpl", url="http://localhost:9200")
102
+ stub_request(:get, "#{url}/_index_template/#{name}").
103
+ to_return({ status: 500, body: 'Internal Server Error' }, { status: 404, body: '{}' })
104
+ end
105
+
106
+ def stub_bulk_feed(datastream_name="foo", ilm_name="foo_ilm_policy", template_name="foo_tpl", url="http://localhost:9200")
107
+ stub_request(:post, "#{url}/#{datastream_name}/_bulk").with do |req|
103
108
  # bulk data must be pair of OP and records
104
109
  # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
105
110
  # {"@timestamp": ...}
106
111
  @bulk_records += req.body.split("\n").size / 2
107
112
  end
108
- stub_request(:post, "http://localhost:9200/#{ilm_name}/_bulk").with do |req|
113
+ stub_request(:post, "#{url}/#{ilm_name}/_bulk").with do |req|
109
114
  # bulk data must be pair of OP and records
110
115
  # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
111
116
  # {"@timestamp": ...}
112
117
  @bulk_records += req.body.split("\n").size / 2
113
118
  end
114
- stub_request(:post, "http://localhost:9200/#{template_name}/_bulk").with do |req|
119
+ stub_request(:post, "#{url}/#{template_name}/_bulk").with do |req|
115
120
  # bulk data must be pair of OP and records
116
121
  # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
117
122
  # {"@timestamp": ...}
@@ -119,12 +124,12 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
119
124
  end
120
125
  end
121
126
 
122
- def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
127
+ def stub_elastic_info(url="http://localhost:9200/", version="7.9.0", headers={})
123
128
  body ="{\"version\":{\"number\":\"#{version}\", \"build_flavor\":\"default\"},\"tagline\" : \"You Know, for Search\"}"
124
- stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
129
+ stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' }.merge(headers) })
125
130
  end
126
131
 
127
- def stub_default(datastream_name="foo", ilm_name="foo_ilm", template_name="foo_tpl", host="http://localhost:9200")
132
+ def stub_default(datastream_name="foo", ilm_name="foo_ilm_policy", template_name="foo_tpl", host="http://localhost:9200")
128
133
  stub_elastic_info(host)
129
134
  stub_nonexistent_ilm?(ilm_name)
130
135
  stub_ilm_policy(ilm_name)
@@ -431,12 +436,62 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
431
436
  'ROOT', '', {
432
437
  '@type' => ELASTIC_DATA_STREAM_TYPE,
433
438
  'data_stream_name' => 'foo',
434
- 'data_stream_ilm_name' => "foo_ilm",
439
+ 'data_stream_ilm_name' => "foo_ilm_policy",
435
440
  'data_stream_template_name' => "foo_tpl"
436
441
  })
437
442
  assert_equal "foo", driver(conf).instance.data_stream_name
438
443
  end
439
444
 
445
+ def test_datastream_configure_retry
446
+ stub_elastic_info
447
+ stub_nonexistent_ilm?
448
+ stub_ilm_policy
449
+ stub_nonexistent_template_retry?
450
+ stub_index_template
451
+ stub_nonexistent_data_stream?
452
+ stub_data_stream
453
+ conf = config_element(
454
+ 'ROOT', '', {
455
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
456
+ 'data_stream_name' => 'foo',
457
+ 'data_stream_ilm_name' => "foo_ilm_policy",
458
+ 'data_stream_template_name' => "foo_tpl"
459
+ })
460
+ assert_equal "foo", driver(conf).instance.data_stream_name
461
+ end
462
+
463
+ def test_hosts_list_configure
464
+ config = %{
465
+ hosts https://john:password@host1:443/elastic/,http://host2
466
+ path /default_path
467
+ user default_user
468
+ password default_password
469
+ data_stream_name default
470
+ }
471
+ stub_elastic_info("https://host1:443/elastic//", "7.9.0",
472
+ {'Authorization'=>"Basic #{Base64.encode64('john:password').split.first}"})
473
+ stub_elastic_info("http://host2/default_path/_data_stream/default", "7.9.0",
474
+ {'Authorization'=>"Basic #{Base64.encode64('john:password').split.first}"})
475
+ stub_existent_data_stream?("default", "https://host1/elastic/")
476
+ instance = driver(config).instance
477
+
478
+ assert_equal 2, instance.get_connection_options[:hosts].length
479
+ host1, host2 = instance.get_connection_options[:hosts]
480
+
481
+ assert_equal 'host1', host1[:host]
482
+ assert_equal 443, host1[:port]
483
+ assert_equal 'https', host1[:scheme]
484
+ assert_equal 'john', host1[:user]
485
+ assert_equal 'password', host1[:password]
486
+ assert_equal '/elastic/', host1[:path]
487
+
488
+ assert_equal 'host2', host2[:host]
489
+ assert_equal 'http', host2[:scheme]
490
+ assert_equal 'default_user', host2[:user]
491
+ assert_equal 'default_password', host2[:password]
492
+ assert_equal '/default_path', host2[:path]
493
+ end
494
+
440
495
  def test_existent_data_stream
441
496
  omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
442
497
 
@@ -449,10 +504,65 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
449
504
  'ROOT', '', {
450
505
  '@type' => ELASTIC_DATA_STREAM_TYPE,
451
506
  'data_stream_name' => 'foo',
452
- 'data_stream_ilm_name' => "foo_ilm",
507
+ 'data_stream_ilm_name' => "foo_ilm_policy",
508
+ 'data_stream_template_name' => "foo_tpl"
509
+ })
510
+ assert_equal "foo", driver(conf).instance.data_stream_name
511
+ end
512
+
513
+ def test_template_unset
514
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
515
+
516
+ stub_ilm_policy
517
+ stub_index_template
518
+ stub_existent_data_stream?
519
+ stub_data_stream
520
+ stub_elastic_info
521
+ conf = config_element(
522
+ 'ROOT', '', {
523
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
524
+ 'data_stream_name' => 'foo',
525
+ 'data_stream_ilm_name' => "foo_ilm_policy",
526
+ })
527
+ assert_equal "foo", driver(conf).instance.data_stream_name
528
+ assert_equal "foo_ilm_policy", driver(conf).instance.data_stream_ilm_name
529
+ assert_equal "foo_template", driver(conf).instance.data_stream_template_name
530
+ end
531
+
532
+ def test_ilm_unset
533
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
534
+
535
+ stub_ilm_policy
536
+ stub_index_template
537
+ stub_existent_data_stream?
538
+ stub_data_stream
539
+ stub_elastic_info
540
+ conf = config_element(
541
+ 'ROOT', '', {
542
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
543
+ 'data_stream_name' => 'foo',
453
544
  'data_stream_template_name' => "foo_tpl"
454
545
  })
455
546
  assert_equal "foo", driver(conf).instance.data_stream_name
547
+ assert_equal "foo_tpl", driver(conf).instance.data_stream_template_name
548
+ end
549
+
550
+ def test_template_and_ilm_unset
551
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
552
+
553
+ stub_ilm_policy
554
+ stub_index_template
555
+ stub_existent_data_stream?
556
+ stub_data_stream
557
+ stub_elastic_info
558
+ conf = config_element(
559
+ 'ROOT', '', {
560
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
561
+ 'data_stream_name' => 'foo',
562
+ })
563
+ assert_equal "foo", driver(conf).instance.data_stream_name
564
+ assert_equal "foo_template", driver(conf).instance.data_stream_template_name
565
+ assert_equal "foo_policy", driver(conf).instance.data_stream_ilm_name
456
566
  end
457
567
 
458
568
  def test_placeholder
@@ -476,6 +586,26 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
476
586
  assert_equal 1, @bulk_records
477
587
  end
478
588
 
589
+ def test_placeholder_params_unset
590
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
591
+
592
+ dsname = "foo_test"
593
+ ilmname = "foo_test_policy"
594
+ tplname = "foo_test_template"
595
+ stub_default(dsname, ilmname, tplname)
596
+ stub_bulk_feed(dsname, ilmname, tplname)
597
+ conf = config_element(
598
+ 'ROOT', '', {
599
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
600
+ 'data_stream_name' => 'foo_${tag}',
601
+ })
602
+ driver(conf).run(default_tag: 'test') do
603
+ driver.feed(sample_record)
604
+ end
605
+ assert_equal 1, @bulk_records
606
+ end
607
+
608
+
479
609
  def test_time_placeholder
480
610
  omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
481
611
 
@@ -540,7 +670,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
540
670
  'ROOT', '', {
541
671
  '@type' => ELASTIC_DATA_STREAM_TYPE,
542
672
  'data_stream_name' => 'foo',
543
- 'data_stream_ilm_name' => 'foo_ilm',
673
+ 'data_stream_ilm_name' => 'foo_ilm_policy',
544
674
  'data_stream_template_name' => 'foo_tpl'
545
675
  })
546
676
  driver(conf).run(default_tag: 'test') do
@@ -560,7 +690,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
560
690
  port 778
561
691
  scheme https
562
692
  data_stream_name foo
563
- data_stream_ilm_name foo_ilm
693
+ data_stream_ilm_name foo_ilm_policy
564
694
  data_stream_template_name foo_tpl
565
695
  user john
566
696
  password doe
@@ -584,4 +714,86 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
584
714
 
585
715
  assert_equal(4, connection_resets)
586
716
  end
717
+
718
+ def test_doesnt_update_ilm_policy_if_overwrite_unset
719
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
720
+
721
+ config = %{
722
+ data_stream_name foo
723
+ data_stream_ilm_name foo_ilm_policy
724
+ data_stream_ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}
725
+ }
726
+
727
+ stub_elastic_info
728
+ stub_index_template
729
+ stub_existent_data_stream?
730
+ stub_existent_ilm?
731
+ stub_data_stream
732
+
733
+ stub_request(:put, "http://localhost:9200/_ilm/policy/foo_ilm_policy").
734
+ to_return(:status => 200, :body => "", :headers => {})
735
+
736
+ assert_nothing_raised {
737
+ driver(config)
738
+ }
739
+ assert_requested(:put, "http://localhost:9200/_ilm/policy/foo_ilm_policy", times: 0)
740
+ end
741
+
742
+ def test_updates_ilm_policy_if_overwrite_set
743
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
744
+
745
+ config = %{
746
+ data_stream_name foo
747
+ data_stream_ilm_name foo_ilm_policy
748
+ data_stream_ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}
749
+ data_stream_ilm_policy_overwrite true
750
+ }
751
+
752
+ stub_elastic_info
753
+ stub_index_template
754
+ stub_existent_data_stream?
755
+ stub_existent_ilm?
756
+ stub_data_stream
757
+
758
+ stub_request(:put, "http://localhost:9200/_ilm/policy/foo_ilm_policy").
759
+ to_return(:status => 200, :body => "", :headers => {})
760
+
761
+ assert_nothing_raised {
762
+ driver(config)
763
+ }
764
+
765
+ assert_requested(:put, "http://localhost:9200/_ilm/policy/foo_ilm_policy", times: 1)
766
+ assert_requested(:put, "http://localhost:9200/_ilm/policy/foo_ilm_policy",
767
+ body: '{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}',
768
+ times: 1)
769
+ end
770
+
771
+ def test_creates_custom_ilm_policy_if_none_exists
772
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
773
+
774
+ config = %{
775
+ data_stream_name foo
776
+ data_stream_ilm_name foo_ilm_policy
777
+ data_stream_ilm_policy {"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}
778
+ }
779
+
780
+ stub_elastic_info
781
+ stub_index_template("foo_template")
782
+ stub_data_stream
783
+ stub_nonexistent_data_stream?
784
+ stub_nonexistent_ilm?
785
+ stub_nonexistent_template?("foo_template")
786
+
787
+ stub_request(:put, "http://localhost:9200/_ilm/policy/foo_ilm_policy").
788
+ to_return(:status => 200, :body => "", :headers => {})
789
+
790
+ assert_nothing_raised {
791
+ driver(config)
792
+ }
793
+
794
+ assert_requested(:put, "http://localhost:9200/_ilm/policy/foo_ilm_policy", times: 1)
795
+ assert_requested(:put, "http://localhost:9200/_ilm/policy/foo_ilm_policy",
796
+ body: '{"policy":{"phases":{"hot":{"actions":{"rollover":{"max_age":"15d"}}}}}}',
797
+ times: 1)
798
+ end
587
799
  end
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: 5.1.1
4
+ version: 5.1.5
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: 2021-10-20 00:00:00.000000000 Z
13
+ date: 2022-02-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluentd
@@ -156,7 +156,6 @@ files:
156
156
  - ".github/workflows/macos.yml"
157
157
  - ".github/workflows/windows.yml"
158
158
  - ".gitignore"
159
- - ".travis.yml"
160
159
  - CONTRIBUTING.md
161
160
  - Gemfile
162
161
  - History.md
@@ -168,7 +167,6 @@ files:
168
167
  - README.Troubleshooting.md
169
168
  - README.md
170
169
  - Rakefile
171
- - appveyor.yml
172
170
  - fluent-plugin-elasticsearch.gemspec
173
171
  - gemfiles/Gemfile.elasticsearch.v6
174
172
  - lib/fluent/log-ext.rb
@@ -223,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
221
  - !ruby/object:Gem::Version
224
222
  version: '0'
225
223
  requirements: []
226
- rubygems_version: 3.2.22
224
+ rubygems_version: 3.2.30
227
225
  signing_key:
228
226
  specification_version: 4
229
227
  summary: Elasticsearch output plugin for Fluent event collector
data/.travis.yml DELETED
@@ -1,40 +0,0 @@
1
- language: ruby
2
-
3
- jobs:
4
- include:
5
- - rvm: 2.4.6
6
- gemfile: Gemfile
7
- os: linux
8
- arch: amd64
9
- - rvm: 2.5.5
10
- gemfile: Gemfile
11
- os: linux
12
- arch: amd64
13
- - rvm: 2.6.3
14
- gemfile: gemfiles/Gemfile.elasticsearch.v6
15
- os: linux
16
- arch: amd64
17
- - rvm: 2.6.3
18
- gemfile: Gemfile
19
- os: linux
20
- arch: amd64
21
- - rvm: 2.6.3
22
- gemfile: Gemfile
23
- os: linux
24
- arch: arm64
25
- - rvm: 2.6.3
26
- gemfile: Gemfile
27
- os: osx
28
- osx_image: xcode11.3
29
- - rvm: 2.7.0
30
- gemfile: Gemfile
31
- os: linux
32
- arch: amd64
33
-
34
- gemfile:
35
- - Gemfile
36
-
37
- before_install:
38
- - gem update --system=2.7.8
39
-
40
- script: bundle exec rake test
data/appveyor.yml DELETED
@@ -1,20 +0,0 @@
1
- version: '{build}'
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ridk.cmd enable
5
- - ruby --version
6
- - gem --version
7
- - bundle install
8
- build: off
9
- test_script:
10
- - bundle exec rake test
11
-
12
- # https://www.appveyor.com/docs/installed-software/#ruby
13
- environment:
14
- matrix:
15
- - ruby_version: "26-x64"
16
- - ruby_version: "26"
17
- - ruby_version: "25-x64"
18
- - ruby_version: "25"
19
- - ruby_version: "24-x64"
20
- - ruby_version: "24"