fluent-plugin-elasticsearch 4.0.9 → 4.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/issue-auto-closer.yml +12 -0
- data/History.md +22 -0
- data/README.ElasticsearchGenID.md +116 -0
- data/README.md +74 -9
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/elasticsearch_fallback_selector.rb +9 -0
- data/lib/fluent/plugin/elasticsearch_index_template.rb +19 -11
- data/lib/fluent/plugin/filter_elasticsearch_genid.rb +52 -0
- data/lib/fluent/plugin/out_elasticsearch.rb +48 -25
- data/test/plugin/test_elasticsearch_fallback_selector.rb +73 -0
- data/test/plugin/test_filter_elasticsearch_genid.rb +171 -0
- data/test/plugin/test_out_elasticsearch.rb +171 -80
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 367f610faf1266994e676a07ca2fc391bf0951036f356fd4a95a6a7d7cce1b61
|
4
|
+
data.tar.gz: 56fc5e47f6dd8e63df03f6190fc0f3dfff2e1fae548b38cc9cdb328f75246ade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 812b336dcf870a4dbb2ecfbc87304b8c6b6cfafb561d2cf6eece11f35e29e9aa484ab8365fa9245a578c51ec540fcaf09925dc68668820ce3ab7c71041720dd2
|
7
|
+
data.tar.gz: da2c1b8bbbdd364ff5a3df1214a54151a7e9e809230b12e75e06b42a0eb7df790124898cd6c137c82edede8c94f5e8adc9d7eea05134bff0a084d1de11b5269e
|
@@ -0,0 +1,12 @@
|
|
1
|
+
name: Autocloser
|
2
|
+
on: [issues]
|
3
|
+
jobs:
|
4
|
+
autoclose:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
steps:
|
7
|
+
- name: Autoclose issues that did not follow issue template
|
8
|
+
uses: roots/issue-closer-action@v1.1
|
9
|
+
with:
|
10
|
+
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
11
|
+
issue-close-message: "@${issue.user.login} this issue was automatically closed because it did not follow the issue template."
|
12
|
+
issue-pattern: "(.*Problem.*)|(.*Expected Behavior or What you need to ask.*)|(.*Using Fluentd and ES plugin versions.*)"
|
data/History.md
CHANGED
@@ -2,6 +2,28 @@
|
|
2
2
|
|
3
3
|
### [Unreleased]
|
4
4
|
|
5
|
+
### 4.1.2
|
6
|
+
- Use Hash#dig instead of Hash#[] on retrieving version information from Elasticsearch info API (#793)
|
7
|
+
|
8
|
+
### 4.1.1
|
9
|
+
- Correct ILM explain on logstash_format case (#786)
|
10
|
+
|
11
|
+
### 4.1.0
|
12
|
+
- Implement Fallback selector and configurable selector class (#782)
|
13
|
+
|
14
|
+
### 4.0.11
|
15
|
+
- Add custom and time placeholders combination testcase for ILM (#781)
|
16
|
+
- Really support ILM on `logstash_format` enabled environment (#779)
|
17
|
+
|
18
|
+
### 4.0.10
|
19
|
+
- filter_elasticsearch_genid: Use entire record as hash seed (#777)
|
20
|
+
- Suppress type in meta with suppress_type_name parameter (#774)
|
21
|
+
- filter\_elasticsearch\_genid: Add hash generation mechanism from events (#773)
|
22
|
+
- Clean up error text (#772)
|
23
|
+
- Use GitHub Actions badges instead of Travis' (#760)
|
24
|
+
- Add issue auto closer workflow (#759)
|
25
|
+
- Document required permissions (#757)
|
26
|
+
|
5
27
|
### 4.0.9
|
6
28
|
- Add possibility to configure multiple ILM policies (#753)
|
7
29
|
- Document required permissions (#757)
|
@@ -0,0 +1,116 @@
|
|
1
|
+
## Index
|
2
|
+
|
3
|
+
* [Usage](#usage)
|
4
|
+
* [Configuration](#configuration)
|
5
|
+
+ [hash_id_key](#hash_id_key)
|
6
|
+
+ [include_tag_in_seed](#include_tag_in_seed)
|
7
|
+
+ [include_time_in_seed](#include_time_in_seed)
|
8
|
+
+ [use_record_as_seed](#use_record_as_seed)
|
9
|
+
+ [use_entire_record](#use_entire_record)
|
10
|
+
+ [record_keys](#record_keys)
|
11
|
+
+ [separator](#separator)
|
12
|
+
+ [hash_type](#hash_type)
|
13
|
+
* [Advanced Usage](#advanced-usage)
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
In your Fluentd configuration, use `@type elasticsearch_genid`. Additional configuration is optional, default values would look like this:
|
18
|
+
|
19
|
+
```
|
20
|
+
<source>
|
21
|
+
@type elasticsearch_genid
|
22
|
+
hash_id_key _hash
|
23
|
+
include_tag_in_seed false
|
24
|
+
include_time_in_seed false
|
25
|
+
use_record_as_seed false
|
26
|
+
use_entire_record false
|
27
|
+
record_keys []
|
28
|
+
separator _
|
29
|
+
hash_type md5
|
30
|
+
</match>
|
31
|
+
```
|
32
|
+
|
33
|
+
## Configuration
|
34
|
+
|
35
|
+
### hash_id_key
|
36
|
+
|
37
|
+
```
|
38
|
+
hash_id_key _id
|
39
|
+
```
|
40
|
+
|
41
|
+
You can specify generated hash storing key.
|
42
|
+
|
43
|
+
### include_tag_in_seed
|
44
|
+
|
45
|
+
```
|
46
|
+
include_tag_in_seed true
|
47
|
+
```
|
48
|
+
|
49
|
+
You can specify to use tag for hash generation seed.
|
50
|
+
|
51
|
+
### include_time_in_seed
|
52
|
+
|
53
|
+
```
|
54
|
+
include_time_in_seed true
|
55
|
+
```
|
56
|
+
|
57
|
+
You can specify to use time for hash generation seed.
|
58
|
+
|
59
|
+
### use_record_as_seed
|
60
|
+
|
61
|
+
```
|
62
|
+
use_record_as_seed true
|
63
|
+
```
|
64
|
+
|
65
|
+
You can specify to use record in events for hash generation seed. This parameter should be used with [record_keys](#record_keys) parameter in practice.
|
66
|
+
|
67
|
+
### record_keys
|
68
|
+
|
69
|
+
```
|
70
|
+
record_keys request_id,pipeline_id
|
71
|
+
```
|
72
|
+
|
73
|
+
You can specify keys which are record in events for hash generation seed. This parameter should be used with [use_record_as_seed](#use_record_as_seed) parameter in practice.
|
74
|
+
|
75
|
+
### use_entire_record
|
76
|
+
|
77
|
+
```
|
78
|
+
use_entire_record true
|
79
|
+
```
|
80
|
+
|
81
|
+
You can specify to use entire record in events for hash generation seed.
|
82
|
+
|
83
|
+
|
84
|
+
### separator
|
85
|
+
|
86
|
+
```
|
87
|
+
separator |
|
88
|
+
```
|
89
|
+
|
90
|
+
You can specify separator charactor to creating seed for hash generation.
|
91
|
+
|
92
|
+
### hash_type
|
93
|
+
|
94
|
+
```
|
95
|
+
hash_type sha1
|
96
|
+
```
|
97
|
+
|
98
|
+
You can specify hash algorithm.
|
99
|
+
|
100
|
+
## Advanced Usage
|
101
|
+
|
102
|
+
Elasticsearch GenID plugin can handle record contents differing with the following parameters:
|
103
|
+
|
104
|
+
```aconf
|
105
|
+
<filter the.awesome.your.routing.tag>
|
106
|
+
@type elasticsearch_genid
|
107
|
+
use_entire_record true
|
108
|
+
hash_type sha1
|
109
|
+
hash_id_key _hash
|
110
|
+
separator _
|
111
|
+
inc_time_as_key true
|
112
|
+
inc_tag_as_key true
|
113
|
+
</filter>
|
114
|
+
```
|
115
|
+
|
116
|
+
The above configuration can handle tag, time, and record differing and generate different base64 encoded hash per record.
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Fluent::Plugin::Elasticsearch, a plugin for [Fluentd](http://fluentd.org)
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/fluent-plugin-elasticsearch.png)](http://badge.fury.io/rb/fluent-plugin-elasticsearch)
|
4
|
-
|
4
|
+
![Testing on Windows](https://github.com/uken/fluent-plugin-elasticsearch/workflows/Testing%20on%20Windows/badge.svg?branch=master)
|
5
|
+
![Testing on macOS](https://github.com/uken/fluent-plugin-elasticsearch/workflows/Testing%20on%20macOS/badge.svg?branch=master)
|
6
|
+
![Testing on Ubuntu](https://github.com/uken/fluent-plugin-elasticsearch/workflows/Testing%20on%20Ubuntu/badge.svg?branch=master)
|
5
7
|
[![Coverage Status](https://coveralls.io/repos/uken/fluent-plugin-elasticsearch/badge.png)](https://coveralls.io/r/uken/fluent-plugin-elasticsearch)
|
6
8
|
[![Code Climate](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch.png)](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch)
|
7
9
|
|
@@ -31,6 +33,7 @@ Current maintainers: @cosmo0920
|
|
31
33
|
+ [time_key_exclude_timestamp](#time_key_exclude_timestamp)
|
32
34
|
+ [include_timestamp](#include_timestamp)
|
33
35
|
+ [utc_index](#utc_index)
|
36
|
+
+ [suppress_type_name](#suppress_type_name)
|
34
37
|
+ [target_index_key](#target_index_key)
|
35
38
|
+ [target_type_key](#target_type_key)
|
36
39
|
+ [template_name](#template_name)
|
@@ -75,6 +78,7 @@ Current maintainers: @cosmo0920
|
|
75
78
|
+ [Hash flattening](#hash-flattening)
|
76
79
|
+ [Generate Hash ID](#generate-hash-id)
|
77
80
|
+ [sniffer_class_name](#sniffer-class-name)
|
81
|
+
+ [selector_class_name](#selector-class-name)
|
78
82
|
+ [reload_after](#reload-after)
|
79
83
|
+ [validate_client_version](#validate-client-version)
|
80
84
|
+ [unrecoverable_error_types](#unrecoverable-error-types)
|
@@ -97,6 +101,7 @@ Current maintainers: @cosmo0920
|
|
97
101
|
+ [ilm_policy_overwrite](#ilm_policy_overwrite)
|
98
102
|
+ [truncate_caches_interval](#truncate_caches_interval)
|
99
103
|
* [Configuration - Elasticsearch Input](#configuration---elasticsearch-input)
|
104
|
+
* [Configuration - Elasticsearch Filter GenID](#configuration---elasticsearch-filter-genid)
|
100
105
|
* [Elasticsearch permissions](#elasticsearch-permissions)
|
101
106
|
* [Troubleshooting](#troubleshooting)
|
102
107
|
+ [Cannot send events to elasticsearch](#cannot-send-events-to-elasticsearch)
|
@@ -116,10 +121,12 @@ Current maintainers: @cosmo0920
|
|
116
121
|
|
117
122
|
## Requirements
|
118
123
|
|
119
|
-
| fluent-plugin-elasticsearch | fluentd
|
120
|
-
|
121
|
-
| >=
|
122
|
-
|
|
124
|
+
| fluent-plugin-elasticsearch | fluentd | ruby |
|
125
|
+
|:----------------------------:|:-----------:|:------:|
|
126
|
+
| >= 4.0.1 | >= v0.14.22 | >= 2.3 |
|
127
|
+
| >= 3.2.4 && < 4.0.1 | >= v0.14.22 | >= 2.1 |
|
128
|
+
| >= 2.0.0 && < 3.2.3 | >= v0.14.20 | >= 2.1 |
|
129
|
+
| < 2.0.0 | >= v0.12.0 | >= 1.9 |
|
123
130
|
|
124
131
|
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.
|
125
132
|
|
@@ -351,6 +358,20 @@ utc_index true
|
|
351
358
|
|
352
359
|
By default, the records inserted into index `logstash-YYMMDD` with UTC (Coordinated Universal Time). This option allows to use local time if you describe utc_index to false.
|
353
360
|
|
361
|
+
### suppress_type_name
|
362
|
+
|
363
|
+
In Elasticsearch 7.x, Elasticsearch cluster complains the following types removal warnings:
|
364
|
+
|
365
|
+
```json
|
366
|
+
{"type": "deprecation", "timestamp": "2020-07-03T08:02:20,830Z", "level": "WARN", "component": "o.e.d.a.b.BulkRequestParser", "cluster.name": "docker-cluster", "node.name": "70dd5c6b94c3", "message": "[types removal] Specifying types in bulk requests is deprecated.", "cluster.uuid": "NoJJmtzfTtSzSMv0peG8Wg", "node.id": "VQ-PteHmTVam2Pnbg7xWHw" }
|
367
|
+
```
|
368
|
+
|
369
|
+
This can be suppressed with:
|
370
|
+
|
371
|
+
```
|
372
|
+
suppress_type_name true
|
373
|
+
```
|
374
|
+
|
354
375
|
### target_index_key
|
355
376
|
|
356
377
|
Tell this plugin to find the index name to write to in the record under this key in preference to other mechanisms. Key can be specified as path to nested record using dot ('.') as a separator.
|
@@ -460,6 +481,8 @@ deflector_alias test-current
|
|
460
481
|
|
461
482
|
If [rollover_index](#rollover_index) is set, then this parameter will be in effect otherwise ignored.
|
462
483
|
|
484
|
+
**NOTE:** Since 4.1.1, `deflector_alias` is prohibited to use with `enable_ilm`.
|
485
|
+
|
463
486
|
### index_prefix
|
464
487
|
|
465
488
|
This parameter is marked as obsoleted.
|
@@ -971,7 +994,7 @@ reload_after 100
|
|
971
994
|
|
972
995
|
#### Tips
|
973
996
|
|
974
|
-
The included sniffer class
|
997
|
+
The included sniffer class is not required `out_elasticsearch`.
|
975
998
|
You should tell Fluentd where the sniffer class exists.
|
976
999
|
|
977
1000
|
If you use td-agent, you must put the following lines into `TD_AGENT_DEFAULT` file:
|
@@ -985,7 +1008,39 @@ If you use Fluentd directly, you must pass the following lines as Fluentd comman
|
|
985
1008
|
|
986
1009
|
```
|
987
1010
|
sniffer=$(td-agent-gem contents fluent-plugin-elasticsearch|grep elasticsearch_simple_sniffer.rb)
|
988
|
-
$ fluentd -r $sniffer
|
1011
|
+
$ fluentd -r $sniffer [AND YOUR OTHER OPTIONS]
|
1012
|
+
```
|
1013
|
+
|
1014
|
+
### Selector Class Name
|
1015
|
+
|
1016
|
+
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.
|
1017
|
+
The parameter `selector_class_name` gives you the ability to provide your own Selector class to implement whatever selection nodes logic you require.
|
1018
|
+
|
1019
|
+
The below configuration is using plugin built-in `ElasticseatchFallbackSelector`:
|
1020
|
+
|
1021
|
+
```
|
1022
|
+
hosts exhausted-host:9201,normal-host:9200
|
1023
|
+
selector_class_name "Fluent::Plugin::ElasticseatchFallbackSelector"
|
1024
|
+
```
|
1025
|
+
|
1026
|
+
#### Tips
|
1027
|
+
|
1028
|
+
The included selector class is required in `out_elasticsearch` by default.
|
1029
|
+
But, your custom selector class is not required in `out_elasticsearch`.
|
1030
|
+
You should tell Fluentd where the selector class exists.
|
1031
|
+
|
1032
|
+
If you use td-agent, you must put the following lines into `TD_AGENT_DEFAULT` file:
|
1033
|
+
|
1034
|
+
```
|
1035
|
+
selector=/path/to/your_awesome_selector.rb
|
1036
|
+
TD_AGENT_OPTIONS="--use-v1-config -r $selector"
|
1037
|
+
```
|
1038
|
+
|
1039
|
+
If you use Fluentd directly, you must pass the following lines as Fluentd command line option:
|
1040
|
+
|
1041
|
+
```
|
1042
|
+
selector=/path/to/your_awesome_selector.rb
|
1043
|
+
$ fluentd -r $selector [AND YOUR OTHER OPTIONS]
|
989
1044
|
```
|
990
1045
|
|
991
1046
|
### Reload After
|
@@ -1243,6 +1298,10 @@ Default value is `nil`.
|
|
1243
1298
|
|
1244
1299
|
See [Elasticsearch Input plugin document](README.ElasticsearchInput.md)
|
1245
1300
|
|
1301
|
+
## Configuration - Elasticsearch Filter GenID
|
1302
|
+
|
1303
|
+
See [Elasticsearch Filter GenID document](README.ElasticsearchGenID.md)
|
1304
|
+
|
1246
1305
|
## Elasticsearch permissions
|
1247
1306
|
|
1248
1307
|
If the target Elasticsearch requires authentication, a user holding the necessary permissions needs to be provided.
|
@@ -1698,7 +1757,7 @@ ILM target index alias is created with `index_name` or an index which is calcula
|
|
1698
1757
|
|
1699
1758
|
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).
|
1700
1759
|
|
1701
|
-
|
1760
|
+
**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.
|
1702
1761
|
|
1703
1762
|
And also, ILM feature users should specify their Elasticsearch template for ILM enabled indices.
|
1704
1763
|
Because ILM settings are injected into their Elasticsearch templates.
|
@@ -1711,7 +1770,13 @@ It usually should be used with default value which is `default`.
|
|
1711
1770
|
|
1712
1771
|
Then, ILM parameters are used in alias index like as:
|
1713
1772
|
|
1714
|
-
|
1773
|
+
##### Simple `index_name` case:
|
1774
|
+
|
1775
|
+
`<index_name><index_separator><application_name>-000001`.
|
1776
|
+
|
1777
|
+
##### `logstash_format` as `true` case:
|
1778
|
+
|
1779
|
+
`<logstash_prefix><logstash_prefix_separator><application_name><logstash_prefix_separator><logstash_dateformat>-000001`.
|
1715
1780
|
|
1716
1781
|
#### Example ILM settings
|
1717
1782
|
|
@@ -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.1.2'
|
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}
|
@@ -65,11 +65,12 @@ module Fluent::ElasticsearchIndexTemplate
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def template_install(name, template_file, overwrite, enable_ilm = false, deflector_alias_name = nil, ilm_policy_id = nil, host = nil)
|
68
|
+
def template_install(name, template_file, overwrite, enable_ilm = false, deflector_alias_name = nil, ilm_policy_id = nil, host = nil, target_index = nil)
|
69
69
|
inject_template_name = get_template_name(enable_ilm, name, deflector_alias_name)
|
70
70
|
if overwrite
|
71
71
|
template_put(inject_template_name,
|
72
72
|
enable_ilm ? inject_ilm_settings_to_template(deflector_alias_name,
|
73
|
+
target_index,
|
73
74
|
ilm_policy_id,
|
74
75
|
get_template(template_file)) :
|
75
76
|
get_template(template_file), host)
|
@@ -80,6 +81,7 @@ module Fluent::ElasticsearchIndexTemplate
|
|
80
81
|
if !template_exists?(inject_template_name, host)
|
81
82
|
template_put(inject_template_name,
|
82
83
|
enable_ilm ? inject_ilm_settings_to_template(deflector_alias_name,
|
84
|
+
target_index,
|
83
85
|
ilm_policy_id,
|
84
86
|
get_template(template_file)) :
|
85
87
|
get_template(template_file), host)
|
@@ -89,10 +91,12 @@ module Fluent::ElasticsearchIndexTemplate
|
|
89
91
|
end
|
90
92
|
end
|
91
93
|
|
92
|
-
def template_custom_install(template_name, template_file, overwrite, customize_template, enable_ilm, deflector_alias_name, ilm_policy_id, host)
|
94
|
+
def template_custom_install(template_name, template_file, overwrite, customize_template, enable_ilm, deflector_alias_name, ilm_policy_id, host, target_index)
|
93
95
|
template_custom_name = get_template_name(enable_ilm, template_name, deflector_alias_name)
|
94
96
|
custom_template = if enable_ilm
|
95
|
-
inject_ilm_settings_to_template(deflector_alias_name,
|
97
|
+
inject_ilm_settings_to_template(deflector_alias_name,
|
98
|
+
target_index,
|
99
|
+
ilm_policy_id,
|
96
100
|
get_custom_template(template_file,
|
97
101
|
customize_template))
|
98
102
|
else
|
@@ -115,26 +119,30 @@ module Fluent::ElasticsearchIndexTemplate
|
|
115
119
|
enable_ilm ? deflector_alias_name : template_name
|
116
120
|
end
|
117
121
|
|
118
|
-
def inject_ilm_settings_to_template(
|
122
|
+
def inject_ilm_settings_to_template(deflector_alias, target_index, ilm_policy_id, template)
|
119
123
|
log.debug("Overwriting index patterns when Index Lifecycle Management is enabled.")
|
120
124
|
template.delete('template') if template.include?('template')
|
121
|
-
template['index_patterns'] = "#{
|
122
|
-
template['order'] = template['order'] ? template['order'] +
|
125
|
+
template['index_patterns'] = "#{target_index}-*"
|
126
|
+
template['order'] = template['order'] ? template['order'] + target_index.split('-').length : 50 + target_index.split('-').length
|
123
127
|
if template['settings'] && (template['settings']['index.lifecycle.name'] || template['settings']['index.lifecycle.rollover_alias'])
|
124
128
|
log.debug("Overwriting index lifecycle name and rollover alias when Index Lifecycle Management is enabled.")
|
125
129
|
end
|
126
|
-
template['settings'].update({ 'index.lifecycle.name' => ilm_policy_id, 'index.lifecycle.rollover_alias' =>
|
130
|
+
template['settings'].update({ 'index.lifecycle.name' => ilm_policy_id, 'index.lifecycle.rollover_alias' => deflector_alias})
|
127
131
|
template
|
128
132
|
end
|
129
133
|
|
130
|
-
def create_rollover_alias(
|
134
|
+
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
135
|
# ILM request to create alias.
|
132
136
|
if rollover_index || enable_ilm
|
133
137
|
if !client.indices.exists_alias(:name => deflector_alias_name)
|
134
|
-
if
|
135
|
-
index_name_temp='<'+
|
138
|
+
if @logstash_format
|
139
|
+
index_name_temp = '<'+target_index+'-000001>'
|
136
140
|
else
|
137
|
-
|
141
|
+
if index_date_pattern.empty?
|
142
|
+
index_name_temp = '<'+target_index.downcase+index_separator+app_name.downcase+'-000001>'
|
143
|
+
else
|
144
|
+
index_name_temp = '<'+target_index.downcase+index_separator+app_name.downcase+'-{'+index_date_pattern+'}-000001>'
|
145
|
+
end
|
138
146
|
end
|
139
147
|
indexcreation(index_name_temp, host)
|
140
148
|
body = rollover_alias_payload(deflector_alias_name)
|
@@ -7,6 +7,13 @@ module Fluent::Plugin
|
|
7
7
|
Fluent::Plugin.register_filter('elasticsearch_genid', self)
|
8
8
|
|
9
9
|
config_param :hash_id_key, :string, :default => '_hash'
|
10
|
+
config_param :include_tag_in_seed, :bool, :default => false
|
11
|
+
config_param :include_time_in_seed, :bool, :default => false
|
12
|
+
config_param :use_record_as_seed, :bool, :default => false
|
13
|
+
config_param :use_entire_record, :bool, :default => false
|
14
|
+
config_param :record_keys, :array, :default => []
|
15
|
+
config_param :separator, :string, :default => '_'
|
16
|
+
config_param :hash_type, :enum, list: [:md5, :sha1, :sha256, :sha512], :default => :sha1
|
10
17
|
|
11
18
|
def initialize
|
12
19
|
super
|
@@ -14,12 +21,57 @@ module Fluent::Plugin
|
|
14
21
|
|
15
22
|
def configure(conf)
|
16
23
|
super
|
24
|
+
|
25
|
+
if !@use_entire_record
|
26
|
+
if @record_keys.empty? && @use_record_as_seed
|
27
|
+
raise Fluent::ConfigError, "When using record as hash seed, users must specify `record_keys`."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if @use_record_as_seed
|
32
|
+
class << self
|
33
|
+
alias_method :filter, :filter_seed_as_record
|
34
|
+
end
|
35
|
+
else
|
36
|
+
class << self
|
37
|
+
alias_method :filter, :filter_simple
|
38
|
+
end
|
39
|
+
end
|
17
40
|
end
|
18
41
|
|
19
42
|
def filter(tag, time, record)
|
43
|
+
# for safety.
|
44
|
+
end
|
45
|
+
|
46
|
+
def filter_simple(tag, time, record)
|
20
47
|
record[@hash_id_key] = Base64.strict_encode64(SecureRandom.uuid)
|
21
48
|
record
|
22
49
|
end
|
23
50
|
|
51
|
+
def filter_seed_as_record(tag, time, record)
|
52
|
+
seed = ""
|
53
|
+
seed += tag + separator if @include_tag_in_seed
|
54
|
+
seed += time.to_s + separator if @include_time_in_seed
|
55
|
+
if @use_entire_record
|
56
|
+
record.each {|k,v| seed += "|#{k}|#{v}"}
|
57
|
+
else
|
58
|
+
seed += record_keys.map {|k| record[k]}.join(separator)
|
59
|
+
end
|
60
|
+
record[@hash_id_key] = Base64.strict_encode64(encode_hash(@hash_type, seed))
|
61
|
+
record
|
62
|
+
end
|
63
|
+
|
64
|
+
def encode_hash(type, seed)
|
65
|
+
case type
|
66
|
+
when :md5
|
67
|
+
Digest::MD5.digest(seed)
|
68
|
+
when :sha1
|
69
|
+
Digest::SHA1.digest(seed)
|
70
|
+
when :sha256
|
71
|
+
Digest::SHA256.digest(seed)
|
72
|
+
when :sha512
|
73
|
+
Digest::SHA512.digest(seed)
|
74
|
+
end
|
75
|
+
end
|
24
76
|
end
|
25
77
|
end
|