fluent-plugin-record_splitter 0.2.0 → 0.2.1
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/VERSION +1 -1
- data/lib/fluent/plugin/out_record_splitter.rb +7 -11
- data/test/test_out_record_splitter.rb +63 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2230a45d9a9323b764283a1291fb8fb9325a2e8e
         | 
| 4 | 
            +
              data.tar.gz: e53abcfdf737b9a2c7b15760943ef17a6a8c8f51
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 21be9d7a7014d94b09b3fd92b9b677050a936ef54e93bf37b764b9718d3a382147f65580524e60ecd1553a04789140f99fb9015c61f8c5bab1c325ca606a17e6
         | 
| 7 | 
            +
              data.tar.gz: a58c65739e47df46ac510eb6e3279cd281942e7c0516a97cf01369625e33968611f21b45122ff34ba44f5135434b9334765993f0f64348a6b37225ff18e7dcad
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.2. | 
| 1 | 
            +
            0.2.1
         | 
| @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            require 'fluent/plugin/output'
         | 
| 2 | 
            +
            require 'fluent/mixin'
         | 
| 2 3 | 
             
            require 'fluent/mixin/config_placeholders'
         | 
| 3 4 | 
             
            require 'fluent/mixin/rewrite_tag_name'
         | 
| 4 5 |  | 
| @@ -7,9 +8,7 @@ module Fluent | |
| 7 8 | 
             
                class RecordSplitterOutput < Output
         | 
| 8 9 | 
             
                  Fluent::Plugin.register_output('record_splitter', self)
         | 
| 9 10 |  | 
| 10 | 
            -
                  config_param :tag, :string
         | 
| 11 | 
            -
                  config_param :remove_prefix, :string, default: nil
         | 
| 12 | 
            -
                  config_param :add_prefix, :string, default: nil
         | 
| 11 | 
            +
                  config_param :tag, :string, default: nil
         | 
| 13 12 | 
             
                  config_param :split_key, :string
         | 
| 14 13 | 
             
                  config_param :keep_other_key, :bool, default: false
         | 
| 15 14 | 
             
                  config_param :keep_keys, :array, default: []
         | 
| @@ -17,7 +16,7 @@ module Fluent | |
| 17 16 |  | 
| 18 17 | 
             
                  include SetTagKeyMixin
         | 
| 19 18 | 
             
                  include Fluent::Mixin::ConfigPlaceholders
         | 
| 20 | 
            -
                  include  | 
| 19 | 
            +
                  include HandleTagNameMixin
         | 
| 21 20 | 
             
                  include Fluent::Mixin::RewriteTagName
         | 
| 22 21 |  | 
| 23 22 | 
             
                  helpers :event_emitter
         | 
| @@ -37,12 +36,6 @@ module Fluent | |
| 37 36 | 
             
                    if !@keep_other_key && !@remove_keys.empty?
         | 
| 38 37 | 
             
                      raise Fluent::ConfigError, 'Cannot set remove_keys when keep_other_key is false.'
         | 
| 39 38 | 
             
                    end
         | 
| 40 | 
            -
                    if !@tag && !@remove_prefix && !@add_prefix
         | 
| 41 | 
            -
                      raise Fluent::ConfigError, 'missing both of remove_prefix and add_prefix'
         | 
| 42 | 
            -
                    end
         | 
| 43 | 
            -
                    if @tag && (@remove_prefix || @add_prefix)
         | 
| 44 | 
            -
                      raise Fluent::ConfigError, 'both of tag and remove_prefix/add_prefix must not be specified'
         | 
| 45 | 
            -
                    end
         | 
| 46 39 | 
             
                  end
         | 
| 47 40 |  | 
| 48 41 | 
             
                  def process(tag, es)
         | 
| @@ -52,7 +45,10 @@ module Fluent | |
| 52 45 | 
             
                      filter_record(emit_tag, time, record)
         | 
| 53 46 |  | 
| 54 47 | 
             
                      if @keep_other_key
         | 
| 55 | 
            -
                        common = record.reject  | 
| 48 | 
            +
                        common = record.reject do |key, _value|
         | 
| 49 | 
            +
                          key == @split_key ||
         | 
| 50 | 
            +
                            @remove_keys.include?(key)
         | 
| 51 | 
            +
                        end
         | 
| 56 52 | 
             
                      else
         | 
| 57 53 | 
             
                        common = record.select { |key, _value| @keep_keys.include?(key) }
         | 
| 58 54 | 
             
                      end
         | 
| @@ -103,4 +103,67 @@ class RecordSplitterOutputTest < Test::Unit::TestCase | |
| 103 103 | 
             
                   { 'common' => 'c', 'general' => 'g', 'k2' => 'v2' }]
         | 
| 104 104 | 
             
                ], d.events
         | 
| 105 105 | 
             
              end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
              def test_tag_nochange
         | 
| 108 | 
            +
                d = create_driver %(
         | 
| 109 | 
            +
                  type record_splitter
         | 
| 110 | 
            +
                  split_key target_field
         | 
| 111 | 
            +
                )
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                d.run(default_tag: 'test') do
         | 
| 114 | 
            +
                  d.feed(event_time, 'target_field' => [{ 'k1' => 'v1' }])
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                d.events.each do |tag, _|
         | 
| 118 | 
            +
                  assert_equal tag, 'test'
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
              end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
              def test_tag_change
         | 
| 123 | 
            +
                d = create_driver %(
         | 
| 124 | 
            +
                  type record_splitter
         | 
| 125 | 
            +
                  tag test.split
         | 
| 126 | 
            +
                  split_key target_field
         | 
| 127 | 
            +
                )
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                d.run(default_tag: 'test') do
         | 
| 130 | 
            +
                  d.feed(event_time, 'target_field' => [{ 'k1' => 'v1' }])
         | 
| 131 | 
            +
                end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                d.events.each do |tag, _|
         | 
| 134 | 
            +
                  assert_equal tag, 'test.split'
         | 
| 135 | 
            +
                end
         | 
| 136 | 
            +
              end
         | 
| 137 | 
            +
             | 
| 138 | 
            +
              def test_add_tag_suffix
         | 
| 139 | 
            +
                d = create_driver %(
         | 
| 140 | 
            +
                  type record_splitter
         | 
| 141 | 
            +
                  add_tag_suffix .split
         | 
| 142 | 
            +
                  split_key target_field
         | 
| 143 | 
            +
                )
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                d.run(default_tag: 'test') do
         | 
| 146 | 
            +
                  d.feed(event_time, 'target_field' => [{ 'k1' => 'v1' }])
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                d.events.each do |tag, _|
         | 
| 150 | 
            +
                  assert_equal tag, 'test.split'
         | 
| 151 | 
            +
                end
         | 
| 152 | 
            +
              end
         | 
| 153 | 
            +
             | 
| 154 | 
            +
              def test_add_tag_prefix
         | 
| 155 | 
            +
                d = create_driver %(
         | 
| 156 | 
            +
                  type record_splitter
         | 
| 157 | 
            +
                  add_tag_prefix split.
         | 
| 158 | 
            +
                  split_key target_field
         | 
| 159 | 
            +
                )
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                d.run(default_tag: 'test') do
         | 
| 162 | 
            +
                  d.feed(event_time, 'target_field' => [{ 'k1' => 'v1' }])
         | 
| 163 | 
            +
                end
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                d.events.each do |tag, _|
         | 
| 166 | 
            +
                  assert_equal tag, 'split.test'
         | 
| 167 | 
            +
                end
         | 
| 168 | 
            +
              end
         | 
| 106 169 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: fluent-plugin-record_splitter
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Yuri Odagiri
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017-08- | 
| 11 | 
            +
            date: 2017-08-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: fluentd
         |