fluent-plugin-record_indexing 0.2.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 033425b882af2c7a8cfc88fcf822fe582214eeab990b07fd1dbe31c12df8f5ac
4
- data.tar.gz: 2368227e5bf02a0c86c9b21a5f6ed4b6f8f9ebec9b2722b9fc03903263c4cce7
3
+ metadata.gz: cda0290a81edfabb93f0dc7739dc1889c2e7f599b3ee674c0baaffebfb7d2a7d
4
+ data.tar.gz: 0b9a9a50bc274c4e1c2aef91482bbbb7c7ea3e0c047dc5fe192735cc03623765
5
5
  SHA512:
6
- metadata.gz: 0e046669d2eb9fbfbd0c69e1354a3cb93331e1cb4a267aa5769b26ae5a28c3d2988db9bc49a860a9ea5f00fe24c571a3d02052c0fc13b9c2245b7fb99ac01c1b
7
- data.tar.gz: 17a7d7c7d9ede5aa87db54a83fbed0116d5a1eced3a2cada1be24fadf643ff64841ccc10de5550260641180960060c00a211e69053b55d7b189e936bb80fc9f9
6
+ metadata.gz: 196d17bfa5b24665b6e1a4d2bda1d0b100032dc30fa6da1e91ed9567444ec8d99a4224daf1df4135e1a5e97dc90d1b2d7494df96639bc82372f44f7eb6fdbc75
7
+ data.tar.gz: 5831f0607dfb888932a4d7476a7e8bb1fd247a2c3e82a1e0a34b0a0cae77276715b579579d3723cb42d2f0f6bad5d5602cd296ba66e585ad4e4056374c341fd8
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # fluent-plugin-record_indexing
2
2
 
3
- [Fluentd](https://fluentd.org/) Filter plugin to spin entry with an array field into multiple entries.
3
+ [Fluentd](https://www.fluentd.org) Filter plugin to spin entry with an array field into multiple entries.
4
4
 
5
5
  ## Examples
6
6
  ```
7
7
  <filter test**>
8
8
  @type record_indexing
9
9
  check_all_key false
10
- key_name baz
10
+ key_names baz
11
11
  key_prefix baz_0
12
12
  </filter>
13
13
 
@@ -20,7 +20,7 @@ Out:
20
20
  <filter test**>
21
21
  @type record_indexing
22
22
  check_all_key false
23
- key_name baz
23
+ key_names baz
24
24
  </filter>
25
25
 
26
26
  In:
@@ -39,13 +39,36 @@ In:
39
39
  Out:
40
40
  {"foo"=>"bar", "baz"=>{"0"=>{"a"=>1} , "1"=>{"a"=>2}, "2"=>{"b"=>3}}, "daz"=>{"0"=>{"a"=>1} , "1"=>{"a"=>2}, "2"=>{"b"=>3}}}
41
41
  ```
42
+ ```
43
+ <filter test**>
44
+ @type record_indexing
45
+ check_all_key false
46
+ key_names baz,daz
47
+ </filter>
48
+
49
+ In:
50
+ {"foo" => "bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}] , "daz" => [{"a"=>1}, {"a"=>2}, {"b"=>3}]}
51
+ Out:
52
+ {"foo"=>"bar", "baz"=>{"0"=>{"a"=>1} , "1"=>{"a"=>2}, "2"=>{"b"=>3}}, "daz"=>{"0"=>{"a"=>1} , "1"=>{"a"=>2}, "2"=>{"b"=>3}}}
53
+ ```
54
+ ```
55
+ <filter test**>
56
+ @type record_indexing
57
+ exclude_keys baz
58
+ </filter>
59
+
60
+ In:
61
+ {"foo" => "bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}] , "daz" => [{"a"=>1}, {"a"=>2}, {"b"=>3}]}
62
+ Out:
63
+ {"foo"=>"bar", "baz"=>[{"a"=>1}, {"a"=>2}, {"b"=>3}], "2"=>{"b"=>3}}, "daz"=>{"0"=>{"a"=>1} , "1"=>{"a"=>2}, "2"=>{"b"=>3}}}
64
+ ```
42
65
 
43
66
  ## Installation
44
67
 
45
68
  ### RubyGems
46
69
 
47
70
  ```
48
- $ gem install fluent-plugin-array-spin
71
+ $ gem install fluent-plugin-record_indexing
49
72
  ```
50
73
 
51
74
  ### Bundler
@@ -64,8 +87,9 @@ $ bundle
64
87
 
65
88
  ## Configuration
66
89
 
67
- * **key_name** (string)
68
- * **key_prefix** (string)
90
+ * **key_names** (array) default: []
91
+ * **key_prefix** (string) default: nil
92
+ * **exclude_keys** (array) default: [] Use this parameter if you need to keep the value as is without indexing
69
93
  * **check_all_key** (bool) default: true
70
94
 
71
95
 
@@ -73,4 +97,4 @@ $ bundle
73
97
 
74
98
  * Copyright(c) 2017, Tema Novikov
75
99
  * License
76
- * Apache License, Version 2.0
100
+ * Apache License, Version 2.0
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "fluent-plugin-record_indexing"
4
- spec.version = "0.2.0"
4
+ spec.version = "0.2.2"
5
5
  spec.authors = ["imcotop"]
6
6
  spec.email = ["imcotop@icloud.com"]
7
7
 
@@ -3,16 +3,17 @@ require "fluent/filter"
3
3
  module Fluent
4
4
  class RecordIndexingFilter < Filter
5
5
  Fluent::Plugin.register_filter("record_indexing", self)
6
-
7
- desc "Key name to spin"
8
- config_param :key_name, :string, default: nil
6
+
7
+ desc "Key names to spin"
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
-
11
+ config_param :exclude_keys, :array, default: []
12
+
12
13
  def filter(tag, time, record)
13
14
  if check_all_key == false
14
- unless key_name
15
- raise ArgumentError, "key_name parameter is required if check_all_key set false"
15
+ unless key_names.any?
16
+ raise ArgumentError, "key_names parameter is required if check_all_key set false"
16
17
  end
17
18
  end
18
19
  new_record = {}
@@ -21,30 +22,34 @@ module Fluent
21
22
  new_record
22
23
  end
23
24
 
24
- def is_nested_field?(field_value)
25
- field_value.is_a?(Hash)
26
- end
27
-
28
25
  def each_with_index(record, new_record)
29
26
  record.each do |key, value|
30
- if check_all_key || key == key_name
31
- if value.nil?
32
- next # Skip if the value is nil
27
+ if check_all_key || key_names.include?(key)
28
+ if exclude_keys.include?(key)
29
+ new_record[key] = value # Keep the value as is without indexing
33
30
  elsif value.is_a?(Array)
34
- new_record[key] = {}
35
- value.each_with_index do |item, index|
36
- new_record[key]["#{key_prefix}#{index}"] = item unless item.nil?
31
+ if value.length == 1
32
+ new_record[key] = value.first
33
+ else
34
+ new_record[key] = {}
35
+ value.each_with_index do |item, index|
36
+ new_record[key]["#{key_prefix}#{index}"] = item
37
+ end
37
38
  end
38
- elsif is_nested_field?(value)
39
+ elsif value.is_a?(Hash)
39
40
  new_record[key] = {}
40
41
  each_with_index(value, new_record[key])
41
42
  else
42
43
  new_record[key] = value
43
44
  end
45
+ elsif value.is_a?(Hash) # Check if the value is a nested Hash
46
+ new_record[key] = {}
47
+ each_with_index(value, new_record[key]) # Recursively index nested fields
44
48
  else
45
49
  new_record[key] = value
46
50
  end
47
51
  end
52
+ new_record
48
53
  end
49
54
 
50
55
  def remove_empty_fields(record)
@@ -57,3 +62,4 @@ module Fluent
57
62
  end
58
63
  end
59
64
  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.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - imcotop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-08 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.2.5
96
+ rubygems_version: 3.0.3.1
97
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