fluent-plugin-mutate_filter 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ module Fluent
2
+ module Plugin
3
+ module Mixin
4
+ class MutateEvent < SimpleDelegator
5
+ def initialize(record, expand_nesting: true)
6
+ super(record)
7
+ @record = record
8
+ @event_time = nil
9
+ @event_tag = nil
10
+ @expand_nesting = expand_nesting
11
+ end
12
+
13
+ attr_accessor :event_time
14
+ attr_accessor :event_tag
15
+
16
+ def to_record
17
+ @record
18
+ end
19
+
20
+ def dig(*keys)
21
+ item = @record
22
+
23
+ keys.each do |key|
24
+ break if item.nil?
25
+ item = item.is_a?(Hash) ? item[key] : nil
26
+ end
27
+
28
+ item
29
+ end
30
+
31
+ def prune
32
+ delete_proc = proc do |_,v|
33
+ v.delete_if(&delete_proc) if v.respond_to?(:delete_if)
34
+ v.nil? || v.respond_to?(:empty?) && v.empty?
35
+ end
36
+
37
+ @record.delete_if(&delete_proc)
38
+ end
39
+
40
+ def get(key_or_path, &block)
41
+ item = dig(*expand_key(key_or_path))
42
+ block_given? ? yield(item) : item
43
+ end
44
+
45
+ def parent(key_or_path, &block)
46
+ path = expand_key(key_or_path)
47
+ child = path.pop
48
+
49
+ item = dig(*path)
50
+ block_given? ? yield(item, child) : item
51
+ end
52
+
53
+ def set(key_or_path, value)
54
+ path = expand_key(key_or_path)
55
+ child = path.pop
56
+
57
+ item = @record
58
+ path.each do |key|
59
+ item = item[key] ||= {}
60
+ end
61
+ item[child] = value
62
+ end
63
+
64
+ def remove(key_or_path)
65
+ parent(key_or_path) do |item, child|
66
+ item.delete(child) unless item.nil?
67
+ end
68
+ end
69
+
70
+ def include?(key_or_path)
71
+ !get(key_or_path).nil?
72
+ end
73
+
74
+ protected
75
+
76
+ def expand_key(key_or_path)
77
+ @expand_nesting ? key_or_path.split(".") : [key_or_path]
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
+ require "test-unit"
3
+ require "fluent/test"
4
+ require "fluent/test/driver/filter"
5
+ require "fluent/test/helpers"
6
+
7
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
8
+ Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -0,0 +1,18 @@
1
+ require "helper"
2
+ require "fluent/plugin/filter_mutate.rb"
3
+
4
+ class MutateFilterTest < Test::Unit::TestCase
5
+ setup do
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ test "failure" do
10
+ flunk
11
+ end
12
+
13
+ private
14
+
15
+ def create_driver(conf)
16
+ Fluent::Test::Driver::Filter.new(Fluent::Plugin::MutateFilter).configure(conf)
17
+ end
18
+ end
metadata CHANGED
@@ -1,58 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mutate_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Serafini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2018-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: fluentd
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.12.0
20
- type: :runtime
19
+ version: '1.14'
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.12.0
26
+ version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.11'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.11'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
55
- description: ''
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fluentd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.10
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '2'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 0.14.10
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '2'
75
+ description: A mutate filter for Fluent which functions like Logstash.
56
76
  email:
57
77
  - jonathan@serafini.ca
58
78
  executables: []
@@ -60,17 +80,20 @@ extensions: []
60
80
  extra_rdoc_files: []
61
81
  files:
62
82
  - ".gitignore"
63
- - CHANGELOG.md
83
+ - ".rbenv-gemsets"
84
+ - ".ruby-version"
64
85
  - Gemfile
86
+ - LICENSE
65
87
  - README.md
66
88
  - Rakefile
67
- - bin/console
68
- - bin/setup
69
89
  - fluent-plugin-mutate_filter.gemspec
70
90
  - lib/fluent/plugin/filter_mutate.rb
71
- - lib/fluent/plugin_mixin/mutate_event.rb
91
+ - lib/fluent/plugin/mixin/mutate_event.rb
92
+ - test/helper.rb
93
+ - test/plugin/test_filter_mutate.rb
72
94
  homepage: https://github.com/JonathanSerafini/fluent-plugin-mutate_filter
73
- licenses: []
95
+ licenses:
96
+ - Apache-2.0
74
97
  metadata: {}
75
98
  post_install_message:
76
99
  rdoc_options: []
@@ -88,8 +111,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
111
  version: '0'
89
112
  requirements: []
90
113
  rubyforge_project:
91
- rubygems_version: 2.5.2
114
+ rubygems_version: 2.7.3
92
115
  signing_key:
93
116
  specification_version: 4
94
117
  summary: A mutate filter for Fluent which functions like Logstash.
95
- test_files: []
118
+ test_files:
119
+ - test/helper.rb
120
+ - test/plugin/test_filter_mutate.rb
data/CHANGELOG.md DELETED
@@ -1,29 +0,0 @@
1
- # Changelog
2
-
3
- v0.3.0
4
- -------------
5
- * Resolve bug in error handling
6
- * Add support for %e{} tags to replace with environment variables
7
- * Add support for %e{hostname} tag to replace with hostname
8
-
9
- v0.2.1
10
- -------------
11
- * Resolve bug in datetime converter
12
-
13
- v0.2.0
14
- -------------
15
- * Fix MutateEvent initializer bug
16
- * Add support for event_tag and event_time substitutions %{event_time}
17
- * Add a datetime conversion
18
-
19
- v0.1.2
20
- -------------
21
- * Resolve bug in gsub attributes
22
-
23
- v0.1.1
24
- -------------
25
- * Update gemspec urls
26
-
27
- v0.1.0
28
- -------------
29
- * Initial release
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "fluent/plugin/mutate_filter"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,83 +0,0 @@
1
- module Fluent
2
- module PluginMixin
3
- class MutateEvent < SimpleDelegator
4
- def initialize(record, expand_nesting: true)
5
- super(record)
6
- @record = record
7
- @event_time = nil
8
- @event_tag = nil
9
- @expand_nesting = expand_nesting
10
- end
11
-
12
- attr_accessor :event_time
13
- attr_accessor :event_tag
14
-
15
- def to_record
16
- @record
17
- end
18
-
19
- def dig(*keys)
20
- item = @record
21
-
22
- keys.each do |key|
23
- break if item.nil?
24
- item = item.is_a?(Hash) ? item[key] : nil
25
- end
26
-
27
- item
28
- end
29
-
30
- def prune
31
- delete_proc = proc do |_,v|
32
- v.delete_if(&delete_proc) if v.respond_to?(:delete_if)
33
- v.nil? || v.respond_to?(:empty?) && v.empty?
34
- end
35
-
36
- @record.delete_if(&delete_proc)
37
- end
38
-
39
- def get(key_or_path, &block)
40
- item = dig(*expand_key(key_or_path))
41
- block_given? ? yield(item) : item
42
- end
43
-
44
- def parent(key_or_path, &block)
45
- path = expand_key(key_or_path)
46
- child = path.pop
47
-
48
- item = dig(*path)
49
- block_given? ? yield(item, child) : item
50
- end
51
-
52
- def set(key_or_path, value)
53
- path = expand_key(key_or_path)
54
- child = path.pop
55
-
56
- item = @record
57
- path.each do |key|
58
- item = item[key] ||= {}
59
- end
60
- item[child] = value
61
- end
62
-
63
- def remove(key_or_path)
64
- path = expand_key(key_or_path)
65
- child = path.pop
66
-
67
- parent(key_or_path) do |item, child|
68
- item.delete(child) unless item.nil?
69
- end
70
- end
71
-
72
- def include?(key_or_path)
73
- !get(key_or_path).nil?
74
- end
75
-
76
- protected
77
-
78
- def expand_key(key_or_path)
79
- @expand_nesting ? key_or_path.split(".") : [key_or_path]
80
- end
81
- end
82
- end
83
- end