fluent-plugin-elasticsearch 1.18.1 → 1.18.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.
- checksums.yaml +4 -4
- data/History.md +3 -0
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/log-ext.rb +38 -0
- data/lib/fluent/plugin/elasticsearch_error_handler.rb +2 -0
- data/lib/fluent/plugin/out_elasticsearch.rb +1 -0
- data/test/plugin/test_elasticsearch_error_handler.rb +63 -19
- data/test/test_log-ext.rb +33 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef82d990d532395ac70cfaca633811ecfec6e9277f02544a2fc73402aea79bd9
|
4
|
+
data.tar.gz: 30beccac0549c496631ba4943c2aae0161db08bb55966f38c1554b8c493beb12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7aaed653bb448e943265718258e9f92e2cb17fb778684483e58bac51c7a4175821aec96da2b6956ccf0f1b2e5c81775672f0c9ad34120e86b6e1e5f7b71aff2
|
7
|
+
data.tar.gz: 37a07ba5b227ce441396984abbedbafd6005d709df2b1489b39fcd5cdbb4e4aee820104b0cf99c944990133a227daa2ccde2b0a0d5f27a07929aa112e980d069
|
data/History.md
CHANGED
@@ -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 = '1.18.
|
6
|
+
s.version = '1.18.2'
|
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}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'fluent/log'
|
2
|
+
# For elasticsearch-ruby v7.0.0 or later
|
3
|
+
# logger for Elasticsearch::Loggable required the following methods:
|
4
|
+
#
|
5
|
+
# * debug?
|
6
|
+
# * info?
|
7
|
+
# * warn?
|
8
|
+
# * error?
|
9
|
+
# * fatal?
|
10
|
+
|
11
|
+
module Fluent
|
12
|
+
class Log
|
13
|
+
# Elasticsearch::Loggable does not request trace? method.
|
14
|
+
# def trace?
|
15
|
+
# @level <= LEVEL_TRACE
|
16
|
+
# end
|
17
|
+
|
18
|
+
def debug?
|
19
|
+
@level <= LEVEL_DEBUG
|
20
|
+
end
|
21
|
+
|
22
|
+
def info?
|
23
|
+
@level <= LEVEL_INFO
|
24
|
+
end
|
25
|
+
|
26
|
+
def warn?
|
27
|
+
@level <= LEVEL_WARN
|
28
|
+
end
|
29
|
+
|
30
|
+
def error?
|
31
|
+
@level <= LEVEL_ERROR
|
32
|
+
end
|
33
|
+
|
34
|
+
def fatal?
|
35
|
+
@level <= LEVEL_FATAL
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -40,6 +40,8 @@ class Fluent::ElasticsearchErrorHandler
|
|
40
40
|
write_operation = @plugin.write_operation
|
41
41
|
elsif INDEX_OP == @plugin.write_operation && item.has_key?(CREATE_OP)
|
42
42
|
write_operation = CREATE_OP
|
43
|
+
elsif UPSERT_OP == @plugin.write_operation && item.has_key?(UPDATE_OP)
|
44
|
+
write_operation = UPDATE_OP
|
43
45
|
else
|
44
46
|
# When we don't have an expected ops field, something changed in the API
|
45
47
|
# expected return values (ES 2.x)
|
@@ -7,7 +7,8 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
class TestPlugin
|
9
9
|
attr_reader :log
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :error_events
|
11
|
+
attr_accessor :write_operation
|
11
12
|
def initialize(log)
|
12
13
|
@log = log
|
13
14
|
@write_operation = 'index'
|
@@ -80,21 +81,13 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
80
81
|
assert_true(@plugin.error_events[0][:error].respond_to?(:backtrace))
|
81
82
|
end
|
82
83
|
|
83
|
-
def
|
84
|
-
|
85
|
-
error_records = Hash.new(false)
|
86
|
-
error_records.merge!({0=>true, 4=>true, 9=>true})
|
87
|
-
10.times do |i|
|
88
|
-
records << {time: 12345, record: {"message"=>"record #{i}","_id"=>i,"raise"=>error_records[i]}}
|
89
|
-
end
|
90
|
-
chunk = MockChunk.new(records)
|
91
|
-
|
92
|
-
response = parse_response(%({
|
84
|
+
def create_mock_response(method)
|
85
|
+
parse_response(%({
|
93
86
|
"took" : 1,
|
94
87
|
"errors" : true,
|
95
88
|
"items" : [
|
96
89
|
{
|
97
|
-
"
|
90
|
+
"#{method}" : {
|
98
91
|
"_index" : "foo",
|
99
92
|
"_type" : "bar",
|
100
93
|
"_id" : "1",
|
@@ -102,7 +95,7 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
102
95
|
}
|
103
96
|
},
|
104
97
|
{
|
105
|
-
"
|
98
|
+
"#{method}" : {
|
106
99
|
"_index" : "foo",
|
107
100
|
"_type" : "bar",
|
108
101
|
"_id" : "2",
|
@@ -114,15 +107,19 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
114
107
|
}
|
115
108
|
},
|
116
109
|
{
|
117
|
-
"
|
110
|
+
"#{method}" : {
|
118
111
|
"_index" : "foo",
|
119
112
|
"_type" : "bar",
|
120
113
|
"_id" : "3",
|
121
|
-
"status" : 409
|
114
|
+
"status" : 409,
|
115
|
+
"error" : {
|
116
|
+
"type":"version_conflict_engine_exception",
|
117
|
+
"reason":"document already exists"
|
118
|
+
}
|
122
119
|
}
|
123
120
|
},
|
124
121
|
{
|
125
|
-
"
|
122
|
+
"#{method}" : {
|
126
123
|
"_index" : "foo",
|
127
124
|
"_type" : "bar",
|
128
125
|
"_id" : "5",
|
@@ -133,7 +130,7 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
133
130
|
}
|
134
131
|
},
|
135
132
|
{
|
136
|
-
"
|
133
|
+
"#{method}" : {
|
137
134
|
"_index" : "foo",
|
138
135
|
"_type" : "bar",
|
139
136
|
"_id" : "6",
|
@@ -145,7 +142,7 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
145
142
|
}
|
146
143
|
},
|
147
144
|
{
|
148
|
-
"
|
145
|
+
"#{method}" : {
|
149
146
|
"_index" : "foo",
|
150
147
|
"_type" : "bar",
|
151
148
|
"_id" : "7",
|
@@ -157,7 +154,7 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
157
154
|
}
|
158
155
|
},
|
159
156
|
{
|
160
|
-
"
|
157
|
+
"#{method}" : {
|
161
158
|
"_index" : "foo",
|
162
159
|
"_type" : "bar",
|
163
160
|
"_id" : "8",
|
@@ -170,7 +167,18 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
170
167
|
}
|
171
168
|
]
|
172
169
|
}))
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_retry_error_index
|
173
|
+
records = []
|
174
|
+
error_records = Hash.new(false)
|
175
|
+
error_records.merge!({0=>true, 4=>true, 9=>true})
|
176
|
+
10.times do |i|
|
177
|
+
records << {time: 12345, record: {"message"=>"record #{i}","_id"=>i,"raise"=>error_records[i]}}
|
178
|
+
end
|
179
|
+
chunk = MockChunk.new(records)
|
173
180
|
|
181
|
+
response = create_mock_response('create')
|
174
182
|
begin
|
175
183
|
failed = false
|
176
184
|
@handler.handle_error(response, 'atag', chunk, response['items'].length)
|
@@ -195,6 +203,42 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
|
|
195
203
|
|
196
204
|
end
|
197
205
|
|
206
|
+
def test_retry_error_upsert
|
207
|
+
@plugin.write_operation = 'upsert'
|
208
|
+
records = []
|
209
|
+
error_records = Hash.new(false)
|
210
|
+
error_records.merge!({0=>true, 4=>true, 9=>true})
|
211
|
+
10.times do |i|
|
212
|
+
records << {time: 12345, record: {"message"=>"record #{i}","_id"=>i,"raise"=>error_records[i]}}
|
213
|
+
end
|
214
|
+
chunk = MockChunk.new(records)
|
215
|
+
|
216
|
+
response = create_mock_response('update')
|
217
|
+
begin
|
218
|
+
failed = false
|
219
|
+
@handler.handle_error(response, 'atag', chunk, response['items'].length)
|
220
|
+
rescue Fluent::ElasticsearchOutput::RetryStreamError=>e
|
221
|
+
failed = true
|
222
|
+
records = [].tap do |records|
|
223
|
+
e.retry_stream.each {|time, record| records << record}
|
224
|
+
end
|
225
|
+
assert_equal 4, records.length
|
226
|
+
assert_equal 2, records[0]['_id']
|
227
|
+
# upsert is retried in case of conflict error.
|
228
|
+
assert_equal 3, records[1]['_id']
|
229
|
+
assert_equal 6, records[2]['_id']
|
230
|
+
assert_equal 8, records[3]['_id']
|
231
|
+
error_ids = @plugin.error_events.collect {|h| h[:record]['_id']}
|
232
|
+
assert_equal 2, error_ids.length
|
233
|
+
assert_equal 5, error_ids[0]
|
234
|
+
assert_equal 7, error_ids[1]
|
235
|
+
@plugin.error_events.collect {|h| h[:error]}.each do |e|
|
236
|
+
assert_true e.respond_to?(:backtrace)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
assert_true failed
|
240
|
+
end
|
241
|
+
|
198
242
|
def test_old_es_1_X_responses
|
199
243
|
records = [{time: 123, record: {"foo" => "bar", '_id' => 'abc'}}]
|
200
244
|
response = parse_response(%({
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fluent/log-ext'
|
3
|
+
|
4
|
+
class TestFluentLogExtHandler < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@log = Fluent::Test::TestLogger.new
|
7
|
+
@log.level = "info"
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_trace?
|
11
|
+
assert_false @log.respond_to?(:trace?)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_debug?
|
15
|
+
assert_true @log.respond_to?(:debug?)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_info?
|
19
|
+
assert_true @log.respond_to?(:info?)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_warn?
|
23
|
+
assert_true @log.respond_to?(:warn?)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_error?
|
27
|
+
assert_true @log.respond_to?(:error?)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_fatal?
|
31
|
+
assert_true @log.respond_to?(:fatal?)
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.18.
|
4
|
+
version: 1.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- diogo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- README.md
|
145
145
|
- Rakefile
|
146
146
|
- fluent-plugin-elasticsearch.gemspec
|
147
|
+
- lib/fluent/log-ext.rb
|
147
148
|
- lib/fluent/plugin/elasticsearch_constants.rb
|
148
149
|
- lib/fluent/plugin/elasticsearch_error_handler.rb
|
149
150
|
- lib/fluent/plugin/elasticsearch_index_template.rb
|
@@ -157,6 +158,7 @@ files:
|
|
157
158
|
- test/plugin/test_out_elasticsearch.rb
|
158
159
|
- test/plugin/test_out_elasticsearch_dynamic.rb
|
159
160
|
- test/plugin/test_template.json
|
161
|
+
- test/test_log-ext.rb
|
160
162
|
homepage: https://github.com/uken/fluent-plugin-elasticsearch
|
161
163
|
licenses:
|
162
164
|
- Apache-2.0
|
@@ -176,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
178
|
- !ruby/object:Gem::Version
|
177
179
|
version: '0'
|
178
180
|
requirements: []
|
179
|
-
rubygems_version: 3.0.
|
181
|
+
rubygems_version: 3.0.3
|
180
182
|
signing_key:
|
181
183
|
specification_version: 4
|
182
184
|
summary: Elasticsearch output plugin for Fluent event collector
|
@@ -187,3 +189,4 @@ test_files:
|
|
187
189
|
- test/plugin/test_out_elasticsearch.rb
|
188
190
|
- test/plugin/test_out_elasticsearch_dynamic.rb
|
189
191
|
- test/plugin/test_template.json
|
192
|
+
- test/test_log-ext.rb
|