fluent-plugin-elasticsearch 4.1.0 → 4.2.0
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 +19 -0
- data/README.ElasticsearchGenID.md +2 -2
- data/README.md +66 -14
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_index_template.rb +49 -17
- data/lib/fluent/plugin/out_elasticsearch.rb +32 -13
- 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 +656 -348
- 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: 46901e5f885a46c37ea29dca2968d53fd4026dec637f007936cabdd3ee070c5c
|
4
|
+
data.tar.gz: 21f3d3e9dd22752bcab060ea46ba12e8309147c2ddbb3be4aea656b527aff103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed30b7f203f9c102fdedb0a28c88210f172e9bccab3f153de81ba88b821a065e1cfdb8caccc097fbb83745069c7c5cd052e70879501ebd83b472f55c835b6116
|
7
|
+
data.tar.gz: 3ded3c8f6041224546a71df34878148a14b0f2e47970b86efb11d8b4fe4008764680534149b1c56c1651bc7dbfffc0df26ad7a459c87e739c91f391d8da83f42
|
data/.github/workflows/linux.yml
CHANGED
data/.github/workflows/macos.yml
CHANGED
data/History.md
CHANGED
@@ -2,6 +2,25 @@
|
|
2
2
|
|
3
3
|
### [Unreleased]
|
4
4
|
|
5
|
+
### 4.2.0
|
6
|
+
- ci: Add Ruby 2.7 jobs (#812)
|
7
|
+
- Support Elasticsearch new style template (#810)
|
8
|
+
|
9
|
+
### 4.1.4
|
10
|
+
- ElasticsearchGenID update docs for hash_type (#809)
|
11
|
+
- Handle api key header (#808)
|
12
|
+
- index_template: Handle error object entirely on index creation failure (#807)
|
13
|
+
|
14
|
+
### 4.1.3
|
15
|
+
- Load multiple templates even if template_name and template_file given (#799)
|
16
|
+
- Handle elasticsearch-ruby 7.9.0 using HTTP method changes (#795)
|
17
|
+
|
18
|
+
### 4.1.2
|
19
|
+
- Use Hash#dig instead of Hash#[] on retrieving version information from Elasticsearch info API (#793)
|
20
|
+
|
21
|
+
### 4.1.1
|
22
|
+
- Correct ILM explain on logstash_format case (#786)
|
23
|
+
|
5
24
|
### 4.1.0
|
6
25
|
- Implement Fallback selector and configurable selector class (#782)
|
7
26
|
|
@@ -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,7 @@ 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)
|
103
105
|
* [Configuration - Elasticsearch Input](#configuration---elasticsearch-input)
|
104
106
|
* [Configuration - Elasticsearch Filter GenID](#configuration---elasticsearch-filter-genid)
|
105
107
|
* [Elasticsearch permissions](#elasticsearch-permissions)
|
@@ -121,10 +123,12 @@ Current maintainers: @cosmo0920
|
|
121
123
|
|
122
124
|
## Requirements
|
123
125
|
|
124
|
-
| fluent-plugin-elasticsearch | fluentd
|
125
|
-
|
126
|
-
| >=
|
127
|
-
|
|
126
|
+
| fluent-plugin-elasticsearch | fluentd | ruby |
|
127
|
+
|:----------------------------:|:-----------:|:------:|
|
128
|
+
| >= 4.0.1 | >= v0.14.22 | >= 2.3 |
|
129
|
+
| >= 3.2.4 && < 4.0.1 | >= v0.14.22 | >= 2.1 |
|
130
|
+
| >= 2.0.0 && < 3.2.3 | >= v0.14.20 | >= 2.1 |
|
131
|
+
| < 2.0.0 | >= v0.12.0 | >= 1.9 |
|
128
132
|
|
129
133
|
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
134
|
|
@@ -429,7 +433,7 @@ Specify index templates in form of hash. Can contain multiple templates.
|
|
429
433
|
templates { "template_name_1": "path_to_template_1_file", "template_name_2": "path_to_template_2_file"}
|
430
434
|
```
|
431
435
|
|
432
|
-
|
436
|
+
**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
437
|
|
434
438
|
### customize_template
|
435
439
|
|
@@ -479,6 +483,8 @@ deflector_alias test-current
|
|
479
483
|
|
480
484
|
If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
|
481
485
|
|
486
|
+
**NOTE:** Since 4.1.1, `deflector_alias` is prohibited to use with `enable_ilm`.
|
487
|
+
|
482
488
|
### index_prefix
|
483
489
|
|
484
490
|
This parameter is marked as obsoleted.
|
@@ -988,9 +994,28 @@ sniffer_class_name Fluent::Plugin::ElasticsearchSimpleSniffer
|
|
988
994
|
reload_after 100
|
989
995
|
```
|
990
996
|
|
997
|
+
#### Tips
|
998
|
+
|
999
|
+
The included sniffer class is not required `out_elasticsearch`.
|
1000
|
+
You should tell Fluentd where the sniffer class exists.
|
1001
|
+
|
1002
|
+
If you use td-agent, you must put the following lines into `TD_AGENT_DEFAULT` file:
|
1003
|
+
|
1004
|
+
```
|
1005
|
+
sniffer=$(td-agent-gem contents fluent-plugin-elasticsearch|grep elasticsearch_simple_sniffer.rb)
|
1006
|
+
TD_AGENT_OPTIONS="--use-v1-config -r $sniffer"
|
1007
|
+
```
|
1008
|
+
|
1009
|
+
If you use Fluentd directly, you must pass the following lines as Fluentd command line option:
|
1010
|
+
|
1011
|
+
```
|
1012
|
+
sniffer=$(td-agent-gem contents fluent-plugin-elasticsearch|grep elasticsearch_simple_sniffer.rb)
|
1013
|
+
$ fluentd -r $sniffer [AND YOUR OTHER OPTIONS]
|
1014
|
+
```
|
1015
|
+
|
991
1016
|
### Selector Class Name
|
992
1017
|
|
993
|
-
The default selector used by the `Elasticsearch::Transport` class works well when Fluentd should round robin and random selector cases. This doesn't work well when Fluentd should
|
1018
|
+
The default selector used by the `Elasticsearch::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.
|
994
1019
|
The parameter `selector_class_name` gives you the ability to provide your own Selector class to implement whatever selection nodes logic you require.
|
995
1020
|
|
996
1021
|
The below configuration is using plugin built-in `ElasticseatchFallbackSelector`:
|
@@ -1002,21 +1027,22 @@ selector_class_name "Fluent::Plugin::ElasticseatchFallbackSelector"
|
|
1002
1027
|
|
1003
1028
|
#### Tips
|
1004
1029
|
|
1005
|
-
The included
|
1006
|
-
|
1030
|
+
The included selector class is required in `out_elasticsearch` by default.
|
1031
|
+
But, your custom selector class is not required in `out_elasticsearch`.
|
1032
|
+
You should tell Fluentd where the selector class exists.
|
1007
1033
|
|
1008
1034
|
If you use td-agent, you must put the following lines into `TD_AGENT_DEFAULT` file:
|
1009
1035
|
|
1010
1036
|
```
|
1011
|
-
|
1012
|
-
TD_AGENT_OPTIONS="--use-v1-config -r $
|
1037
|
+
selector=/path/to/your_awesome_selector.rb
|
1038
|
+
TD_AGENT_OPTIONS="--use-v1-config -r $selector"
|
1013
1039
|
```
|
1014
1040
|
|
1015
1041
|
If you use Fluentd directly, you must pass the following lines as Fluentd command line option:
|
1016
1042
|
|
1017
1043
|
```
|
1018
|
-
|
1019
|
-
$ fluentd -r $
|
1044
|
+
selector=/path/to/your_awesome_selector.rb
|
1045
|
+
$ fluentd -r $selector [AND YOUR OTHER OPTIONS]
|
1020
1046
|
```
|
1021
1047
|
|
1022
1048
|
### Reload After
|
@@ -1082,6 +1108,14 @@ This parameter adds additional headers to request. The default value is `{}`.
|
|
1082
1108
|
custom_headers {"token":"secret"}
|
1083
1109
|
```
|
1084
1110
|
|
1111
|
+
### api_key
|
1112
|
+
|
1113
|
+
This parameter adds authentication header. The default value is `nil`.
|
1114
|
+
|
1115
|
+
```
|
1116
|
+
api_key "ElasticsearchAPIKEY"
|
1117
|
+
```
|
1118
|
+
|
1085
1119
|
### Not seeing a config you need?
|
1086
1120
|
|
1087
1121
|
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.
|
@@ -1270,6 +1304,18 @@ If it is set, timer for clearing `alias_indexes` and `template_names` caches wil
|
|
1270
1304
|
|
1271
1305
|
Default value is `nil`.
|
1272
1306
|
|
1307
|
+
## use_legacy_template
|
1308
|
+
|
1309
|
+
Use legacy template or not.
|
1310
|
+
|
1311
|
+
Elasticsearch 7.8 or later supports the brand new composable templates.
|
1312
|
+
|
1313
|
+
For Elasticsearch 7.7 or older, users should specify this parameter as `false`.
|
1314
|
+
|
1315
|
+
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).
|
1316
|
+
|
1317
|
+
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.
|
1318
|
+
|
1273
1319
|
## Configuration - Elasticsearch Input
|
1274
1320
|
|
1275
1321
|
See [Elasticsearch Input plugin document](README.ElasticsearchInput.md)
|
@@ -1733,7 +1779,7 @@ ILM target index alias is created with `index_name` or an index which is calcula
|
|
1733
1779
|
|
1734
1780
|
From Elasticsearch plugin v4.0.0, ILM target index will be calculated from `index_name` (normal mode) or `logstash_prefix` (using with `logstash_format`as true).
|
1735
1781
|
|
1736
|
-
|
1782
|
+
**NOTE:** Before Elasticsearch plugin v4.1.0, using `deflector_alias` parameter when ILM is enabled is permitted and handled, but, in the later releases such that 4.1.1 or later, it cannot use with when ILM is enabled.
|
1737
1783
|
|
1738
1784
|
And also, ILM feature users should specify their Elasticsearch template for ILM enabled indices.
|
1739
1785
|
Because ILM settings are injected into their Elasticsearch templates.
|
@@ -1746,7 +1792,13 @@ It usually should be used with default value which is `default`.
|
|
1746
1792
|
|
1747
1793
|
Then, ILM parameters are used in alias index like as:
|
1748
1794
|
|
1749
|
-
|
1795
|
+
##### Simple `index_name` case:
|
1796
|
+
|
1797
|
+
`<index_name><index_separator><application_name>-000001`.
|
1798
|
+
|
1799
|
+
##### `logstash_format` as `true` case:
|
1800
|
+
|
1801
|
+
`<logstash_prefix><logstash_prefix_separator><application_name><logstash_prefix_separator><logstash_dateformat>-000001`.
|
1750
1802
|
|
1751
1803
|
#### Example ILM settings
|
1752
1804
|
|
@@ -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.0'
|
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,15 +69,16 @@ 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
|
|
68
|
-
def template_install(name, template_file, overwrite, enable_ilm = false, deflector_alias_name = nil, ilm_policy_id = nil, host = nil)
|
76
|
+
def template_install(name, template_file, overwrite, enable_ilm = false, deflector_alias_name = nil, ilm_policy_id = nil, host = nil, target_index = nil)
|
69
77
|
inject_template_name = get_template_name(enable_ilm, name, deflector_alias_name)
|
70
78
|
if overwrite
|
71
79
|
template_put(inject_template_name,
|
72
80
|
enable_ilm ? inject_ilm_settings_to_template(deflector_alias_name,
|
81
|
+
target_index,
|
73
82
|
ilm_policy_id,
|
74
83
|
get_template(template_file)) :
|
75
84
|
get_template(template_file), host)
|
@@ -80,6 +89,7 @@ module Fluent::ElasticsearchIndexTemplate
|
|
80
89
|
if !template_exists?(inject_template_name, host)
|
81
90
|
template_put(inject_template_name,
|
82
91
|
enable_ilm ? inject_ilm_settings_to_template(deflector_alias_name,
|
92
|
+
target_index,
|
83
93
|
ilm_policy_id,
|
84
94
|
get_template(template_file)) :
|
85
95
|
get_template(template_file), host)
|
@@ -89,10 +99,12 @@ module Fluent::ElasticsearchIndexTemplate
|
|
89
99
|
end
|
90
100
|
end
|
91
101
|
|
92
|
-
def template_custom_install(template_name, template_file, overwrite, customize_template, enable_ilm, deflector_alias_name, ilm_policy_id, host)
|
102
|
+
def template_custom_install(template_name, template_file, overwrite, customize_template, enable_ilm, deflector_alias_name, ilm_policy_id, host, target_index)
|
93
103
|
template_custom_name = get_template_name(enable_ilm, template_name, deflector_alias_name)
|
94
104
|
custom_template = if enable_ilm
|
95
|
-
inject_ilm_settings_to_template(deflector_alias_name,
|
105
|
+
inject_ilm_settings_to_template(deflector_alias_name,
|
106
|
+
target_index,
|
107
|
+
ilm_policy_id,
|
96
108
|
get_custom_template(template_file,
|
97
109
|
customize_template))
|
98
110
|
else
|
@@ -115,26 +127,46 @@ module Fluent::ElasticsearchIndexTemplate
|
|
115
127
|
enable_ilm ? deflector_alias_name : template_name
|
116
128
|
end
|
117
129
|
|
118
|
-
def inject_ilm_settings_to_template(
|
130
|
+
def inject_ilm_settings_to_template(deflector_alias, target_index, ilm_policy_id, template)
|
119
131
|
log.debug("Overwriting index patterns when Index Lifecycle Management is enabled.")
|
120
|
-
template
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
132
|
+
template['index_patterns'] = "#{target_index}-*"
|
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
|
125
154
|
end
|
126
|
-
template['settings'].update({ 'index.lifecycle.name' => ilm_policy_id, 'index.lifecycle.rollover_alias' => deflector_alias_name})
|
127
155
|
template
|
128
156
|
end
|
129
157
|
|
130
|
-
def create_rollover_alias(
|
158
|
+
def create_rollover_alias(target_index, rollover_index, deflector_alias_name, app_name, index_date_pattern, index_separator, enable_ilm, ilm_policy_id, ilm_policy, ilm_policy_overwrite, host)
|
131
159
|
# ILM request to create alias.
|
132
160
|
if rollover_index || enable_ilm
|
133
161
|
if !client.indices.exists_alias(:name => deflector_alias_name)
|
134
|
-
if
|
135
|
-
index_name_temp='<'+
|
162
|
+
if @logstash_format
|
163
|
+
index_name_temp = '<'+target_index+'-000001>'
|
136
164
|
else
|
137
|
-
|
165
|
+
if index_date_pattern.empty?
|
166
|
+
index_name_temp = '<'+target_index.downcase+index_separator+app_name.downcase+'-000001>'
|
167
|
+
else
|
168
|
+
index_name_temp = '<'+target_index.downcase+index_separator+app_name.downcase+'-{'+index_date_pattern+'}-000001>'
|
169
|
+
end
|
138
170
|
end
|
139
171
|
indexcreation(index_name_temp, host)
|
140
172
|
body = rollover_alias_payload(deflector_alias_name)
|
@@ -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
|
@@ -51,12 +52,13 @@ module Fluent::Plugin
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
54
|
-
RequestInfo = Struct.new(:host, :index, :ilm_index)
|
55
|
+
RequestInfo = Struct.new(:host, :index, :ilm_index, :ilm_alias)
|
55
56
|
|
56
57
|
attr_reader :alias_indexes
|
57
58
|
attr_reader :template_names
|
58
59
|
attr_reader :ssl_version_options
|
59
60
|
attr_reader :compressable_connection
|
61
|
+
attr_reader :api_key_header
|
60
62
|
|
61
63
|
helpers :event_emitter, :compat_parameters, :record_accessor, :timer
|
62
64
|
|
@@ -155,6 +157,7 @@ EOC
|
|
155
157
|
config_param :default_elasticsearch_version, :integer, :default => DEFAULT_ELASTICSEARCH_VERSION
|
156
158
|
config_param :log_es_400_reason, :bool, :default => false
|
157
159
|
config_param :custom_headers, :hash, :default => {}
|
160
|
+
config_param :api_key, :string, :default => nil, :secret => true
|
158
161
|
config_param :suppress_doc_wrap, :bool, :default => false
|
159
162
|
config_param :ignore_exceptions, :array, :default => [], value_type: :string, :desc => "Ignorable exception list"
|
160
163
|
config_param :exception_backup, :bool, :default => true, :desc => "Chunk backup flag when ignore exception occured"
|
@@ -166,6 +169,7 @@ EOC
|
|
166
169
|
config_param :ilm_policies, :hash, :default => {}
|
167
170
|
config_param :ilm_policy_overwrite, :bool, :default => false
|
168
171
|
config_param :truncate_caches_interval, :time, :default => nil
|
172
|
+
config_param :use_legacy_template, :bool, :default => true
|
169
173
|
|
170
174
|
config_section :buffer do
|
171
175
|
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
@@ -212,6 +216,8 @@ EOC
|
|
212
216
|
@remove_keys_on_update = @remove_keys_on_update.split ','
|
213
217
|
end
|
214
218
|
|
219
|
+
@api_key_header = setup_api_key
|
220
|
+
|
215
221
|
raise Fluent::ConfigError, "'max_retry_putting_template' must be greater than or equal to zero." if @max_retry_putting_template < 0
|
216
222
|
raise Fluent::ConfigError, "'max_retry_get_es_version' must be greater than or equal to zero." if @max_retry_get_es_version < 0
|
217
223
|
|
@@ -234,7 +240,7 @@ EOC
|
|
234
240
|
if !dry_run?
|
235
241
|
if @template_name && @template_file
|
236
242
|
if @enable_ilm
|
237
|
-
raise Fluent::ConfigError, "deflector_alias is prohibited to use with
|
243
|
+
raise Fluent::ConfigError, "deflector_alias is prohibited to use with enable_ilm at same time." if @deflector_alias
|
238
244
|
end
|
239
245
|
if @ilm_policy.empty? && @ilm_policy_overwrite
|
240
246
|
raise Fluent::ConfigError, "ilm_policy_overwrite requires a non empty ilm_policy."
|
@@ -247,7 +253,8 @@ EOC
|
|
247
253
|
template_installation_actual(@deflector_alias ? @deflector_alias : @index_name, @template_name, @customize_template, @application_name, @index_name, @ilm_policy_id)
|
248
254
|
end
|
249
255
|
verify_ilm_working if @enable_ilm
|
250
|
-
|
256
|
+
end
|
257
|
+
if @templates
|
251
258
|
retry_operate(@max_retry_putting_template, @fail_on_putting_template_retry_exceed) do
|
252
259
|
templates_hash_install(@templates, @template_overwrite)
|
253
260
|
end
|
@@ -397,6 +404,12 @@ EOC
|
|
397
404
|
end
|
398
405
|
end
|
399
406
|
|
407
|
+
def setup_api_key
|
408
|
+
return {} unless @api_key
|
409
|
+
|
410
|
+
{ "Authorization" => "ApiKey " + Base64.strict_encode64(@api_key) }
|
411
|
+
end
|
412
|
+
|
400
413
|
def dry_run?
|
401
414
|
if Fluent::Engine.respond_to?(:dry_run_mode)
|
402
415
|
Fluent::Engine.dry_run_mode
|
@@ -461,7 +474,10 @@ EOC
|
|
461
474
|
|
462
475
|
def detect_es_major_version
|
463
476
|
@_es_info ||= client.info
|
464
|
-
@_es_info
|
477
|
+
unless version = @_es_info.dig("version", "number")
|
478
|
+
version = @default_elasticsearch_version
|
479
|
+
end
|
480
|
+
version.to_i
|
465
481
|
end
|
466
482
|
|
467
483
|
def client_library_version
|
@@ -554,7 +570,10 @@ EOC
|
|
554
570
|
else
|
555
571
|
{}
|
556
572
|
end
|
557
|
-
headers = { 'Content-Type' => @content_type.to_s }
|
573
|
+
headers = { 'Content-Type' => @content_type.to_s }
|
574
|
+
.merge(@custom_headers)
|
575
|
+
.merge(@api_key_header)
|
576
|
+
.merge(gzip_headers)
|
558
577
|
ssl_options = { verify: @ssl_verify, ca_file: @ca_file}.merge(@ssl_version_options)
|
559
578
|
|
560
579
|
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(connection_options.merge(
|
@@ -771,9 +790,9 @@ EOC
|
|
771
790
|
begin
|
772
791
|
meta, header, record = process_message(tag, meta, header, time, record, extracted_values)
|
773
792
|
info = if @include_index_in_url
|
774
|
-
RequestInfo.new(host, meta.delete("_index".freeze), meta.delete("_alias".freeze))
|
793
|
+
RequestInfo.new(host, meta.delete("_index".freeze), meta["_index".freeze], meta.delete("_alias".freeze))
|
775
794
|
else
|
776
|
-
RequestInfo.new(host, nil, meta.delete("_alias".freeze))
|
795
|
+
RequestInfo.new(host, nil, meta["_index".freeze], meta.delete("_alias".freeze))
|
777
796
|
end
|
778
797
|
|
779
798
|
if split_request?(bulk_message, info)
|
@@ -944,16 +963,16 @@ EOC
|
|
944
963
|
|
945
964
|
def template_installation_actual(deflector_alias, template_name, customize_template, application_name, target_index, ilm_policy_id, host=nil)
|
946
965
|
if template_name && @template_file
|
947
|
-
if @alias_indexes.include?
|
966
|
+
if !@logstash_format && @alias_indexes.include?(deflector_alias)
|
948
967
|
log.debug("Index alias #{deflector_alias} already exists (cached)")
|
949
|
-
elsif @template_names.include?
|
968
|
+
elsif !@logstash_format && @template_names.include?(template_name)
|
950
969
|
log.debug("Template name #{template_name} already exists (cached)")
|
951
970
|
else
|
952
971
|
retry_operate(@max_retry_putting_template, @fail_on_putting_template_retry_exceed) do
|
953
972
|
if customize_template
|
954
|
-
template_custom_install(template_name, @template_file, @template_overwrite, customize_template, @enable_ilm, deflector_alias, ilm_policy_id, host)
|
973
|
+
template_custom_install(template_name, @template_file, @template_overwrite, customize_template, @enable_ilm, deflector_alias, ilm_policy_id, host, target_index)
|
955
974
|
else
|
956
|
-
template_install(template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, ilm_policy_id, host)
|
975
|
+
template_install(template_name, @template_file, @template_overwrite, @enable_ilm, deflector_alias, ilm_policy_id, host, target_index)
|
957
976
|
end
|
958
977
|
ilm_policy = @ilm_policies[ilm_policy_id] || {}
|
959
978
|
create_rollover_alias(target_index, @rollover_index, deflector_alias, application_name, @index_date_pattern, @index_separator, @enable_ilm, ilm_policy_id, ilm_policy, @ilm_policy_overwrite, host)
|
@@ -967,11 +986,11 @@ EOC
|
|
967
986
|
# send_bulk given a specific bulk request, the original tag,
|
968
987
|
# chunk, and bulk_message_count
|
969
988
|
def send_bulk(data, tag, chunk, bulk_message_count, extracted_values, info)
|
970
|
-
|
989
|
+
_logstash_prefix, _logstash_dateformat, index_name, _type_name, template_name, customize_template, deflector_alias, application_name, _pipeline, ilm_policy_id = extracted_values
|
971
990
|
if deflector_alias
|
972
991
|
template_installation(deflector_alias, template_name, customize_template, application_name, index_name, ilm_policy_id, info.host)
|
973
992
|
else
|
974
|
-
template_installation(info.ilm_index, template_name, customize_template, application_name, @logstash_format ?
|
993
|
+
template_installation(info.ilm_index, template_name, customize_template, application_name, @logstash_format ? info.ilm_alias : index_name, ilm_policy_id, info.host)
|
975
994
|
end
|
976
995
|
|
977
996
|
begin
|