fluent-plugin-record_indexing 0.2.2 → 0.2.3
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/README.md +28 -1
- data/fluent-plugin-record_indexing.gemspec +1 -1
- data/lib/fluent/plugin/filter_record_indexing.rb +18 -9
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b42b59a9bee0a768347ad76f149c631d930bc0fe56b3d8c9761de45a27a7958d
|
4
|
+
data.tar.gz: 57a58f3625de7c3c31a3d5e36426e8ab575f796da9d4fb8d7ed6a18f983b4c53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f627a68a573dc16849ce53506d8a4119571d81d3f433aaf7571beb2bd9a31c688d9af2a9ee78b010d2d67b0c37434bbdcf57ffe9bd54bd1305b13e79c119900
|
7
|
+
data.tar.gz: a9f3621addcd73beb52028ec73ccaab98a74bfffdce4197d11bf86bdba9bd74741783af8d214b0b92b6e075c169216935b25498e06ecbd7e92351fb87a1a3e05
|
data/README.md
CHANGED
@@ -60,7 +60,34 @@ Out:
|
|
60
60
|
In:
|
61
61
|
{"foo" => "bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}] , "daz" => [{"a"=>1}, {"a"=>2}, {"b"=>3}]}
|
62
62
|
Out:
|
63
|
-
{"foo"=>"bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}], "2"=>{"b"=>3}
|
63
|
+
{"foo"=>"bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}], "2"=>{"b"=>3}], "daz"=>{"0"=>{"a"=>1} , "1"=>{"a"=>2}, "2"=>{"b"=>3}}}
|
64
|
+
```
|
65
|
+
|
66
|
+
```
|
67
|
+
<filter test**>
|
68
|
+
@type record_indexing
|
69
|
+
exclude_keys baz
|
70
|
+
</filter>
|
71
|
+
|
72
|
+
In:
|
73
|
+
{"foo" => "bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}] , "daz" => [{"name"=>1, "value"=>2}, {"a"=>2}, {"b"=>3}]}
|
74
|
+
Out:
|
75
|
+
{"foo"=>"bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}], "2"=>{"b"=>3}], "daz"=>{"a"=>2 , "1"=>{"a"=>2}, "2"=>{"b"=>3}}}
|
76
|
+
```
|
77
|
+
|
78
|
+
```
|
79
|
+
ignore_length by default set true
|
80
|
+
|
81
|
+
<filter test**>
|
82
|
+
@type record_indexing
|
83
|
+
ignore_length false
|
84
|
+
exclude_keys baz
|
85
|
+
</filter>
|
86
|
+
|
87
|
+
In:
|
88
|
+
{"foo" => "bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}] , "daz" => [{"name"=>1}]}
|
89
|
+
Out:
|
90
|
+
{"foo"=>"bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}], "2"=>{"b"=>3}], "daz"=>[{"a"=>2}]}
|
64
91
|
```
|
65
92
|
|
66
93
|
## Installation
|
@@ -8,13 +8,12 @@ module Fluent
|
|
8
8
|
config_param :key_names, :array, default: []
|
9
9
|
config_param :key_prefix, :string, default: nil
|
10
10
|
config_param :check_all_key, :bool, default: true
|
11
|
+
config_param :ignore_length, :bool, default: true
|
11
12
|
config_param :exclude_keys, :array, default: []
|
12
13
|
|
13
14
|
def filter(tag, time, record)
|
14
|
-
if check_all_key
|
15
|
-
|
16
|
-
raise ArgumentError, "key_names parameter is required if check_all_key set false"
|
17
|
-
end
|
15
|
+
if !@check_all_key && key_names.empty?
|
16
|
+
raise ArgumentError, "key_names parameter is required if check_all_key set false"
|
18
17
|
end
|
19
18
|
new_record = {}
|
20
19
|
each_with_index(record, new_record)
|
@@ -23,17 +22,28 @@ module Fluent
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def each_with_index(record, new_record)
|
25
|
+
seen_keys = {} # To keep track of duplicate names
|
26
26
|
record.each do |key, value|
|
27
|
-
if check_all_key || key_names.include?(key)
|
28
|
-
if exclude_keys.include?(key)
|
27
|
+
if @check_all_key || @key_names.include?(key)
|
28
|
+
if @exclude_keys.include?(key)
|
29
29
|
new_record[key] = value # Keep the value as is without indexing
|
30
30
|
elsif value.is_a?(Array)
|
31
|
-
if value.length == 1
|
31
|
+
if !@ignore_length && value.length == 1
|
32
32
|
new_record[key] = value.first
|
33
33
|
else
|
34
34
|
new_record[key] = {}
|
35
35
|
value.each_with_index do |item, index|
|
36
|
-
|
36
|
+
if item.is_a?(Hash) && item.key?("name") && item.key?("value")
|
37
|
+
item_name = item["name"]
|
38
|
+
if seen_keys[item_name]
|
39
|
+
new_record[key]["#{@key_prefix}#{index}"] = item
|
40
|
+
else
|
41
|
+
new_record[key][item_name] = item["value"]
|
42
|
+
seen_keys[item_name] = true
|
43
|
+
end
|
44
|
+
else
|
45
|
+
new_record[key]["#{@key_prefix}#{index}"] = item
|
46
|
+
end
|
37
47
|
end
|
38
48
|
end
|
39
49
|
elsif value.is_a?(Hash)
|
@@ -62,4 +72,3 @@ module Fluent
|
|
62
72
|
end
|
63
73
|
end
|
64
74
|
end
|
65
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-record_indexing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- imcotop
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,7 +78,7 @@ homepage: https://github.com/imcotop/fluent-plugin-record_indexing
|
|
78
78
|
licenses:
|
79
79
|
- apache2
|
80
80
|
metadata: {}
|
81
|
-
post_install_message:
|
81
|
+
post_install_message:
|
82
82
|
rdoc_options: []
|
83
83
|
require_paths:
|
84
84
|
- lib
|
@@ -93,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
97
|
-
signing_key:
|
96
|
+
rubygems_version: 3.5.7
|
97
|
+
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: A fluentd filter plugin that will be used to Iterate over the object with
|
100
100
|
its index and returns the value of the given object.
|