fluent-plugin-opensearch 1.0.3 → 1.0.6
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 +10 -0
- data/README.md +2 -2
- data/fluent-plugin-opensearch.gemspec +1 -1
- data/lib/fluent/plugin/opensearch_error_handler.rb +6 -9
- data/lib/fluent/plugin/opensearch_index_template.rb +2 -2
- data/lib/fluent/plugin/out_opensearch.rb +6 -9
- data/lib/fluent/plugin/out_opensearch_data_stream.rb +2 -17
- data/test/plugin/test_out_opensearch.rb +9 -3
- data/test/plugin/test_out_opensearch_data_stream.rb +17 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 988e07d44cf92e9f0a09dfa57191ac4acdfd3a3fb1cd9598f12cb3e196ea88ac
|
4
|
+
data.tar.gz: 786b826f8fdb04d2c16804c42efaa4c40042deb43f71bcb6bed31de13742b413
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a6c39ce68b3d8616d490cd04006c85397ccf0fc4bb768f5f8182dad3f63abf5d29f721928ee7f074b361ba44d529e7080f99814300949ea5464ce4279ee1ba8
|
7
|
+
data.tar.gz: 8eb1f4a48740d1d85dfeb0d25de3877c2e4dcf4f228d0bc3f4907c952aad17327ee4f157972338dad21ce38a0b5b44571553b918aa096191444772c18ef6f2d9
|
data/History.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
### [Unreleased]
|
4
4
|
|
5
|
+
### 1.0.6
|
6
|
+
- out\_opensearch: Handle suppress\_type\_name operation correctly (#61)
|
7
|
+
|
8
|
+
### 1.0.5
|
9
|
+
- Use if clause to detect requirements for emitting error label events (#57)
|
10
|
+
- opensearch_data_stream: Align lowercases for data_stream and its template names (#50)
|
11
|
+
|
12
|
+
### 1.0.4
|
13
|
+
- Automatically create data streams (#44)
|
14
|
+
|
5
15
|
### 1.0.3
|
6
16
|
- Configurable unrecoverable record types (#40)
|
7
17
|
- Handle exceptions on retrieving AWS credentials (#39)
|
data/README.md
CHANGED
@@ -1047,11 +1047,11 @@ $ fluentd -r $sniffer [AND YOUR OTHER OPTIONS]
|
|
1047
1047
|
The default selector used by the `OpenSearch::Transport` class works well when Fluentd should behave round robin and random selector cases. This doesn't work well when Fluentd should behave fallbacking from exhausted ES cluster to normal ES cluster.
|
1048
1048
|
The parameter `selector_class_name` gives you the ability to provide your own Selector class to implement whatever selection nodes logic you require.
|
1049
1049
|
|
1050
|
-
The below configuration is using plugin built-in `
|
1050
|
+
The below configuration is using plugin built-in `OpenSearchFallbackSelector`:
|
1051
1051
|
|
1052
1052
|
```
|
1053
1053
|
hosts exhausted-host:9201,normal-host:9200
|
1054
|
-
selector_class_name "Fluent::Plugin::
|
1054
|
+
selector_class_name "Fluent::Plugin::OpenSeartchFallbackSelector"
|
1055
1055
|
```
|
1056
1056
|
|
1057
1057
|
#### Tips
|
@@ -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-opensearch'
|
6
|
-
s.version = '1.0.
|
6
|
+
s.version = '1.0.6'
|
7
7
|
s.authors = ['Hiroshi Hatake']
|
8
8
|
s.email = ['cosmo0920.wp@gmail.com']
|
9
9
|
s.description = %q{Opensearch output plugin for Fluent event collector}
|
@@ -65,11 +65,8 @@ class Fluent::Plugin::OpenSearchErrorHandler
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def emit_error_label_event
|
69
|
-
|
70
|
-
if @plugin.emit_error_label_event
|
71
|
-
block.call
|
72
|
-
end
|
68
|
+
def emit_error_label_event?
|
69
|
+
!!@plugin.emit_error_label_event
|
73
70
|
end
|
74
71
|
|
75
72
|
def handle_error(response, tag, chunk, bulk_message_count, extracted_values)
|
@@ -138,14 +135,14 @@ class Fluent::Plugin::OpenSearchErrorHandler
|
|
138
135
|
reason += " [reason]: \'#{item[write_operation]['error']['reason']}\'"
|
139
136
|
end
|
140
137
|
end
|
141
|
-
emit_error_label_event
|
138
|
+
if emit_error_label_event?
|
142
139
|
@plugin.router.emit_error_event(tag, time, rawrecord, OpenSearchError.new("400 - Rejected by OpenSearch#{reason}"))
|
143
140
|
end
|
144
141
|
else
|
145
142
|
if item[write_operation]['error'].is_a?(String)
|
146
143
|
reason = item[write_operation]['error']
|
147
144
|
stats[:errors_block_resp] += 1
|
148
|
-
emit_error_label_event
|
145
|
+
if emit_error_label_event?
|
149
146
|
@plugin.router.emit_error_event(tag, time, rawrecord, OpenSearchError.new("#{status} - #{reason}"))
|
150
147
|
end
|
151
148
|
next
|
@@ -156,7 +153,7 @@ class Fluent::Plugin::OpenSearchErrorHandler
|
|
156
153
|
raise OpenSearchRequestAbortError, "Rejected OpenSearch due to #{type}"
|
157
154
|
end
|
158
155
|
if unrecoverable_record_error?(type)
|
159
|
-
emit_error_label_event
|
156
|
+
if emit_error_label_event?
|
160
157
|
@plugin.router.emit_error_event(tag, time, rawrecord, OpenSearchError.new("#{status} - #{type}: #{reason}"))
|
161
158
|
end
|
162
159
|
next
|
@@ -167,7 +164,7 @@ class Fluent::Plugin::OpenSearchErrorHandler
|
|
167
164
|
# When we don't have a type field, something changed in the API
|
168
165
|
# expected return values.
|
169
166
|
stats[:errors_bad_resp] += 1
|
170
|
-
emit_error_label_event
|
167
|
+
if emit_error_label_event?
|
171
168
|
@plugin.router.emit_error_event(tag, time, rawrecord, OpenSearchError.new("#{status} - No error type provided in the response"))
|
172
169
|
end
|
173
170
|
next
|
@@ -62,10 +62,10 @@ module Fluent::OpenSearchIndexTemplate
|
|
62
62
|
client.transport.transport.host_unreachable_exceptions
|
63
63
|
end
|
64
64
|
|
65
|
-
def retry_operate(max_retries, fail_on_retry_exceed = true,
|
65
|
+
def retry_operate(max_retries, fail_on_retry_exceed = true, catch_transport_exceptions = true)
|
66
66
|
return unless block_given?
|
67
67
|
retries = 0
|
68
|
-
transport_errors = OpenSearch::Transport::Transport::Errors.constants.map{ |c| OpenSearch::Transport::Transport::Errors.const_get c } if
|
68
|
+
transport_errors = OpenSearch::Transport::Transport::Errors.constants.map{ |c| OpenSearch::Transport::Transport::Errors.const_get c } if catch_transport_exceptions
|
69
69
|
begin
|
70
70
|
yield
|
71
71
|
rescue *host_unreachable_exceptions, *transport_errors, Timeout::Error => e
|
@@ -465,11 +465,8 @@ module Fluent::Plugin
|
|
465
465
|
placeholder_validities.include?(true)
|
466
466
|
end
|
467
467
|
|
468
|
-
def emit_error_label_event
|
469
|
-
|
470
|
-
if @emit_error_label_event
|
471
|
-
block.call
|
472
|
-
end
|
468
|
+
def emit_error_label_event?
|
469
|
+
!!@emit_error_label_event
|
473
470
|
end
|
474
471
|
|
475
472
|
def compression
|
@@ -588,7 +585,7 @@ module Fluent::Plugin
|
|
588
585
|
def parse_time(value, event_time, tag)
|
589
586
|
@time_parser.call(value)
|
590
587
|
rescue => e
|
591
|
-
emit_error_label_event
|
588
|
+
if emit_error_label_event?
|
592
589
|
router.emit_error_event(@time_parse_error_tag, Fluent::Engine.now, {'tag' => tag, 'time' => event_time, 'format' => @time_key_format, 'value' => value}, e)
|
593
590
|
end
|
594
591
|
return Time.at(event_time).to_datetime
|
@@ -882,7 +879,7 @@ module Fluent::Plugin
|
|
882
879
|
end
|
883
880
|
end
|
884
881
|
rescue => e
|
885
|
-
emit_error_label_event
|
882
|
+
if emit_error_label_event?
|
886
883
|
router.emit_error_event(tag, time, record, e)
|
887
884
|
end
|
888
885
|
end
|
@@ -992,7 +989,7 @@ module Fluent::Plugin
|
|
992
989
|
end
|
993
990
|
end
|
994
991
|
|
995
|
-
if @suppress_type_name
|
992
|
+
if @suppress_type_name || @last_seen_major_version >= 2
|
996
993
|
target_type = nil
|
997
994
|
else
|
998
995
|
# OpenSearch only supports "_doc".
|
@@ -1001,7 +998,7 @@ module Fluent::Plugin
|
|
1001
998
|
|
1002
999
|
meta.clear
|
1003
1000
|
meta["_index".freeze] = target_index
|
1004
|
-
meta["_type".freeze] = target_type
|
1001
|
+
meta["_type".freeze] = target_type unless target_type.nil?
|
1005
1002
|
meta["_alias".freeze] = target_index_alias
|
1006
1003
|
|
1007
1004
|
if @pipeline
|
@@ -36,7 +36,6 @@ module Fluent::Plugin
|
|
36
36
|
@fail_on_putting_template_retry_exceed,
|
37
37
|
@catch_transport_exception_on_retry) do
|
38
38
|
create_index_template(@data_stream_name, @data_stream_template_name)
|
39
|
-
create_data_stream(@data_stream_name)
|
40
39
|
end
|
41
40
|
rescue => e
|
42
41
|
raise Fluent::ConfigError, "Failed to create data stream: <#{@data_stream_name}> #{e.message}"
|
@@ -105,19 +104,6 @@ module Fluent::Plugin
|
|
105
104
|
end
|
106
105
|
end
|
107
106
|
|
108
|
-
def create_data_stream(datastream_name, host = nil)
|
109
|
-
return if data_stream_exist?(datastream_name, host)
|
110
|
-
params = {
|
111
|
-
name: datastream_name
|
112
|
-
}
|
113
|
-
retry_operate(@max_retry_putting_template,
|
114
|
-
@fail_on_putting_template_retry_exceed,
|
115
|
-
@catch_transport_exception_on_retry) do
|
116
|
-
# TODO: Use X-Pack equivalent performing DataStream operation method on the following line
|
117
|
-
client(host).perform_request('PUT', "/_data_stream/#{datastream_name}", {}, params)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
107
|
def template_exists?(name, host = nil)
|
122
108
|
if @use_legacy_template
|
123
109
|
client(host).indices.get_template(:name => name)
|
@@ -171,12 +157,11 @@ module Fluent::Plugin
|
|
171
157
|
else
|
172
158
|
extract_placeholders(@host, chunk)
|
173
159
|
end
|
174
|
-
data_stream_name = extract_placeholders(@data_stream_name, chunk)
|
175
|
-
data_stream_template_name = extract_placeholders(@data_stream_template_name, chunk)
|
160
|
+
data_stream_name = extract_placeholders(@data_stream_name, chunk).downcase
|
161
|
+
data_stream_template_name = extract_placeholders(@data_stream_template_name, chunk).downcase
|
176
162
|
unless @data_stream_names.include?(data_stream_name)
|
177
163
|
begin
|
178
164
|
create_index_template(data_stream_name, data_stream_template_name, host)
|
179
|
-
create_data_stream(data_stream_name, host)
|
180
165
|
@data_stream_names << data_stream_name
|
181
166
|
rescue => e
|
182
167
|
raise Fluent::ConfigError, "Failed to create data stream: <#{data_stream_name}> #{e.message}"
|
@@ -2320,8 +2320,9 @@ class OpenSearchOutputTest < Test::Unit::TestCase
|
|
2320
2320
|
end
|
2321
2321
|
|
2322
2322
|
data(
|
2323
|
-
"OpenSearch default"=> {"os_version" => 1, "_type" => "_doc", "suppress_type" => false},
|
2324
|
-
"Suppressed type"
|
2323
|
+
"OpenSearch default" => {"os_version" => 1, "_type" => "_doc", "suppress_type" => false},
|
2324
|
+
"Suppressed type" => {"os_version" => 1, "_type" => nil, "suppress_type" => true},
|
2325
|
+
"OpenSearch 2" => {"os_version" => 2, "_type" => nil, "suppress_type" => true},
|
2325
2326
|
)
|
2326
2327
|
def test_writes_to_speficied_type(data)
|
2327
2328
|
driver('', data["os_version"]).configure("suppress_type_name #{data['suppress_type']}")
|
@@ -2330,7 +2331,12 @@ class OpenSearchOutputTest < Test::Unit::TestCase
|
|
2330
2331
|
driver.run(default_tag: 'test') do
|
2331
2332
|
driver.feed(sample_record)
|
2332
2333
|
end
|
2333
|
-
|
2334
|
+
if data["suppress_type"] || data["os_version"] >= 2
|
2335
|
+
assert_false(index_cmds.first['index'].has_key?("_type"))
|
2336
|
+
else
|
2337
|
+
assert_true(index_cmds.first['index'].has_key?("_type"))
|
2338
|
+
assert_equal(data['_type'], index_cmds.first['index']['_type'])
|
2339
|
+
end
|
2334
2340
|
end
|
2335
2341
|
|
2336
2342
|
def test_writes_to_speficied_host
|
@@ -439,6 +439,23 @@ class OpenSearchOutputDataStreamTest < Test::Unit::TestCase
|
|
439
439
|
assert_equal 1, @bulk_records
|
440
440
|
end
|
441
441
|
|
442
|
+
def test_placeholder_with_capital_letters
|
443
|
+
dsname = "foo_test.capital_letters"
|
444
|
+
tplname = "foo_tpl_test.capital_letters"
|
445
|
+
stub_default(dsname, tplname)
|
446
|
+
stub_bulk_feed(dsname, tplname)
|
447
|
+
conf = config_element(
|
448
|
+
'ROOT', '', {
|
449
|
+
'@type' => OPENSEARCH_DATA_STREAM_TYPE,
|
450
|
+
'data_stream_name' => 'foo_${tag}',
|
451
|
+
'data_stream_template_name' => "foo_tpl_${tag}"
|
452
|
+
})
|
453
|
+
driver(conf).run(default_tag: 'TEST.CAPITAL_LETTERS') do
|
454
|
+
driver.feed(sample_record)
|
455
|
+
end
|
456
|
+
assert_equal 1, @bulk_records
|
457
|
+
end
|
458
|
+
|
442
459
|
def test_placeholder_params_unset
|
443
460
|
dsname = "foo_test"
|
444
461
|
tplname = "foo_test_template"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-opensearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Hatake
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
242
|
- !ruby/object:Gem::Version
|
243
243
|
version: '0'
|
244
244
|
requirements: []
|
245
|
-
rubygems_version: 3.2.
|
245
|
+
rubygems_version: 3.2.32
|
246
246
|
signing_key:
|
247
247
|
specification_version: 4
|
248
248
|
summary: Opensearch output plugin for Fluent event collector
|