fluent-plugin-opensearch 1.0.1 → 1.0.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6382f3ad5be4b3c2c5aaa425568e4421c761bcb8cc5de65369123d01830a8888
|
4
|
+
data.tar.gz: 3e38aceba420423bf15065a0203ed6d696fa862d86d365a090d72d8da290a92a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bccfd9d20535f856b4dd115eb9126efc2cf2cfbe02d52fcb1f2e14db43747ee90de71f87873924540ea973f1d077d4618b87beb053e09e4d1c52d7b1b33bcc6
|
7
|
+
data.tar.gz: 3d9a7ce81fbb624f4af5e42dcfef10e4059073523a5b410af67575cffb11bf7e243f11d66cc6bf87851ea5e5dd0f2f7d76100923d53cf386df82ede3beb0c3ad
|
data/History.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
### [Unreleased]
|
4
4
|
|
5
|
+
### 1.0.2
|
6
|
+
- Honor @hosts parameter for Data Streams (#21)
|
7
|
+
- Use template_file for Data Streams (#20)
|
8
|
+
- Specify host argument if needed (#11)
|
9
|
+
|
5
10
|
### 1.0.1
|
6
11
|
- Add testcases for hosts parameter (#10)
|
7
12
|
- Permit to handle @hosts parameter (#9)
|
@@ -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.2'
|
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}
|
@@ -29,16 +29,14 @@ module Fluent::Plugin
|
|
29
29
|
@data_stream_names = []
|
30
30
|
end
|
31
31
|
|
32
|
-
host = data_stream_connection
|
33
|
-
|
34
32
|
unless @use_placeholder
|
35
33
|
begin
|
36
34
|
@data_stream_names = [@data_stream_name]
|
37
35
|
retry_operate(@max_retry_putting_template,
|
38
36
|
@fail_on_putting_template_retry_exceed,
|
39
37
|
@catch_transport_exception_on_retry) do
|
40
|
-
create_index_template(@data_stream_name, @data_stream_template_name
|
41
|
-
create_data_stream(@data_stream_name
|
38
|
+
create_index_template(@data_stream_name, @data_stream_template_name)
|
39
|
+
create_data_stream(@data_stream_name)
|
42
40
|
end
|
43
41
|
rescue => e
|
44
42
|
raise Fluent::ConfigError, "Failed to create data stream: <#{@data_stream_name}> #{e.message}"
|
@@ -46,18 +44,9 @@ module Fluent::Plugin
|
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
49
|
-
# FIXME: Currently, the first element from hosts is only used and extracted.
|
50
|
-
def data_stream_connection
|
51
|
-
if host = get_connection_options[:hosts].first
|
52
|
-
"#{host[:scheme]}://#{host[:host]}:#{host[:port]}#{host[:path]}"
|
53
|
-
else
|
54
|
-
@host
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
47
|
def validate_data_stream_parameters
|
59
48
|
{"data_stream_name" => @data_stream_name,
|
60
|
-
"data_stream_template_name"=> @data_stream_template_name}.each do |parameter, value|
|
49
|
+
"data_stream_template_name" => @data_stream_template_name}.each do |parameter, value|
|
61
50
|
unless valid_data_stream_parameters?(value)
|
62
51
|
unless start_with_valid_characters?(value)
|
63
52
|
if not_dots?(value)
|
@@ -80,19 +69,25 @@ module Fluent::Plugin
|
|
80
69
|
end
|
81
70
|
|
82
71
|
def create_index_template(datastream_name, template_name, host = nil)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
72
|
+
# Create index template from file
|
73
|
+
if @template_file
|
74
|
+
template_installation_actual(template_name, @customize_template, @application_name, datastream_name, host)
|
75
|
+
else # Create default index template
|
76
|
+
return if data_stream_exist?(datastream_name, host) or template_exists?(template_name, host)
|
77
|
+
body = {
|
78
|
+
"index_patterns" => ["#{datastream_name}*"],
|
79
|
+
"data_stream" => {},
|
80
|
+
}
|
81
|
+
|
82
|
+
params = {
|
83
|
+
name: template_name,
|
84
|
+
body: body
|
85
|
+
}
|
86
|
+
retry_operate(@max_retry_putting_template,
|
87
|
+
@fail_on_putting_template_retry_exceed,
|
88
|
+
@catch_transport_exception_on_retry) do
|
89
|
+
client(host).indices.put_index_template(params)
|
90
|
+
end
|
96
91
|
end
|
97
92
|
end
|
98
93
|
|
@@ -169,8 +164,13 @@ module Fluent::Plugin
|
|
169
164
|
def write(chunk)
|
170
165
|
data_stream_name = @data_stream_name
|
171
166
|
data_stream_template_name = @data_stream_template_name
|
172
|
-
host =
|
167
|
+
host = nil
|
173
168
|
if @use_placeholder
|
169
|
+
host = if @hosts
|
170
|
+
extract_placeholders(@hosts, chunk)
|
171
|
+
else
|
172
|
+
extract_placeholders(@host, chunk)
|
173
|
+
end
|
174
174
|
data_stream_name = extract_placeholders(@data_stream_name, chunk)
|
175
175
|
data_stream_template_name = extract_placeholders(@data_stream_template_name, chunk)
|
176
176
|
unless @data_stream_names.include?(data_stream_name)
|
@@ -118,6 +118,18 @@ class OpenSearchOutputDataStreamTest < Test::Unit::TestCase
|
|
118
118
|
stub_data_stream(datastream_name)
|
119
119
|
end
|
120
120
|
|
121
|
+
def stub_opensearch_with_store_index_command_counts(url="http://localhost:9200/_bulk")
|
122
|
+
if @index_command_counts == nil
|
123
|
+
@index_command_counts = {}
|
124
|
+
@index_command_counts.default = 0
|
125
|
+
end
|
126
|
+
|
127
|
+
stub_request(:post, url).with do |req|
|
128
|
+
index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
|
129
|
+
@index_command_counts[url] += index_cmds.size
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
121
133
|
# ref. https://opensearch.org/docs/latest/opensearch/data-streams/
|
122
134
|
class DataStreamNameTest < self
|
123
135
|
|
@@ -329,9 +341,9 @@ class OpenSearchOutputDataStreamTest < Test::Unit::TestCase
|
|
329
341
|
data_stream_name default
|
330
342
|
}
|
331
343
|
stub_opensearch_info("https://host1:443/elastic//", "1.2.2",
|
332
|
-
{'Authorization'=>
|
344
|
+
{'Authorization'=>"Basic #{Base64.encode64('john:password').split.first}"})
|
333
345
|
stub_opensearch_info("http://host2/default_path/_data_stream/default", "1.2.2",
|
334
|
-
{'Authorization'=>
|
346
|
+
{'Authorization'=>"Basic #{Base64.encode64('john:password').split.first}"})
|
335
347
|
stub_existent_data_stream?("default", "https://host1/elastic/")
|
336
348
|
instance = driver(config).instance
|
337
349
|
|
@@ -367,6 +379,19 @@ class OpenSearchOutputDataStreamTest < Test::Unit::TestCase
|
|
367
379
|
assert_equal "foo", driver(conf).instance.data_stream_name
|
368
380
|
end
|
369
381
|
|
382
|
+
def test_template_file
|
383
|
+
stub_default
|
384
|
+
cwd = File.dirname(__FILE__)
|
385
|
+
conf = config_element(
|
386
|
+
'ROOT', '', {
|
387
|
+
'@type' => OPENSEARCH_DATA_STREAM_TYPE,
|
388
|
+
'data_stream_name' => 'foo',
|
389
|
+
'data_stream_template_name' => "foo_tpl",
|
390
|
+
'template_file' => File.join(cwd, 'datastream_template.json')
|
391
|
+
})
|
392
|
+
assert_equal "foo", driver(conf).instance.data_stream_name
|
393
|
+
end
|
394
|
+
|
370
395
|
def test_existent_data_stream
|
371
396
|
stub_index_template
|
372
397
|
stub_existent_data_stream?
|
@@ -484,13 +509,56 @@ class OpenSearchOutputDataStreamTest < Test::Unit::TestCase
|
|
484
509
|
'@type' => OPENSEARCH_DATA_STREAM_TYPE,
|
485
510
|
'data_stream_name' => 'foo',
|
486
511
|
'data_stream_template_name' => 'foo_tpl'
|
487
|
-
|
512
|
+
})
|
488
513
|
driver(conf).run(default_tag: 'test') do
|
489
514
|
driver.feed(sample_record)
|
490
515
|
end
|
491
516
|
assert_equal 1, @bulk_records
|
492
517
|
end
|
493
518
|
|
519
|
+
def test_placeholder_writes_to_multi_hosts
|
520
|
+
stub_default("foo_bar", "foo_tpl_bar")
|
521
|
+
hosts = [['192.168.33.50', 9201], ['192.168.33.51', 9201], ['192.168.33.52', 9201]]
|
522
|
+
hosts_string = hosts.map {|x| "#{x[0]}:#{x[1]}"}.compact.join(',')
|
523
|
+
hosts.each do |host_info|
|
524
|
+
host, port = host_info
|
525
|
+
stub_opensearch_with_store_index_command_counts("http://#{host}:#{port}/foo_bar/_bulk")
|
526
|
+
stub_opensearch_info("http://#{host}:#{port}/")
|
527
|
+
stub_request(:get, "http://#{host}:#{port}/_data_stream/foo_bar").
|
528
|
+
to_return(status: 200, body: "", headers: {})
|
529
|
+
end
|
530
|
+
|
531
|
+
conf = config_element(
|
532
|
+
'ROOT', '', {
|
533
|
+
'@type' => OPENSEARCH_DATA_STREAM_TYPE,
|
534
|
+
'data_stream_name' => 'foo_${key1}',
|
535
|
+
'data_stream_template_name' => 'foo_tpl_${key1}',
|
536
|
+
'hosts' => "#{hosts_string}"
|
537
|
+
}, [config_element('buffer', 'tag,key1', {
|
538
|
+
'timekey' => '1d'
|
539
|
+
}, [])])
|
540
|
+
driver(conf).run(default_tag: 'test') do
|
541
|
+
hashes = {
|
542
|
+
'age' => rand(100),
|
543
|
+
'key1' => 'bar'
|
544
|
+
}
|
545
|
+
1000.times do
|
546
|
+
driver.feed(sample_record.merge(hashes))
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
# @note: we cannot make multi chunks with options (flush_interval, buffer_chunk_limit)
|
551
|
+
# it's Fluentd test driver's constraint
|
552
|
+
# so @index_command_counts.size is always 1
|
553
|
+
assert(@index_command_counts.size > 0, "not working with hosts options")
|
554
|
+
|
555
|
+
total = 0
|
556
|
+
@index_command_counts.each do |_, count|
|
557
|
+
total += count
|
558
|
+
end
|
559
|
+
assert_equal(2000, total)
|
560
|
+
end
|
561
|
+
|
494
562
|
def test_template_retry_install_fails
|
495
563
|
cwd = File.dirname(__FILE__)
|
496
564
|
template_file = File.join(cwd, 'test_index_template.json')
|
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.2
|
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-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -208,6 +208,7 @@ files:
|
|
208
208
|
- lib/fluent/plugin/out_opensearch.rb
|
209
209
|
- lib/fluent/plugin/out_opensearch_data_stream.rb
|
210
210
|
- test/helper.rb
|
211
|
+
- test/plugin/datastream_template.json
|
211
212
|
- test/plugin/test_alias_template.json
|
212
213
|
- test/plugin/test_filter_opensearch_genid.rb
|
213
214
|
- test/plugin/test_in_opensearch.rb
|
@@ -247,6 +248,7 @@ specification_version: 4
|
|
247
248
|
summary: Opensearch output plugin for Fluent event collector
|
248
249
|
test_files:
|
249
250
|
- test/helper.rb
|
251
|
+
- test/plugin/datastream_template.json
|
250
252
|
- test/plugin/test_alias_template.json
|
251
253
|
- test/plugin/test_filter_opensearch_genid.rb
|
252
254
|
- test/plugin/test_in_opensearch.rb
|