fluent-plugin-array-splitter 0.1.1 → 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: 0d04da9205757d519b782b4f8603c6cd5999a0ca1ed15d50044ab9600259d200
4
- data.tar.gz: c97d3587db8921bf2b25ca8b930b6e0e96dcc6e47f41ad2169a48775073217cc
3
+ metadata.gz: 8cea5ad4ac184f61f7d06d8622302aa980515a9b446f1e0113981dcdb886c149
4
+ data.tar.gz: 2e677713dc26b1f3d3e37785c6dba12f2d15eff1f51aefe49731972c67f263b8
5
5
  SHA512:
6
- metadata.gz: 720519d90f4c95983ec89fc616626cce0712be211673724d3f8db15e2bd0a4e562dd196344a13127f4c177c923ee5018c0ad98b19be27ee71f189868a43216c1
7
- data.tar.gz: 40d369cb984e7b01125328e98df4c01b0c5a7f6725fae82d55a26e7cd8ab37001474a14913f4cd27c34260cf71ab4a115df69ddc9c8a9298da4339e7dc8b41cf
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.1"
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"
@@ -7,34 +28,42 @@ module Fluent
7
28
  class ArraySplitterFilter < Fluent::Plugin::Filter
8
29
  Fluent::Plugin.register_filter("array_splitter", self)
9
30
 
31
+ desc 'The field name to split and expand array values'
32
+ config_param :array_key, :string, default: 'message'
33
+
34
+ desc 'The field name to rename the key of a single array element'
35
+ config_param :key_name, :string, default: nil
36
+
10
37
  def configure(conf)
11
38
  super
39
+ raise Fluent::ConfigError, "'array_key' parameter is required" unless conf.has_key?('array_key')
12
40
  log.info "Configuring Array Splitter Filter"
13
41
  end
14
42
 
15
43
  def filter_stream(tag, es)
16
44
  new_es = Fluent::MultiEventStream.new
45
+
17
46
  es.each do |time, record|
18
- if record['message'].is_a?(Array)
19
- record['message'].each do |value|
47
+ if record[@array_key].is_a?(Array)
48
+ record[@array_key].each do |value|
20
49
  new_record = record.dup
21
- new_record.delete('message')
50
+ new_record.delete(@array_key)
51
+
22
52
  if value.is_a?(Hash)
23
- value.each do |k, v|
24
- new_record[k] = v
25
- end
53
+ value.each { |k, v| new_record[k] = v }
26
54
  else
27
- new_record['message'] = value
55
+ new_record[@key_name.nil? ? @array_key : @key_name] = value
28
56
  end
57
+
29
58
  new_es.add(time, new_record)
30
59
  end
31
60
  else
32
61
  new_es.add(time, record)
33
62
  end
34
63
  end
64
+
35
65
  new_es
36
66
  end
37
67
  end
38
68
  end
39
69
  end
40
-
@@ -4,7 +4,9 @@ require "fluent/plugin/filter_array_splitter.rb"
4
4
  class ArraySplitterFilterTest < Test::Unit::TestCase
5
5
  setup do
6
6
  Fluent::Test.setup
7
- @driver = create_driver
7
+ @driver = create_driver(%[
8
+ array_key message
9
+ ])
8
10
  end
9
11
 
10
12
  def create_driver(conf = "")
@@ -28,7 +30,7 @@ class ArraySplitterFilterTest < Test::Unit::TestCase
28
30
  assert_equal("v2", filtered_records[1]["message"])
29
31
  assert_equal("v3", filtered_records[2]["message"])
30
32
  end
31
-
33
+
32
34
  test "expand array with hashes in message field" do
33
35
  record = {
34
36
  "key1" => "foo",
@@ -49,6 +51,25 @@ class ArraySplitterFilterTest < Test::Unit::TestCase
49
51
  assert_equal("foobar", filtered_records[1]["k2"])
50
52
  assert_nil(filtered_records[1]["message"])
51
53
  end
54
+
55
+ test "expand array with custom key" do
56
+ driver = create_driver(%[
57
+ array_key record
58
+ ])
59
+ record = {
60
+ "key1" => "foo",
61
+ "key2" => "bar",
62
+ "record" => ["v1", "v2", "v3"]
63
+ }
64
+ driver.run(default_tag: "test") do
65
+ driver.feed(record)
66
+ end
67
+ filtered_records = driver.filtered_records
68
+ assert_equal(3, filtered_records.size)
69
+ assert_equal("v1", filtered_records[0]["record"])
70
+ assert_equal("v2", filtered_records[1]["record"])
71
+ assert_equal("v3", filtered_records[2]["record"])
72
+ end
52
73
  end
53
74
  end
54
75
 
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.1
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'