fluent-plugin-opensearch 1.0.4 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +10 -0
- data/README.md +13 -0
- data/fluent-plugin-opensearch.gemspec +1 -1
- data/lib/fluent/plugin/opensearch_error_handler.rb +6 -9
- data/lib/fluent/plugin/out_opensearch.rb +24 -10
- data/lib/fluent/plugin/out_opensearch_data_stream.rb +2 -2
- data/test/plugin/test_out_opensearch.rb +9 -3
- data/test/plugin/test_out_opensearch_data_stream.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c44bf1e420cb64daf8b5a2f21f38c47e692ed31feb0bd400189e737c19e819df
|
4
|
+
data.tar.gz: 896882755f7394472a8a4874a7a48786c50aee729b283e7be32818edcacc3e0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0718cd172d5549040faad8698a09eeeb9f5aadb00e19ab994d406143fa8789f20ce18e5b7526d9697822036c39f99aa96bdeeaace50b0b412f209d4057a3f5b
|
7
|
+
data.tar.gz: 59f7c8c735f4df3f69d4bc618df0653f00db191bd7c85f1a498509486f3fd7040073763436b0833279e24bdc52cf57b0a61322e896257a0e6ba6f19af9bc49e1
|
data/History.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
### [Unreleased]
|
4
4
|
|
5
|
+
### 1.0.7
|
6
|
+
- Expire AWS credentials with a certain interval (#52)
|
7
|
+
|
8
|
+
### 1.0.6
|
9
|
+
- out\_opensearch: Handle suppress\_type\_name operation correctly (#61)
|
10
|
+
|
11
|
+
### 1.0.5
|
12
|
+
- Use if clause to detect requirements for emitting error label events (#57)
|
13
|
+
- opensearch_data_stream: Align lowercases for data_stream and its template names (#50)
|
14
|
+
|
5
15
|
### 1.0.4
|
6
16
|
- Automatically create data streams (#44)
|
7
17
|
|
data/README.md
CHANGED
@@ -1564,6 +1564,19 @@ In this case, the endpoint configuration looks like:
|
|
1564
1564
|
</endpoint>
|
1565
1565
|
```
|
1566
1566
|
|
1567
|
+
### Expiring AWS credentials
|
1568
|
+
|
1569
|
+
If you want to expire AWS credentials in certain interval, you should specify `refresh_credentials_interval` parameter under `endpoint` section:
|
1570
|
+
|
1571
|
+
```aconf
|
1572
|
+
<endpoint>
|
1573
|
+
url https://CLUSTER_ENDPOINT_URL
|
1574
|
+
region eu-west-1
|
1575
|
+
# ...
|
1576
|
+
refresh_credentials_interval 3h # default is 5h (five hours).
|
1577
|
+
</endpoint>
|
1578
|
+
```
|
1579
|
+
|
1567
1580
|
## Troubleshooting
|
1568
1581
|
|
1569
1582
|
See [Troubleshooting document](README.Troubleshooting.md)
|
@@ -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.7'
|
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
|
@@ -194,6 +194,7 @@ module Fluent::Plugin
|
|
194
194
|
config_param :assume_role_session_name, :string, :default => "fluentd"
|
195
195
|
config_param :assume_role_web_identity_token_file, :string, :default => nil
|
196
196
|
config_param :sts_credentials_region, :string, :default => nil
|
197
|
+
config_param :refresh_credentials_interval, :time, :default => "5h"
|
197
198
|
end
|
198
199
|
|
199
200
|
config_section :buffer do
|
@@ -336,6 +337,22 @@ module Fluent::Plugin
|
|
336
337
|
}
|
337
338
|
end
|
338
339
|
end
|
340
|
+
# If AWS credentials is set, consider to expire credentials information forcibly before expired.
|
341
|
+
@credential_mutex = Mutex.new
|
342
|
+
if @endpoint
|
343
|
+
@_aws_credentials = aws_credentials(@endpoint)
|
344
|
+
|
345
|
+
if @endpoint.refresh_credentials_interval
|
346
|
+
timer_execute(:out_opensearch_expire_credentials, @endpoint.refresh_credentials_interval) do
|
347
|
+
log.debug('Recreate the AWS credentials')
|
348
|
+
|
349
|
+
@credential_mutex.synchronize do
|
350
|
+
@_os = nil
|
351
|
+
@_aws_credentials = aws_credentials(@endpoint)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
339
356
|
|
340
357
|
@serializer_class = nil
|
341
358
|
begin
|
@@ -465,11 +482,8 @@ module Fluent::Plugin
|
|
465
482
|
placeholder_validities.include?(true)
|
466
483
|
end
|
467
484
|
|
468
|
-
def emit_error_label_event
|
469
|
-
|
470
|
-
if @emit_error_label_event
|
471
|
-
block.call
|
472
|
-
end
|
485
|
+
def emit_error_label_event?
|
486
|
+
!!@emit_error_label_event
|
473
487
|
end
|
474
488
|
|
475
489
|
def compression
|
@@ -588,7 +602,7 @@ module Fluent::Plugin
|
|
588
602
|
def parse_time(value, event_time, tag)
|
589
603
|
@time_parser.call(value)
|
590
604
|
rescue => e
|
591
|
-
emit_error_label_event
|
605
|
+
if emit_error_label_event?
|
592
606
|
router.emit_error_event(@time_parse_error_tag, Fluent::Engine.now, {'tag' => tag, 'time' => event_time, 'format' => @time_key_format, 'value' => value}, e)
|
593
607
|
end
|
594
608
|
return Time.at(event_time).to_datetime
|
@@ -610,7 +624,7 @@ module Fluent::Plugin
|
|
610
624
|
:aws_sigv4,
|
611
625
|
service: 'es',
|
612
626
|
region: @endpoint.region,
|
613
|
-
credentials:
|
627
|
+
credentials: @_aws_credentials,
|
614
628
|
)
|
615
629
|
|
616
630
|
f.adapter @http_backend, @backend_options
|
@@ -882,7 +896,7 @@ module Fluent::Plugin
|
|
882
896
|
end
|
883
897
|
end
|
884
898
|
rescue => e
|
885
|
-
emit_error_label_event
|
899
|
+
if emit_error_label_event?
|
886
900
|
router.emit_error_event(tag, time, record, e)
|
887
901
|
end
|
888
902
|
end
|
@@ -992,7 +1006,7 @@ module Fluent::Plugin
|
|
992
1006
|
end
|
993
1007
|
end
|
994
1008
|
|
995
|
-
if @suppress_type_name
|
1009
|
+
if @suppress_type_name || @last_seen_major_version >= 2
|
996
1010
|
target_type = nil
|
997
1011
|
else
|
998
1012
|
# OpenSearch only supports "_doc".
|
@@ -1001,7 +1015,7 @@ module Fluent::Plugin
|
|
1001
1015
|
|
1002
1016
|
meta.clear
|
1003
1017
|
meta["_index".freeze] = target_index
|
1004
|
-
meta["_type".freeze] = target_type
|
1018
|
+
meta["_type".freeze] = target_type unless target_type.nil?
|
1005
1019
|
meta["_alias".freeze] = target_index_alias
|
1006
1020
|
|
1007
1021
|
if @pipeline
|
@@ -157,8 +157,8 @@ module Fluent::Plugin
|
|
157
157
|
else
|
158
158
|
extract_placeholders(@host, chunk)
|
159
159
|
end
|
160
|
-
data_stream_name = extract_placeholders(@data_stream_name, chunk)
|
161
|
-
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
|
162
162
|
unless @data_stream_names.include?(data_stream_name)
|
163
163
|
begin
|
164
164
|
create_index_template(data_stream_name, data_stream_template_name, host)
|
@@ -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.7
|
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-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|