fluent-plugin-elasticsearch 5.3.0 → 5.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a475837f544383a6d7c59f43f31c9d79a7c6154b2b8c851c266a9bbbe393e50a
4
- data.tar.gz: 300ad2d07e3009f9d50433ceecee0e410fbd129d75c86d71646e659f58f19df3
3
+ metadata.gz: 61bd10f31500ee04a5f1cbf8f9a25a22c8cf22feac51ce7728c1adec21f63565
4
+ data.tar.gz: 73f6a791314e73d4669b26105b3377ad99a90948e4f153086c0188484119f5ee
5
5
  SHA512:
6
- metadata.gz: d1b12f9ee8582952388aadb13e06ef2538677bb761e9e55f1ea41214442c224b3334252a2b78bc35db6a334c19fa2183fff4a9311bd55bf8edeb44cbab30a1b5
7
- data.tar.gz: eff7db364b8c307f01935b18221effc879e65d9ef300caba3cbdfc3a1c0fe7d84f3f4d8741fdb934bed553f58d0475a76b235598145e9f39c56c124766015540
6
+ metadata.gz: 9f2ddddd3297b4c69a1499f0dcd4e3b690224523afacce1787f2490bee809ea2cc6d81cbf723fb3ce4275ca4a9ea83a1e7da908b33ff86c94fa79799fd6cabb4
7
+ data.tar.gz: cecb42477e365df347ebdfeded701f2faebf1084c01a76b1b4319920c241af6f785cebff47531181de8d3eeea03d50783df5c44c46202b95ef28bb42e366168d
@@ -16,7 +16,7 @@ jobs:
16
16
  - ubuntu-latest
17
17
  name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
18
18
  steps:
19
- - uses: actions/checkout@v3
19
+ - uses: actions/checkout@v4
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  ruby-version: ${{ matrix.ruby }}
@@ -16,7 +16,7 @@ jobs:
16
16
  - macOS-latest
17
17
  name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
18
18
  steps:
19
- - uses: actions/checkout@v3
19
+ - uses: actions/checkout@v4
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  ruby-version: ${{ matrix.ruby }}
@@ -16,7 +16,7 @@ jobs:
16
16
  - windows-latest
17
17
  name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
18
18
  steps:
19
- - uses: actions/checkout@v3
19
+ - uses: actions/checkout@v4
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  ruby-version: ${{ matrix.ruby }}
data/History.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ### [Unreleased]
4
4
 
5
+ ### 5.4.1
6
+ - Adjust ilm endpoint (#1036)
7
+
8
+ ### 5.4.0
9
+ - Fix support for host/hosts placeholders for ipv6 addresses (#1030)
10
+ - Handle newer es library (#1032)
11
+
5
12
  ### 5.3.0
6
13
 
7
14
  - Unpin `faraday` from v1, upgrade to v2. (#1012)
@@ -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.3.0'
6
+ s.version = '5.4.1'
7
7
  s.authors = ['diogo', 'pitr', 'Hiroshi Hatake']
8
8
  s.email = ['pitr.vern@gmail.com', 'me@diogoterror.com', 'cosmo0920.wp@gmail.com']
9
9
  s.description = %q{Elasticsearch output plugin for Fluent event collector}
@@ -12,6 +12,7 @@ if Gem::Version.new(Elasticsearch::VERSION) < Gem::Version.new("8.0.0")
12
12
  begin
13
13
  require 'elasticsearch/xpack'
14
14
  rescue LoadError
15
+ require 'elasticsearch/api' # For elasticsearch-ruby 8 or later
15
16
  end
16
17
  end
17
18
 
@@ -45,19 +45,19 @@ module Fluent::Plugin::ElasticsearchIndexLifecycleManagement
45
45
  end
46
46
 
47
47
  def get_ilm_policy
48
- if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
49
- client.ilm.get_policy
48
+ if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("8.0.0")
49
+ client.ilm.get_lifecycle
50
50
  else
51
- client.enrich.get_policy
51
+ client.ilm.get_policy
52
52
  end
53
53
  end
54
54
 
55
55
  def ilm_policy_exists?(policy_id)
56
56
  begin
57
- if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
58
- client.ilm.get_policy(policy_id: policy_id)
57
+ if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("8.0.0")
58
+ client.ilm.get_lifecycle(policy: policy_id)
59
59
  else
60
- client.enrich.get_policy(name: policy_id)
60
+ client.ilm.get_policy(policy_id: policy_id)
61
61
  end
62
62
  true
63
63
  rescue
@@ -67,10 +67,10 @@ module Fluent::Plugin::ElasticsearchIndexLifecycleManagement
67
67
 
68
68
  def ilm_policy_put(policy_id, policy)
69
69
  log.info("Installing ILM policy: #{policy}")
70
- if Gem::Version.new(TRANSPORT_CLASS::VERSION) < Gem::Version.new("8.0.0")
71
- client.ilm.put_policy(policy_id: policy_id, body: policy)
70
+ if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("8.0.0")
71
+ client.ilm.put_lifecycle(policy: policy_id, body: policy)
72
72
  else
73
- client.enrich.put_policy(name: policy_id, body: policy)
73
+ client.ilm.put_policy(policy_id: policy_id, body: policy)
74
74
  end
75
75
  end
76
76
 
@@ -653,6 +653,14 @@ EOC
653
653
  end
654
654
  end
655
655
 
656
+ def is_ipv6_host(host_str)
657
+ begin
658
+ IPAddr.new(host_str).ipv6?
659
+ rescue IPAddr::InvalidAddressError
660
+ return false
661
+ end
662
+ end
663
+
656
664
  def get_connection_options(con_host=nil)
657
665
 
658
666
  hosts = if con_host || @hosts
@@ -664,6 +672,21 @@ EOC
664
672
  port: (host_str.split(':')[1] || @port).to_i,
665
673
  scheme: @scheme.to_s
666
674
  }
675
+ # Support ipv6 for host/host placeholders
676
+ elsif is_ipv6_host(host_str)
677
+ if Resolv::IPv6::Regex.match(host_str)
678
+ {
679
+ host: "[#{host_str}]",
680
+ port: @port.to_i,
681
+ scheme: @scheme.to_s
682
+ }
683
+ else
684
+ {
685
+ host: host_str,
686
+ port: @port.to_i,
687
+ scheme: @scheme.to_s
688
+ }
689
+ end
667
690
  else
668
691
  # New hosts format expects URLs such as http://logs.foo.com,https://john:pass@logs2.foo.com/elastic
669
692
  uri = URI(get_escaped_userinfo(host_str))
@@ -102,8 +102,8 @@ module Fluent::Plugin
102
102
  retry_operate(@max_retry_putting_template,
103
103
  @fail_on_putting_template_retry_exceed,
104
104
  @catch_transport_exception_on_retry) do
105
- if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
106
- client(host).enrich.put_policy(params.merge(name: ilm_name))
105
+ if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("8.0.0")
106
+ client(host).ilm.put_lifecycle(params.merge(policy: ilm_name))
107
107
  else
108
108
  client(host).xpack.ilm.put_policy(params.merge(policy_id: ilm_name))
109
109
  end
@@ -159,8 +159,8 @@ module Fluent::Plugin
159
159
 
160
160
  def ilm_policy_exists?(policy_id, host = nil)
161
161
  begin
162
- if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
163
- client(host).enrich.get_policy(name: policy_id)
162
+ if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("8.0.0")
163
+ client(host).ilm.get_lifecycle(policy: policy_id)
164
164
  else
165
165
  client(host).ilm.get_policy(policy_id: policy_id)
166
166
  end
data/test/helper.rb CHANGED
@@ -15,7 +15,6 @@ end
15
15
 
16
16
  require 'test/unit'
17
17
  require 'fluent/test'
18
- require 'minitest/pride'
19
18
 
20
19
  require 'webmock/test_unit'
21
20
  WebMock.disable_net_connect!
@@ -15,7 +15,7 @@ class ElasticsearchFallbackSelectorTest < Test::Unit::TestCase
15
15
  def stub_elastic(url="http://localhost:9200/_bulk")
16
16
  stub_request(:post, url).with do |req|
17
17
  @index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
18
- end
18
+ end.to_return({:status => 200, :body => "{}", :headers => { 'Content-Type' => 'json', 'x-elastic-product' => 'Elasticsearch' } })
19
19
  end
20
20
 
21
21
  def elasticsearch_version
@@ -38,19 +38,15 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
38
38
  end
39
39
 
40
40
  def ilm_existence_endpoint(policy_id)
41
- if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
42
- "_enrich/policy/#{policy_id}"
41
+ if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("8.0.0")
42
+ "_ilm/policy/#{policy_id}"
43
43
  else
44
44
  "_ilm/policy/%7B:policy_id=%3E%22#{policy_id}%22%7D"
45
45
  end
46
46
  end
47
47
 
48
48
  def ilm_creation_endpoint(policy_id)
49
- if Gem::Version.new(TRANSPORT_CLASS::VERSION) >= Gem::Version.new("8.0.0")
50
- "_enrich/policy/#{policy_id}"
51
- else
52
- "_ilm/policy/#{policy_id}"
53
- end
49
+ "_ilm/policy/#{policy_id}"
54
50
  end
55
51
 
56
52
  def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_version)
@@ -60,7 +56,7 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
60
56
 
61
57
  def test_xpack_info
62
58
  stub_request(:get, "http://localhost:9200/_xpack").
63
- to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json" })
59
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json", 'x-elastic-product' => 'Elasticsearch' })
64
60
  stub_elastic_info
65
61
  expected = {"features"=>{"ilm"=>{"available"=>true, "enabled"=>true}}}
66
62
  if xpack_info.is_a?(Elasticsearch::API::Response)
@@ -72,32 +68,32 @@ class TestElasticsearchIndexLifecycleManagement < Test::Unit::TestCase
72
68
 
73
69
  def test_verify_ilm_working
74
70
  stub_request(:get, "http://localhost:9200/_xpack").
75
- to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json" })
71
+ to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json", 'x-elastic-product' => 'Elasticsearch' })
76
72
  stub_elastic_info
77
73
  assert_nothing_raised { verify_ilm_working }
78
74
  end
79
75
 
80
76
  def test_ilm_policy_doesnt_exists
81
77
  stub_request(:get, "http://localhost:9200/#{ilm_existence_endpoint("fluentd-policy")}").
82
- to_return(:status => 404, :body => "", :headers => {})
78
+ to_return(:status => 404, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
83
79
  stub_elastic_info
84
80
  assert_false(ilm_policy_exists?("fluentd-policy"))
85
81
  end
86
82
 
87
83
  def test_ilm_policy_exists
88
84
  stub_request(:get, "http://localhost:9200/#{ilm_existence_endpoint("fluent-policy")}").
89
- to_return(:status => 200, :body => "", :headers => {})
85
+ to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
90
86
  stub_elastic_info
91
87
  assert_true(ilm_policy_exists?("fluent-policy"))
92
88
  end
93
89
 
94
90
  def test_create_ilm_policy
95
91
  stub_request(:get, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
96
- to_return(:status => 404, :body => "", :headers => {})
92
+ to_return(:status => 404, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
97
93
  stub_request(:put, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
98
94
  with(:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}",
99
95
  :headers => {'Content-Type'=>'application/json'}).
100
- to_return(:status => 200, :body => "", :headers => {})
96
+ to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
101
97
  stub_elastic_info
102
98
  create_ilm_policy("fluent-policy")
103
99
 
@@ -334,7 +334,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
334
334
  stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
335
335
  with(body: "{\"sort\":[\"_doc\"]}").
336
336
  to_return(status: 200, body: sample_response.to_s,
337
- headers: {'Content-Type' => 'application/json'})
337
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
338
338
  stub_elastic_info
339
339
 
340
340
  driver(CONFIG)
@@ -350,7 +350,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
350
350
  stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
351
351
  with(body: "{\"sort\":[\"_doc\"]}").
352
352
  to_return(status: 200, body: sample_response(index_name).to_s,
353
- headers: {'Content-Type' => 'application/json'})
353
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
354
354
  stub_elastic_info
355
355
 
356
356
  driver(CONFIG + %[index_name #{index_name}])
@@ -366,7 +366,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
366
366
  stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
367
367
  with(body: "{\"sort\":[\"_doc\"]}").
368
368
  to_return(status: 200, body: sample_response(index_name).to_s,
369
- headers: {'Content-Type' => 'application/json'})
369
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
370
370
  stub_elastic_info
371
371
 
372
372
  driver(CONFIG + %[parse_timestamp])
@@ -385,7 +385,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
385
385
  stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
386
386
  with(body: "{\"sort\":[\"_doc\"]}").
387
387
  to_return(status: 200, body: sample_response(index_name).to_s,
388
- headers: {'Content-Type' => 'application/json'})
388
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
389
389
  stub_elastic_info
390
390
 
391
391
  driver(CONFIG + %[parse_timestamp true
@@ -405,7 +405,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
405
405
  stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
406
406
  with(body: "{\"sort\":[\"_doc\"]}").
407
407
  to_return(status: 200, body: sample_response.to_s,
408
- headers: {'Content-Type' => 'application/json'})
408
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
409
409
  stub_elastic_info
410
410
 
411
411
  driver(CONFIG + %[docinfo true])
@@ -425,11 +425,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
425
425
  stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
426
426
  with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":0,\"max\":2}}").
427
427
  to_return(status: 200, body: sample_response.to_s,
428
- headers: {'Content-Type' => 'application/json'})
428
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
429
429
  stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
430
430
  with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":1,\"max\":2}}").
431
431
  to_return(status: 200, body: sample_response.to_s,
432
- headers: {'Content-Type' => 'application/json'})
432
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
433
433
  stub_elastic_info
434
434
 
435
435
  driver(CONFIG + %[num_slices 2])
@@ -446,7 +446,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
446
446
  stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1").
447
447
  with(body: "{\"sort\":[\"_doc\"]}").
448
448
  to_return(status: 200, body: sample_scroll_response.to_s,
449
- headers: {'Content-Type' => 'application/json'})
449
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
450
450
  connection = 0
451
451
  scroll_request = stub_request(@http_method, "http://localhost:9200/_search/scroll?scroll=1m").
452
452
  with(
@@ -457,10 +457,10 @@ class ElasticsearchInputTest < Test::Unit::TestCase
457
457
  scroll_request.to_return(lambda do |req|
458
458
  if connection <= 1
459
459
  {status: 200, body: sample_scroll_response_2.to_s,
460
- headers: {'Content-Type' => 'application/json'}}
460
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'}}
461
461
  else
462
462
  {status: 200, body: sample_scroll_response_terminate.to_s,
463
- headers: {'Content-Type' => 'application/json'}}
463
+ headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'}}
464
464
  end
465
465
  end)
466
466
  stub_request(:delete, "http://localhost:9200/_search/scroll/WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz").