fluent-plugin-kubernetes_metadata_filter 2.1.2 → 2.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
  SHA1:
3
- metadata.gz: fe17406dc7a359a7bb8b52271680b041397bf567
4
- data.tar.gz: 449541c91baaa0a96ee27adf6a74464941c96916
3
+ metadata.gz: 8e478872fe7fd194bb1746e4e44a917a7d07067b
4
+ data.tar.gz: dfc10c0b81a8a3a8a805e53fb914bf5525f4e328
5
5
  SHA512:
6
- metadata.gz: 7f8d366a2eb39f8c43ce9d240817cc251524ec58c2cde4186d85824b7d1e861b8396443d2c4a148ffc84892632f3ff4c87f4ca8396ddfb2c46d4f5bf55ee5caa
7
- data.tar.gz: fdc11df9a3d428929e2aa986b48848cc7204273a83b212f77277a295990afd6fd968d24105c4ebb30be4abdbd629e899478a76f6a03be6582492324b6f26cb28
6
+ metadata.gz: 27ac4b15b101d557411aebc943d5d1e5b464ec94d4e5e9318b960f0c022b09232f6112936af84b30a17834ee67562a3d0f12cea477639672089e1d3afd3541ae
7
+ data.tar.gz: bd79142fc9afde71d94ab772e65cc36cb118e0d6624014275fe2a151d5353e3e25a214ee8fc8a74e8e0d519e475cc0aa8ee364ace1f25091e0af88498685de26
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "fluent-plugin-kubernetes_metadata_filter"
7
- gem.version = "2.1.2"
7
+ gem.version = "2.1.3"
8
8
  gem.authors = ["Jimmi Dyson"]
9
9
  gem.email = ["jimmidyson@gmail.com"]
10
10
  gem.description = %q{Filter plugin to add Kubernetes metadata}
@@ -299,22 +299,24 @@ module Fluent::Plugin
299
299
  end
300
300
 
301
301
  def filter_stream_from_files(tag, es)
302
- return es if es.nil? || es.empty?
302
+ return es if (es.respond_to?(:empty?) && es.empty?) || !es.is_a?(Fluent::EventStream)
303
303
  new_es = Fluent::MultiEventStream.new
304
304
 
305
305
  match_data = tag.match(@tag_to_kubernetes_name_regexp_compiled)
306
306
  batch_miss_cache = {}
307
- if match_data
308
- container_id = match_data['docker_id']
309
- metadata = {
310
- 'docker' => {
311
- 'container_id' => container_id
312
- },
313
- 'kubernetes' => get_metadata_for_record(match_data, container_id, create_time_from_record(es.first[1]), batch_miss_cache)
314
- }
315
- end
307
+ metadata = nil
316
308
 
317
309
  es.each do |time, record|
310
+ if match_data && metadata.nil?
311
+ container_id = match_data['docker_id']
312
+ metadata = {
313
+ 'docker' => {
314
+ 'container_id' => container_id
315
+ },
316
+ 'kubernetes' => get_metadata_for_record(match_data, container_id, create_time_from_record(record), batch_miss_cache)
317
+ }
318
+ end
319
+
318
320
  record = record.merge(Marshal.load(Marshal.dump(metadata))) if metadata
319
321
  new_es.add(time, record)
320
322
  end
@@ -323,7 +325,7 @@ module Fluent::Plugin
323
325
  end
324
326
 
325
327
  def filter_stream_from_journal(tag, es)
326
- return es if es.nil? || es.empty?
328
+ return es if (es.respond_to?(:empty?) && es.empty?) || !es.is_a?(Fluent::EventStream)
327
329
  new_es = Fluent::MultiEventStream.new
328
330
  batch_miss_cache = {}
329
331
  es.each do |time, record|
@@ -160,11 +160,21 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
160
160
 
161
161
  test 'nil event stream from journal' do
162
162
  #not certain how this is possible but adding test to properly
163
- #guard against this condition we have seen
164
-
163
+ #guard against this condition we have seen - test for nil,
164
+ #empty, no empty method, not an event stream
165
165
  plugin = create_driver.instance
166
- plugin.filter_stream_from_journal('tag', nil)
167
- plugin.filter_stream_from_journal('tag', Fluent::MultiEventStream.new)
166
+ [nil, Fluent::MultiEventStream.new, 1, [1]].each do |es|
167
+ assert_equal es, plugin.filter_stream_from_journal('tag', es)
168
+ end
169
+ # and make sure OneEventStream works
170
+ ts = Time.now()
171
+ rec = {"message"=>"hello"}
172
+ es = Fluent::OneEventStream.new(ts, rec)
173
+ newes = plugin.filter_stream_from_journal('tag', es)
174
+ newes.each do |newts, newrec|
175
+ assert_equal ts, newts
176
+ assert_equal rec, newrec
177
+ end
168
178
  end
169
179
 
170
180
  test 'nil event stream from files' do
@@ -172,8 +182,18 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
172
182
  #guard against this condition we have seen
173
183
 
174
184
  plugin = create_driver.instance
175
- plugin.filter_stream_from_files('tag', nil)
176
- plugin.filter_stream_from_files('tag', Fluent::MultiEventStream.new)
185
+ [nil, Fluent::MultiEventStream.new, 1, [1]].each do |es|
186
+ assert_equal es, plugin.filter_stream_from_files('tag', es)
187
+ end
188
+ # and make sure OneEventStream works
189
+ ts = Time.now()
190
+ rec = {"message"=>"hello"}
191
+ es = Fluent::OneEventStream.new(ts, rec)
192
+ newes = plugin.filter_stream_from_journal('tag', es)
193
+ newes.each do |newts, newrec|
194
+ assert_equal ts, newts
195
+ assert_equal rec, newrec
196
+ end
177
197
  end
178
198
 
179
199
  test 'inability to connect to the api server handles exception and doensnt block pipeline' do
@@ -773,5 +793,47 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
773
793
  assert_equal(expected_kube_metadata, filtered[0])
774
794
  end
775
795
  end
796
+
797
+ test 'processes all events when reading from MessagePackEventStream' do
798
+ VCR.use_cassette('kubernetes_docker_metadata') do
799
+ entries = [[@time, {'time'=>'2015-05-08T09:22:01Z'}], [@time, {'time'=>'2015-05-08T09:22:01Z'}]]
800
+ array_stream = Fluent::ArrayEventStream.new(entries)
801
+ msgpack_stream = Fluent::MessagePackEventStream.new(array_stream.to_msgpack_stream)
802
+
803
+ d = create_driver('
804
+ kubernetes_url https://localhost:8443
805
+ watch false
806
+ cache_size 1
807
+ ')
808
+ d.run {
809
+ d.feed(DEFAULT_TAG, msgpack_stream)
810
+ }
811
+ filtered = d.filtered.map{|e| e.last}
812
+
813
+ expected_kube_metadata = {
814
+ 'time'=>'2015-05-08T09:22:01Z',
815
+ 'docker' => {
816
+ 'container_id' => '49095a2894da899d3b327c5fde1e056a81376cc9a8f8b09a195f2a92bceed459'
817
+ },
818
+ 'kubernetes' => {
819
+ 'host' => 'jimmi-redhat.localnet',
820
+ 'pod_name' => 'fabric8-console-controller-98rqc',
821
+ 'container_name' => 'fabric8-console-container',
822
+ 'container_image' => 'fabric8/hawtio-kubernetes:latest',
823
+ 'container_image_id' => 'docker://b2bd1a24a68356b2f30128e6e28e672c1ef92df0d9ec01ec0c7faea5d77d2303',
824
+ 'namespace_name' => 'default',
825
+ 'namespace_id' => '898268c8-4a36-11e5-9d81-42010af0194c',
826
+ 'pod_id' => 'c76927af-f563-11e4-b32d-54ee7527188d',
827
+ 'master_url' => 'https://localhost:8443',
828
+ 'labels' => {
829
+ 'component' => 'fabric8Console'
830
+ }
831
+ }
832
+ }
833
+
834
+ assert_equal(expected_kube_metadata, filtered[0])
835
+ assert_equal(expected_kube_metadata, filtered[1])
836
+ end
837
+ end
776
838
  end
777
839
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-kubernetes_metadata_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmi Dyson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-17 00:00:00.000000000 Z
11
+ date: 2018-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd