fluent-plugin-elasticsearch 5.0.4 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
45
45
  {
46
46
  'data_streams': [
47
47
  {
48
- 'name' => 'my-data-stream',
48
+ 'name' => 'foo',
49
49
  'timestamp_field' => {
50
50
  'name' => '@timestamp'
51
51
  }
@@ -62,11 +62,11 @@ 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")
65
+ def stub_ilm_policy(name="foo_ilm")
66
66
  stub_request(:put, "http://localhost:9200/_ilm/policy/#{name}_policy").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
67
67
  end
68
68
 
69
- def stub_index_template(name="foo")
69
+ def stub_index_template(name="foo_tpl")
70
70
  stub_request(:put, "http://localhost:9200/_index_template/#{name}").to_return(:status => [200, RESPONSE_ACKNOWLEDGED])
71
71
  end
72
72
 
@@ -78,24 +78,60 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
78
78
  stub_request(:get, "http://localhost:9200/_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])
83
+ end
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])
87
+ end
88
+
81
89
  def stub_nonexistent_data_stream?(name="foo")
82
90
  stub_request(:get, "http://localhost:9200/_data_stream/#{name}").to_return(:status => [404, Elasticsearch::Transport::Transport::Errors::NotFound])
83
91
  end
84
92
 
85
- def stub_bulk_feed(name="foo")
86
- stub_request(:post, "http://localhost:9200/#{name}/_bulk").with do |req|
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])
95
+ end
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])
99
+ end
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|
87
103
  # bulk data must be pair of OP and records
88
- # {"create": {}}\n
104
+ # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
89
105
  # {"@timestamp": ...}
90
106
  @bulk_records += req.body.split("\n").size / 2
91
107
  end
108
+ stub_request(:post, "http://localhost:9200/#{ilm_name}/_bulk").with do |req|
109
+ # bulk data must be pair of OP and records
110
+ # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
111
+ # {"@timestamp": ...}
112
+ @bulk_records += req.body.split("\n").size / 2
113
+ end
114
+ stub_request(:post, "http://localhost:9200/#{template_name}/_bulk").with do |req|
115
+ # bulk data must be pair of OP and records
116
+ # {"create": {}}\nhttp://localhost:9200/_ilm/policy/foo_ilm_bar
117
+ # {"@timestamp": ...}
118
+ @bulk_records += req.body.split("\n").size / 2
119
+ end
120
+ end
121
+
122
+ def stub_elastic_info(url="http://localhost:9200/", version="7.9.0")
123
+ 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' } })
92
125
  end
93
126
 
94
- def stub_default(name="foo")
95
- stub_ilm_policy(name)
96
- stub_index_template(name)
97
- stub_nonexistent_data_stream?(name)
98
- stub_data_stream(name)
127
+ def stub_default(datastream_name="foo", ilm_name="foo_ilm", template_name="foo_tpl", host="http://localhost:9200")
128
+ stub_elastic_info(host)
129
+ stub_nonexistent_ilm?(ilm_name)
130
+ stub_ilm_policy(ilm_name)
131
+ stub_nonexistent_template?(template_name)
132
+ stub_index_template(template_name)
133
+ stub_nonexistent_data_stream?(datastream_name)
134
+ stub_data_stream(datastream_name)
99
135
  end
100
136
 
101
137
  def data_stream_supported?
@@ -115,82 +151,274 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
115
151
  end
116
152
  end
117
153
 
118
- def test_invalid_uppercase
119
- conf = config_element(
120
- 'ROOT', '', {
121
- '@type' => 'elasticsearch_datastream',
122
- 'data_stream_name' => 'TEST'
123
- })
124
- assert_raise Fluent::ConfigError.new("'data_stream_name' must be lowercase only: <TEST>") do
125
- driver(conf)
154
+ sub_test_case "invalid uppercase" do
155
+ def test_stream_name
156
+ conf = config_element(
157
+ 'ROOT', '', {
158
+ '@type' => 'elasticsearch_datastream',
159
+ 'data_stream_name' => 'TEST',
160
+ 'data_stream_ilm_name' => 'default-policy',
161
+ 'data_stream_template_name' => 'template'
162
+ })
163
+ assert_raise Fluent::ConfigError.new("'data_stream_name' must be lowercase only: <TEST>") do
164
+ driver(conf)
165
+ end
166
+ end
167
+ def test_stream_ilm_name
168
+ conf = config_element(
169
+ 'ROOT', '', {
170
+ '@type' => 'elasticsearch_datastream',
171
+ 'data_stream_name' => 'data_stream',
172
+ 'data_stream_ilm_name' => 'TEST-ILM',
173
+ 'data_stream_template_name' => 'template'
174
+ })
175
+ assert_raise Fluent::ConfigError.new("'data_stream_ilm_name' must be lowercase only: <TEST-ILM>") do
176
+ driver(conf)
177
+ end
178
+ end
179
+ def test_stream_template_name
180
+ conf = config_element(
181
+ 'ROOT', '', {
182
+ '@type' => 'elasticsearch_datastream',
183
+ 'data_stream_name' => 'default',
184
+ 'data_stream_ilm_name' => 'default-policy',
185
+ 'data_stream_template_name' => 'TEST-TPL'
186
+ })
187
+ assert_raise Fluent::ConfigError.new("'data_stream_template_name' must be lowercase only: <TEST-TPL>") do
188
+ driver(conf)
189
+ end
126
190
  end
127
191
  end
128
192
 
129
- data("backslash" => "\\",
130
- "slash" => "/",
131
- "asterisk" => "*",
132
- "question" => "?",
133
- "doublequote" => "\"",
134
- "lt" => "<",
135
- "gt" => ">",
136
- "bar" => "|",
137
- "space" => " ",
138
- "comma" => ",",
139
- "sharp" => "#",
140
- "colon" => ":")
141
- def test_invalid_characters(data)
142
- c, _ = data
143
- conf = config_element(
144
- 'ROOT', '', {
145
- '@type' => ELASTIC_DATA_STREAM_TYPE,
146
- 'data_stream_name' => "TEST#{c}"
147
- })
148
- label = Fluent::Plugin::ElasticsearchOutputDataStream::INVALID_CHARACTERS.join(',')
149
- assert_raise Fluent::ConfigError.new("'data_stream_name' must not contain invalid characters #{label}: <TEST#{c}>") do
150
- driver(conf)
193
+ sub_test_case "invalid parameters" do
194
+ data("backslash" => "\\",
195
+ "slash" => "/",
196
+ "asterisk" => "*",
197
+ "question" => "?",
198
+ "doublequote" => "\"",
199
+ "lt" => "<",
200
+ "gt" => ">",
201
+ "bar" => "|",
202
+ "space" => " ",
203
+ "comma" => ",",
204
+ "sharp" => "#",
205
+ "colon" => ":")
206
+ def test_stream_name(data)
207
+ c, _ = data
208
+ conf = config_element(
209
+ 'ROOT', '', {
210
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
211
+ 'data_stream_name' => "TEST#{c}",
212
+ 'data_stream_ilm_name' => "default_policy",
213
+ 'data_stream_template_name' => "data_stream"
214
+ })
215
+ label = Fluent::Plugin::ElasticsearchOutputDataStream::INVALID_CHARACTERS.join(',')
216
+ assert_raise Fluent::ConfigError.new("'data_stream_name' must not contain invalid characters #{label}: <TEST#{c}>") do
217
+ driver(conf)
218
+ end
219
+ end
220
+
221
+ data("backslash" => "\\",
222
+ "slash" => "/",
223
+ "asterisk" => "*",
224
+ "question" => "?",
225
+ "doublequote" => "\"",
226
+ "lt" => "<",
227
+ "gt" => ">",
228
+ "bar" => "|",
229
+ "space" => " ",
230
+ "comma" => ",",
231
+ "sharp" => "#",
232
+ "colon" => ":")
233
+ def test_stream_ilm_name(data)
234
+ c, _ = data
235
+ conf = config_element(
236
+ 'ROOT', '', {
237
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
238
+ 'data_stream_name' => "default",
239
+ 'data_stream_ilm_name' => "TEST#{c}",
240
+ 'data_stream_template_name' => "data_stream"
241
+ })
242
+ label = Fluent::Plugin::ElasticsearchOutputDataStream::INVALID_CHARACTERS.join(',')
243
+ assert_raise Fluent::ConfigError.new("'data_stream_ilm_name' must not contain invalid characters #{label}: <TEST#{c}>") do
244
+ driver(conf)
245
+ end
246
+ end
247
+
248
+ data("backslash" => "\\",
249
+ "slash" => "/",
250
+ "asterisk" => "*",
251
+ "question" => "?",
252
+ "doublequote" => "\"",
253
+ "lt" => "<",
254
+ "gt" => ">",
255
+ "bar" => "|",
256
+ "space" => " ",
257
+ "comma" => ",",
258
+ "sharp" => "#",
259
+ "colon" => ":")
260
+ def test_stream_template_name(data)
261
+ c, _ = data
262
+ conf = config_element(
263
+ 'ROOT', '', {
264
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
265
+ 'data_stream_name' => "default",
266
+ 'data_stream_ilm_name' => "default_policy",
267
+ 'data_stream_template_name' => "TEST#{c}"
268
+ })
269
+ label = Fluent::Plugin::ElasticsearchOutputDataStream::INVALID_CHARACTERS.join(',')
270
+ assert_raise Fluent::ConfigError.new("'data_stream_template_name' must not contain invalid characters #{label}: <TEST#{c}>") do
271
+ driver(conf)
272
+ end
151
273
  end
152
274
  end
153
275
 
154
- data("hyphen" => "-",
155
- "underscore" => "_",
156
- "plus" => "+",
157
- "period" => ".")
158
- def test_invalid_start_characters(data)
159
- c, _ = data
160
- conf = config_element(
161
- 'ROOT', '', {
162
- '@type' => ELASTIC_DATA_STREAM_TYPE,
163
- 'data_stream_name' => "#{c}TEST"
164
- })
165
- label = Fluent::Plugin::ElasticsearchOutputDataStream::INVALID_START_CHRACTERS.join(',')
166
- assert_raise Fluent::ConfigError.new("'data_stream_name' must not start with #{label}: <#{c}TEST>") do
167
- driver(conf)
276
+ sub_test_case "invalid start characters" do
277
+ data("hyphen" => "-",
278
+ "underscore" => "_",
279
+ "plus" => "+",
280
+ "period" => ".")
281
+ def test_stream_name(data)
282
+ c, _ = data
283
+ conf = config_element(
284
+ 'ROOT', '', {
285
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
286
+ 'data_stream_name' => "#{c}TEST",
287
+ 'data_stream_ilm_name' => "default-policy",
288
+ 'data_stream_template_name' => "template"
289
+ })
290
+ label = Fluent::Plugin::ElasticsearchOutputDataStream::INVALID_START_CHRACTERS.join(',')
291
+ assert_raise Fluent::ConfigError.new("'data_stream_name' must not start with #{label}: <#{c}TEST>") do
292
+ driver(conf)
293
+ end
294
+ end
295
+ data("hyphen" => "-",
296
+ "underscore" => "_",
297
+ "plus" => "+",
298
+ "period" => ".")
299
+ def test_stream_ilm_name(data)
300
+ c, _ = data
301
+ conf = config_element(
302
+ 'ROOT', '', {
303
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
304
+ 'data_stream_name' => "default",
305
+ 'data_stream_ilm_name' => "#{c}TEST",
306
+ 'data_stream_template_name' => "template"
307
+ })
308
+ label = Fluent::Plugin::ElasticsearchOutputDataStream::INVALID_START_CHRACTERS.join(',')
309
+ assert_raise Fluent::ConfigError.new("'data_stream_ilm_name' must not start with #{label}: <#{c}TEST>") do
310
+ driver(conf)
311
+ end
312
+ end
313
+ data("hyphen" => "-",
314
+ "underscore" => "_",
315
+ "plus" => "+",
316
+ "period" => ".")
317
+ def test_stream_template_name(data)
318
+ c, _ = data
319
+ conf = config_element(
320
+ 'ROOT', '', {
321
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
322
+ 'data_stream_name' => "default",
323
+ 'data_stream_ilm_name' => "default-policy",
324
+ 'data_stream_template_name' => "#{c}TEST"
325
+ })
326
+ label = Fluent::Plugin::ElasticsearchOutputDataStream::INVALID_START_CHRACTERS.join(',')
327
+ assert_raise Fluent::ConfigError.new("'data_stream_template_name' must not start with #{label}: <#{c}TEST>") do
328
+ driver(conf)
329
+ end
168
330
  end
169
331
  end
170
332
 
171
- data("current" => ".",
172
- "parents" => "..")
173
- def test_invalid_dots
174
- c, _ = data
175
- conf = config_element(
176
- 'ROOT', '', {
177
- '@type' => ELASTIC_DATA_STREAM_TYPE,
178
- 'data_stream_name' => "#{c}"
179
- })
180
- assert_raise Fluent::ConfigError.new("'data_stream_name' must not be . or ..: <#{c}>") do
181
- driver(conf)
333
+ sub_test_case "invalid dots" do
334
+ data("current" => ".",
335
+ "parents" => "..")
336
+ def test_stream_name
337
+ c, _ = data
338
+ conf = config_element(
339
+ 'ROOT', '', {
340
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
341
+ 'data_stream_name' => "#{c}",
342
+ 'data_stream_ilm_name' => "default-policy",
343
+ 'data_stream_template_name' => "template"
344
+ })
345
+ assert_raise Fluent::ConfigError.new("'data_stream_name' must not be . or ..: <#{c}>") do
346
+ driver(conf)
347
+ end
348
+ end
349
+
350
+ data("current" => ".",
351
+ "parents" => "..")
352
+ def test_stream_ilm_name
353
+ c, _ = data
354
+ conf = config_element(
355
+ 'ROOT', '', {
356
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
357
+ 'data_stream_name' => "default",
358
+ 'data_stream_ilm_name' => "#{c}",
359
+ 'data_stream_template_name' => "template"
360
+ })
361
+ assert_raise Fluent::ConfigError.new("'data_stream_ilm_name' must not be . or ..: <#{c}>") do
362
+ driver(conf)
363
+ end
364
+ end
365
+
366
+ data("current" => ".",
367
+ "parents" => "..")
368
+ def test_stream_template_name
369
+ c, _ = data
370
+ conf = config_element(
371
+ 'ROOT', '', {
372
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
373
+ 'data_stream_name' => "default",
374
+ 'data_stream_ilm_name' => "default-policy",
375
+ 'data_stream_template_name' => "#{c}"
376
+ })
377
+ assert_raise Fluent::ConfigError.new("'data_stream_template_name' must not be . or ..: <#{c}>") do
378
+ driver(conf)
379
+ end
182
380
  end
183
381
  end
184
382
 
185
- def test_invalid_length
186
- c = "a" * 256
187
- conf = config_element(
188
- 'ROOT', '', {
189
- '@type' => ELASTIC_DATA_STREAM_TYPE,
190
- 'data_stream_name' => "#{c}"
191
- })
192
- assert_raise Fluent::ConfigError.new("'data_stream_name' must not be longer than 255 bytes: <#{c}>") do
193
- driver(conf)
383
+ sub_test_case "invalid length" do
384
+ def test_stream_name
385
+ c = "a" * 256
386
+ conf = config_element(
387
+ 'ROOT', '', {
388
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
389
+ 'data_stream_name' => "#{c}",
390
+ 'data_stream_ilm_name' => "default-policy",
391
+ 'data_stream_template_name' => "template"
392
+ })
393
+ assert_raise Fluent::ConfigError.new("'data_stream_name' must not be longer than 255 bytes: <#{c}>") do
394
+ driver(conf)
395
+ end
396
+ end
397
+ def test_stream_ilm_name
398
+ c = "a" * 256
399
+ conf = config_element(
400
+ 'ROOT', '', {
401
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
402
+ 'data_stream_name' => "default",
403
+ 'data_stream_ilm_name' => "#{c}",
404
+ 'data_stream_template_name' => "template"
405
+ })
406
+ assert_raise Fluent::ConfigError.new("'data_stream_ilm_name' must not be longer than 255 bytes: <#{c}>") do
407
+ driver(conf)
408
+ end
409
+ end
410
+ def test_stream_template_name
411
+ c = "a" * 256
412
+ conf = config_element(
413
+ 'ROOT', '', {
414
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
415
+ 'data_stream_name' => "default",
416
+ 'data_stream_ilm_name' => "default-policy",
417
+ 'data_stream_template_name' => "#{c}"
418
+ })
419
+ assert_raise Fluent::ConfigError.new("'data_stream_template_name' must not be longer than 255 bytes: <#{c}>") do
420
+ driver(conf)
421
+ end
194
422
  end
195
423
  end
196
424
  end
@@ -202,7 +430,9 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
202
430
  conf = config_element(
203
431
  'ROOT', '', {
204
432
  '@type' => ELASTIC_DATA_STREAM_TYPE,
205
- 'data_stream_name' => 'foo'
433
+ 'data_stream_name' => 'foo',
434
+ 'data_stream_ilm_name' => "foo_ilm",
435
+ 'data_stream_template_name' => "foo_tpl"
206
436
  })
207
437
  assert_equal "foo", driver(conf).instance.data_stream_name
208
438
  end
@@ -214,24 +444,105 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
214
444
  stub_index_template
215
445
  stub_existent_data_stream?
216
446
  stub_data_stream
447
+ stub_elastic_info
217
448
  conf = config_element(
218
449
  'ROOT', '', {
219
450
  '@type' => ELASTIC_DATA_STREAM_TYPE,
220
- 'data_stream_name' => 'foo'
451
+ 'data_stream_name' => 'foo',
452
+ 'data_stream_ilm_name' => "foo_ilm",
453
+ 'data_stream_template_name' => "foo_tpl"
221
454
  })
222
455
  assert_equal "foo", driver(conf).instance.data_stream_name
223
456
  end
224
457
 
458
+ def test_template_unset
459
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
460
+
461
+ stub_ilm_policy
462
+ stub_index_template
463
+ stub_existent_data_stream?
464
+ stub_data_stream
465
+ stub_elastic_info
466
+ conf = config_element(
467
+ 'ROOT', '', {
468
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
469
+ 'data_stream_name' => 'foo',
470
+ 'data_stream_ilm_name' => "foo_ilm",
471
+ })
472
+ assert_equal "foo", driver(conf).instance.data_stream_name
473
+ assert_equal "foo_ilm", driver(conf).instance.data_stream_ilm_name
474
+ assert_equal "foo_template", driver(conf).instance.data_stream_template_name
475
+ end
476
+
477
+ def test_ilm_unset
478
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
479
+
480
+ stub_ilm_policy
481
+ stub_index_template
482
+ stub_existent_data_stream?
483
+ stub_data_stream
484
+ stub_elastic_info
485
+ conf = config_element(
486
+ 'ROOT', '', {
487
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
488
+ 'data_stream_name' => 'foo',
489
+ 'data_stream_template_name' => "foo_tpl"
490
+ })
491
+ assert_equal "foo", driver(conf).instance.data_stream_name
492
+ assert_equal "foo_tpl", driver(conf).instance.data_stream_template_name
493
+ end
494
+
495
+ def test_template_and_ilm_unset
496
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
497
+
498
+ stub_ilm_policy
499
+ stub_index_template
500
+ stub_existent_data_stream?
501
+ stub_data_stream
502
+ stub_elastic_info
503
+ conf = config_element(
504
+ 'ROOT', '', {
505
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
506
+ 'data_stream_name' => 'foo',
507
+ })
508
+ assert_equal "foo", driver(conf).instance.data_stream_name
509
+ assert_equal "foo_template", driver(conf).instance.data_stream_template_name
510
+ assert_equal "foo_policy", driver(conf).instance.data_stream_ilm_name
511
+ end
512
+
225
513
  def test_placeholder
226
514
  omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
227
515
 
228
- name = "foo_test"
229
- stub_default(name)
230
- stub_bulk_feed(name)
516
+ dsname = "foo_test"
517
+ ilmname = "foo_ilm_test"
518
+ tplname = "foo_tpl_test"
519
+ stub_default(dsname, ilmname, tplname)
520
+ stub_bulk_feed(dsname, ilmname, tplname)
521
+ conf = config_element(
522
+ 'ROOT', '', {
523
+ '@type' => ELASTIC_DATA_STREAM_TYPE,
524
+ 'data_stream_name' => 'foo_${tag}',
525
+ 'data_stream_ilm_name' => "foo_ilm_${tag}",
526
+ 'data_stream_template_name' => "foo_tpl_${tag}"
527
+ })
528
+ driver(conf).run(default_tag: 'test') do
529
+ driver.feed(sample_record)
530
+ end
531
+ assert_equal 1, @bulk_records
532
+ end
533
+
534
+ def test_placeholder_params_unset
535
+ omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
536
+
537
+ dsname = "foo_test"
538
+ ilmname = "foo_test_policy"
539
+ tplname = "foo_test_template"
540
+ stub_default(dsname, ilmname, tplname)
541
+ stub_bulk_feed(dsname, ilmname, tplname)
231
542
  conf = config_element(
232
543
  'ROOT', '', {
233
544
  '@type' => ELASTIC_DATA_STREAM_TYPE,
234
- 'data_stream_name' => 'foo_${tag}'
545
+ 'data_stream_name' => 'foo_${tag}',
235
546
  })
236
547
  driver(conf).run(default_tag: 'test') do
237
548
  driver.feed(sample_record)
@@ -239,17 +550,22 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
239
550
  assert_equal 1, @bulk_records
240
551
  end
241
552
 
553
+
242
554
  def test_time_placeholder
243
555
  omit REQUIRED_ELASTIC_MESSAGE unless data_stream_supported?
244
556
 
245
557
  time = Time.now
246
- name = "foo_#{time.strftime("%Y%m%d")}"
247
- stub_default(name)
248
- stub_bulk_feed(name)
558
+ dsname = "foo_#{time.strftime("%Y%m%d")}"
559
+ ilmname = "foo_ilm_#{time.strftime("%Y%m%d")}"
560
+ tplname = "foo_tpl_#{time.strftime("%Y%m%d")}"
561
+ stub_default(dsname, ilmname, tplname)
562
+ stub_bulk_feed(dsname, ilmname, tplname)
249
563
  conf = config_element(
250
564
  'ROOT', '', {
251
565
  '@type' => ELASTIC_DATA_STREAM_TYPE,
252
- 'data_stream_name' => 'foo_%Y%m%d'
566
+ 'data_stream_name' => 'foo_%Y%m%d',
567
+ 'data_stream_ilm_name' => 'foo_ilm_%Y%m%d',
568
+ 'data_stream_template_name' => 'foo_tpl_%Y%m%d'
253
569
  }, [config_element('buffer', 'time', {
254
570
  'timekey' => '1d'
255
571
  }, [])]
@@ -265,14 +581,18 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
265
581
 
266
582
  keys = ["bar", "baz"]
267
583
  keys.each do |key|
268
- name = "foo_#{key}"
269
- stub_default(name)
270
- stub_bulk_feed(name)
584
+ dsname = "foo_#{key}"
585
+ ilmname = "foo_ilm_#{key}"
586
+ tplname = "foo_tpl_#{key}"
587
+ stub_default(dsname, ilmname, tplname)
588
+ stub_bulk_feed(dsname, ilmname, tplname)
271
589
  end
272
590
  conf = config_element(
273
591
  'ROOT', '', {
274
592
  '@type' => ELASTIC_DATA_STREAM_TYPE,
275
- 'data_stream_name' => 'foo_${key1}'
593
+ 'data_stream_name' => 'foo_${key1}',
594
+ 'data_stream_ilm_name' => 'foo_ilm_${key1}',
595
+ 'data_stream_template_name' => 'foo_tpl_${key1}'
276
596
  }, [config_element('buffer', 'tag,key1', {
277
597
  'timekey' => '1d'
278
598
  }, [])]
@@ -294,7 +614,9 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
294
614
  conf = config_element(
295
615
  'ROOT', '', {
296
616
  '@type' => ELASTIC_DATA_STREAM_TYPE,
297
- 'data_stream_name' => 'foo'
617
+ 'data_stream_name' => 'foo',
618
+ 'data_stream_ilm_name' => 'foo_ilm',
619
+ 'data_stream_template_name' => 'foo_tpl'
298
620
  })
299
621
  driver(conf).run(default_tag: 'test') do
300
622
  driver.feed(sample_record)
@@ -309,14 +631,16 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
309
631
  template_file = File.join(cwd, 'test_index_template.json')
310
632
 
311
633
  config = %{
312
- host logs.google.com
313
- port 778
314
- scheme https
315
- data_stream_name foo
316
- user john
317
- password doe
318
- template_name logstash
319
- template_file #{template_file}
634
+ host logs.google.com
635
+ port 778
636
+ scheme https
637
+ data_stream_name foo
638
+ data_stream_ilm_name foo_ilm
639
+ data_stream_template_name foo_tpl
640
+ user john
641
+ password doe
642
+ template_name logstash
643
+ template_file #{template_file}
320
644
  max_retry_putting_template 3
321
645
  }
322
646
 
@@ -327,6 +651,7 @@ class ElasticsearchOutputDataStreamTest < Test::Unit::TestCase
327
651
  connection_resets += 1
328
652
  raise Faraday::ConnectionFailed, "Test message"
329
653
  end
654
+ stub_elastic_info("https://logs.google.com:778/")
330
655
 
331
656
  assert_raise(Fluent::Plugin::ElasticsearchError::RetryableOperationExhaustedFailure) do
332
657
  driver(config)