fluent-plugin-elasticsearch 1.18.2 → 2.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.travis.yml +0 -1
- data/History.md +4 -96
- data/README.md +23 -162
- data/fluent-plugin-elasticsearch.gemspec +5 -5
- data/lib/fluent/plugin/elasticsearch_index_template.rb +3 -8
- data/lib/fluent/plugin/out_elasticsearch.rb +314 -420
- data/lib/fluent/plugin/out_elasticsearch_dynamic.rb +206 -220
- data/test/plugin/test_out_elasticsearch.rb +303 -806
- data/test/plugin/test_out_elasticsearch_dynamic.rb +180 -257
- metadata +13 -24
- data/Gemfile.v0.12 +0 -11
- data/lib/fluent/log-ext.rb +0 -38
- data/lib/fluent/plugin/elasticsearch_constants.rb +0 -11
- data/lib/fluent/plugin/elasticsearch_error_handler.rb +0 -89
- data/lib/fluent/plugin/elasticsearch_simple_sniffer.rb +0 -10
- data/lib/fluent/plugin/filter_elasticsearch_genid.rb +0 -25
- data/test/plugin/test_elasticsearch_error_handler.rb +0 -264
- data/test/plugin/test_filter_elasticsearch_genid.rb +0 -40
- data/test/test_log-ext.rb +0 -33
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require 'date'
|
3
|
-
require '
|
3
|
+
require 'fluent/test/driver/output'
|
4
4
|
require 'flexmock/test_unit'
|
5
5
|
|
6
6
|
class ElasticsearchOutput < Test::Unit::TestCase
|
@@ -16,8 +16,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
16
16
|
log.out.logs.slice!(0, log.out.logs.length)
|
17
17
|
end
|
18
18
|
|
19
|
-
def driver(
|
20
|
-
@driver ||= Fluent::Test::
|
19
|
+
def driver(conf='')
|
20
|
+
@driver ||= Fluent::Test::Driver::Output.new(Fluent::Plugin::ElasticsearchOutput) {
|
21
21
|
# v0.12's test driver assume format definition. This simulates ObjectBufferedOutput format
|
22
22
|
if !defined?(Fluent::Plugin::Output)
|
23
23
|
def format(tag, time, record)
|
@@ -27,8 +27,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
27
27
|
}.configure(conf)
|
28
28
|
end
|
29
29
|
|
30
|
-
def sample_record
|
31
|
-
|
30
|
+
def sample_record
|
31
|
+
{'age' => 26, 'request_id' => '42', 'parent_id' => 'parent', 'routing_id' => 'routing'}
|
32
32
|
end
|
33
33
|
|
34
34
|
def stub_elastic_ping(url="http://localhost:9200")
|
@@ -37,7 +37,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
37
37
|
|
38
38
|
def stub_elastic(url="http://localhost:9200/_bulk")
|
39
39
|
stub_request(:post, url).with do |req|
|
40
|
-
|
40
|
+
@index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -57,112 +57,6 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
def make_response_body(req, error_el = nil, error_status = nil, error = nil)
|
61
|
-
req_index_cmds = req.body.split("\n").map { |r| JSON.parse(r) }
|
62
|
-
items = []
|
63
|
-
count = 0
|
64
|
-
ids = 1
|
65
|
-
op = nil
|
66
|
-
index = nil
|
67
|
-
type = nil
|
68
|
-
id = nil
|
69
|
-
req_index_cmds.each do |cmd|
|
70
|
-
if count.even?
|
71
|
-
op = cmd.keys[0]
|
72
|
-
index = cmd[op]['_index']
|
73
|
-
type = cmd[op]['_type']
|
74
|
-
if cmd[op].has_key?('_id')
|
75
|
-
id = cmd[op]['_id']
|
76
|
-
else
|
77
|
-
# Note: this appears to be an undocumented feature of Elasticsearch
|
78
|
-
# https://www.elastic.co/guide/en/elasticsearch/reference/2.4/docs-bulk.html
|
79
|
-
# When you submit an "index" write_operation, with no "_id" field in the
|
80
|
-
# metadata header, Elasticsearch will turn this into a "create"
|
81
|
-
# operation in the response.
|
82
|
-
if "index" == op
|
83
|
-
op = "create"
|
84
|
-
end
|
85
|
-
id = ids
|
86
|
-
ids += 1
|
87
|
-
end
|
88
|
-
else
|
89
|
-
item = {
|
90
|
-
op => {
|
91
|
-
'_index' => index, '_type' => type, '_id' => id, '_version' => 1,
|
92
|
-
'_shards' => { 'total' => 1, 'successful' => 1, 'failed' => 0 },
|
93
|
-
'status' => op == 'create' ? 201 : 200
|
94
|
-
}
|
95
|
-
}
|
96
|
-
items.push(item)
|
97
|
-
end
|
98
|
-
count += 1
|
99
|
-
end
|
100
|
-
if !error_el.nil? && !error_status.nil? && !error.nil?
|
101
|
-
op = items[error_el].keys[0]
|
102
|
-
items[error_el][op].delete('_version')
|
103
|
-
items[error_el][op].delete('_shards')
|
104
|
-
items[error_el][op]['error'] = error
|
105
|
-
items[error_el][op]['status'] = error_status
|
106
|
-
errors = true
|
107
|
-
else
|
108
|
-
errors = false
|
109
|
-
end
|
110
|
-
@index_cmds = items
|
111
|
-
body = { 'took' => 6, 'errors' => errors, 'items' => items }
|
112
|
-
return body.to_json
|
113
|
-
end
|
114
|
-
|
115
|
-
def stub_elastic_bad_argument(url="http://localhost:9200/_bulk")
|
116
|
-
error = {
|
117
|
-
"type" => "mapper_parsing_exception",
|
118
|
-
"reason" => "failed to parse [...]",
|
119
|
-
"caused_by" => {
|
120
|
-
"type" => "illegal_argument_exception",
|
121
|
-
"reason" => "Invalid format: \"...\""
|
122
|
-
}
|
123
|
-
}
|
124
|
-
stub_request(:post, url).to_return(lambda { |req| { :status => 200, :body => make_response_body(req, 1, 400, error), :headers => { 'Content-Type' => 'json' } } })
|
125
|
-
end
|
126
|
-
|
127
|
-
def stub_elastic_bulk_error(url="http://localhost:9200/_bulk")
|
128
|
-
error = {
|
129
|
-
"type" => "some-unrecognized-error",
|
130
|
-
"reason" => "some message printed here ...",
|
131
|
-
}
|
132
|
-
stub_request(:post, url).to_return(lambda { |req| { :status => 200, :body => make_response_body(req, 1, 500, error), :headers => { 'Content-Type' => 'json' } } })
|
133
|
-
end
|
134
|
-
|
135
|
-
def stub_elastic_bulk_rejected(url="http://localhost:9200/_bulk")
|
136
|
-
error = {
|
137
|
-
"status" => 500,
|
138
|
-
"type" => "es_rejected_execution_exception",
|
139
|
-
"reason" => "rejected execution of org.elasticsearch.transport.TransportService$4@1a34d37a on EsThreadPoolExecutor[bulk, queue capacity = 50, org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor@312a2162[Running, pool size = 32, active threads = 32, queued tasks = 50, completed tasks = 327053]]"
|
140
|
-
}
|
141
|
-
stub_request(:post, url).to_return(lambda { |req| { :status => 200, :body => make_response_body(req, 1, 429, error), :headers => { 'Content-Type' => 'json' } } })
|
142
|
-
end
|
143
|
-
|
144
|
-
def stub_elastic_out_of_memory(url="http://localhost:9200/_bulk")
|
145
|
-
error = {
|
146
|
-
"status" => 500,
|
147
|
-
"type" => "out_of_memory_error",
|
148
|
-
"reason" => "Java heap space"
|
149
|
-
}
|
150
|
-
stub_request(:post, url).to_return(lambda { |req| { :status => 200, :body => make_response_body(req, 1, 500, error), :headers => { 'Content-Type' => 'json' } } })
|
151
|
-
end
|
152
|
-
|
153
|
-
def stub_elastic_unexpected_response_op(url="http://localhost:9200/_bulk")
|
154
|
-
error = {
|
155
|
-
"category" => "some-other-type",
|
156
|
-
"reason" => "some-other-reason"
|
157
|
-
}
|
158
|
-
stub_request(:post, url).to_return(lambda { |req| bodystr = make_response_body(req, 0, 500, error); body = JSON.parse(bodystr); body['items'][0]['unknown'] = body['items'][0].delete('create'); { :status => 200, :body => body.to_json, :headers => { 'Content-Type' => 'json' } } })
|
159
|
-
end
|
160
|
-
|
161
|
-
def assert_logs_include(logs, msg, exp_matches=1)
|
162
|
-
matches = logs.grep /#{msg}/
|
163
|
-
assert_equal(exp_matches, matches.length, "Logs do not contain '#{msg}' '#{logs}'")
|
164
|
-
end
|
165
|
-
|
166
60
|
def test_configure
|
167
61
|
config = %{
|
168
62
|
host logs.google.com
|
@@ -172,19 +66,34 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
172
66
|
user john
|
173
67
|
password doe
|
174
68
|
}
|
175
|
-
instance = driver(
|
69
|
+
instance = driver(config).instance
|
176
70
|
|
177
71
|
assert_equal 'logs.google.com', instance.host
|
178
72
|
assert_equal 777, instance.port
|
179
|
-
assert_equal
|
73
|
+
assert_equal 'https', instance.scheme
|
180
74
|
assert_equal '/es/', instance.path
|
181
75
|
assert_equal 'john', instance.user
|
182
76
|
assert_equal 'doe', instance.password
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'lack of tag in chunk_keys' do
|
80
|
+
assert_raise_message(/'tag' in chunk_keys is required./) do
|
81
|
+
driver(Fluent::Config::Element.new(
|
82
|
+
'ROOT', '', {
|
83
|
+
'@type' => 'elasticsearch',
|
84
|
+
'host' => 'log.google.com',
|
85
|
+
'port' => 777,
|
86
|
+
'scheme' => 'https',
|
87
|
+
'path' => '/es/',
|
88
|
+
'user' => 'john',
|
89
|
+
'pasword' => 'doe',
|
90
|
+
}, [
|
91
|
+
Fluent::Config::Element.new('buffer', 'mykey', {
|
92
|
+
'chunk_keys' => 'mykey'
|
93
|
+
}, [])
|
94
|
+
]
|
95
|
+
))
|
96
|
+
end
|
188
97
|
end
|
189
98
|
|
190
99
|
def test_template_already_present
|
@@ -206,9 +115,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
206
115
|
stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash").
|
207
116
|
to_return(:status => 200, :body => "", :headers => {})
|
208
117
|
|
209
|
-
driver(
|
210
|
-
|
211
|
-
assert_not_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash")
|
118
|
+
driver(config)
|
212
119
|
end
|
213
120
|
|
214
121
|
def test_template_create
|
@@ -236,40 +143,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
236
143
|
stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash").
|
237
144
|
to_return(:status => 200, :body => "", :headers => {})
|
238
145
|
|
239
|
-
driver(
|
240
|
-
|
241
|
-
assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash", times: 1)
|
242
|
-
end
|
243
|
-
|
244
|
-
def test_template_overwrite
|
245
|
-
cwd = File.dirname(__FILE__)
|
246
|
-
template_file = File.join(cwd, 'test_template.json')
|
247
|
-
|
248
|
-
config = %{
|
249
|
-
host logs.google.com
|
250
|
-
port 777
|
251
|
-
scheme https
|
252
|
-
path /es/
|
253
|
-
user john
|
254
|
-
password doe
|
255
|
-
template_name logstash
|
256
|
-
template_file #{template_file}
|
257
|
-
template_overwrite true
|
258
|
-
}
|
259
|
-
|
260
|
-
# connection start
|
261
|
-
stub_request(:head, "https://john:doe@logs.google.com:777/es//").
|
262
|
-
to_return(:status => 200, :body => "", :headers => {})
|
263
|
-
# check if template exists
|
264
|
-
stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash").
|
265
|
-
to_return(:status => 200, :body => "", :headers => {})
|
266
|
-
# creation
|
267
|
-
stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash").
|
268
|
-
to_return(:status => 200, :body => "", :headers => {})
|
269
|
-
|
270
|
-
driver('test', config)
|
271
|
-
|
272
|
-
assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash", times: 1)
|
146
|
+
driver(config)
|
273
147
|
end
|
274
148
|
|
275
149
|
|
@@ -293,7 +167,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
293
167
|
to_return(:status => 404, :body => "", :headers => {})
|
294
168
|
|
295
169
|
assert_raise(RuntimeError) {
|
296
|
-
driver(
|
170
|
+
driver(config)
|
297
171
|
}
|
298
172
|
end
|
299
173
|
|
@@ -328,51 +202,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
328
202
|
stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash3").
|
329
203
|
to_return(:status => 200, :body => "", :headers => {})
|
330
204
|
|
331
|
-
driver(
|
205
|
+
driver(config)
|
332
206
|
|
333
207
|
assert_requested( :put, "https://john:doe@logs.google.com:777/es//_template/logstash1", times: 1)
|
334
208
|
assert_requested( :put, "https://john:doe@logs.google.com:777/es//_template/logstash2", times: 1)
|
335
209
|
assert_not_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash3") #exists
|
336
210
|
end
|
337
211
|
|
338
|
-
def test_templates_overwrite
|
339
|
-
cwd = File.dirname(__FILE__)
|
340
|
-
template_file = File.join(cwd, 'test_template.json')
|
341
|
-
config = %{
|
342
|
-
host logs.google.com
|
343
|
-
port 777
|
344
|
-
scheme https
|
345
|
-
path /es/
|
346
|
-
user john
|
347
|
-
password doe
|
348
|
-
templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}","logstash3":"#{template_file}" }
|
349
|
-
template_overwrite true
|
350
|
-
}
|
351
|
-
|
352
|
-
stub_request(:head, "https://john:doe@logs.google.com:777/es//").
|
353
|
-
to_return(:status => 200, :body => "", :headers => {})
|
354
|
-
# check if template exists
|
355
|
-
stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash1").
|
356
|
-
to_return(:status => 200, :body => "", :headers => {})
|
357
|
-
stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash2").
|
358
|
-
to_return(:status => 200, :body => "", :headers => {})
|
359
|
-
stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash3").
|
360
|
-
to_return(:status => 200, :body => "", :headers => {}) #exists
|
361
|
-
|
362
|
-
stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash1").
|
363
|
-
to_return(:status => 200, :body => "", :headers => {})
|
364
|
-
stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash2").
|
365
|
-
to_return(:status => 200, :body => "", :headers => {})
|
366
|
-
stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash3").
|
367
|
-
to_return(:status => 200, :body => "", :headers => {})
|
368
|
-
|
369
|
-
driver('test', config)
|
370
|
-
|
371
|
-
assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash1", times: 1)
|
372
|
-
assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash2", times: 1)
|
373
|
-
assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash3", times: 1)
|
374
|
-
end
|
375
|
-
|
376
212
|
def test_templates_not_used
|
377
213
|
cwd = File.dirname(__FILE__)
|
378
214
|
template_file = File.join(cwd, 'test_template.json')
|
@@ -406,7 +242,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
406
242
|
stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash2").
|
407
243
|
to_return(:status => 200, :body => "", :headers => {})
|
408
244
|
|
409
|
-
driver(
|
245
|
+
driver(config)
|
410
246
|
|
411
247
|
assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash", times: 1)
|
412
248
|
|
@@ -440,7 +276,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
440
276
|
to_return(:status => 200, :body => "", :headers => {})
|
441
277
|
|
442
278
|
assert_raise(RuntimeError) {
|
443
|
-
driver(
|
279
|
+
driver(config)
|
444
280
|
}
|
445
281
|
|
446
282
|
assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash1", times: 1)
|
@@ -454,7 +290,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
454
290
|
path /es/
|
455
291
|
port 123
|
456
292
|
}
|
457
|
-
instance = driver(
|
293
|
+
instance = driver(config).instance
|
458
294
|
|
459
295
|
assert_equal 3, instance.get_connection_options[:hosts].length
|
460
296
|
host1, host2, host3 = instance.get_connection_options[:hosts]
|
@@ -476,7 +312,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
476
312
|
user default_user
|
477
313
|
password default_password
|
478
314
|
}
|
479
|
-
instance = driver(
|
315
|
+
instance = driver(config).instance
|
480
316
|
|
481
317
|
assert_equal 2, instance.get_connection_options[:hosts].length
|
482
318
|
host1, host2 = instance.get_connection_options[:hosts]
|
@@ -495,39 +331,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
495
331
|
assert_equal '/default_path', host2[:path]
|
496
332
|
end
|
497
333
|
|
498
|
-
def test_hosts_list_with_escape_placeholders
|
499
|
-
config = %{
|
500
|
-
hosts https://%{j+hn}:%{passw@rd}@host1:443/elastic/,http://host2
|
501
|
-
path /default_path
|
502
|
-
user default_user
|
503
|
-
password default_password
|
504
|
-
}
|
505
|
-
instance = driver('test', config).instance
|
506
|
-
|
507
|
-
assert_equal 2, instance.get_connection_options[:hosts].length
|
508
|
-
host1, host2 = instance.get_connection_options[:hosts]
|
509
|
-
|
510
|
-
assert_equal 'host1', host1[:host]
|
511
|
-
assert_equal 443, host1[:port]
|
512
|
-
assert_equal 'https', host1[:scheme]
|
513
|
-
assert_equal 'j%2Bhn', host1[:user]
|
514
|
-
assert_equal 'passw%40rd', host1[:password]
|
515
|
-
assert_equal '/elastic/', host1[:path]
|
516
|
-
|
517
|
-
assert_equal 'host2', host2[:host]
|
518
|
-
assert_equal 'http', host2[:scheme]
|
519
|
-
assert_equal 'default_user', host2[:user]
|
520
|
-
assert_equal 'default_password', host2[:password]
|
521
|
-
assert_equal '/default_path', host2[:path]
|
522
|
-
end
|
523
|
-
|
524
334
|
def test_single_host_params_and_defaults
|
525
335
|
config = %{
|
526
336
|
host logs.google.com
|
527
337
|
user john
|
528
338
|
password doe
|
529
339
|
}
|
530
|
-
instance = driver(
|
340
|
+
instance = driver(config).instance
|
531
341
|
|
532
342
|
assert_equal 1, instance.get_connection_options[:hosts].length
|
533
343
|
host1 = instance.get_connection_options[:hosts][0]
|
@@ -540,63 +350,32 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
540
350
|
assert_equal nil, host1[:path]
|
541
351
|
end
|
542
352
|
|
543
|
-
def test_single_host_params_and_defaults_with_escape_placeholders
|
544
|
-
config = %{
|
545
|
-
host logs.google.com
|
546
|
-
user %{j+hn}
|
547
|
-
password %{d@e}
|
548
|
-
}
|
549
|
-
instance = driver('test', config).instance
|
550
|
-
|
551
|
-
assert_equal 1, instance.get_connection_options[:hosts].length
|
552
|
-
host1 = instance.get_connection_options[:hosts][0]
|
553
|
-
|
554
|
-
assert_equal 'logs.google.com', host1[:host]
|
555
|
-
assert_equal 9200, host1[:port]
|
556
|
-
assert_equal 'http', host1[:scheme]
|
557
|
-
assert_equal 'j%2Bhn', host1[:user]
|
558
|
-
assert_equal 'd%40e', host1[:password]
|
559
|
-
assert_equal nil, host1[:path]
|
560
|
-
end
|
561
|
-
|
562
353
|
def test_content_type_header
|
563
354
|
stub_request(:head, "http://localhost:9200/").
|
564
355
|
to_return(:status => 200, :body => "", :headers => {})
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
with(headers: { "Content-Type" => "application/json" })
|
571
|
-
end
|
572
|
-
driver.emit(sample_record)
|
573
|
-
driver.run
|
356
|
+
elastic_request = stub_request(:post, "http://localhost:9200/_bulk").
|
357
|
+
with(headers: { "Content-Type" => "application/json" })
|
358
|
+
driver.run(default_tag: 'test') do
|
359
|
+
driver.feed(sample_record)
|
360
|
+
end
|
574
361
|
assert_requested(elastic_request)
|
575
362
|
end
|
576
363
|
|
577
|
-
def test_write_message_with_bad_chunk
|
578
|
-
driver.configure("target_index_key bad_value\n")
|
579
|
-
log = driver.instance.router.emit_error_handler.log
|
580
|
-
stub_elastic_ping
|
581
|
-
stub_elastic
|
582
|
-
driver.emit({'bad_value'=>"\255"})
|
583
|
-
driver.run
|
584
|
-
assert_logs_include(log.out.logs, /(input string invalid)|(invalid byte sequence in UTF-8)/)
|
585
|
-
end
|
586
|
-
|
587
364
|
def test_writes_to_default_index
|
588
365
|
stub_elastic_ping
|
589
366
|
stub_elastic
|
590
|
-
driver.
|
591
|
-
|
367
|
+
driver.run(default_tag: 'test') do
|
368
|
+
driver.feed(sample_record)
|
369
|
+
end
|
592
370
|
assert_equal('fluentd', index_cmds.first['index']['_index'])
|
593
371
|
end
|
594
372
|
|
595
373
|
def test_writes_to_default_type
|
596
374
|
stub_elastic_ping
|
597
375
|
stub_elastic
|
598
|
-
driver.
|
599
|
-
|
376
|
+
driver.run(default_tag: 'test') do
|
377
|
+
driver.feed(sample_record)
|
378
|
+
end
|
600
379
|
assert_equal('fluentd', index_cmds.first['index']['_type'])
|
601
380
|
end
|
602
381
|
|
@@ -604,8 +383,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
604
383
|
driver.configure("index_name myindex\n")
|
605
384
|
stub_elastic_ping
|
606
385
|
stub_elastic
|
607
|
-
driver.
|
608
|
-
|
386
|
+
driver.run(default_tag: 'test') do
|
387
|
+
driver.feed(sample_record)
|
388
|
+
end
|
609
389
|
assert_equal('myindex', index_cmds.first['index']['_index'])
|
610
390
|
end
|
611
391
|
|
@@ -613,8 +393,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
613
393
|
driver.configure("index_name MyIndex\n")
|
614
394
|
stub_elastic_ping
|
615
395
|
stub_elastic
|
616
|
-
driver.
|
617
|
-
|
396
|
+
driver.run(default_tag: 'test') do
|
397
|
+
driver.feed(sample_record)
|
398
|
+
end
|
618
399
|
# Allthough index_name has upper-case characters,
|
619
400
|
# it should be set as lower-case when sent to elasticsearch.
|
620
401
|
assert_equal('myindex', index_cmds.first['index']['_index'])
|
@@ -625,8 +406,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
625
406
|
stub_elastic_ping
|
626
407
|
stub_elastic
|
627
408
|
record = sample_record.clone
|
628
|
-
driver.
|
629
|
-
|
409
|
+
driver.run(default_tag: 'test') do
|
410
|
+
driver.feed(sample_record.merge('@target_index' => 'local-override'))
|
411
|
+
end
|
630
412
|
assert_equal('local-override', index_cmds.first['index']['_index'])
|
631
413
|
assert_nil(index_cmds[1]['@target_index'])
|
632
414
|
end
|
@@ -634,55 +416,49 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
634
416
|
def test_writes_to_target_index_key_logstash
|
635
417
|
driver.configure("target_index_key @target_index
|
636
418
|
logstash_format true")
|
637
|
-
time = Time.parse Date.today.
|
419
|
+
time = Time.parse Date.today.to_s
|
638
420
|
stub_elastic_ping
|
639
421
|
stub_elastic
|
640
|
-
driver.
|
641
|
-
|
422
|
+
driver.run(default_tag: 'test') do
|
423
|
+
driver.feed(time.to_i, sample_record.merge('@target_index' => 'local-override'))
|
424
|
+
end
|
642
425
|
assert_equal('local-override', index_cmds.first['index']['_index'])
|
643
426
|
end
|
644
427
|
|
645
428
|
def test_writes_to_target_index_key_logstash_uppercase
|
646
429
|
driver.configure("target_index_key @target_index
|
647
430
|
logstash_format true")
|
648
|
-
time = Time.parse Date.today.
|
431
|
+
time = Time.parse Date.today.to_s
|
649
432
|
stub_elastic_ping
|
650
433
|
stub_elastic
|
651
|
-
driver.
|
652
|
-
|
434
|
+
driver.run(default_tag: 'test') do
|
435
|
+
driver.feed(time.to_i, sample_record.merge('@target_index' => 'local-override'))
|
436
|
+
end
|
653
437
|
# Allthough @target_index has upper-case characters,
|
654
438
|
# it should be set as lower-case when sent to elasticsearch.
|
655
439
|
assert_equal('local-override', index_cmds.first['index']['_index'])
|
656
440
|
end
|
657
441
|
|
658
|
-
def test_writes_to_default_index_with_pipeline
|
659
|
-
pipeline = "fluentd"
|
660
|
-
driver.configure("pipeline #{pipeline}")
|
661
|
-
stub_elastic_ping
|
662
|
-
stub_elastic
|
663
|
-
driver.emit(sample_record)
|
664
|
-
driver.run
|
665
|
-
assert_equal(pipeline, index_cmds.first['index']['pipeline'])
|
666
|
-
end
|
667
|
-
|
668
442
|
def test_writes_to_target_index_key_fallack
|
669
443
|
driver.configure("target_index_key @target_index\n")
|
670
444
|
stub_elastic_ping
|
671
445
|
stub_elastic
|
672
|
-
driver.
|
673
|
-
|
446
|
+
driver.run(default_tag: 'test') do
|
447
|
+
driver.feed(sample_record)
|
448
|
+
end
|
674
449
|
assert_equal('fluentd', index_cmds.first['index']['_index'])
|
675
450
|
end
|
676
451
|
|
677
452
|
def test_writes_to_target_index_key_fallack_logstash
|
678
453
|
driver.configure("target_index_key @target_index\n
|
679
454
|
logstash_format true")
|
680
|
-
time = Time.parse Date.today.
|
455
|
+
time = Time.parse Date.today.to_s
|
681
456
|
logstash_index = "logstash-#{time.getutc.strftime("%Y.%m.%d")}"
|
682
457
|
stub_elastic_ping
|
683
458
|
stub_elastic
|
684
|
-
driver.
|
685
|
-
|
459
|
+
driver.run(default_tag: 'test') do
|
460
|
+
driver.feed(time.to_i, sample_record)
|
461
|
+
end
|
686
462
|
assert_equal(logstash_index, index_cmds.first['index']['_index'])
|
687
463
|
end
|
688
464
|
|
@@ -690,8 +466,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
690
466
|
driver.configure("type_name mytype\n")
|
691
467
|
stub_elastic_ping
|
692
468
|
stub_elastic
|
693
|
-
driver.
|
694
|
-
|
469
|
+
driver.run(default_tag: 'test') do
|
470
|
+
driver.feed(sample_record)
|
471
|
+
end
|
695
472
|
assert_equal('mytype', index_cmds.first['index']['_type'])
|
696
473
|
end
|
697
474
|
|
@@ -700,8 +477,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
700
477
|
stub_elastic_ping
|
701
478
|
stub_elastic
|
702
479
|
record = sample_record.clone
|
703
|
-
driver.
|
704
|
-
|
480
|
+
driver.run(default_tag: 'test') do
|
481
|
+
driver.feed(sample_record.merge('@target_type' => 'local-override'))
|
482
|
+
end
|
705
483
|
assert_equal('local-override', index_cmds.first['index']['_type'])
|
706
484
|
assert_nil(index_cmds[1]['@target_type'])
|
707
485
|
end
|
@@ -710,8 +488,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
710
488
|
driver.configure("target_type_key @target_type\n")
|
711
489
|
stub_elastic_ping
|
712
490
|
stub_elastic
|
713
|
-
driver.
|
714
|
-
|
491
|
+
driver.run(default_tag: 'test') do
|
492
|
+
driver.feed(sample_record)
|
493
|
+
end
|
715
494
|
assert_equal('fluentd', index_cmds.first['index']['_type'])
|
716
495
|
end
|
717
496
|
|
@@ -720,8 +499,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
720
499
|
type_name mytype")
|
721
500
|
stub_elastic_ping
|
722
501
|
stub_elastic
|
723
|
-
driver.
|
724
|
-
|
502
|
+
driver.run(default_tag: 'test') do
|
503
|
+
driver.feed(sample_record)
|
504
|
+
end
|
725
505
|
assert_equal('mytype', index_cmds.first['index']['_type'])
|
726
506
|
end
|
727
507
|
|
@@ -729,12 +509,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
729
509
|
driver.configure("target_type_key kubernetes.labels.log_type\n")
|
730
510
|
stub_elastic_ping
|
731
511
|
stub_elastic
|
732
|
-
driver.
|
733
|
-
'
|
734
|
-
'
|
735
|
-
|
736
|
-
|
737
|
-
|
512
|
+
driver.run(default_tag: 'test') do
|
513
|
+
driver.feed(sample_record.merge('kubernetes' => {
|
514
|
+
'labels' => {
|
515
|
+
'log_type' => 'local-override'
|
516
|
+
}
|
517
|
+
}))
|
518
|
+
end
|
738
519
|
assert_equal('local-override', index_cmds.first['index']['_type'])
|
739
520
|
assert_nil(index_cmds[1]['kubernetes']['labels']['log_type'])
|
740
521
|
end
|
@@ -743,12 +524,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
743
524
|
driver.configure("target_type_key kubernetes.labels.log_type\n")
|
744
525
|
stub_elastic_ping
|
745
526
|
stub_elastic
|
746
|
-
driver.
|
747
|
-
'
|
748
|
-
'
|
749
|
-
|
750
|
-
|
751
|
-
|
527
|
+
driver.run(default_tag: 'test') do
|
528
|
+
driver.feed(sample_record.merge('kubernetes' => {
|
529
|
+
'labels' => {
|
530
|
+
'other_labels' => 'test'
|
531
|
+
}
|
532
|
+
}))
|
533
|
+
end
|
752
534
|
assert_equal('fluentd', index_cmds.first['index']['_type'])
|
753
535
|
end
|
754
536
|
|
@@ -756,8 +538,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
756
538
|
driver.configure("host 192.168.33.50\n")
|
757
539
|
stub_elastic_ping("http://192.168.33.50:9200")
|
758
540
|
elastic_request = stub_elastic("http://192.168.33.50:9200/_bulk")
|
759
|
-
driver.
|
760
|
-
|
541
|
+
driver.run(default_tag: 'test') do
|
542
|
+
driver.feed(sample_record)
|
543
|
+
end
|
761
544
|
assert_requested(elastic_request)
|
762
545
|
end
|
763
546
|
|
@@ -765,8 +548,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
765
548
|
driver.configure("port 9201\n")
|
766
549
|
stub_elastic_ping("http://localhost:9201")
|
767
550
|
elastic_request = stub_elastic("http://localhost:9201/_bulk")
|
768
|
-
driver.
|
769
|
-
|
551
|
+
driver.run(default_tag: 'test') do
|
552
|
+
driver.feed(sample_record)
|
553
|
+
end
|
770
554
|
assert_requested(elastic_request)
|
771
555
|
end
|
772
556
|
|
@@ -782,12 +566,12 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
782
566
|
stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
|
783
567
|
end
|
784
568
|
|
785
|
-
|
786
|
-
|
569
|
+
driver.run(default_tag: 'test') do
|
570
|
+
1000.times do
|
571
|
+
driver.feed(sample_record.merge('age'=>rand(100)))
|
572
|
+
end
|
787
573
|
end
|
788
574
|
|
789
|
-
driver.run
|
790
|
-
|
791
575
|
# @note: we cannot make multi chunks with options (flush_interval, buffer_chunk_limit)
|
792
576
|
# it's Fluentd test driver's constraint
|
793
577
|
# so @index_command_counts.size is always 1
|
@@ -817,8 +601,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
817
601
|
|
818
602
|
stub_elastic_ping
|
819
603
|
stub_elastic
|
820
|
-
driver.
|
821
|
-
|
604
|
+
driver.run(default_tag: 'test') do
|
605
|
+
driver.feed(original_hash)
|
606
|
+
end
|
822
607
|
assert_equal expected_output, index_cmds[1]
|
823
608
|
end
|
824
609
|
|
@@ -830,26 +615,29 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
830
615
|
|
831
616
|
stub_elastic_ping
|
832
617
|
stub_elastic
|
833
|
-
driver.
|
834
|
-
|
618
|
+
driver.run(default_tag: 'test') do
|
619
|
+
driver.feed(original_hash)
|
620
|
+
end
|
835
621
|
assert_equal expected_output, index_cmds[1]
|
836
622
|
end
|
837
623
|
|
838
624
|
def test_makes_bulk_request
|
839
625
|
stub_elastic_ping
|
840
626
|
stub_elastic
|
841
|
-
driver.
|
842
|
-
|
843
|
-
|
627
|
+
driver.run(default_tag: 'test') do
|
628
|
+
driver.feed(sample_record)
|
629
|
+
driver.feed(sample_record.merge('age' => 27))
|
630
|
+
end
|
844
631
|
assert_equal(4, index_cmds.count)
|
845
632
|
end
|
846
633
|
|
847
634
|
def test_all_records_are_preserved_in_bulk
|
848
635
|
stub_elastic_ping
|
849
636
|
stub_elastic
|
850
|
-
driver.
|
851
|
-
|
852
|
-
|
637
|
+
driver.run(default_tag: 'test') do
|
638
|
+
driver.feed(sample_record)
|
639
|
+
driver.feed(sample_record.merge('age' => 27))
|
640
|
+
end
|
853
641
|
assert_equal(26, index_cmds[1]['age'])
|
854
642
|
assert_equal(27, index_cmds[3]['age'])
|
855
643
|
end
|
@@ -862,8 +650,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
862
650
|
logstash_index = "logstash-2015.05.31"
|
863
651
|
stub_elastic_ping
|
864
652
|
stub_elastic
|
865
|
-
driver.
|
866
|
-
|
653
|
+
driver.run(default_tag: 'test') do
|
654
|
+
driver.feed(dt.to_time.to_i, sample_record)
|
655
|
+
end
|
867
656
|
assert_equal(logstash_index, index_cmds.first['index']['_index'])
|
868
657
|
end
|
869
658
|
|
@@ -876,46 +665,35 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
876
665
|
index = "logstash-#{time.strftime("%Y.%m.%d")}"
|
877
666
|
stub_elastic_ping
|
878
667
|
stub_elastic
|
879
|
-
driver.
|
880
|
-
|
668
|
+
driver.run(default_tag: 'test') do
|
669
|
+
driver.feed(time.to_i, sample_record)
|
670
|
+
end
|
881
671
|
assert_equal(index, index_cmds.first['index']['_index'])
|
882
672
|
end
|
883
673
|
|
884
674
|
def test_writes_to_logstash_index_with_specified_prefix
|
885
675
|
driver.configure("logstash_format true
|
886
676
|
logstash_prefix myprefix")
|
887
|
-
time = Time.parse Date.today.
|
677
|
+
time = Time.parse Date.today.to_s
|
888
678
|
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
|
889
679
|
stub_elastic_ping
|
890
680
|
stub_elastic
|
891
|
-
driver.
|
892
|
-
|
893
|
-
|
894
|
-
end
|
895
|
-
|
896
|
-
def test_writes_to_logstash_index_with_specified_prefix_and_separator
|
897
|
-
separator = '_'
|
898
|
-
driver.configure("logstash_format true
|
899
|
-
logstash_prefix_separator #{separator}
|
900
|
-
logstash_prefix myprefix")
|
901
|
-
time = Time.parse Date.today.iso8601
|
902
|
-
logstash_index = "myprefix#{separator}#{time.getutc.strftime("%Y.%m.%d")}"
|
903
|
-
stub_elastic_ping
|
904
|
-
stub_elastic
|
905
|
-
driver.emit(sample_record, time.to_i)
|
906
|
-
driver.run
|
681
|
+
driver.run(default_tag: 'test') do
|
682
|
+
driver.feed(time.to_i, sample_record)
|
683
|
+
end
|
907
684
|
assert_equal(logstash_index, index_cmds.first['index']['_index'])
|
908
685
|
end
|
909
686
|
|
910
687
|
def test_writes_to_logstash_index_with_specified_prefix_uppercase
|
911
688
|
driver.configure("logstash_format true
|
912
689
|
logstash_prefix MyPrefix")
|
913
|
-
time = Time.parse Date.today.
|
690
|
+
time = Time.parse Date.today.to_s
|
914
691
|
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
|
915
692
|
stub_elastic_ping
|
916
693
|
stub_elastic
|
917
|
-
driver.
|
918
|
-
|
694
|
+
driver.run(default_tag: 'test') do
|
695
|
+
driver.feed(time.to_i, sample_record)
|
696
|
+
end
|
919
697
|
# Allthough logstash_prefix has upper-case characters,
|
920
698
|
# it should be set as lower-case when sent to elasticsearch.
|
921
699
|
assert_equal(logstash_index, index_cmds.first['index']['_index'])
|
@@ -924,12 +702,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
924
702
|
def test_writes_to_logstash_index_with_specified_dateformat
|
925
703
|
driver.configure("logstash_format true
|
926
704
|
logstash_dateformat %Y.%m")
|
927
|
-
time = Time.parse Date.today.
|
705
|
+
time = Time.parse Date.today.to_s
|
928
706
|
logstash_index = "logstash-#{time.getutc.strftime("%Y.%m")}"
|
929
707
|
stub_elastic_ping
|
930
708
|
stub_elastic
|
931
|
-
driver.
|
932
|
-
|
709
|
+
driver.run(default_tag: 'test') do
|
710
|
+
driver.feed(time.to_i, sample_record)
|
711
|
+
end
|
933
712
|
assert_equal(logstash_index, index_cmds.first['index']['_index'])
|
934
713
|
end
|
935
714
|
|
@@ -937,64 +716,66 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
937
716
|
driver.configure("logstash_format true
|
938
717
|
logstash_prefix myprefix
|
939
718
|
logstash_dateformat %Y.%m")
|
940
|
-
time = Time.parse Date.today.
|
719
|
+
time = Time.parse Date.today.to_s
|
941
720
|
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
|
942
721
|
stub_elastic_ping
|
943
722
|
stub_elastic
|
944
|
-
driver.
|
945
|
-
|
723
|
+
driver.run(default_tag: 'test') do
|
724
|
+
driver.feed(time.to_i, sample_record)
|
725
|
+
end
|
946
726
|
assert_equal(logstash_index, index_cmds.first['index']['_index'])
|
947
727
|
end
|
948
728
|
|
729
|
+
def test_error_if_tag_not_in_chunk_keys
|
730
|
+
assert_raise(Fluent::ConfigError) {
|
731
|
+
config = %{
|
732
|
+
<buffer foo>
|
733
|
+
</buffer>
|
734
|
+
}
|
735
|
+
driver.configure(config)
|
736
|
+
}
|
737
|
+
end
|
738
|
+
|
739
|
+
def test_can_use_custom_chunk_along_with_tag
|
740
|
+
config = %{
|
741
|
+
<buffer tag, foo>
|
742
|
+
</buffer>
|
743
|
+
}
|
744
|
+
driver.configure(config)
|
745
|
+
end
|
746
|
+
|
949
747
|
def test_doesnt_add_logstash_timestamp_by_default
|
950
748
|
stub_elastic_ping
|
951
749
|
stub_elastic
|
952
|
-
driver.
|
953
|
-
|
750
|
+
driver.run(default_tag: 'test') do
|
751
|
+
driver.feed(sample_record)
|
752
|
+
end
|
954
753
|
assert_nil(index_cmds[1]['@timestamp'])
|
955
754
|
end
|
956
755
|
|
957
|
-
def
|
756
|
+
def test_adds_logstash_timestamp_when_configured
|
958
757
|
driver.configure("logstash_format true\n")
|
959
758
|
stub_elastic_ping
|
960
759
|
stub_elastic
|
961
|
-
ts = DateTime.now.iso8601
|
962
|
-
driver.emit(sample_record)
|
963
|
-
driver.run
|
964
|
-
assert(index_cmds[1].has_key? '@timestamp')
|
965
|
-
assert_equal(index_cmds[1]['@timestamp'], ts)
|
966
|
-
end
|
967
|
-
|
968
|
-
def test_adds_timestamp_when_include_timestamp
|
969
|
-
driver.configure("include_timestamp true\n")
|
970
|
-
stub_elastic_ping
|
971
|
-
stub_elastic
|
972
760
|
ts = DateTime.now
|
973
|
-
time = ts.to_time
|
974
|
-
driver.
|
975
|
-
|
761
|
+
time = Fluent::EventTime.from_time(ts.to_time)
|
762
|
+
driver.run(default_tag: 'test') do
|
763
|
+
driver.feed(time, sample_record)
|
764
|
+
end
|
765
|
+
tf = "%Y-%m-%dT%H:%M:%S%:z"
|
766
|
+
timef = Fluent::TimeFormatter.new(tf, true, ENV["TZ"])
|
976
767
|
assert(index_cmds[1].has_key? '@timestamp')
|
977
|
-
assert_equal(index_cmds[1]['@timestamp'], ts.
|
768
|
+
assert_equal(timef.format(Time.parse(index_cmds[1]['@timestamp'])).to_s, ts.to_s)
|
978
769
|
end
|
979
770
|
|
980
771
|
def test_uses_custom_timestamp_when_included_in_record
|
981
772
|
driver.configure("logstash_format true\n")
|
982
773
|
stub_elastic_ping
|
983
774
|
stub_elastic
|
984
|
-
ts = DateTime.new(2001,2,3).
|
985
|
-
driver.
|
986
|
-
|
987
|
-
|
988
|
-
assert_equal(index_cmds[1]['@timestamp'], ts)
|
989
|
-
end
|
990
|
-
|
991
|
-
def test_uses_custom_timestamp_when_included_in_record_without_logstash
|
992
|
-
driver.configure("include_timestamp true\n")
|
993
|
-
stub_elastic_ping
|
994
|
-
stub_elastic
|
995
|
-
ts = DateTime.new(2001,2,3).iso8601
|
996
|
-
driver.emit(sample_record.merge!('@timestamp' => ts))
|
997
|
-
driver.run
|
775
|
+
ts = DateTime.new(2001,2,3).to_s
|
776
|
+
driver.run(default_tag: 'test') do
|
777
|
+
driver.feed(sample_record.merge!('@timestamp' => ts))
|
778
|
+
end
|
998
779
|
assert(index_cmds[1].has_key? '@timestamp')
|
999
780
|
assert_equal(index_cmds[1]['@timestamp'], ts)
|
1000
781
|
end
|
@@ -1004,40 +785,12 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1004
785
|
time_key vtm\n")
|
1005
786
|
stub_elastic_ping
|
1006
787
|
stub_elastic
|
1007
|
-
ts = DateTime.new(2001,2,3).
|
1008
|
-
driver.
|
1009
|
-
|
1010
|
-
|
1011
|
-
assert_equal(index_cmds[1]['@timestamp'], ts)
|
1012
|
-
end
|
1013
|
-
|
1014
|
-
def test_uses_custom_time_key_with_format
|
1015
|
-
driver.configure("logstash_format true
|
1016
|
-
time_key_format %Y-%m-%d %H:%M:%S.%N%z
|
1017
|
-
time_key vtm\n")
|
1018
|
-
stub_elastic_ping
|
1019
|
-
stub_elastic
|
1020
|
-
ts = "2001-02-03 13:14:01.673+02:00"
|
1021
|
-
driver.emit(sample_record.merge!('vtm' => ts))
|
1022
|
-
driver.run
|
1023
|
-
assert(index_cmds[1].has_key? '@timestamp')
|
1024
|
-
assert_equal(index_cmds[1]['@timestamp'], ts)
|
1025
|
-
assert_equal("logstash-2001.02.03", index_cmds[0]['index']['_index'])
|
1026
|
-
end
|
1027
|
-
|
1028
|
-
def test_uses_custom_time_key_with_format_without_logstash
|
1029
|
-
driver.configure("include_timestamp true
|
1030
|
-
index_name test
|
1031
|
-
time_key_format %Y-%m-%d %H:%M:%S.%N%z
|
1032
|
-
time_key vtm\n")
|
1033
|
-
stub_elastic_ping
|
1034
|
-
stub_elastic
|
1035
|
-
ts = "2001-02-03 13:14:01.673+02:00"
|
1036
|
-
driver.emit(sample_record.merge!('vtm' => ts))
|
1037
|
-
driver.run
|
788
|
+
ts = DateTime.new(2001,2,3).to_s
|
789
|
+
driver.run(default_tag: 'test') do
|
790
|
+
driver.feed(sample_record.merge!('vtm' => ts))
|
791
|
+
end
|
1038
792
|
assert(index_cmds[1].has_key? '@timestamp')
|
1039
793
|
assert_equal(index_cmds[1]['@timestamp'], ts)
|
1040
|
-
assert_equal("test", index_cmds[0]['index']['_index'])
|
1041
794
|
end
|
1042
795
|
|
1043
796
|
def test_uses_custom_time_key_exclude_timekey
|
@@ -1046,9 +799,10 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1046
799
|
time_key_exclude_timestamp true\n")
|
1047
800
|
stub_elastic_ping
|
1048
801
|
stub_elastic
|
1049
|
-
ts = DateTime.new(2001,2,3).
|
1050
|
-
driver.
|
1051
|
-
|
802
|
+
ts = DateTime.new(2001,2,3).to_s
|
803
|
+
driver.run(default_tag: 'test') do
|
804
|
+
driver.feed(sample_record.merge!('vtm' => ts))
|
805
|
+
end
|
1052
806
|
assert(!index_cmds[1].key?('@timestamp'), '@timestamp should be messing')
|
1053
807
|
end
|
1054
808
|
|
@@ -1058,27 +812,14 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1058
812
|
stub_elastic_ping
|
1059
813
|
stub_elastic
|
1060
814
|
ts = "2001-02-03T13:14:01.673+02:00"
|
1061
|
-
driver.
|
1062
|
-
|
815
|
+
driver.run(default_tag: 'test') do
|
816
|
+
driver.feed(sample_record.merge!('@timestamp' => ts))
|
817
|
+
end
|
1063
818
|
assert_equal("logstash-2001.02.03", index_cmds[0]['index']['_index'])
|
1064
819
|
assert(index_cmds[1].has_key? '@timestamp')
|
1065
820
|
assert_equal(index_cmds[1]['@timestamp'], ts)
|
1066
821
|
end
|
1067
822
|
|
1068
|
-
def test_uses_custom_time_key_format_without_logstash
|
1069
|
-
driver.configure("include_timestamp true
|
1070
|
-
index_name test
|
1071
|
-
time_key_format %Y-%m-%dT%H:%M:%S.%N%z\n")
|
1072
|
-
stub_elastic_ping
|
1073
|
-
stub_elastic
|
1074
|
-
ts = "2001-02-03T13:14:01.673+02:00"
|
1075
|
-
driver.emit(sample_record.merge!('@timestamp' => ts))
|
1076
|
-
driver.run
|
1077
|
-
assert_equal("test", index_cmds[0]['index']['_index'])
|
1078
|
-
assert(index_cmds[1].has_key? '@timestamp')
|
1079
|
-
assert_equal(index_cmds[1]['@timestamp'], ts)
|
1080
|
-
end
|
1081
|
-
|
1082
823
|
data(:default => nil,
|
1083
824
|
:custom_tag => 'es_plugin.output.time.error')
|
1084
825
|
def test_uses_custom_time_key_format_logs_an_error(tag_for_error)
|
@@ -1092,12 +833,11 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1092
833
|
ts = "2001/02/03 13:14:01,673+02:00"
|
1093
834
|
index = "logstash-#{Date.today.strftime("%Y.%m.%d")}"
|
1094
835
|
|
1095
|
-
driver.
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
assert_equal(1, errors.length, "Error was logged for timestamp parse failure")
|
836
|
+
flexmock(driver.instance.router).should_receive(:emit_error_event)
|
837
|
+
.with(tag_for_error, Fluent::EventTime, Hash, ArgumentError).once
|
838
|
+
driver.run(default_tag: 'test') do
|
839
|
+
driver.feed(sample_record.merge!('@timestamp' => ts))
|
840
|
+
end
|
1101
841
|
|
1102
842
|
assert_equal(index, index_cmds[0]['index']['_index'])
|
1103
843
|
assert(index_cmds[1].has_key? '@timestamp')
|
@@ -1111,14 +851,15 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1111
851
|
stub_elastic_ping
|
1112
852
|
stub_elastic
|
1113
853
|
ts = "Thu Nov 29 14:33:20 GMT 2001"
|
1114
|
-
driver.
|
1115
|
-
|
854
|
+
driver.run(default_tag: 'test') do
|
855
|
+
driver.feed(sample_record.merge!('@timestamp' => ts))
|
856
|
+
end
|
1116
857
|
assert_equal("logstash-2001.11.29", index_cmds[0]['index']['_index'])
|
1117
858
|
assert(index_cmds[1].has_key? '@timestamp')
|
1118
859
|
assert_equal(index_cmds[1]['@timestamp'], ts)
|
1119
860
|
end
|
1120
861
|
|
1121
|
-
def
|
862
|
+
def test_uses_nanosecond_precision_by_default
|
1122
863
|
driver.configure("logstash_format true\n")
|
1123
864
|
stub_elastic_ping
|
1124
865
|
stub_elastic
|
@@ -1127,10 +868,11 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1127
868
|
rescue
|
1128
869
|
time = Fluent::Engine.now
|
1129
870
|
end
|
1130
|
-
driver.
|
1131
|
-
|
871
|
+
driver.run(default_tag: 'test') do
|
872
|
+
driver.feed(time.to_i, sample_record)
|
873
|
+
end
|
1132
874
|
assert(index_cmds[1].has_key? '@timestamp')
|
1133
|
-
assert_equal(index_cmds[1]['@timestamp'], Time.at(time).iso8601)
|
875
|
+
assert_equal(index_cmds[1]['@timestamp'], Time.at(time).iso8601(9))
|
1134
876
|
end
|
1135
877
|
|
1136
878
|
def test_uses_subsecond_precision_when_configured
|
@@ -1143,8 +885,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1143
885
|
rescue
|
1144
886
|
time = Fluent::Engine.now
|
1145
887
|
end
|
1146
|
-
driver.
|
1147
|
-
|
888
|
+
driver.run(default_tag: 'test') do
|
889
|
+
driver.feed(time.to_i, sample_record)
|
890
|
+
end
|
1148
891
|
assert(index_cmds[1].has_key? '@timestamp')
|
1149
892
|
assert_equal(index_cmds[1]['@timestamp'], Time.at(time).iso8601(3))
|
1150
893
|
end
|
@@ -1152,17 +895,19 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1152
895
|
def test_doesnt_add_tag_key_by_default
|
1153
896
|
stub_elastic_ping
|
1154
897
|
stub_elastic
|
1155
|
-
driver.
|
1156
|
-
|
898
|
+
driver.run(default_tag: 'test') do
|
899
|
+
driver.feed(sample_record)
|
900
|
+
end
|
1157
901
|
assert_nil(index_cmds[1]['tag'])
|
1158
902
|
end
|
1159
903
|
|
1160
904
|
def test_adds_tag_key_when_configured
|
1161
|
-
driver
|
905
|
+
driver.configure("include_tag_key true\n")
|
1162
906
|
stub_elastic_ping
|
1163
907
|
stub_elastic
|
1164
|
-
driver.
|
1165
|
-
|
908
|
+
driver.run(default_tag: 'mytag') do
|
909
|
+
driver.feed(sample_record)
|
910
|
+
end
|
1166
911
|
assert(index_cmds[1].has_key?('tag'))
|
1167
912
|
assert_equal(index_cmds[1]['tag'], 'mytag')
|
1168
913
|
end
|
@@ -1171,8 +916,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1171
916
|
driver.configure("id_key request_id\n")
|
1172
917
|
stub_elastic_ping
|
1173
918
|
stub_elastic
|
1174
|
-
driver.
|
1175
|
-
|
919
|
+
driver.run(default_tag: 'test') do
|
920
|
+
driver.feed(sample_record)
|
921
|
+
end
|
1176
922
|
assert_equal(index_cmds[0]['index']['_id'], '42')
|
1177
923
|
end
|
1178
924
|
|
@@ -1180,16 +926,18 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1180
926
|
driver.configure("id_key another_request_id\n")
|
1181
927
|
stub_elastic_ping
|
1182
928
|
stub_elastic
|
1183
|
-
driver.
|
1184
|
-
|
929
|
+
driver.run(default_tag: 'test') do
|
930
|
+
driver.feed(sample_record)
|
931
|
+
end
|
1185
932
|
assert(!index_cmds[0]['index'].has_key?('_id'))
|
1186
933
|
end
|
1187
934
|
|
1188
935
|
def test_adds_id_key_when_not_configured
|
1189
936
|
stub_elastic_ping
|
1190
937
|
stub_elastic
|
1191
|
-
driver.
|
1192
|
-
|
938
|
+
driver.run(default_tag: 'test') do
|
939
|
+
driver.feed(sample_record)
|
940
|
+
end
|
1193
941
|
assert(!index_cmds[0]['index'].has_key?('_id'))
|
1194
942
|
end
|
1195
943
|
|
@@ -1197,8 +945,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1197
945
|
driver.configure("parent_key parent_id\n")
|
1198
946
|
stub_elastic_ping
|
1199
947
|
stub_elastic
|
1200
|
-
driver.
|
1201
|
-
|
948
|
+
driver.run(default_tag: 'test') do
|
949
|
+
driver.feed(sample_record)
|
950
|
+
end
|
1202
951
|
assert_equal(index_cmds[0]['index']['_parent'], 'parent')
|
1203
952
|
end
|
1204
953
|
|
@@ -1206,16 +955,18 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1206
955
|
driver.configure("parent_key another_parent_id\n")
|
1207
956
|
stub_elastic_ping
|
1208
957
|
stub_elastic
|
1209
|
-
driver.
|
1210
|
-
|
958
|
+
driver.run(default_tag: 'test') do
|
959
|
+
driver.feed(sample_record)
|
960
|
+
end
|
1211
961
|
assert(!index_cmds[0]['index'].has_key?('_parent'))
|
1212
962
|
end
|
1213
963
|
|
1214
964
|
def test_adds_parent_key_when_not_configured
|
1215
965
|
stub_elastic_ping
|
1216
966
|
stub_elastic
|
1217
|
-
driver.
|
1218
|
-
|
967
|
+
driver.run(default_tag: 'test') do
|
968
|
+
driver.feed(sample_record)
|
969
|
+
end
|
1219
970
|
assert(!index_cmds[0]['index'].has_key?('_parent'))
|
1220
971
|
end
|
1221
972
|
|
@@ -1223,8 +974,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1223
974
|
driver.configure("routing_key routing_id\n")
|
1224
975
|
stub_elastic_ping
|
1225
976
|
stub_elastic
|
1226
|
-
driver.
|
1227
|
-
|
977
|
+
driver.run(default_tag: 'test') do
|
978
|
+
driver.feed(sample_record)
|
979
|
+
end
|
1228
980
|
assert_equal(index_cmds[0]['index']['_routing'], 'routing')
|
1229
981
|
end
|
1230
982
|
|
@@ -1232,16 +984,18 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1232
984
|
driver.configure("routing_key another_routing_id\n")
|
1233
985
|
stub_elastic_ping
|
1234
986
|
stub_elastic
|
1235
|
-
driver.
|
1236
|
-
|
987
|
+
driver.run(default_tag: 'test') do
|
988
|
+
driver.feed(sample_record)
|
989
|
+
end
|
1237
990
|
assert(!index_cmds[0]['index'].has_key?('_routing'))
|
1238
991
|
end
|
1239
992
|
|
1240
993
|
def test_adds_routing_key_when_not_configured
|
1241
994
|
stub_elastic_ping
|
1242
995
|
stub_elastic
|
1243
|
-
driver.
|
1244
|
-
|
996
|
+
driver.run(default_tag: 'test') do
|
997
|
+
driver.feed(sample_record)
|
998
|
+
end
|
1245
999
|
assert(!index_cmds[0]['index'].has_key?('_routing'))
|
1246
1000
|
end
|
1247
1001
|
|
@@ -1249,8 +1003,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1249
1003
|
driver.configure("remove_keys key1\n")
|
1250
1004
|
stub_elastic_ping
|
1251
1005
|
stub_elastic
|
1252
|
-
driver.
|
1253
|
-
|
1006
|
+
driver.run(default_tag: 'test') do
|
1007
|
+
driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
|
1008
|
+
end
|
1254
1009
|
assert(!index_cmds[1].has_key?('key1'))
|
1255
1010
|
assert(index_cmds[1].has_key?('key2'))
|
1256
1011
|
end
|
@@ -1259,8 +1014,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1259
1014
|
driver.configure("remove_keys key1, key2\n")
|
1260
1015
|
stub_elastic_ping
|
1261
1016
|
stub_elastic
|
1262
|
-
driver.
|
1263
|
-
|
1017
|
+
driver.run(default_tag: 'test') do
|
1018
|
+
driver.feed(sample_record.merge('key1' => 'v1', 'key2' => 'v2'))
|
1019
|
+
end
|
1264
1020
|
assert(!index_cmds[1].has_key?('key1'))
|
1265
1021
|
assert(!index_cmds[1].has_key?('key2'))
|
1266
1022
|
end
|
@@ -1268,19 +1024,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1268
1024
|
def test_request_error
|
1269
1025
|
stub_elastic_ping
|
1270
1026
|
stub_elastic_unavailable
|
1271
|
-
driver.emit(sample_record)
|
1272
1027
|
assert_raise(Elasticsearch::Transport::Transport::Errors::ServiceUnavailable) {
|
1273
|
-
driver.run
|
1028
|
+
driver.run(default_tag: 'test') do
|
1029
|
+
driver.feed(sample_record)
|
1030
|
+
end
|
1274
1031
|
}
|
1275
1032
|
end
|
1276
1033
|
|
1277
|
-
def test_garbage_record_error
|
1278
|
-
stub_elastic_ping
|
1279
|
-
stub_elastic
|
1280
|
-
driver.emit("some garbage string")
|
1281
|
-
driver.run
|
1282
|
-
end
|
1283
|
-
|
1284
1034
|
def test_connection_failed_retry
|
1285
1035
|
connection_resets = 0
|
1286
1036
|
|
@@ -1292,11 +1042,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1292
1042
|
raise Faraday::ConnectionFailed, "Test message"
|
1293
1043
|
end
|
1294
1044
|
|
1295
|
-
driver.
|
1296
|
-
|
1297
|
-
|
1298
|
-
driver.run
|
1299
|
-
}
|
1045
|
+
driver.run(default_tag: 'test') do
|
1046
|
+
driver.feed(sample_record)
|
1047
|
+
end
|
1300
1048
|
assert_equal(connection_resets, 3)
|
1301
1049
|
end
|
1302
1050
|
|
@@ -1312,16 +1060,21 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1312
1060
|
end
|
1313
1061
|
|
1314
1062
|
driver.configure("reconnect_on_error true\n")
|
1315
|
-
driver.emit(sample_record)
|
1316
1063
|
|
1317
1064
|
assert_raise(ZeroDivisionError) {
|
1318
|
-
driver.run
|
1065
|
+
driver.run(default_tag: 'test', shutdown: false) do
|
1066
|
+
driver.feed(sample_record)
|
1067
|
+
end
|
1319
1068
|
}
|
1320
1069
|
|
1321
|
-
assert_raise(
|
1322
|
-
driver.run
|
1070
|
+
assert_raise(Timeout::Error) {
|
1071
|
+
driver.run(default_tag: 'test', shutdown: false) do
|
1072
|
+
driver.feed(sample_record)
|
1073
|
+
end
|
1323
1074
|
}
|
1324
|
-
|
1075
|
+
# FIXME: Consider keywords arguments in #run and how to test this later.
|
1076
|
+
# Because v0.14 test driver does not have 1 to 1 correspondence between #run and #flush in tests.
|
1077
|
+
assert_equal(connection_resets, 1)
|
1325
1078
|
end
|
1326
1079
|
|
1327
1080
|
def test_reconnect_on_error_disabled
|
@@ -1336,219 +1089,28 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1336
1089
|
end
|
1337
1090
|
|
1338
1091
|
driver.configure("reconnect_on_error false\n")
|
1339
|
-
driver.emit(sample_record)
|
1340
1092
|
|
1341
1093
|
assert_raise(ZeroDivisionError) {
|
1342
|
-
driver.run
|
1094
|
+
driver.run(default_tag: 'test', shutdown: false) do
|
1095
|
+
driver.feed(sample_record)
|
1096
|
+
end
|
1343
1097
|
}
|
1344
1098
|
|
1345
|
-
assert_raise(
|
1346
|
-
driver.run
|
1099
|
+
assert_raise(Timeout::Error) {
|
1100
|
+
driver.run(default_tag: 'test', shutdown: false) do
|
1101
|
+
driver.feed(sample_record)
|
1102
|
+
end
|
1347
1103
|
}
|
1348
1104
|
assert_equal(connection_resets, 1)
|
1349
1105
|
end
|
1350
1106
|
|
1351
|
-
def test_bulk_error_retags_when_configured
|
1352
|
-
driver.configure("retry_tag retry\n")
|
1353
|
-
stub_elastic_ping
|
1354
|
-
stub_request(:post, 'http://localhost:9200/_bulk')
|
1355
|
-
.to_return(lambda do |req|
|
1356
|
-
{ :status => 200,
|
1357
|
-
:headers => { 'Content-Type' => 'json' },
|
1358
|
-
:body => %({
|
1359
|
-
"took" : 1,
|
1360
|
-
"errors" : true,
|
1361
|
-
"items" : [
|
1362
|
-
{
|
1363
|
-
"create" : {
|
1364
|
-
"_index" : "foo",
|
1365
|
-
"_type" : "bar",
|
1366
|
-
"_id" : "abc",
|
1367
|
-
"status" : 500,
|
1368
|
-
"error" : {
|
1369
|
-
"type" : "some unrecognized type",
|
1370
|
-
"reason":"some error to cause version mismatch"
|
1371
|
-
}
|
1372
|
-
}
|
1373
|
-
}
|
1374
|
-
]
|
1375
|
-
})
|
1376
|
-
}
|
1377
|
-
end)
|
1378
|
-
driver.emit(sample_record, 1)
|
1379
|
-
|
1380
|
-
driver.expect_emit('retry', 1, sample_record)
|
1381
|
-
driver.run
|
1382
|
-
end
|
1383
|
-
|
1384
|
-
def test_create_should_write_records_with_ids_and_skip_those_without
|
1385
|
-
driver.configure("write_operation create\nid_key my_id\nlog_level debug")
|
1386
|
-
log = driver.instance.router.emit_error_handler.log
|
1387
|
-
stub_elastic_ping
|
1388
|
-
stub_request(:post, 'http://localhost:9200/_bulk')
|
1389
|
-
.to_return(lambda do |req|
|
1390
|
-
{ :status => 200,
|
1391
|
-
:headers => { 'Content-Type' => 'json' },
|
1392
|
-
:body => %({
|
1393
|
-
"took" : 1,
|
1394
|
-
"errors" : true,
|
1395
|
-
"items" : [
|
1396
|
-
{
|
1397
|
-
"create" : {
|
1398
|
-
"_index" : "foo",
|
1399
|
-
"_type" : "bar",
|
1400
|
-
"_id" : "abc"
|
1401
|
-
}
|
1402
|
-
},
|
1403
|
-
{
|
1404
|
-
"create" : {
|
1405
|
-
"_index" : "foo",
|
1406
|
-
"_type" : "bar",
|
1407
|
-
"_id" : "xyz",
|
1408
|
-
"status" : 500,
|
1409
|
-
"error" : {
|
1410
|
-
"type" : "some unrecognized type",
|
1411
|
-
"reason":"some error to cause version mismatch"
|
1412
|
-
}
|
1413
|
-
}
|
1414
|
-
}
|
1415
|
-
]
|
1416
|
-
})
|
1417
|
-
}
|
1418
|
-
end)
|
1419
|
-
sample_record1 = sample_record('my_id' => 'abc')
|
1420
|
-
sample_record4 = sample_record('my_id' => 'xyz')
|
1421
|
-
driver.emit(sample_record1, 1)
|
1422
|
-
driver.emit(sample_record, 2)
|
1423
|
-
driver.emit(sample_record, 3)
|
1424
|
-
driver.emit(sample_record4, 4)
|
1425
|
-
|
1426
|
-
# one record succeeded while the other should be 'retried'
|
1427
|
-
driver.expect_emit('test', 4, sample_record4)
|
1428
|
-
driver.run
|
1429
|
-
assert_logs_include(log.out.logs, /(Dropping record)/, 2)
|
1430
|
-
end
|
1431
|
-
|
1432
|
-
def test_create_should_write_records_with_ids_and_emit_those_without
|
1433
|
-
driver.configure("write_operation create\nid_key my_id\nemit_error_for_missing_id true")
|
1434
|
-
log = driver.instance.router.emit_error_handler.log
|
1435
|
-
stub_elastic_ping
|
1436
|
-
stub_request(:post, 'http://localhost:9200/_bulk')
|
1437
|
-
.to_return(lambda do |req|
|
1438
|
-
{ :status => 200,
|
1439
|
-
:headers => { 'Content-Type' => 'json' },
|
1440
|
-
:body => %({
|
1441
|
-
"took" : 1,
|
1442
|
-
"errors" : true,
|
1443
|
-
"items" : [
|
1444
|
-
{
|
1445
|
-
"create" : {
|
1446
|
-
"_index" : "foo",
|
1447
|
-
"_type" : "bar",
|
1448
|
-
"_id" : "abc"
|
1449
|
-
}
|
1450
|
-
},
|
1451
|
-
{
|
1452
|
-
"create" : {
|
1453
|
-
"_index" : "foo",
|
1454
|
-
"_type" : "bar",
|
1455
|
-
"_id" : "xyz",
|
1456
|
-
"status" : 500,
|
1457
|
-
"error" : {
|
1458
|
-
"type" : "some unrecognized type",
|
1459
|
-
"reason":"some error to cause version mismatch"
|
1460
|
-
}
|
1461
|
-
}
|
1462
|
-
}
|
1463
|
-
]
|
1464
|
-
})
|
1465
|
-
}
|
1466
|
-
end)
|
1467
|
-
sample_record1 = sample_record('my_id' => 'abc')
|
1468
|
-
sample_record4 = sample_record('my_id' => 'xyz')
|
1469
|
-
driver.emit(sample_record1, 1)
|
1470
|
-
driver.emit(sample_record, 2)
|
1471
|
-
driver.emit(sample_record, 3)
|
1472
|
-
driver.emit(sample_record4, 4)
|
1473
|
-
|
1474
|
-
# one record succeeded while the other should be 'retried'
|
1475
|
-
driver.expect_emit('test', 4, sample_record4)
|
1476
|
-
driver.run
|
1477
|
-
assert_logs_include(log.out.logs, /(Missing '_id' field)/, 2)
|
1478
|
-
end
|
1479
|
-
|
1480
|
-
def test_bulk_error
|
1481
|
-
stub_elastic_ping
|
1482
|
-
stub_request(:post, 'http://localhost:9200/_bulk')
|
1483
|
-
.to_return(lambda do |req|
|
1484
|
-
{ :status => 200,
|
1485
|
-
:headers => { 'Content-Type' => 'json' },
|
1486
|
-
:body => %({
|
1487
|
-
"took" : 1,
|
1488
|
-
"errors" : true,
|
1489
|
-
"items" : [
|
1490
|
-
{
|
1491
|
-
"create" : {
|
1492
|
-
"_index" : "foo",
|
1493
|
-
"_type" : "bar",
|
1494
|
-
"_id" : "abc",
|
1495
|
-
"status" : 500,
|
1496
|
-
"error" : {
|
1497
|
-
"type" : "some unrecognized type",
|
1498
|
-
"reason":"some error to cause version mismatch"
|
1499
|
-
}
|
1500
|
-
}
|
1501
|
-
},
|
1502
|
-
{
|
1503
|
-
"create" : {
|
1504
|
-
"_index" : "foo",
|
1505
|
-
"_type" : "bar",
|
1506
|
-
"_id" : "abc",
|
1507
|
-
"status" : 201
|
1508
|
-
}
|
1509
|
-
},
|
1510
|
-
{
|
1511
|
-
"create" : {
|
1512
|
-
"_index" : "foo",
|
1513
|
-
"_type" : "bar",
|
1514
|
-
"_id" : "abc",
|
1515
|
-
"status" : 500,
|
1516
|
-
"error" : {
|
1517
|
-
"type" : "some unrecognized type",
|
1518
|
-
"reason":"some error to cause version mismatch"
|
1519
|
-
}
|
1520
|
-
}
|
1521
|
-
},
|
1522
|
-
{
|
1523
|
-
"create" : {
|
1524
|
-
"_index" : "foo",
|
1525
|
-
"_type" : "bar",
|
1526
|
-
"_id" : "abc",
|
1527
|
-
"_id" : "abc",
|
1528
|
-
"status" : 409
|
1529
|
-
}
|
1530
|
-
}
|
1531
|
-
]
|
1532
|
-
})
|
1533
|
-
}
|
1534
|
-
end)
|
1535
|
-
|
1536
|
-
driver.emit(sample_record, 1)
|
1537
|
-
driver.emit(sample_record, 2)
|
1538
|
-
driver.emit(sample_record, 3)
|
1539
|
-
driver.emit(sample_record, 4)
|
1540
|
-
|
1541
|
-
driver.expect_emit('test', 1, sample_record)
|
1542
|
-
driver.expect_emit('test', 3, sample_record)
|
1543
|
-
driver.run
|
1544
|
-
end
|
1545
|
-
|
1546
1107
|
def test_update_should_not_write_if_theres_no_id
|
1547
1108
|
driver.configure("write_operation update\n")
|
1548
1109
|
stub_elastic_ping
|
1549
1110
|
stub_elastic
|
1550
|
-
driver.
|
1551
|
-
|
1111
|
+
driver.run(default_tag: 'test') do
|
1112
|
+
driver.feed(sample_record)
|
1113
|
+
end
|
1552
1114
|
assert_nil(index_cmds)
|
1553
1115
|
end
|
1554
1116
|
|
@@ -1556,8 +1118,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1556
1118
|
driver.configure("write_operation upsert\n")
|
1557
1119
|
stub_elastic_ping
|
1558
1120
|
stub_elastic
|
1559
|
-
driver.
|
1560
|
-
|
1121
|
+
driver.run(default_tag: 'test') do
|
1122
|
+
driver.feed(sample_record)
|
1123
|
+
end
|
1561
1124
|
assert_nil(index_cmds)
|
1562
1125
|
end
|
1563
1126
|
|
@@ -1565,8 +1128,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1565
1128
|
driver.configure("write_operation create\n")
|
1566
1129
|
stub_elastic_ping
|
1567
1130
|
stub_elastic
|
1568
|
-
driver.
|
1569
|
-
|
1131
|
+
driver.run(default_tag: 'test') do
|
1132
|
+
driver.feed(sample_record)
|
1133
|
+
end
|
1570
1134
|
assert_nil(index_cmds)
|
1571
1135
|
end
|
1572
1136
|
|
@@ -1575,8 +1139,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1575
1139
|
id_key request_id")
|
1576
1140
|
stub_elastic_ping
|
1577
1141
|
stub_elastic
|
1578
|
-
driver.
|
1579
|
-
|
1142
|
+
driver.run(default_tag: 'test') do
|
1143
|
+
driver.feed(sample_record)
|
1144
|
+
end
|
1580
1145
|
assert(index_cmds[0].has_key?("update"))
|
1581
1146
|
assert(!index_cmds[1]["doc_as_upsert"])
|
1582
1147
|
assert(!index_cmds[1]["upsert"])
|
@@ -1588,8 +1153,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1588
1153
|
remove_keys_on_update parent_id")
|
1589
1154
|
stub_elastic_ping
|
1590
1155
|
stub_elastic
|
1591
|
-
driver.
|
1592
|
-
|
1156
|
+
driver.run(default_tag: 'test') do
|
1157
|
+
driver.feed(sample_record)
|
1158
|
+
end
|
1593
1159
|
assert(index_cmds[1]["doc"])
|
1594
1160
|
assert(!index_cmds[1]["doc"]["parent_id"])
|
1595
1161
|
end
|
@@ -1599,8 +1165,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1599
1165
|
id_key request_id")
|
1600
1166
|
stub_elastic_ping
|
1601
1167
|
stub_elastic
|
1602
|
-
driver.
|
1603
|
-
|
1168
|
+
driver.run(default_tag: 'test') do
|
1169
|
+
driver.feed(sample_record)
|
1170
|
+
end
|
1604
1171
|
assert(index_cmds[0].has_key?("update"))
|
1605
1172
|
assert(index_cmds[1]["doc_as_upsert"])
|
1606
1173
|
assert(!index_cmds[1]["upsert"])
|
@@ -1612,8 +1179,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1612
1179
|
remove_keys_on_update parent_id")
|
1613
1180
|
stub_elastic_ping
|
1614
1181
|
stub_elastic
|
1615
|
-
driver.
|
1616
|
-
|
1182
|
+
driver.run(default_tag: 'test') do
|
1183
|
+
driver.feed(sample_record)
|
1184
|
+
end
|
1617
1185
|
assert(index_cmds[0].has_key?("update"))
|
1618
1186
|
assert(!index_cmds[1]["doc_as_upsert"])
|
1619
1187
|
assert(index_cmds[1]["upsert"])
|
@@ -1626,8 +1194,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1626
1194
|
remove_keys_on_update parent_id")
|
1627
1195
|
stub_elastic_ping
|
1628
1196
|
stub_elastic
|
1629
|
-
driver.
|
1630
|
-
|
1197
|
+
driver.run(default_tag: 'test') do
|
1198
|
+
driver.feed(sample_record)
|
1199
|
+
end
|
1631
1200
|
assert(index_cmds[1]["upsert"] != index_cmds[1]["doc"])
|
1632
1201
|
assert(!index_cmds[1]["doc"]["parent_id"])
|
1633
1202
|
assert(index_cmds[1]["upsert"]["parent_id"])
|
@@ -1639,8 +1208,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1639
1208
|
remove_keys_on_update foo,baz")
|
1640
1209
|
stub_elastic_ping
|
1641
1210
|
stub_elastic
|
1642
|
-
driver.
|
1643
|
-
|
1211
|
+
driver.run(default_tag: 'test') do
|
1212
|
+
driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "zip" => "zam")
|
1213
|
+
end
|
1644
1214
|
assert(
|
1645
1215
|
index_cmds[1]["doc"] == {
|
1646
1216
|
"id" => 1,
|
@@ -1663,8 +1233,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1663
1233
|
remove_keys_on_update_key keys_to_skip")
|
1664
1234
|
stub_elastic_ping
|
1665
1235
|
stub_elastic
|
1666
|
-
driver.
|
1667
|
-
|
1236
|
+
driver.run(default_tag: 'test') do
|
1237
|
+
driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "keys_to_skip" => ["baz"])
|
1238
|
+
end
|
1668
1239
|
assert(
|
1669
1240
|
index_cmds[1]["doc"] == {
|
1670
1241
|
"id" => 1,
|
@@ -1687,8 +1258,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1687
1258
|
remove_keys_on_update_key keys_to_skip")
|
1688
1259
|
stub_elastic_ping
|
1689
1260
|
stub_elastic
|
1690
|
-
driver.
|
1691
|
-
|
1261
|
+
driver.run(default_tag: 'test') do
|
1262
|
+
driver.feed("id" => 1, "foo" => "bar", "baz" => "quix", "keys_to_skip" => ["baz"])
|
1263
|
+
end
|
1692
1264
|
assert(
|
1693
1265
|
index_cmds[1]["doc"] == {
|
1694
1266
|
"id" => 1,
|
@@ -1711,84 +1283,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
1711
1283
|
id_key request_id")
|
1712
1284
|
stub_elastic_ping
|
1713
1285
|
stub_elastic
|
1714
|
-
driver.
|
1715
|
-
|
1286
|
+
driver.run(default_tag: 'test') do
|
1287
|
+
driver.feed(sample_record)
|
1288
|
+
end
|
1716
1289
|
assert(index_cmds[0].has_key?("create"))
|
1717
1290
|
end
|
1718
|
-
|
1719
|
-
def test_use_simple_sniffer
|
1720
|
-
require 'fluent/plugin/elasticsearch_simple_sniffer'
|
1721
|
-
driver.configure("sniffer_class_name Fluent::ElasticsearchSimpleSniffer
|
1722
|
-
log_level debug
|
1723
|
-
with_transporter_log true
|
1724
|
-
reload_connections true
|
1725
|
-
reload_after 1")
|
1726
|
-
stub_elastic_ping
|
1727
|
-
stub_elastic
|
1728
|
-
driver.emit(sample_record)
|
1729
|
-
driver.run
|
1730
|
-
log = driver.instance.router.emit_error_handler.log
|
1731
|
-
# 2 - one for the ping, one for the _bulk
|
1732
|
-
assert_logs_include(log.out.logs, /In Fluent::ElasticsearchSimpleSniffer hosts/, 2)
|
1733
|
-
end
|
1734
|
-
|
1735
|
-
def test_suppress_doc_wrap
|
1736
|
-
driver.configure('write_operation update
|
1737
|
-
id_key id
|
1738
|
-
remove_keys id
|
1739
|
-
suppress_doc_wrap true')
|
1740
|
-
stub_elastic_ping
|
1741
|
-
stub_elastic
|
1742
|
-
doc_body = {'field' => 'value'}
|
1743
|
-
doc_record = {'id' => 1, 'doc' => doc_body}
|
1744
|
-
script_body = {'source' => 'ctx._source.counter += params.param1',
|
1745
|
-
'lang' => 'painless',
|
1746
|
-
'params' => {'param1' => 1}}
|
1747
|
-
upsert_body = {'counter' => 1}
|
1748
|
-
script_record = {'id' => 2, 'script' => script_body, 'upsert' => upsert_body}
|
1749
|
-
driver.emit(doc_record, 1)
|
1750
|
-
driver.emit(script_record, 2)
|
1751
|
-
driver.run
|
1752
|
-
assert(
|
1753
|
-
index_cmds[1] == {'doc' => doc_body}
|
1754
|
-
)
|
1755
|
-
assert(
|
1756
|
-
index_cmds[3] == {
|
1757
|
-
'script' => script_body,
|
1758
|
-
'upsert' => upsert_body
|
1759
|
-
}
|
1760
|
-
)
|
1761
|
-
end
|
1762
|
-
|
1763
|
-
def test_suppress_doc_wrap_should_handle_record_as_is_at_upsert
|
1764
|
-
driver.configure('write_operation upsert
|
1765
|
-
id_key id
|
1766
|
-
remove_keys id
|
1767
|
-
suppress_doc_wrap true')
|
1768
|
-
stub_elastic_ping
|
1769
|
-
stub_elastic
|
1770
|
-
doc_body = {'field' => 'value'}
|
1771
|
-
doc_record = {'id' => 1, 'doc' => doc_body, 'doc_as_upsert' => true}
|
1772
|
-
script_body = {'source' => 'ctx._source.counter += params.param1',
|
1773
|
-
'lang' => 'painless',
|
1774
|
-
'params' => {'param1' => 1}}
|
1775
|
-
upsert_body = {'counter' => 1}
|
1776
|
-
script_record = {'id' => 2, 'script' => script_body, 'upsert' => upsert_body}
|
1777
|
-
driver.emit(doc_record, 1)
|
1778
|
-
driver.emit(script_record, 2)
|
1779
|
-
driver.run
|
1780
|
-
assert(
|
1781
|
-
index_cmds[1] == {
|
1782
|
-
'doc' => doc_body,
|
1783
|
-
'doc_as_upsert' => true
|
1784
|
-
}
|
1785
|
-
)
|
1786
|
-
assert(
|
1787
|
-
index_cmds[3] == {
|
1788
|
-
'script' => script_body,
|
1789
|
-
'upsert' => upsert_body
|
1790
|
-
}
|
1791
|
-
)
|
1792
|
-
end
|
1793
|
-
|
1794
1291
|
end
|