fluent-plugin-array-splitter 0.1.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bf5d03998979b55a12ce89992692bbda3b010bfbccb2b1cf9dbd670a3c63cec
4
- data.tar.gz: 311c9c506b8e7e3b1a48fa77df5e500ac630b7df3797066756beafe985e4468b
3
+ metadata.gz: 8cea5ad4ac184f61f7d06d8622302aa980515a9b446f1e0113981dcdb886c149
4
+ data.tar.gz: 2e677713dc26b1f3d3e37785c6dba12f2d15eff1f51aefe49731972c67f263b8
5
5
  SHA512:
6
- metadata.gz: 789c595e0ae1f9c8cc14d8668e25dba1984e72f1df6c8c51eb29ecb5299ee2fa3482936e78d9ba28427cf7f25c38dc45a336b26080960934af54b6e0f7ec93e2
7
- data.tar.gz: 00e5532d24f9eb2e2e0ecc7829356daca338f5a26f79deaaccae09ec1414aba3c74fabe65e7f83dfe2daffa8ab0d5645e3bfdae673bab0879106210c56c5a13b
6
+ metadata.gz: c738b1b8182e357ea6d2d18cdf4165136c2a993fd0208780852d12b657866e1b372079513ccaaed0836f7cc8041117a7d86de803611b5d9528f02f04fc9ef82c
7
+ data.tar.gz: 6a77e6070bf38b21e087d1b42fcb3dc5b6808545d06c28802f27bab4b14d3d37e9abdffb176bcc084fe86bbfa452c32bf5f94d3ae87c2765c5c3ca7a0a63f8cf
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # fluent-plugin-array-splitter
2
2
 
3
- [Fluentd](https://fluentd.org/) filter plugin to do something.
4
-
5
- TODO: write description for you plugin.
3
+ ## Overview
4
+ This [Fluentd](https://fluentd.org/) filter plugin allows you to split array values within json formatted log records.
6
5
 
7
6
  ## Installation
8
7
 
@@ -28,16 +27,48 @@ $ bundle
28
27
 
29
28
  ## Configuration
30
29
 
31
- You can generate configuration template:
30
+ ### Parameters
31
+
32
+ |parameter|type|description|default|
33
+ |---|---|---|---|
34
+ |array_key|string (required)|The target field name to split array values||
35
+ |key_name|string (optional)|The field name to rename the key of a single array element|nil|
36
+
37
+ ### Example Configuration
38
+
39
+ ```
40
+ <filter pattern>
41
+ @type array_splitter
42
+ array_key message
43
+ key_name new_key
44
+ </filter>
45
+ ```
46
+
47
+ ## Usage
32
48
 
49
+ With the above configuration, an input like:
33
50
  ```
34
- $ fluent-plugin-config-format filter array_splitter
51
+ {"message": ["value1", "value2"]}
35
52
  ```
36
53
 
37
- You can copy and paste generated documents here.
54
+ will result in two records:
55
+ ```
56
+ {"new_key": "value1"}
57
+ {"new_key": "value2"}
58
+ ```
59
+
60
+ If you have an input like:
61
+ ```
62
+ {"message": [{"key1": "value1"}, {"key2": "value2"}]}
63
+ ```
64
+ will result as follows:
65
+ ```
66
+ {"key1": "value1"}
67
+ {"key2": "value2"}
68
+ ```
38
69
 
39
70
  ## Copyright
40
71
 
41
72
  * Copyright(c) 2023- pcoffmanjr
42
73
  * License
43
- *
74
+ * MIT License
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-array-splitter"
6
- spec.version = "0.1.2"
6
+ spec.version = "0.1.3"
7
7
  spec.authors = ["pcoffmanjr"]
8
8
  spec.email = ["pcoffman@ctc-america.com"]
9
9
 
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 2.1.2"
24
24
  spec.add_development_dependency "rake", "~> 13.0.6"
25
25
  spec.add_development_dependency "test-unit", "~> 3.3.9"
26
- spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
26
+ spec.add_runtime_dependency "fluentd", [">= 1.11.1", "< 2"]
27
27
  end
@@ -1,3 +1,24 @@
1
+ # MIT License
2
+
3
+ # Copyright (c) 2023 pcoffmanjr
4
+
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
1
22
 
2
23
 
3
24
  require "fluent/plugin/filter"
@@ -10,6 +31,9 @@ module Fluent
10
31
  desc 'The field name to split and expand array values'
11
32
  config_param :array_key, :string, default: 'message'
12
33
 
34
+ desc 'The field name to rename the key of a single array element'
35
+ config_param :key_name, :string, default: nil
36
+
13
37
  def configure(conf)
14
38
  super
15
39
  raise Fluent::ConfigError, "'array_key' parameter is required" unless conf.has_key?('array_key')
@@ -18,27 +42,28 @@ module Fluent
18
42
 
19
43
  def filter_stream(tag, es)
20
44
  new_es = Fluent::MultiEventStream.new
45
+
21
46
  es.each do |time, record|
22
47
  if record[@array_key].is_a?(Array)
23
48
  record[@array_key].each do |value|
24
49
  new_record = record.dup
25
50
  new_record.delete(@array_key)
51
+
26
52
  if value.is_a?(Hash)
27
- value.each do |k, v|
28
- new_record[k] = v
29
- end
53
+ value.each { |k, v| new_record[k] = v }
30
54
  else
31
- new_record[@array_key] = value
55
+ new_record[@key_name.nil? ? @array_key : @key_name] = value
32
56
  end
57
+
33
58
  new_es.add(time, new_record)
34
59
  end
35
60
  else
36
61
  new_es.add(time, record)
37
62
  end
38
63
  end
64
+
39
65
  new_es
40
66
  end
41
67
  end
42
68
  end
43
69
  end
44
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-array-splitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - pcoffmanjr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-16 00:00:00.000000000 Z
11
+ date: 2023-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.14.10
61
+ version: 1.11.1
62
62
  - - "<"
63
63
  - !ruby/object:Gem::Version
64
64
  version: '2'
@@ -68,7 +68,7 @@ dependencies:
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: 0.14.10
71
+ version: 1.11.1
72
72
  - - "<"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2'