fluent-plugin-elasticsearch 4.1.1 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/linux.yml +1 -1
- data/.github/workflows/macos.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/History.md +21 -0
- data/README.ElasticsearchGenID.md +2 -2
- data/README.md +78 -6
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_index_template.rb +32 -8
- data/lib/fluent/plugin/out_elasticsearch.rb +41 -3
- data/test/plugin/test_elasticsearch_tls.rb +8 -2
- data/test/plugin/test_in_elasticsearch.rb +14 -9
- data/test/plugin/test_index_alias_template.json +11 -0
- data/test/plugin/test_index_template.json +25 -0
- data/test/plugin/test_out_elasticsearch.rb +678 -250
- data/test/plugin/test_out_elasticsearch_dynamic.rb +7 -2
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9eb6b06e90f827162d669e94fb9a622c09f12b35e0a05f82c961ad870e3f9726
|
4
|
+
data.tar.gz: c7964330b33c36176e4b1238e4ba4f2d55e60e6ee6da4fec6799f25d943ab85f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5d961731f5866a7c841f9cbeb11f8434868988862cb9929af4cfbe174a7ce65c38d125b91dc8952120be2da4b5ad08e89c127f9c65b9e38585185acccd1cdc
|
7
|
+
data.tar.gz: 0c15c5670b0a2a9eda90b6962768c8db7e510e2da4b2434e3cb841d2fa5b15cf52a8f65f35b4236ab01cb8721d640c690f3bf753a4f4f269b2c802d9f2d7a9b6
|
data/.github/workflows/linux.yml
CHANGED
data/.github/workflows/macos.yml
CHANGED
data/History.md
CHANGED
@@ -2,6 +2,27 @@
|
|
2
2
|
|
3
3
|
### [Unreleased]
|
4
4
|
|
5
|
+
### 4.2.1
|
6
|
+
- Update a broken link (#821)
|
7
|
+
- Include chunk_id in records (#820)
|
8
|
+
- Fix a failing testcase (#818)
|
9
|
+
|
10
|
+
### 4.2.0
|
11
|
+
- ci: Add Ruby 2.7 jobs (#812)
|
12
|
+
- Support Elasticsearch new style template (#810)
|
13
|
+
|
14
|
+
### 4.1.4
|
15
|
+
- ElasticsearchGenID update docs for hash_type (#809)
|
16
|
+
- Handle api key header (#808)
|
17
|
+
- index_template: Handle error object entirely on index creation failure (#807)
|
18
|
+
|
19
|
+
### 4.1.3
|
20
|
+
- Load multiple templates even if template_name and template_file given (#799)
|
21
|
+
- Handle elasticsearch-ruby 7.9.0 using HTTP method changes (#795)
|
22
|
+
|
23
|
+
### 4.1.2
|
24
|
+
- Use Hash#dig instead of Hash#[] on retrieving version information from Elasticsearch info API (#793)
|
25
|
+
|
5
26
|
### 4.1.1
|
6
27
|
- Correct ILM explain on logstash_format case (#786)
|
7
28
|
|
@@ -26,7 +26,7 @@ In your Fluentd configuration, use `@type elasticsearch_genid`. Additional confi
|
|
26
26
|
use_entire_record false
|
27
27
|
record_keys []
|
28
28
|
separator _
|
29
|
-
hash_type
|
29
|
+
hash_type sha1
|
30
30
|
</match>
|
31
31
|
```
|
32
32
|
|
@@ -95,7 +95,7 @@ You can specify separator charactor to creating seed for hash generation.
|
|
95
95
|
hash_type sha1
|
96
96
|
```
|
97
97
|
|
98
|
-
You can specify hash algorithm.
|
98
|
+
You can specify hash algorithm. Support algorithms `md5`, `sha1`, `sha256`, `sha512`. Default: `sha1`
|
99
99
|
|
100
100
|
## Advanced Usage
|
101
101
|
|
data/README.md
CHANGED
@@ -85,6 +85,7 @@ Current maintainers: @cosmo0920
|
|
85
85
|
+ [verify_es version at startup](#verify_es_version_at_startup)
|
86
86
|
+ [default_elasticsearch_version](#default_elasticsearch_version)
|
87
87
|
+ [custom_headers](#custom_headers)
|
88
|
+
+ [api_key](#api_key)
|
88
89
|
+ [Not seeing a config you need?](#not-seeing-a-config-you-need)
|
89
90
|
+ [Dynamic configuration](#dynamic-configuration)
|
90
91
|
+ [Placeholders](#placeholders)
|
@@ -100,6 +101,10 @@ Current maintainers: @cosmo0920
|
|
100
101
|
+ [ilm_policies](#ilm_policies)
|
101
102
|
+ [ilm_policy_overwrite](#ilm_policy_overwrite)
|
102
103
|
+ [truncate_caches_interval](#truncate_caches_interval)
|
104
|
+
+ [use_legacy_template](#use_legacy_template)
|
105
|
+
+ [metadata section](#metadata-section)
|
106
|
+
+ [include_chunk_id](#include_chunk_id)
|
107
|
+
+ [chunk_id_key](#chunk_id_key)
|
103
108
|
* [Configuration - Elasticsearch Input](#configuration---elasticsearch-input)
|
104
109
|
* [Configuration - Elasticsearch Filter GenID](#configuration---elasticsearch-filter-genid)
|
105
110
|
* [Elasticsearch permissions](#elasticsearch-permissions)
|
@@ -121,10 +126,12 @@ Current maintainers: @cosmo0920
|
|
121
126
|
|
122
127
|
## Requirements
|
123
128
|
|
124
|
-
| fluent-plugin-elasticsearch | fluentd
|
125
|
-
|
126
|
-
| >=
|
127
|
-
|
|
129
|
+
| fluent-plugin-elasticsearch | fluentd | ruby |
|
130
|
+
|:----------------------------:|:-----------:|:------:|
|
131
|
+
| >= 4.0.1 | >= v0.14.22 | >= 2.3 |
|
132
|
+
| >= 3.2.4 && < 4.0.1 | >= v0.14.22 | >= 2.1 |
|
133
|
+
| >= 2.0.0 && < 3.2.3 | >= v0.14.20 | >= 2.1 |
|
134
|
+
| < 2.0.0 | >= v0.12.0 | >= 1.9 |
|
128
135
|
|
129
136
|
NOTE: For v0.12 version, you should use 1.x.y version. Please send patch into v0.12 branch if you encountered 1.x version's bug.
|
130
137
|
|
@@ -429,7 +436,7 @@ Specify index templates in form of hash. Can contain multiple templates.
|
|
429
436
|
templates { "template_name_1": "path_to_template_1_file", "template_name_2": "path_to_template_2_file"}
|
430
437
|
```
|
431
438
|
|
432
|
-
|
439
|
+
**Note:** Before ES plugin v4.1.2, if `template_file` and `template_name` are set, then this parameter will be ignored. In 4.1.3 or later, `template_file` and `template_name` can work with `templates`.
|
433
440
|
|
434
441
|
### customize_template
|
435
442
|
|
@@ -917,7 +924,7 @@ Starting with version 0.8.0, this gem uses excon, which supports proxy with envi
|
|
917
924
|
|
918
925
|
### Buffer options
|
919
926
|
|
920
|
-
`fluentd-plugin-elasticsearch` extends [Fluentd's builtin Output plugin](https://docs.fluentd.org/
|
927
|
+
`fluentd-plugin-elasticsearch` extends [Fluentd's builtin Output plugin](https://docs.fluentd.org/output#overview) and use `compat_parameters` plugin helper. It adds the following options:
|
921
928
|
|
922
929
|
```
|
923
930
|
buffer_type memory
|
@@ -1104,6 +1111,14 @@ This parameter adds additional headers to request. The default value is `{}`.
|
|
1104
1111
|
custom_headers {"token":"secret"}
|
1105
1112
|
```
|
1106
1113
|
|
1114
|
+
### api_key
|
1115
|
+
|
1116
|
+
This parameter adds authentication header. The default value is `nil`.
|
1117
|
+
|
1118
|
+
```
|
1119
|
+
api_key "ElasticsearchAPIKEY"
|
1120
|
+
```
|
1121
|
+
|
1107
1122
|
### Not seeing a config you need?
|
1108
1123
|
|
1109
1124
|
We try to keep the scope of this plugin small and not add too many configuration options. If you think an option would be useful to others, feel free to open an issue or contribute a Pull Request.
|
@@ -1292,6 +1307,63 @@ If it is set, timer for clearing `alias_indexes` and `template_names` caches wil
|
|
1292
1307
|
|
1293
1308
|
Default value is `nil`.
|
1294
1309
|
|
1310
|
+
## use_legacy_template
|
1311
|
+
|
1312
|
+
Use legacy template or not.
|
1313
|
+
|
1314
|
+
Elasticsearch 7.8 or later supports the brand new composable templates.
|
1315
|
+
|
1316
|
+
For Elasticsearch 7.7 or older, users should specify this parameter as `false`.
|
1317
|
+
|
1318
|
+
Composable template documentation is [Put Index Template API | Elasticsearch Reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html) and legacy template documentation is [Index Templates | Elasticsearch Reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates-v1.html).
|
1319
|
+
|
1320
|
+
Please confirm that whether the using Elasticsearch cluster(s) support the composable template feature or not when turn on the brand new feature with this parameter.
|
1321
|
+
|
1322
|
+
## <metadata\> section
|
1323
|
+
|
1324
|
+
Users can specify whether including `chunk_id` information into records or not:
|
1325
|
+
|
1326
|
+
```aconf
|
1327
|
+
<match your.awesome.routing.tag>
|
1328
|
+
@type elasticsearch
|
1329
|
+
# Other configurations.
|
1330
|
+
<metadata>
|
1331
|
+
include_chunk_id true
|
1332
|
+
# chunk_id_key chunk_id # Default value is "chunk_id".
|
1333
|
+
</metadata>
|
1334
|
+
</match>
|
1335
|
+
```
|
1336
|
+
|
1337
|
+
### include_chunk_id
|
1338
|
+
|
1339
|
+
Whether including `chunk_id` for not. Default value is `false`.
|
1340
|
+
|
1341
|
+
```aconf
|
1342
|
+
<match your.awesome.routing.tag>
|
1343
|
+
@type elasticsearch
|
1344
|
+
# Other configurations.
|
1345
|
+
<metadata>
|
1346
|
+
include_chunk_id true
|
1347
|
+
</metadata>
|
1348
|
+
</match>
|
1349
|
+
```
|
1350
|
+
|
1351
|
+
|
1352
|
+
### chunk_id_key
|
1353
|
+
|
1354
|
+
Specify `chunk_id_key` to store `chunk_id` information into records. Default value is `chunk_id`.
|
1355
|
+
|
1356
|
+
```aconf
|
1357
|
+
<match your.awesome.routing.tag>
|
1358
|
+
@type elasticsearch
|
1359
|
+
# Other configurations.
|
1360
|
+
<metadata>
|
1361
|
+
include_chunk_id
|
1362
|
+
chunk_id_key chunk_hex
|
1363
|
+
</metadata>
|
1364
|
+
</match>
|
1365
|
+
```
|
1366
|
+
|
1295
1367
|
## Configuration - Elasticsearch Input
|
1296
1368
|
|
1297
1369
|
See [Elasticsearch Input plugin document](README.ElasticsearchInput.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-elasticsearch'
|
6
|
-
s.version = '4.
|
6
|
+
s.version = '4.2.1'
|
7
7
|
s.authors = ['diogo', 'pitr', 'Hiroshi Hatake']
|
8
8
|
s.email = ['pitr.vern@gmail.com', 'me@diogoterror.com', 'cosmo0920.wp@gmail.com']
|
9
9
|
s.description = %q{Elasticsearch output plugin for Fluent event collector}
|
@@ -22,7 +22,11 @@ module Fluent::ElasticsearchIndexTemplate
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def template_exists?(name, host = nil)
|
25
|
-
|
25
|
+
if @use_legacy_template
|
26
|
+
client(host).indices.get_template(:name => name)
|
27
|
+
else
|
28
|
+
client(host).indices.get_index_template(:name => name)
|
29
|
+
end
|
26
30
|
return true
|
27
31
|
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
28
32
|
return false
|
@@ -52,7 +56,11 @@ module Fluent::ElasticsearchIndexTemplate
|
|
52
56
|
end
|
53
57
|
|
54
58
|
def template_put(name, template, host = nil)
|
55
|
-
|
59
|
+
if @use_legacy_template
|
60
|
+
client(host).indices.put_template(:name => name, :body => template)
|
61
|
+
else
|
62
|
+
client(host).indices.put_index_template(:name => name, :body => template)
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
def indexcreation(index_name, host = nil)
|
@@ -61,7 +69,7 @@ module Fluent::ElasticsearchIndexTemplate
|
|
61
69
|
if e.message =~ /"already exists"/ || e.message =~ /resource_already_exists_exception/
|
62
70
|
log.debug("Index #{index_name} already exists")
|
63
71
|
else
|
64
|
-
log.error("Error while index creation - #{index_name}:
|
72
|
+
log.error("Error while index creation - #{index_name}", error: e)
|
65
73
|
end
|
66
74
|
end
|
67
75
|
|
@@ -121,13 +129,29 @@ module Fluent::ElasticsearchIndexTemplate
|
|
121
129
|
|
122
130
|
def inject_ilm_settings_to_template(deflector_alias, target_index, ilm_policy_id, template)
|
123
131
|
log.debug("Overwriting index patterns when Index Lifecycle Management is enabled.")
|
124
|
-
template.delete('template') if template.include?('template')
|
125
132
|
template['index_patterns'] = "#{target_index}-*"
|
126
|
-
|
127
|
-
|
128
|
-
|
133
|
+
if @use_legacy_template
|
134
|
+
template.delete('template') if template.include?('template')
|
135
|
+
# Prepare settings Hash
|
136
|
+
if !template.key?('settings')
|
137
|
+
template['settings'] = {}
|
138
|
+
end
|
139
|
+
if template['settings'] && (template['settings']['index.lifecycle.name'] || template['settings']['index.lifecycle.rollover_alias'])
|
140
|
+
log.debug("Overwriting index lifecycle name and rollover alias when Index Lifecycle Management is enabled.")
|
141
|
+
end
|
142
|
+
template['settings'].update({ 'index.lifecycle.name' => ilm_policy_id, 'index.lifecycle.rollover_alias' => deflector_alias})
|
143
|
+
template['order'] = template['order'] ? template['order'] + target_index.split('-').length : 50 + target_index.split('-').length
|
144
|
+
else
|
145
|
+
# Prepare template.settings Hash
|
146
|
+
if !template['template'].key?('settings')
|
147
|
+
template['template']['settings'] = {}
|
148
|
+
end
|
149
|
+
if template['template']['settings'] && (template['template']['settings']['index.lifecycle.name'] || template['template']['settings']['index.lifecycle.rollover_alias'])
|
150
|
+
log.debug("Overwriting index lifecycle name and rollover alias when Index Lifecycle Management is enabled.")
|
151
|
+
end
|
152
|
+
template['template']['settings'].update({ 'index.lifecycle.name' => ilm_policy_id, 'index.lifecycle.rollover_alias' => deflector_alias})
|
153
|
+
template['priority'] = template['priority'] ? template['priority'] + target_index.split('-').length : 100 + target_index.split('-').length
|
129
154
|
end
|
130
|
-
template['settings'].update({ 'index.lifecycle.name' => ilm_policy_id, 'index.lifecycle.rollover_alias' => deflector_alias})
|
131
155
|
template
|
132
156
|
end
|
133
157
|
|
@@ -8,6 +8,7 @@ rescue LoadError
|
|
8
8
|
end
|
9
9
|
require 'json'
|
10
10
|
require 'uri'
|
11
|
+
require 'base64'
|
11
12
|
begin
|
12
13
|
require 'strptime'
|
13
14
|
rescue LoadError
|
@@ -17,6 +18,7 @@ require 'fluent/plugin/output'
|
|
17
18
|
require 'fluent/event'
|
18
19
|
require 'fluent/error'
|
19
20
|
require 'fluent/time'
|
21
|
+
require 'fluent/unique_id'
|
20
22
|
require 'fluent/log-ext'
|
21
23
|
require 'zlib'
|
22
24
|
require_relative 'elasticsearch_constants'
|
@@ -57,6 +59,7 @@ module Fluent::Plugin
|
|
57
59
|
attr_reader :template_names
|
58
60
|
attr_reader :ssl_version_options
|
59
61
|
attr_reader :compressable_connection
|
62
|
+
attr_reader :api_key_header
|
60
63
|
|
61
64
|
helpers :event_emitter, :compat_parameters, :record_accessor, :timer
|
62
65
|
|
@@ -155,6 +158,7 @@ EOC
|
|
155
158
|
config_param :default_elasticsearch_version, :integer, :default => DEFAULT_ELASTICSEARCH_VERSION
|
156
159
|
config_param :log_es_400_reason, :bool, :default => false
|
157
160
|
config_param :custom_headers, :hash, :default => {}
|
161
|
+
config_param :api_key, :string, :default => nil, :secret => true
|
158
162
|
config_param :suppress_doc_wrap, :bool, :default => false
|
159
163
|
config_param :ignore_exceptions, :array, :default => [], value_type: :string, :desc => "Ignorable exception list"
|
160
164
|
config_param :exception_backup, :bool, :default => true, :desc => "Chunk backup flag when ignore exception occured"
|
@@ -166,6 +170,12 @@ EOC
|
|
166
170
|
config_param :ilm_policies, :hash, :default => {}
|
167
171
|
config_param :ilm_policy_overwrite, :bool, :default => false
|
168
172
|
config_param :truncate_caches_interval, :time, :default => nil
|
173
|
+
config_param :use_legacy_template, :bool, :default => true
|
174
|
+
|
175
|
+
config_section :metadata, param_name: :metainfo, multi: false do
|
176
|
+
config_param :include_chunk_id, :bool, :default => false
|
177
|
+
config_param :chunk_id_key, :string, :default => "chunk_id".freeze
|
178
|
+
end
|
169
179
|
|
170
180
|
config_section :buffer do
|
171
181
|
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
@@ -212,6 +222,8 @@ EOC
|
|
212
222
|
@remove_keys_on_update = @remove_keys_on_update.split ','
|
213
223
|
end
|
214
224
|
|
225
|
+
@api_key_header = setup_api_key
|
226
|
+
|
215
227
|
raise Fluent::ConfigError, "'max_retry_putting_template' must be greater than or equal to zero." if @max_retry_putting_template < 0
|
216
228
|
raise Fluent::ConfigError, "'max_retry_get_es_version' must be greater than or equal to zero." if @max_retry_get_es_version < 0
|
217
229
|
|
@@ -247,7 +259,8 @@ EOC
|
|
247
259
|
template_installation_actual(@deflector_alias ? @deflector_alias : @index_name, @template_name, @customize_template, @application_name, @index_name, @ilm_policy_id)
|
248
260
|
end
|
249
261
|
verify_ilm_working if @enable_ilm
|
250
|
-
|
262
|
+
end
|
263
|
+
if @templates
|
251
264
|
retry_operate(@max_retry_putting_template, @fail_on_putting_template_retry_exceed) do
|
252
265
|
templates_hash_install(@templates, @template_overwrite)
|
253
266
|
end
|
@@ -397,6 +410,12 @@ EOC
|
|
397
410
|
end
|
398
411
|
end
|
399
412
|
|
413
|
+
def setup_api_key
|
414
|
+
return {} unless @api_key
|
415
|
+
|
416
|
+
{ "Authorization" => "ApiKey " + Base64.strict_encode64(@api_key) }
|
417
|
+
end
|
418
|
+
|
400
419
|
def dry_run?
|
401
420
|
if Fluent::Engine.respond_to?(:dry_run_mode)
|
402
421
|
Fluent::Engine.dry_run_mode
|
@@ -461,7 +480,10 @@ EOC
|
|
461
480
|
|
462
481
|
def detect_es_major_version
|
463
482
|
@_es_info ||= client.info
|
464
|
-
@_es_info
|
483
|
+
unless version = @_es_info.dig("version", "number")
|
484
|
+
version = @default_elasticsearch_version
|
485
|
+
end
|
486
|
+
version.to_i
|
465
487
|
end
|
466
488
|
|
467
489
|
def client_library_version
|
@@ -554,7 +576,10 @@ EOC
|
|
554
576
|
else
|
555
577
|
{}
|
556
578
|
end
|
557
|
-
headers = { 'Content-Type' => @content_type.to_s }
|
579
|
+
headers = { 'Content-Type' => @content_type.to_s }
|
580
|
+
.merge(@custom_headers)
|
581
|
+
.merge(@api_key_header)
|
582
|
+
.merge(gzip_headers)
|
558
583
|
ssl_options = { verify: @ssl_verify, ca_file: @ca_file}.merge(@ssl_version_options)
|
559
584
|
|
560
585
|
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(connection_options.merge(
|
@@ -752,6 +777,15 @@ EOC
|
|
752
777
|
true
|
753
778
|
end
|
754
779
|
|
780
|
+
def inject_chunk_id_to_record_if_needed(record, chunk_id)
|
781
|
+
if @metainfo&.include_chunk_id
|
782
|
+
record[@metainfo.chunk_id_key] = chunk_id
|
783
|
+
record
|
784
|
+
else
|
785
|
+
record
|
786
|
+
end
|
787
|
+
end
|
788
|
+
|
755
789
|
def write(chunk)
|
756
790
|
bulk_message_count = Hash.new { |h,k| h[k] = 0 }
|
757
791
|
bulk_message = Hash.new { |h,k| h[k] = '' }
|
@@ -759,6 +793,7 @@ EOC
|
|
759
793
|
meta = {}
|
760
794
|
|
761
795
|
tag = chunk.metadata.tag
|
796
|
+
chunk_id = dump_unique_id_hex(chunk.unique_id)
|
762
797
|
extracted_values = expand_placeholders(chunk)
|
763
798
|
host = if @hosts
|
764
799
|
extract_placeholders(@hosts, chunk)
|
@@ -768,6 +803,9 @@ EOC
|
|
768
803
|
|
769
804
|
chunk.msgpack_each do |time, record|
|
770
805
|
next unless record.is_a? Hash
|
806
|
+
|
807
|
+
record = inject_chunk_id_to_record_if_needed(record, chunk_id)
|
808
|
+
|
771
809
|
begin
|
772
810
|
meta, header, record = process_message(tag, meta, header, time, record, extracted_values)
|
773
811
|
info = if @include_index_in_url
|
@@ -62,8 +62,14 @@ class TestElasticsearchTLS < Test::Unit::TestCase
|
|
62
62
|
d = driver('')
|
63
63
|
ssl_version_options = d.instance.set_tls_minmax_version_config(d.instance.ssl_version, nil, nil)
|
64
64
|
if @use_tls_minmax_version
|
65
|
-
|
66
|
-
|
65
|
+
if @enabled_tlsv1_3
|
66
|
+
assert_equal({max_version: OpenSSL::SSL::TLS1_3_VERSION,
|
67
|
+
min_version: OpenSSL::SSL::TLS1_2_VERSION}, ssl_version_options)
|
68
|
+
else
|
69
|
+
assert_equal({max_version: nil,
|
70
|
+
min_version: OpenSSL::SSL::TLS1_2_VERSION}, ssl_version_options)
|
71
|
+
|
72
|
+
end
|
67
73
|
else
|
68
74
|
assert_equal({version: Fluent::Plugin::ElasticsearchTLS::DEFAULT_VERSION}, ssl_version_options)
|
69
75
|
end
|
@@ -20,6 +20,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
20
20
|
@driver = nil
|
21
21
|
log = Fluent::Engine.log
|
22
22
|
log.out.logs.slice!(0, log.out.logs.length)
|
23
|
+
@http_method = if Gem::Version.new(Elasticsearch::VERSION) >= Gem::Version.new("7.9.0")
|
24
|
+
:post
|
25
|
+
else
|
26
|
+
:get
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
def driver(conf='')
|
@@ -313,7 +318,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
313
318
|
end
|
314
319
|
|
315
320
|
def test_emit
|
316
|
-
stub_request(
|
321
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
|
317
322
|
with(body: "{\"sort\":[\"_doc\"]}").
|
318
323
|
to_return(status: 200, body: sample_response.to_s,
|
319
324
|
headers: {'Content-Type' => 'application/json'})
|
@@ -328,7 +333,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
328
333
|
|
329
334
|
def test_emit_with_custom_index_name
|
330
335
|
index_name = "logstash"
|
331
|
-
stub_request(
|
336
|
+
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
|
332
337
|
with(body: "{\"sort\":[\"_doc\"]}").
|
333
338
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
334
339
|
headers: {'Content-Type' => 'application/json'})
|
@@ -343,7 +348,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
343
348
|
|
344
349
|
def test_emit_with_parse_timestamp
|
345
350
|
index_name = "fluentd"
|
346
|
-
stub_request(
|
351
|
+
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
|
347
352
|
with(body: "{\"sort\":[\"_doc\"]}").
|
348
353
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
349
354
|
headers: {'Content-Type' => 'application/json'})
|
@@ -361,7 +366,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
361
366
|
|
362
367
|
def test_emit_with_parse_timestamp_and_timstamp_format
|
363
368
|
index_name = "fluentd"
|
364
|
-
stub_request(
|
369
|
+
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
|
365
370
|
with(body: "{\"sort\":[\"_doc\"]}").
|
366
371
|
to_return(status: 200, body: sample_response(index_name).to_s,
|
367
372
|
headers: {'Content-Type' => 'application/json'})
|
@@ -380,7 +385,7 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
380
385
|
end
|
381
386
|
|
382
387
|
def test_emit_with_docinfo
|
383
|
-
stub_request(
|
388
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
|
384
389
|
with(body: "{\"sort\":[\"_doc\"]}").
|
385
390
|
to_return(status: 200, body: sample_response.to_s,
|
386
391
|
headers: {'Content-Type' => 'application/json'})
|
@@ -399,11 +404,11 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
399
404
|
end
|
400
405
|
|
401
406
|
def test_emit_with_slices
|
402
|
-
stub_request(
|
407
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
|
403
408
|
with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":0,\"max\":2}}").
|
404
409
|
to_return(status: 200, body: sample_response.to_s,
|
405
410
|
headers: {'Content-Type' => 'application/json'})
|
406
|
-
stub_request(
|
411
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
|
407
412
|
with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":1,\"max\":2}}").
|
408
413
|
to_return(status: 200, body: sample_response.to_s,
|
409
414
|
headers: {'Content-Type' => 'application/json'})
|
@@ -419,12 +424,12 @@ class ElasticsearchInputTest < Test::Unit::TestCase
|
|
419
424
|
end
|
420
425
|
|
421
426
|
def test_emit_with_size
|
422
|
-
stub_request(
|
427
|
+
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1").
|
423
428
|
with(body: "{\"sort\":[\"_doc\"]}").
|
424
429
|
to_return(status: 200, body: sample_scroll_response.to_s,
|
425
430
|
headers: {'Content-Type' => 'application/json'})
|
426
431
|
connection = 0
|
427
|
-
scroll_request = stub_request(
|
432
|
+
scroll_request = stub_request(@http_method, "http://localhost:9200/_search/scroll?scroll=1m").
|
428
433
|
with(
|
429
434
|
body: "{\"scroll_id\":\"WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz\"}") do
|
430
435
|
connection += 1
|