fluent-plugin-elasticsearch 2.12.5 → 3.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: 2e61b71d57d8dcc1f75180c40f8e926804b694004b30cb0ecff73407fb1c647c
4
- data.tar.gz: b1503054bd7fe71e15bc3aa0c9f0fd90e320926ae40138924ddae9511e1bde8a
3
+ metadata.gz: c5f8aa97feb4191caf5f4bb14fcdd6de7e453ccabee8b0fc50a3b256e56ebc93
4
+ data.tar.gz: 35df640f4f7c7944ea2190fe4627ad2385c102c551fcf3b8bbf25984a00bdd58
5
5
  SHA512:
6
- metadata.gz: ccf3115fb1d7e434cb7bf986bc4c3f2ef91af0eeeddab5b49bf5603089b4ce48919eb56a60a5f07222be8695caf03ea1d9017ff54a6e0c8e96fcd7adec2dfbec
7
- data.tar.gz: a5a2b1ee4a2bcf33406e3c754547d0b8de41082a334c196c4ab7b4a9f410770bcf018064ddf5375ceea9e5e935a23e5d88b3b9e17e4a27e9cfc43e1fa6d1acee
6
+ metadata.gz: 9bb28681d6b85d4260a4797a244c37cfcedd4f23a1d0b5b690df45845c287e0c20741033eb4f6289d7ed2bff5517d0749b5258361fe056bdf628445d69979920
7
+ data.tar.gz: 2947d2e1fa50a87b507b1e8792a254ae0d595472e40553d0d14ec74a533c2be8c1fcbc59347c098440354f5949e3e07bbf4f7aa397ed3fd2c3a7ff16e692aacd
data/History.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ### [Unreleased]
4
4
 
5
+ ### 3.0.0
6
+ - Use fluentd core retry mechanism (#519)
7
+ - Depends on builtin retrying mechanism (#518)
8
+ - Loosen ConnectionRetryFailure condition when flush_thread_count > 1 and depends on Fluentd core retrying mechanism (#516)
9
+
5
10
  ### 2.12.5
6
11
  - Ensure sniffer class constants definition before calling #client (#515)
7
12
 
data/README.md CHANGED
@@ -83,6 +83,7 @@ Current maintainers: @cosmo0920
83
83
  + [Cannot see detailed failure log](#cannot-see-detailed-failure-log)
84
84
  + [Cannot connect TLS enabled reverse Proxy](#cannot-connect-tls-enabled-reverse-proxy)
85
85
  + [Declined logs are resubmitted forever, why?](#declined-logs-are-resubmitted-forever-why)
86
+ + [Suggested to increase flush_thread_count, why?](#suggested-to-increase-flush_thread_count-why)
86
87
  * [Contact](#contact)
87
88
  * [Contributing](#contributing)
88
89
  * [Running tests](#running-tests)
@@ -1226,6 +1227,30 @@ The following configuration uses label:
1226
1227
  </label>
1227
1228
  ```
1228
1229
 
1230
+ ### Suggested to increase flush_thread_count, why?
1231
+
1232
+ fluent-plugin-elasticsearch default behavior has a possibility to cause events traffic jam.
1233
+ When users use `flush_thread_count` = 1, ES plugin retries to send events if connection errors are disappeared.
1234
+
1235
+ To prevent the following warning and sending events blocking, you must specify `flush_thread_count` > 2:
1236
+
1237
+ ```log
1238
+ 2018-12-24 14:32:06 +0900 [warn]: #0 To prevent events traffic jam, you should specify 2 or more 'flush_thread_count'.
1239
+ ```
1240
+
1241
+ ```aconf
1242
+ <match out.elasticsearch.**>
1243
+ @type elasticsearch
1244
+ host localhost
1245
+ port 9200
1246
+ # ...
1247
+ <buffer tag>
1248
+ @type memory # or file
1249
+ flush_thread_count 4
1250
+ </buffer>
1251
+ </match>
1252
+ ```
1253
+
1229
1254
  ## Contact
1230
1255
 
1231
1256
  If you have a question, [open an Issue](https://github.com/uken/fluent-plugin-elasticsearch/issues).
@@ -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.12.5'
6
+ s.version = '3.0.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}
@@ -1,4 +1,7 @@
1
+ require 'fluent/error'
2
+
1
3
  module Fluent::ElasticsearchIndexTemplate
4
+ class TemplateInstallationFailure < Fluent::UnrecoverableError; end
2
5
 
3
6
  def get_template(template_file)
4
7
  if !File.exists?(template_file)
@@ -31,7 +34,7 @@ module Fluent::ElasticsearchIndexTemplate
31
34
  retries = 0
32
35
  begin
33
36
  yield
34
- rescue Fluent::Plugin::ElasticsearchOutput::ConnectionFailure, Timeout::Error => e
37
+ rescue *client.transport.host_unreachable_exceptions, Timeout::Error => e
35
38
  @_es = nil
36
39
  @_es_info = nil
37
40
  if retries < max_retries
@@ -40,7 +43,7 @@ module Fluent::ElasticsearchIndexTemplate
40
43
  log.warn "Could not push template(s) to Elasticsearch, resetting connection and trying again. #{e.message}"
41
44
  retry
42
45
  end
43
- raise Fluent::Plugin::ElasticsearchOutput::ConnectionFailure, "Could not push template(s) to Elasticsearch after #{retries} retries. #{e.message}"
46
+ raise TemplateInstallationFailure, "Could not push template(s) to Elasticsearch after #{retries} retries. #{e.message}"
44
47
  end
45
48
  end
46
49
 
@@ -22,8 +22,8 @@ end
22
22
 
23
23
  module Fluent::Plugin
24
24
  class ElasticsearchOutput < Output
25
- class ConnectionFailure < StandardError; end
26
- class ConnectionRetryFailure < Fluent::UnrecoverableError; end
25
+ class RecoverableRequestFailure < StandardError; end
26
+ class UnrecoverableRequestFailure < Fluent::UnrecoverableError; end
27
27
 
28
28
  # MissingIdFieldError is raised for records that do not
29
29
  # include the field for the unique record identifier
@@ -264,6 +264,10 @@ EOC
264
264
  end
265
265
  end
266
266
  end
267
+
268
+ if @buffer_config.flush_thread_count < 2
269
+ log.warn "To prevent events traffic jam, you should specify 2 or more 'flush_thread_count'."
270
+ end
267
271
  end
268
272
 
269
273
  def backend_options
@@ -342,7 +346,6 @@ EOC
342
346
  reload_connections: local_reload_connections,
343
347
  reload_on_failure: @reload_on_failure,
344
348
  resurrect_after: @resurrect_after,
345
- retry_on_failure: 5,
346
349
  logger: @transport_logger,
347
350
  transport_options: {
348
351
  headers: { 'Content-Type' => @content_type.to_s },
@@ -356,16 +359,7 @@ EOC
356
359
  sniffer_class: @sniffer_class,
357
360
  serializer_class: @serializer_class,
358
361
  }), &adapter_conf)
359
- es = Elasticsearch::Client.new transport: transport
360
-
361
- begin
362
- raise ConnectionFailure, "Can not reach Elasticsearch cluster (#{connection_options_description})!" unless es.ping
363
- rescue *es.transport.host_unreachable_exceptions => e
364
- raise ConnectionFailure, "Can not reach Elasticsearch cluster (#{connection_options_description})! #{e.message}"
365
- end
366
-
367
- log.info "Connection opened to Elasticsearch cluster => #{connection_options_description}"
368
- es
362
+ Elasticsearch::Client.new transport: transport
369
363
  end
370
364
  end
371
365
 
@@ -632,7 +626,6 @@ EOC
632
626
  # send_bulk given a specific bulk request, the original tag,
633
627
  # chunk, and bulk_message_count
634
628
  def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, index)
635
- retries = 0
636
629
  begin
637
630
 
638
631
  log.on_trace { log.trace "bulk request: #{data}" }
@@ -646,20 +639,11 @@ EOC
646
639
  rescue RetryStreamError => e
647
640
  emit_tag = @retry_tag ? @retry_tag : tag
648
641
  router.emit_stream(emit_tag, e.retry_stream)
649
- rescue *client.transport.host_unreachable_exceptions => e
650
- if retries < 2
651
- retries += 1
652
- @_es = nil
653
- @_es_info = nil
654
- log.warn "Could not push logs to Elasticsearch, resetting connection and trying again. #{e.message}"
655
- sleep 2**retries
656
- retry
657
- end
658
- raise ConnectionRetryFailure, "Could not push logs to Elasticsearch after #{retries} retries. #{e.message}"
659
- rescue Exception
642
+ rescue => e
660
643
  @_es = nil if @reconnect_on_error
661
644
  @_es_info = nil if @reconnect_on_error
662
- raise
645
+ # FIXME: identify unrecoverable errors and raise UnrecoverableRequestFailure instead
646
+ raise RecoverableRequestFailure, "could not push logs to Elasticsearch cluster (#{connection_options_description}): #{e.message}"
663
647
  end
664
648
  end
665
649
  end
@@ -50,7 +50,6 @@ module Fluent::Plugin
50
50
  reload_connections: @reload_connections,
51
51
  reload_on_failure: @reload_on_failure,
52
52
  resurrect_after: @resurrect_after,
53
- retry_on_failure: 5,
54
53
  logger: @transport_logger,
55
54
  transport_options: {
56
55
  headers: { 'Content-Type' => @content_type.to_s },
@@ -62,16 +61,7 @@ module Fluent::Plugin
62
61
  password: @password
63
62
  }
64
63
  }), &adapter_conf)
65
- es = Elasticsearch::Client.new transport: transport
66
-
67
- begin
68
- raise ConnectionFailure, "Can not reach Elasticsearch cluster (#{connection_options_description(host)})!" unless es.ping
69
- rescue *es.transport.host_unreachable_exceptions => e
70
- raise ConnectionFailure, "Can not reach Elasticsearch cluster (#{connection_options_description(host)})! #{e.message}"
71
- end
72
-
73
- log.info "Connection opened to Elasticsearch cluster => #{connection_options_description(host)}"
74
- es
64
+ Elasticsearch::Client.new transport: transport
75
65
  end
76
66
  end
77
67
 
@@ -220,24 +210,15 @@ module Fluent::Plugin
220
210
  end
221
211
 
222
212
  def send_bulk(data, host, index)
223
- retries = 0
224
213
  begin
225
214
  response = client(host).bulk body: data, index: index
226
215
  if response['errors']
227
216
  log.error "Could not push log to Elasticsearch: #{response}"
228
217
  end
229
- rescue *client(host).transport.host_unreachable_exceptions => e
230
- if retries < 2
231
- retries += 1
232
- @_es = nil
233
- log.warn "Could not push logs to Elasticsearch, resetting connection and trying again. #{e.message}"
234
- sleep 2**retries
235
- retry
236
- end
237
- raise ConnectionRetryFailure, "Could not push logs to Elasticsearch after #{retries} retries. #{e.message}"
238
- rescue Exception
218
+ rescue => e
239
219
  @_es = nil if @reconnect_on_error
240
- raise
220
+ # FIXME: identify unrecoverable errors and raise UnrecoverableRequestFailure instead
221
+ raise RecoverableRequestFailure, "could not push logs to Elasticsearch cluster (#{connection_options_description(host)}): #{e.message}"
241
222
  end
242
223
  end
243
224
 
@@ -59,10 +59,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
59
59
  }
60
60
  end
61
61
 
62
- def stub_elastic_ping(url="http://localhost:9200")
63
- stub_request(:head, url).to_return(:status => 200, :body => "", :headers => {})
64
- end
65
-
66
62
  def stub_elastic_info(url="http://localhost:9200/", version="6.4.2")
67
63
  body ="{\"version\":{\"number\":\"#{version}\"}}"
68
64
  stub_request(:get, url).to_return({:status => 200, :body => body, :headers => { 'Content-Type' => 'json' } })
@@ -333,6 +329,27 @@ class ElasticsearchOutput < Test::Unit::TestCase
333
329
  end
334
330
  end
335
331
 
332
+ sub_test_case 'connection exceptions' do
333
+ test 'default connection exception' do
334
+ driver(Fluent::Config::Element.new(
335
+ 'ROOT', '', {
336
+ '@type' => 'elasticsearch',
337
+ 'host' => 'log.google.com',
338
+ 'port' => 777,
339
+ 'scheme' => 'https',
340
+ 'path' => '/es/',
341
+ 'user' => 'john',
342
+ 'pasword' => 'doe',
343
+ }, [
344
+ Fluent::Config::Element.new('buffer', 'tag', {
345
+ }, [])
346
+ ]
347
+ ))
348
+ logs = driver.logs
349
+ assert_logs_include(logs, /you should specify 2 or more 'flush_thread_count'/, 1)
350
+ end
351
+ end
352
+
336
353
  def test_template_already_present
337
354
  config = %{
338
355
  host logs.google.com
@@ -613,20 +630,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
613
630
  }
614
631
 
615
632
  connection_resets = 0
616
- # connection start
617
- stub_request(:head, "https://john:doe@logs.google.com:778/es//").with do |req|
618
- connection_resets += 1
619
- end
620
633
  # check if template exists
621
634
  stub_request(:get, "https://john:doe@logs.google.com:778/es//_template/logstash").with do |req|
622
- raise Fluent::Plugin::ElasticsearchOutput::ConnectionFailure, "Test message"
623
- end
624
- # creation
625
- stub_request(:put, "https://john:doe@logs.google.com:778/es//_template/logstash").with do |req|
626
- raise Fluent::Plugin::ElasticsearchOutput::ConnectionFailure, "Test message"
635
+ connection_resets += 1
636
+ raise Faraday::ConnectionFailed, "Test message"
627
637
  end
628
638
 
629
- assert_raise(Fluent::Plugin::ElasticsearchOutput::ConnectionFailure) do
639
+ assert_raise(Fluent::ElasticsearchIndexTemplate::TemplateInstallationFailure) do
630
640
  driver(config)
631
641
  end
632
642
 
@@ -913,7 +923,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
913
923
 
914
924
  def test_write_message_with_bad_chunk
915
925
  driver.configure("target_index_key bad_value\n@log_level debug\n")
916
- stub_elastic_ping
917
926
  stub_elastic
918
927
  driver.run(default_tag: 'test') do
919
928
  driver.feed({'bad_value'=>"\255"})
@@ -924,7 +933,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
924
933
  end
925
934
 
926
935
  def test_writes_to_default_index
927
- stub_elastic_ping
928
936
  stub_elastic
929
937
  driver.run(default_tag: 'test') do
930
938
  driver.feed(sample_record)
@@ -933,7 +941,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
933
941
  end
934
942
 
935
943
  def test_writes_to_default_type
936
- stub_elastic_ping
937
944
  stub_elastic
938
945
  driver.run(default_tag: 'test') do
939
946
  driver.feed(sample_record)
@@ -943,7 +950,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
943
950
 
944
951
  def test_writes_to_speficied_index
945
952
  driver.configure("index_name myindex\n")
946
- stub_elastic_ping
947
953
  stub_elastic
948
954
  driver.run(default_tag: 'test') do
949
955
  driver.feed(sample_record)
@@ -954,7 +960,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
954
960
  class IndexNamePlaceholdersTest < self
955
961
  def test_writes_to_speficied_index_with_tag_placeholder
956
962
  driver.configure("index_name myindex.${tag}\n")
957
- stub_elastic_ping
958
963
  stub_elastic
959
964
  driver.run(default_tag: 'test') do
960
965
  driver.feed(sample_record)
@@ -974,7 +979,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
974
979
  }, [])
975
980
  ]
976
981
  ))
977
- stub_elastic_ping
978
982
  stub_elastic
979
983
  time = Time.parse Date.today.iso8601
980
984
  driver.run(default_tag: 'test') do
@@ -995,7 +999,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
995
999
  time = Time.parse Date.today.iso8601
996
1000
  pipeline_id = "mypipeline"
997
1001
  logstash_index = "myindex.#{pipeline_id}"
998
- stub_elastic_ping
999
1002
  stub_elastic
1000
1003
  driver.run(default_tag: 'test') do
1001
1004
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
@@ -1006,7 +1009,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1006
1009
 
1007
1010
  def test_writes_to_speficied_index_uppercase
1008
1011
  driver.configure("index_name MyIndex\n")
1009
- stub_elastic_ping
1010
1012
  stub_elastic
1011
1013
  driver.run(default_tag: 'test') do
1012
1014
  driver.feed(sample_record)
@@ -1018,7 +1020,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1018
1020
 
1019
1021
  def test_writes_to_target_index_key
1020
1022
  driver.configure("target_index_key @target_index\n")
1021
- stub_elastic_ping
1022
1023
  stub_elastic
1023
1024
  record = sample_record.clone
1024
1025
  driver.run(default_tag: 'test') do
@@ -1032,7 +1033,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1032
1033
  driver.configure("target_index_key @target_index
1033
1034
  logstash_format true")
1034
1035
  time = Time.parse Date.today.iso8601
1035
- stub_elastic_ping
1036
1036
  stub_elastic
1037
1037
  driver.run(default_tag: 'test') do
1038
1038
  driver.feed(time.to_i, sample_record.merge('@target_index' => 'local-override'))
@@ -1044,7 +1044,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1044
1044
  driver.configure("target_index_key @target_index
1045
1045
  logstash_format true")
1046
1046
  time = Time.parse Date.today.iso8601
1047
- stub_elastic_ping
1048
1047
  stub_elastic
1049
1048
  driver.run(default_tag: 'test') do
1050
1049
  driver.feed(time.to_i, sample_record.merge('@target_index' => 'local-override'))
@@ -1057,7 +1056,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1057
1056
  def test_writes_to_default_index_with_pipeline
1058
1057
  pipeline = "fluentd"
1059
1058
  driver.configure("pipeline #{pipeline}")
1060
- stub_elastic_ping
1061
1059
  stub_elastic
1062
1060
  driver.run(default_tag: 'test') do
1063
1061
  driver.feed(sample_record)
@@ -1067,7 +1065,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1067
1065
 
1068
1066
  def test_writes_to_target_index_key_fallack
1069
1067
  driver.configure("target_index_key @target_index\n")
1070
- stub_elastic_ping
1071
1068
  stub_elastic
1072
1069
  driver.run(default_tag: 'test') do
1073
1070
  driver.feed(sample_record)
@@ -1080,7 +1077,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1080
1077
  logstash_format true")
1081
1078
  time = Time.parse Date.today.iso8601
1082
1079
  logstash_index = "logstash-#{time.getutc.strftime("%Y.%m.%d")}"
1083
- stub_elastic_ping
1084
1080
  stub_elastic
1085
1081
  driver.run(default_tag: 'test') do
1086
1082
  driver.feed(time.to_i, sample_record)
@@ -1093,7 +1089,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1093
1089
  )
1094
1090
  def test_writes_to_speficied_type(data)
1095
1091
  driver('', data["es_version"]).configure("type_name mytype\n")
1096
- stub_elastic_ping
1097
1092
  stub_elastic
1098
1093
  driver.run(default_tag: 'test') do
1099
1094
  driver.feed(sample_record)
@@ -1106,7 +1101,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1106
1101
  )
1107
1102
  def test_writes_to_speficied_type_with_placeholders(data)
1108
1103
  driver('', data["es_version"]).configure("type_name mytype.${tag}\n")
1109
- stub_elastic_ping
1110
1104
  stub_elastic
1111
1105
  driver.run(default_tag: 'test') do
1112
1106
  driver.feed(sample_record)
@@ -1121,7 +1115,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1121
1115
  )
1122
1116
  def test_writes_to_target_type_key(data)
1123
1117
  driver('', data["es_version"]).configure("target_type_key @target_type\n")
1124
- stub_elastic_ping
1125
1118
  stub_elastic
1126
1119
  record = sample_record.clone
1127
1120
  driver.run(default_tag: 'test') do
@@ -1133,7 +1126,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1133
1126
 
1134
1127
  def test_writes_to_target_type_key_fallack_to_default
1135
1128
  driver.configure("target_type_key @target_type\n")
1136
- stub_elastic_ping
1137
1129
  stub_elastic
1138
1130
  driver.run(default_tag: 'test') do
1139
1131
  driver.feed(sample_record)
@@ -1144,7 +1136,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1144
1136
  def test_writes_to_target_type_key_fallack_to_type_name
1145
1137
  driver.configure("target_type_key @target_type
1146
1138
  type_name mytype")
1147
- stub_elastic_ping
1148
1139
  stub_elastic
1149
1140
  driver.run(default_tag: 'test') do
1150
1141
  driver.feed(sample_record)
@@ -1159,7 +1150,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1159
1150
  )
1160
1151
  def test_writes_to_target_type_key_nested(data)
1161
1152
  driver('', data["es_version"]).configure("target_type_key kubernetes.labels.log_type\n")
1162
- stub_elastic_ping
1163
1153
  stub_elastic
1164
1154
  driver.run(default_tag: 'test') do
1165
1155
  driver.feed(sample_record.merge('kubernetes' => {
@@ -1174,7 +1164,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1174
1164
 
1175
1165
  def test_writes_to_target_type_key_fallack_to_default_nested
1176
1166
  driver.configure("target_type_key kubernetes.labels.log_type\n")
1177
- stub_elastic_ping
1178
1167
  stub_elastic
1179
1168
  driver.run(default_tag: 'test') do
1180
1169
  driver.feed(sample_record.merge('kubernetes' => {
@@ -1188,7 +1177,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1188
1177
 
1189
1178
  def test_writes_to_speficied_host
1190
1179
  driver.configure("host 192.168.33.50\n")
1191
- stub_elastic_ping("http://192.168.33.50:9200")
1192
1180
  elastic_request = stub_elastic("http://192.168.33.50:9200/_bulk")
1193
1181
  driver.run(default_tag: 'test') do
1194
1182
  driver.feed(sample_record)
@@ -1198,7 +1186,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1198
1186
 
1199
1187
  def test_writes_to_speficied_port
1200
1188
  driver.configure("port 9201\n")
1201
- stub_elastic_ping("http://localhost:9201")
1202
1189
  elastic_request = stub_elastic("http://localhost:9201/_bulk")
1203
1190
  driver.run(default_tag: 'test') do
1204
1191
  driver.feed(sample_record)
@@ -1214,7 +1201,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1214
1201
 
1215
1202
  hosts.each do |host_info|
1216
1203
  host, port = host_info
1217
- stub_elastic_ping("http://#{host}:#{port}")
1218
1204
  stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
1219
1205
  end
1220
1206
 
@@ -1251,7 +1237,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1251
1237
  {"age" => "30", "height" => "2ft"}
1252
1238
  ]}
1253
1239
 
1254
- stub_elastic_ping
1255
1240
  stub_elastic
1256
1241
  driver.run(default_tag: 'test') do
1257
1242
  driver.feed(original_hash)
@@ -1265,7 +1250,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1265
1250
  original_hash = {"foo" => {"bar" => "baz"}}
1266
1251
  expected_output = {"foo" => {"bar" => "baz"}}
1267
1252
 
1268
- stub_elastic_ping
1269
1253
  stub_elastic
1270
1254
  driver.run(default_tag: 'test') do
1271
1255
  driver.feed(original_hash)
@@ -1274,7 +1258,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1274
1258
  end
1275
1259
 
1276
1260
  def test_makes_bulk_request
1277
- stub_elastic_ping
1278
1261
  stub_elastic
1279
1262
  driver.run(default_tag: 'test') do
1280
1263
  driver.feed(sample_record)
@@ -1284,7 +1267,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1284
1267
  end
1285
1268
 
1286
1269
  def test_all_records_are_preserved_in_bulk
1287
- stub_elastic_ping
1288
1270
  stub_elastic
1289
1271
  driver.run(default_tag: 'test') do
1290
1272
  driver.feed(sample_record)
@@ -1300,7 +1282,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1300
1282
  # This is 1 second past midnight in BST, so the UTC index should be the day before
1301
1283
  dt = DateTime.new(2015, 6, 1, 0, 0, 1, "+01:00")
1302
1284
  logstash_index = "logstash-2015.05.31"
1303
- stub_elastic_ping
1304
1285
  stub_elastic
1305
1286
  driver.run(default_tag: 'test') do
1306
1287
  driver.feed(dt.to_time.to_i, sample_record)
@@ -1315,7 +1296,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1315
1296
  # ingestion time
1316
1297
  time = Date.today.to_time
1317
1298
  index = "logstash-#{time.strftime("%Y.%m.%d")}"
1318
- stub_elastic_ping
1319
1299
  stub_elastic
1320
1300
  driver.run(default_tag: 'test') do
1321
1301
  driver.feed(time.to_i, sample_record)
@@ -1328,7 +1308,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1328
1308
  logstash_prefix myprefix")
1329
1309
  time = Time.parse Date.today.iso8601
1330
1310
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
1331
- stub_elastic_ping
1332
1311
  stub_elastic
1333
1312
  driver.run(default_tag: 'test') do
1334
1313
  driver.feed(time.to_i, sample_record)
@@ -1343,7 +1322,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1343
1322
  logstash_prefix myprefix")
1344
1323
  time = Time.parse Date.today.iso8601
1345
1324
  logstash_index = "myprefix#{separator}#{time.getutc.strftime("%Y.%m.%d")}"
1346
- stub_elastic_ping
1347
1325
  stub_elastic
1348
1326
  driver.run(default_tag: 'test') do
1349
1327
  driver.feed(time.to_i, sample_record)
@@ -1357,7 +1335,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1357
1335
  logstash_prefix myprefix-${tag}")
1358
1336
  time = Time.parse Date.today.iso8601
1359
1337
  logstash_index = "myprefix-test-#{time.getutc.strftime("%Y.%m.%d")}"
1360
- stub_elastic_ping
1361
1338
  stub_elastic
1362
1339
  driver.run(default_tag: 'test') do
1363
1340
  driver.feed(time.to_i, sample_record)
@@ -1380,7 +1357,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1380
1357
  ))
1381
1358
  time = Time.parse Date.today.iso8601
1382
1359
  logstash_index = "myprefix-#{time.getutc.strftime("%H")}-#{time.getutc.strftime("%Y.%m.%d")}"
1383
- stub_elastic_ping
1384
1360
  stub_elastic
1385
1361
  driver.run(default_tag: 'test') do
1386
1362
  driver.feed(time.to_i, sample_record)
@@ -1401,7 +1377,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1401
1377
  time = Time.parse Date.today.iso8601
1402
1378
  pipeline_id = "mypipeline"
1403
1379
  logstash_index = "myprefix-#{pipeline_id}-#{time.getutc.strftime("%Y.%m.%d")}"
1404
- stub_elastic_ping
1405
1380
  stub_elastic
1406
1381
  driver.run(default_tag: 'test') do
1407
1382
  driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
@@ -1415,7 +1390,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1415
1390
  logstash_prefix MyPrefix")
1416
1391
  time = Time.parse Date.today.iso8601
1417
1392
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
1418
- stub_elastic_ping
1419
1393
  stub_elastic
1420
1394
  driver.run(default_tag: 'test') do
1421
1395
  driver.feed(time.to_i, sample_record)
@@ -1430,7 +1404,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1430
1404
  logstash_dateformat %Y.%m")
1431
1405
  time = Time.parse Date.today.iso8601
1432
1406
  logstash_index = "logstash-#{time.getutc.strftime("%Y.%m")}"
1433
- stub_elastic_ping
1434
1407
  stub_elastic
1435
1408
  driver.run(default_tag: 'test') do
1436
1409
  driver.feed(time.to_i, sample_record)
@@ -1444,7 +1417,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1444
1417
  logstash_dateformat %Y.%m")
1445
1418
  time = Time.parse Date.today.iso8601
1446
1419
  logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
1447
- stub_elastic_ping
1448
1420
  stub_elastic
1449
1421
  driver.run(default_tag: 'test') do
1450
1422
  driver.feed(time.to_i, sample_record)
@@ -1471,7 +1443,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1471
1443
  end
1472
1444
 
1473
1445
  def test_doesnt_add_logstash_timestamp_by_default
1474
- stub_elastic_ping
1475
1446
  stub_elastic
1476
1447
  driver.run(default_tag: 'test') do
1477
1448
  driver.feed(sample_record)
@@ -1481,7 +1452,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1481
1452
 
1482
1453
  def test_adds_timestamp_when_logstash
1483
1454
  driver.configure("logstash_format true\n")
1484
- stub_elastic_ping
1485
1455
  stub_elastic
1486
1456
  ts = DateTime.now
1487
1457
  time = Fluent::EventTime.from_time(ts.to_time)
@@ -1494,7 +1464,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1494
1464
 
1495
1465
  def test_adds_timestamp_when_include_timestamp
1496
1466
  driver.configure("include_timestamp true\n")
1497
- stub_elastic_ping
1498
1467
  stub_elastic
1499
1468
  ts = DateTime.now
1500
1469
  time = Fluent::EventTime.from_time(ts.to_time)
@@ -1507,7 +1476,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1507
1476
 
1508
1477
  def test_uses_custom_timestamp_when_included_in_record
1509
1478
  driver.configure("logstash_format true\n")
1510
- stub_elastic_ping
1511
1479
  stub_elastic
1512
1480
  ts = DateTime.new(2001,2,3).iso8601
1513
1481
  driver.run(default_tag: 'test') do
@@ -1519,7 +1487,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1519
1487
 
1520
1488
  def test_uses_custom_timestamp_when_included_in_record_without_logstash
1521
1489
  driver.configure("include_timestamp true\n")
1522
- stub_elastic_ping
1523
1490
  stub_elastic
1524
1491
  ts = DateTime.new(2001,2,3).iso8601
1525
1492
  driver.run(default_tag: 'test') do
@@ -1532,7 +1499,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1532
1499
  def test_uses_custom_time_key
1533
1500
  driver.configure("logstash_format true
1534
1501
  time_key vtm\n")
1535
- stub_elastic_ping
1536
1502
  stub_elastic
1537
1503
  ts = DateTime.new(2001,2,3).iso8601(9)
1538
1504
  driver.run(default_tag: 'test') do
@@ -1546,7 +1512,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1546
1512
  driver.configure("logstash_format true
1547
1513
  time_key_format %Y-%m-%d %H:%M:%S.%N%z
1548
1514
  time_key vtm\n")
1549
- stub_elastic_ping
1550
1515
  stub_elastic
1551
1516
  ts = "2001-02-03 13:14:01.673+02:00"
1552
1517
  driver.run(default_tag: 'test') do
@@ -1562,7 +1527,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1562
1527
  index_name test
1563
1528
  time_key_format %Y-%m-%d %H:%M:%S.%N%z
1564
1529
  time_key vtm\n")
1565
- stub_elastic_ping
1566
1530
  stub_elastic
1567
1531
  ts = "2001-02-03 13:14:01.673+02:00"
1568
1532
  driver.run(default_tag: 'test') do
@@ -1577,7 +1541,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1577
1541
  driver.configure("logstash_format true
1578
1542
  time_key vtm
1579
1543
  time_key_exclude_timestamp true\n")
1580
- stub_elastic_ping
1581
1544
  stub_elastic
1582
1545
  ts = DateTime.new(2001,2,3).iso8601
1583
1546
  driver.run(default_tag: 'test') do
@@ -1589,7 +1552,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1589
1552
  def test_uses_custom_time_key_format
1590
1553
  driver.configure("logstash_format true
1591
1554
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n")
1592
- stub_elastic_ping
1593
1555
  stub_elastic
1594
1556
  ts = "2001-02-03T13:14:01.673+02:00"
1595
1557
  driver.run(default_tag: 'test') do
@@ -1604,7 +1566,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1604
1566
  driver.configure("include_timestamp true
1605
1567
  index_name test
1606
1568
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n")
1607
- stub_elastic_ping
1608
1569
  stub_elastic
1609
1570
  ts = "2001-02-03T13:14:01.673+02:00"
1610
1571
  driver.run(default_tag: 'test') do
@@ -1622,7 +1583,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1622
1583
  tag_for_error = 'Fluent::ElasticsearchOutput::TimeParser.error' if tag_for_error.nil?
1623
1584
  driver.configure("logstash_format true
1624
1585
  time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n#{tag_config}\n")
1625
- stub_elastic_ping
1626
1586
  stub_elastic
1627
1587
 
1628
1588
  ts = "2001/02/03 13:14:01,673+02:00"
@@ -1643,7 +1603,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1643
1603
  def test_uses_custom_time_key_format_obscure_format
1644
1604
  driver.configure("logstash_format true
1645
1605
  time_key_format %a %b %d %H:%M:%S %Z %Y\n")
1646
- stub_elastic_ping
1647
1606
  stub_elastic
1648
1607
  ts = "Thu Nov 29 14:33:20 GMT 2001"
1649
1608
  driver.run(default_tag: 'test') do
@@ -1656,7 +1615,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1656
1615
 
1657
1616
  def test_uses_nanosecond_precision_by_default
1658
1617
  driver.configure("logstash_format true\n")
1659
- stub_elastic_ping
1660
1618
  stub_elastic
1661
1619
  time = Fluent::EventTime.new(Time.now.to_i, 123456789)
1662
1620
  driver.run(default_tag: 'test') do
@@ -1669,7 +1627,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1669
1627
  def test_uses_subsecond_precision_when_configured
1670
1628
  driver.configure("logstash_format true
1671
1629
  time_precision 3\n")
1672
- stub_elastic_ping
1673
1630
  stub_elastic
1674
1631
  time = Fluent::EventTime.new(Time.now.to_i, 123456789)
1675
1632
  driver.run(default_tag: 'test') do
@@ -1680,7 +1637,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1680
1637
  end
1681
1638
 
1682
1639
  def test_doesnt_add_tag_key_by_default
1683
- stub_elastic_ping
1684
1640
  stub_elastic
1685
1641
  driver.run(default_tag: 'test') do
1686
1642
  driver.feed(sample_record)
@@ -1690,7 +1646,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1690
1646
 
1691
1647
  def test_adds_tag_key_when_configured
1692
1648
  driver.configure("include_tag_key true\n")
1693
- stub_elastic_ping
1694
1649
  stub_elastic
1695
1650
  driver.run(default_tag: 'mytag') do
1696
1651
  driver.feed(sample_record)
@@ -1701,7 +1656,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1701
1656
 
1702
1657
  def test_adds_id_key_when_configured
1703
1658
  driver.configure("id_key request_id\n")
1704
- stub_elastic_ping
1705
1659
  stub_elastic
1706
1660
  driver.run(default_tag: 'test') do
1707
1661
  driver.feed(sample_record)
@@ -1712,7 +1666,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1712
1666
  class NestedIdKeyTest < self
1713
1667
  def test_adds_nested_id_key_with_dot
1714
1668
  driver.configure("id_key nested.request_id\n")
1715
- stub_elastic_ping
1716
1669
  stub_elastic
1717
1670
  driver.run(default_tag: 'test') do
1718
1671
  driver.feed(nested_sample_record)
@@ -1722,7 +1675,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1722
1675
 
1723
1676
  def test_adds_nested_id_key_with_dollar_dot
1724
1677
  driver.configure("id_key $.nested.request_id\n")
1725
- stub_elastic_ping
1726
1678
  stub_elastic
1727
1679
  driver.run(default_tag: 'test') do
1728
1680
  driver.feed(nested_sample_record)
@@ -1732,7 +1684,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1732
1684
 
1733
1685
  def test_adds_nested_id_key_with_bracket
1734
1686
  driver.configure("id_key $['nested']['request_id']\n")
1735
- stub_elastic_ping
1736
1687
  stub_elastic
1737
1688
  driver.run(default_tag: 'test') do
1738
1689
  driver.feed(nested_sample_record)
@@ -1743,7 +1694,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1743
1694
 
1744
1695
  def test_doesnt_add_id_key_if_missing_when_configured
1745
1696
  driver.configure("id_key another_request_id\n")
1746
- stub_elastic_ping
1747
1697
  stub_elastic
1748
1698
  driver.run(default_tag: 'test') do
1749
1699
  driver.feed(sample_record)
@@ -1752,7 +1702,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1752
1702
  end
1753
1703
 
1754
1704
  def test_adds_id_key_when_not_configured
1755
- stub_elastic_ping
1756
1705
  stub_elastic
1757
1706
  driver.run(default_tag: 'test') do
1758
1707
  driver.feed(sample_record)
@@ -1762,7 +1711,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1762
1711
 
1763
1712
  def test_adds_parent_key_when_configured
1764
1713
  driver.configure("parent_key parent_id\n")
1765
- stub_elastic_ping
1766
1714
  stub_elastic
1767
1715
  driver.run(default_tag: 'test') do
1768
1716
  driver.feed(sample_record)
@@ -1773,7 +1721,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1773
1721
  class NestedParentKeyTest < self
1774
1722
  def test_adds_nested_parent_key_with_dot
1775
1723
  driver.configure("parent_key nested.parent_id\n")
1776
- stub_elastic_ping
1777
1724
  stub_elastic
1778
1725
  driver.run(default_tag: 'test') do
1779
1726
  driver.feed(nested_sample_record)
@@ -1783,7 +1730,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1783
1730
 
1784
1731
  def test_adds_nested_parent_key_with_dollar_dot
1785
1732
  driver.configure("parent_key $.nested.parent_id\n")
1786
- stub_elastic_ping
1787
1733
  stub_elastic
1788
1734
  driver.run(default_tag: 'test') do
1789
1735
  driver.feed(nested_sample_record)
@@ -1793,7 +1739,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1793
1739
 
1794
1740
  def test_adds_nested_parent_key_with_bracket
1795
1741
  driver.configure("parent_key $['nested']['parent_id']\n")
1796
- stub_elastic_ping
1797
1742
  stub_elastic
1798
1743
  driver.run(default_tag: 'test') do
1799
1744
  driver.feed(nested_sample_record)
@@ -1804,7 +1749,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1804
1749
 
1805
1750
  def test_doesnt_add_parent_key_if_missing_when_configured
1806
1751
  driver.configure("parent_key another_parent_id\n")
1807
- stub_elastic_ping
1808
1752
  stub_elastic
1809
1753
  driver.run(default_tag: 'test') do
1810
1754
  driver.feed(sample_record)
@@ -1813,7 +1757,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1813
1757
  end
1814
1758
 
1815
1759
  def test_adds_parent_key_when_not_configured
1816
- stub_elastic_ping
1817
1760
  stub_elastic
1818
1761
  driver.run(default_tag: 'test') do
1819
1762
  driver.feed(sample_record)
@@ -1823,7 +1766,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1823
1766
 
1824
1767
  def test_adds_routing_key_when_configured
1825
1768
  driver.configure("routing_key routing_id\n")
1826
- stub_elastic_ping
1827
1769
  stub_elastic
1828
1770
  driver.run(default_tag: 'test') do
1829
1771
  driver.feed(sample_record)
@@ -1834,7 +1776,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1834
1776
  class NestedRoutingKeyTest < self
1835
1777
  def test_adds_nested_routing_key_with_dot
1836
1778
  driver.configure("routing_key nested.routing_id\n")
1837
- stub_elastic_ping
1838
1779
  stub_elastic
1839
1780
  driver.run(default_tag: 'test') do
1840
1781
  driver.feed(nested_sample_record)
@@ -1844,7 +1785,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1844
1785
 
1845
1786
  def test_adds_nested_routing_key_with_dollar_dot
1846
1787
  driver.configure("routing_key $.nested.routing_id\n")
1847
- stub_elastic_ping
1848
1788
  stub_elastic
1849
1789
  driver.run(default_tag: 'test') do
1850
1790
  driver.feed(nested_sample_record)
@@ -1854,7 +1794,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1854
1794
 
1855
1795
  def test_adds_nested_routing_key_with_bracket
1856
1796
  driver.configure("routing_key $['nested']['routing_id']\n")
1857
- stub_elastic_ping
1858
1797
  stub_elastic
1859
1798
  driver.run(default_tag: 'test') do
1860
1799
  driver.feed(nested_sample_record)
@@ -1865,7 +1804,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1865
1804
 
1866
1805
  def test_doesnt_add_routing_key_if_missing_when_configured
1867
1806
  driver.configure("routing_key another_routing_id\n")
1868
- stub_elastic_ping
1869
1807
  stub_elastic
1870
1808
  driver.run(default_tag: 'test') do
1871
1809
  driver.feed(sample_record)
@@ -1874,7 +1812,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1874
1812
  end
1875
1813
 
1876
1814
  def test_adds_routing_key_when_not_configured
1877
- stub_elastic_ping
1878
1815
  stub_elastic
1879
1816
  driver.run(default_tag: 'test') do
1880
1817
  driver.feed(sample_record)
@@ -1884,7 +1821,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1884
1821
 
1885
1822
  def test_remove_one_key
1886
1823
  driver.configure("remove_keys key1\n")
1887
- stub_elastic_ping
1888
1824
  stub_elastic
1889
1825
  driver.run(default_tag: 'test') do
1890
1826
  driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
@@ -1895,7 +1831,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
1895
1831
 
1896
1832
  def test_remove_multi_keys
1897
1833
  driver.configure("remove_keys key1, key2\n")
1898
- stub_elastic_ping
1899
1834
  stub_elastic
1900
1835
  driver.run(default_tag: 'test') do
1901
1836
  driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
@@ -1905,17 +1840,16 @@ class ElasticsearchOutput < Test::Unit::TestCase
1905
1840
  end
1906
1841
 
1907
1842
  def test_request_error
1908
- stub_elastic_ping
1909
1843
  stub_elastic_unavailable
1910
- assert_raise(Elasticsearch::Transport::Transport::Errors::ServiceUnavailable) {
1911
- driver.run(default_tag: 'test') do
1844
+ assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
1845
+ driver.run(default_tag: 'test', shutdown: false) do
1912
1846
  driver.feed(sample_record)
1913
1847
  end
1914
1848
  }
1915
1849
  end
1916
1850
 
1917
1851
  def test_request_forever
1918
- stub_elastic_ping
1852
+ omit("retry_forever test is unstable.") if ENV["CI"]
1919
1853
  stub_elastic
1920
1854
  driver.configure(Fluent::Config::Element.new(
1921
1855
  'ROOT', '', {
@@ -1927,42 +1861,40 @@ class ElasticsearchOutput < Test::Unit::TestCase
1927
1861
  ]
1928
1862
  ))
1929
1863
  stub_elastic_timeout
1930
- driver.run(default_tag: 'test', timeout: 10) do
1931
- driver.feed(sample_record)
1932
- end
1864
+ assert_raise(Timeout::Error) {
1865
+ driver.run(default_tag: 'test', timeout: 10, force_flush_retry: true) do
1866
+ driver.feed(sample_record)
1867
+ end
1868
+ }
1933
1869
  end
1934
1870
 
1935
- def test_connection_failed_retry
1871
+ def test_connection_failed
1936
1872
  connection_resets = 0
1937
1873
 
1938
- stub_elastic_ping(url="http://localhost:9200").with do |req|
1939
- connection_resets += 1
1940
- end
1941
-
1942
1874
  stub_request(:post, "http://localhost:9200/_bulk").with do |req|
1875
+ connection_resets += 1
1943
1876
  raise Faraday::ConnectionFailed, "Test message"
1944
1877
  end
1945
1878
 
1946
- driver.run(default_tag: 'test') do
1947
- driver.feed(sample_record)
1948
- end
1949
- assert_equal(connection_resets, 3)
1879
+ assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
1880
+ driver.run(default_tag: 'test', shutdown: false) do
1881
+ driver.feed(sample_record)
1882
+ end
1883
+ }
1884
+ assert_equal(connection_resets, 1)
1950
1885
  end
1951
1886
 
1952
1887
  def test_reconnect_on_error_enabled
1953
1888
  connection_resets = 0
1954
1889
 
1955
- stub_elastic_ping(url="http://localhost:9200").with do |req|
1956
- connection_resets += 1
1957
- end
1958
-
1959
1890
  stub_request(:post, "http://localhost:9200/_bulk").with do |req|
1891
+ connection_resets += 1
1960
1892
  raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
1961
1893
  end
1962
1894
 
1963
1895
  driver.configure("reconnect_on_error true\n")
1964
1896
 
1965
- assert_raise(ZeroDivisionError) {
1897
+ assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
1966
1898
  driver.run(default_tag: 'test', shutdown: false) do
1967
1899
  driver.feed(sample_record)
1968
1900
  end
@@ -1981,17 +1913,14 @@ class ElasticsearchOutput < Test::Unit::TestCase
1981
1913
  def test_reconnect_on_error_disabled
1982
1914
  connection_resets = 0
1983
1915
 
1984
- stub_elastic_ping(url="http://localhost:9200").with do |req|
1985
- connection_resets += 1
1986
- end
1987
-
1988
1916
  stub_request(:post, "http://localhost:9200/_bulk").with do |req|
1917
+ connection_resets += 1
1989
1918
  raise ZeroDivisionError, "any not host_unreachable_exceptions exception"
1990
1919
  end
1991
1920
 
1992
1921
  driver.configure("reconnect_on_error false\n")
1993
1922
 
1994
- assert_raise(ZeroDivisionError) {
1923
+ assert_raise(Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure) {
1995
1924
  driver.run(default_tag: 'test', shutdown: false) do
1996
1925
  driver.feed(sample_record)
1997
1926
  end
@@ -2007,7 +1936,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2007
1936
 
2008
1937
  def test_bulk_error_retags_when_configured
2009
1938
  driver.configure("retry_tag retry\n")
2010
- stub_elastic_ping
2011
1939
  stub_request(:post, 'http://localhost:9200/_bulk')
2012
1940
  .to_return(lambda do |req|
2013
1941
  { :status => 200,
@@ -2042,7 +1970,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2042
1970
 
2043
1971
  def test_create_should_write_records_with_ids_and_skip_those_without
2044
1972
  driver.configure("write_operation create\nid_key my_id\n@log_level debug")
2045
- stub_elastic_ping
2046
1973
  stub_request(:post, 'http://localhost:9200/_bulk')
2047
1974
  .to_return(lambda do |req|
2048
1975
  { :status => 200,
@@ -2092,7 +2019,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2092
2019
 
2093
2020
  def test_create_should_write_records_with_ids_and_emit_those_without
2094
2021
  driver.configure("write_operation create\nid_key my_id\nemit_error_for_missing_id true\n@log_level debug")
2095
- stub_elastic_ping
2096
2022
  stub_request(:post, 'http://localhost:9200/_bulk')
2097
2023
  .to_return(lambda do |req|
2098
2024
  { :status => 200,
@@ -2141,7 +2067,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2141
2067
  end
2142
2068
 
2143
2069
  def test_bulk_error
2144
- stub_elastic_ping
2145
2070
  stub_request(:post, 'http://localhost:9200/_bulk')
2146
2071
  .to_return(lambda do |req|
2147
2072
  { :status => 200,
@@ -2210,7 +2135,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2210
2135
 
2211
2136
  def test_update_should_not_write_if_theres_no_id
2212
2137
  driver.configure("write_operation update\n")
2213
- stub_elastic_ping
2214
2138
  stub_elastic
2215
2139
  driver.run(default_tag: 'test') do
2216
2140
  driver.feed(sample_record)
@@ -2220,7 +2144,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2220
2144
 
2221
2145
  def test_upsert_should_not_write_if_theres_no_id
2222
2146
  driver.configure("write_operation upsert\n")
2223
- stub_elastic_ping
2224
2147
  stub_elastic
2225
2148
  driver.run(default_tag: 'test') do
2226
2149
  driver.feed(sample_record)
@@ -2230,7 +2153,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2230
2153
 
2231
2154
  def test_create_should_not_write_if_theres_no_id
2232
2155
  driver.configure("write_operation create\n")
2233
- stub_elastic_ping
2234
2156
  stub_elastic
2235
2157
  driver.run(default_tag: 'test') do
2236
2158
  driver.feed(sample_record)
@@ -2241,7 +2163,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2241
2163
  def test_update_should_write_update_op_and_doc_as_upsert_is_false
2242
2164
  driver.configure("write_operation update
2243
2165
  id_key request_id")
2244
- stub_elastic_ping
2245
2166
  stub_elastic
2246
2167
  driver.run(default_tag: 'test') do
2247
2168
  driver.feed(sample_record)
@@ -2255,7 +2176,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2255
2176
  driver.configure("write_operation update
2256
2177
  id_key request_id
2257
2178
  remove_keys_on_update parent_id")
2258
- stub_elastic_ping
2259
2179
  stub_elastic
2260
2180
  driver.run(default_tag: 'test') do
2261
2181
  driver.feed(sample_record)
@@ -2267,7 +2187,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2267
2187
  def test_upsert_should_write_update_op_and_doc_as_upsert_is_true
2268
2188
  driver.configure("write_operation upsert
2269
2189
  id_key request_id")
2270
- stub_elastic_ping
2271
2190
  stub_elastic
2272
2191
  driver.run(default_tag: 'test') do
2273
2192
  driver.feed(sample_record)
@@ -2281,7 +2200,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2281
2200
  driver.configure("write_operation upsert
2282
2201
  id_key request_id
2283
2202
  remove_keys_on_update parent_id")
2284
- stub_elastic_ping
2285
2203
  stub_elastic
2286
2204
  driver.run(default_tag: 'test') do
2287
2205
  driver.feed(sample_record)
@@ -2296,7 +2214,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2296
2214
  driver.configure("write_operation upsert
2297
2215
  id_key request_id
2298
2216
  remove_keys_on_update parent_id")
2299
- stub_elastic_ping
2300
2217
  stub_elastic
2301
2218
  driver.run(default_tag: 'test') do
2302
2219
  driver.feed(sample_record)
@@ -2310,7 +2227,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2310
2227
  driver.configure("write_operation upsert
2311
2228
  id_key id
2312
2229
  remove_keys_on_update foo,baz")
2313
- stub_elastic_ping
2314
2230
  stub_elastic
2315
2231
  driver.run(default_tag: 'test') do
2316
2232
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "zip" => "zam")
@@ -2335,7 +2251,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2335
2251
  driver.configure("write_operation upsert
2336
2252
  id_key id
2337
2253
  remove_keys_on_update_key keys_to_skip")
2338
- stub_elastic_ping
2339
2254
  stub_elastic
2340
2255
  driver.run(default_tag: 'test') do
2341
2256
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "keys_to_skip" => ["baz"])
@@ -2360,7 +2275,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2360
2275
  id_key id
2361
2276
  remove_keys_on_update foo,bar
2362
2277
  remove_keys_on_update_key keys_to_skip")
2363
- stub_elastic_ping
2364
2278
  stub_elastic
2365
2279
  driver.run(default_tag: 'test') do
2366
2280
  driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "keys_to_skip" => ["baz"])
@@ -2385,7 +2299,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2385
2299
  def test_create_should_write_create_op
2386
2300
  driver.configure("write_operation create
2387
2301
  id_key request_id")
2388
- stub_elastic_ping
2389
2302
  stub_elastic
2390
2303
  driver.run(default_tag: 'test') do
2391
2304
  driver.feed(sample_record)
@@ -2394,7 +2307,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2394
2307
  end
2395
2308
 
2396
2309
  def test_include_index_in_url
2397
- stub_elastic_ping
2398
2310
  stub_elastic('http://localhost:9200/logstash-2018.01.01/_bulk')
2399
2311
 
2400
2312
  driver.configure("index_name logstash-2018.01.01
@@ -2409,7 +2321,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
2409
2321
 
2410
2322
  def test_use_simple_sniffer
2411
2323
  require 'fluent/plugin/elasticsearch_simple_sniffer'
2412
- stub_elastic_ping
2413
2324
  stub_elastic_info
2414
2325
  stub_elastic
2415
2326
  config = %[
@@ -2425,8 +2336,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
2425
2336
  end
2426
2337
  log = driver.logs
2427
2338
  # 2 or 3 - one for the ping, one for the _bulk, (and client.info)
2428
- assert_logs_include_compare_size(4, ">", log, /In Fluent::Plugin::ElasticsearchSimpleSniffer hosts/)
2429
- assert_logs_include_compare_size(2, "<=", log, /In Fluent::Plugin::ElasticsearchSimpleSniffer hosts/)
2339
+ assert_logs_include_compare_size(3, ">", log, /In Fluent::Plugin::ElasticsearchSimpleSniffer hosts/)
2340
+ assert_logs_include_compare_size(1, "<=", log, /In Fluent::Plugin::ElasticsearchSimpleSniffer hosts/)
2430
2341
  end
2431
2342
 
2432
2343
  end