fluent-plugin-record-demux 0.3.0 → 0.4.0
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 +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +63 -6
- data/fluent-plugin-record-demux.gemspec +1 -1
- data/lib/fluent/plugin/filter_record_array_demux.rb +103 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3c3c56b3996c80096423cb21c058f778c52ef98f6235cd4ea0ba1ba47236e918
|
|
4
|
+
data.tar.gz: 04006b6d00d241abeea57d56041816405dc17a88284e4e8409eee57668842caa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 28ea048eb175624647b564df623109a0d380de38ff4a4c8125a6b6212ff2c7ad38b80c8922d7af133a009b2acdb807cc9184423723168ccf797fd0fededa27d8
|
|
7
|
+
data.tar.gz: f9ebf69ccb5fa1c9d8793db3c35fcc7f656039ca3debcf7dcce0d40ae2ba98b5c8df43f080f00cf2789ae55fdbee6704ea2c5a3bab2d1ad50ee217ee57262cde
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
# fluent-plugin-record-demux
|
|
2
2
|
|
|
3
|
-
[Fluentd](https://fluentd.org/) plugin to
|
|
3
|
+
[Fluentd](https://fluentd.org/) plugin to demux records.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
## Table of Contents
|
|
7
|
+
* [plugin - out - record_demux](#plugin---out---record_demux)
|
|
8
|
+
* [plugin - out - record_demux_picker](#plugin---out---record_demux_picker)
|
|
9
|
+
* [plugin - filter - record_array demux](#plugin---filter---record_array_demux)
|
|
10
|
+
* [Installation](#installation)
|
|
11
|
+
* [Contribution](#contribution)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## plugin - out - record_demux
|
|
6
15
|
|
|
7
16
|
### config
|
|
8
17
|
|
|
@@ -76,11 +85,12 @@ into events:
|
|
|
76
85
|
{ "c": "data_c", "tags_1": "data_1", "tags_2": "data_2" }
|
|
77
86
|
```
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
|
|
89
|
+
## plugin - out - record_demux_picker
|
|
80
90
|
|
|
81
91
|
Demux record/event, by selecting nested fields for shared and demux parts.
|
|
82
92
|
|
|
83
|
-
It transforms 1 record/event to multiple
|
|
93
|
+
It transforms 1 record/event to multiple records/events.
|
|
84
94
|
|
|
85
95
|
### params
|
|
86
96
|
|
|
@@ -97,7 +107,7 @@ It transforms 1 record/event to multiple record/event.
|
|
|
97
107
|
|
|
98
108
|
### example 1
|
|
99
109
|
|
|
100
|
-
|
|
110
|
+
Given this event :
|
|
101
111
|
|
|
102
112
|
``` text
|
|
103
113
|
{
|
|
@@ -136,6 +146,49 @@ It will produce :
|
|
|
136
146
|
|
|
137
147
|
```
|
|
138
148
|
|
|
149
|
+
|
|
150
|
+
## plugin - filter - record_array_demux
|
|
151
|
+
|
|
152
|
+
Demux record/event, by specified fields when they are arrays.
|
|
153
|
+
|
|
154
|
+
It transforms 1 record/event to multiple records/events, one for each element of the arrays.
|
|
155
|
+
|
|
156
|
+
| setting | type | default | description |
|
|
157
|
+
|-------------|-----------------|---------|-----------------------------------------|
|
|
158
|
+
| demux_keys | array of string | *nil* | arrays keys to demux, computed when nil |
|
|
159
|
+
| shared_keys | array of string | [] | keys to be shared in new record |
|
|
160
|
+
| remove_keys | array of string | [] | keys to remove |
|
|
161
|
+
|
|
162
|
+
### example 1
|
|
163
|
+
|
|
164
|
+
Given this event :
|
|
165
|
+
|
|
166
|
+
``` text
|
|
167
|
+
{
|
|
168
|
+
"source": ["source1", "source2", "source3"],
|
|
169
|
+
"status": "active",
|
|
170
|
+
"timestamp": "2026-01-02T03:04:05.678Z"
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
With this conf :
|
|
175
|
+
|
|
176
|
+
``` text
|
|
177
|
+
<filter data>
|
|
178
|
+
@type record_array_demux
|
|
179
|
+
demux_keys source
|
|
180
|
+
</filter>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
It will produce :
|
|
184
|
+
|
|
185
|
+
``` text
|
|
186
|
+
{"source":"source1","status":"active","timestamp": "2026-01-02T03:04:05.678Z"}
|
|
187
|
+
{"source":"source2","status":"active","timestamp": "2026-01-02T03:04:05.678Z"}
|
|
188
|
+
{"source":"source3","status":"active","timestamp": "2026-01-02T03:04:05.678Z"}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
|
|
139
192
|
## Installation
|
|
140
193
|
|
|
141
194
|
Manual install, by executing:
|
|
@@ -146,9 +199,13 @@ Add to Gemfile with:
|
|
|
146
199
|
|
|
147
200
|
$ bundle add fluent-plugin-record-demux
|
|
148
201
|
|
|
202
|
+
## Contribution
|
|
203
|
+
|
|
204
|
+
PR WELCOME !
|
|
205
|
+
|
|
149
206
|
|
|
150
207
|
## Copyright
|
|
151
208
|
|
|
152
|
-
* Copyright(c) 2024-
|
|
209
|
+
* Copyright(c) 2024-2026 Thomas Tych
|
|
153
210
|
* License
|
|
154
211
|
* Apache License, Version 2.0
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2026- Thomas Tych
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
require 'fluent/plugin/filter'
|
|
19
|
+
|
|
20
|
+
module Fluent
|
|
21
|
+
module Plugin
|
|
22
|
+
class RecordArrayDemuxFilter < Fluent::Plugin::Filter
|
|
23
|
+
NAME = 'record_array_demux'
|
|
24
|
+
Fluent::Plugin.register_filter(NAME, self)
|
|
25
|
+
|
|
26
|
+
helpers :event_emitter, :timer
|
|
27
|
+
|
|
28
|
+
desc 'list of arrays keys to demux'
|
|
29
|
+
config_param :demux_keys, :array, value_type: :string, default: nil
|
|
30
|
+
desc 'list of keys to be shared in all new records'
|
|
31
|
+
config_param :shared_keys, :array, value_type: :string, default: nil
|
|
32
|
+
desc 'list of keys to be removed'
|
|
33
|
+
config_param :remove_keys, :array, value_type: :string, default: []
|
|
34
|
+
|
|
35
|
+
def configure(conf)
|
|
36
|
+
super
|
|
37
|
+
|
|
38
|
+
if demux_keys.nil? && shared_keys.nil?
|
|
39
|
+
raise Fluent::ConfigError, 'specify demux_keys or shared_keys'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def multi_workers_ready?
|
|
46
|
+
true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def filter_stream(_tag, es)
|
|
50
|
+
new_es = Fluent::MultiEventStream.new
|
|
51
|
+
es.each do |time, record|
|
|
52
|
+
new_records = process_record(time, record)
|
|
53
|
+
new_records.each { |new_record| new_es.add(time, new_record) }
|
|
54
|
+
end
|
|
55
|
+
new_es
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def dispatch_record_keys(record)
|
|
59
|
+
record_keys = record.keys - remove_keys
|
|
60
|
+
|
|
61
|
+
record_shared_keys = if shared_keys.nil?
|
|
62
|
+
record_keys - demux_keys
|
|
63
|
+
else
|
|
64
|
+
record_keys.intersection(shared_keys)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
record_demux_keys = if demux_keys.nil?
|
|
68
|
+
record_keys - record_shared_keys
|
|
69
|
+
else
|
|
70
|
+
record_keys.intersection(demux_keys)
|
|
71
|
+
end
|
|
72
|
+
real_record_demux_keys, non_record_demux_keys = record_demux_keys.partition do |key|
|
|
73
|
+
record[key].is_a?(Array)
|
|
74
|
+
end
|
|
75
|
+
record_shared_keys += non_record_demux_keys
|
|
76
|
+
|
|
77
|
+
[real_record_demux_keys, record_shared_keys]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def process_record(_time, record)
|
|
81
|
+
record_demux_keys, record_shared_keys = dispatch_record_keys(record)
|
|
82
|
+
|
|
83
|
+
return [record] if record_demux_keys.empty?
|
|
84
|
+
|
|
85
|
+
record_shared = record.slice(*record_shared_keys)
|
|
86
|
+
|
|
87
|
+
demux_arrays = record_demux_keys.map do |key|
|
|
88
|
+
array_demux_value = record[key]
|
|
89
|
+
array_demux_value.size.positive? ? array_demux_value : [nil]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
demux_combinations = demux_arrays.first.product(*demux_arrays[1..])
|
|
93
|
+
demux_combinations.map do |combination|
|
|
94
|
+
new_record = record_shared.dup
|
|
95
|
+
record_demux_keys.each_with_index do |key, index|
|
|
96
|
+
new_record[key] = combination[index]
|
|
97
|
+
end
|
|
98
|
+
new_record
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-plugin-record-demux
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Tych
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: bump
|
|
@@ -238,6 +238,7 @@ files:
|
|
|
238
238
|
- README.md
|
|
239
239
|
- Rakefile
|
|
240
240
|
- fluent-plugin-record-demux.gemspec
|
|
241
|
+
- lib/fluent/plugin/filter_record_array_demux.rb
|
|
241
242
|
- lib/fluent/plugin/out_record_demux.rb
|
|
242
243
|
- lib/fluent/plugin/out_record_demux_picker.rb
|
|
243
244
|
homepage: https://gitlab.com/ttych/fluent-plugin-record-demux
|
|
@@ -259,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
259
260
|
- !ruby/object:Gem::Version
|
|
260
261
|
version: '0'
|
|
261
262
|
requirements: []
|
|
262
|
-
rubygems_version:
|
|
263
|
+
rubygems_version: 4.0.3
|
|
263
264
|
specification_version: 4
|
|
264
265
|
summary: fluentd plugin to demux record by keys.
|
|
265
266
|
test_files: []
|