fluent-plugin-kubernetes_metadata_filter 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51343e9798a88739c3959e9cf6e350ec1b213ac3
4
- data.tar.gz: d361fbbaa5f7f43832f4ae261746c5715c2e3aa0
3
+ metadata.gz: b6b445ba2f0982bd35de2efb14c3c63018929a88
4
+ data.tar.gz: ca6ca38cc0dc1c02617b5656249b81ea3079c463
5
5
  SHA512:
6
- metadata.gz: 4307c9fc6195ed933cca79e12dbedb6698266943632814c9f25ad669cb909ebab2957317694ce764cc5abed0eabd4366622f2446e0e45f68566ad15f4f3082ce
7
- data.tar.gz: 62f89e376091e5d4f856d034a8f47f0b15839e346912840cd3fafa2e7654e91bb4aa990030b22d87cc9056496b9c2aa4f893cbebbf8379993d9616d9aecb634a
6
+ metadata.gz: 9a6494885196744461c705ee8216ce6dc2471a30819c9346ee4661860b613ca3795e079aa3b80b6a00ebea3fc184bf8eedacfca60d11d24ea5be3a24ccd7a5ab
7
+ data.tar.gz: da5ed5376cc30f925cbef088aeb8c1aea78cd687964b12b399df835f11de2fb495daac661b69a077343612e544163a51f6fd9674430fe2b9c6dc1a62a724ef5c
data/README.md CHANGED
@@ -42,8 +42,6 @@ This must used named capture groups for `container_name`, `pod_name` & `namespac
42
42
  * `cache_size` - size of the cache of Kubernetes metadata to reduce requests to the API server (default: `1000`)
43
43
  * `cache_ttl` - TTL in seconds of each cached element. Set to negative value to disable TTL eviction (default: `3600` - 1 hour)
44
44
  * `watch` - set up a watch on pods on the API server for updates to metadata (default: `true`)
45
- * `merge_json_log` - merge logs in JSON format as top level keys (default: `true`)
46
- * `preserve_json_log` - preserve JSON logs in raw form in the `log` key, only used if the previous option is true (default: `true`)
47
45
  * `de_dot` - replace dots in labels and annotations with configured `de_dot_separator`, required for ElasticSearch 2.x compatibility (default: `true`)
48
46
  * `de_dot_separator` - separator to use if `de_dot` is enabled (default: `_`)
49
47
  * `use_journal` - If false (default), messages are expected to be formatted and tagged as if read by the fluentd in\_tail plugin with wildcard filename. If true, messages are expected to be formatted as if read from the systemd journal. The `MESSAGE` field has the full message. The `CONTAINER_NAME` field has the encoded k8s metadata (see below). The `CONTAINER_ID_FULL` field has the full container uuid. This requires docker to use the `--log-driver=journald` log driver.
@@ -55,6 +53,12 @@ when true (default: `true`)
55
53
  * `orphaned_namespace_name` - The namespace to associate with records where the namespace can not be determined (default: `.orphaned`)
56
54
  * `orphaned_namespace_id` - The namespace id to associate with records where the namespace can not be determined (default: `orphaned`)
57
55
 
56
+ **NOTE:** As of the release 1.1.x of this plugin, it no longer supports parsing the source message into JSON and attaching it to the
57
+ payload. The following configuration options are removed:
58
+
59
+ * `merge_json_log`
60
+ * `preserve_json_log`
61
+
58
62
  Reading from the JSON formatted log files with `in_tail` and wildcard filenames:
59
63
  ```
60
64
  <source>
@@ -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 = "1.0.3"
7
+ gem.version = "1.1.0"
8
8
  gem.authors = ["Jimmi Dyson"]
9
9
  gem.email = ["jimmidyson@gmail.com"]
10
10
  gem.description = %q{Filter plugin to add Kubernetes metadata}
@@ -48,8 +48,6 @@ module Fluent
48
48
  :string,
49
49
  :default => 'var\.log\.containers\.(?<pod_name>[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)_(?<namespace>[^_]+)_(?<container_name>.+)-(?<docker_id>[a-z0-9]{64})\.log$'
50
50
  config_param :bearer_token_file, :string, default: nil
51
- config_param :merge_json_log, :bool, default: true
52
- config_param :preserve_json_log, :bool, default: true
53
51
  config_param :secret_dir, :string, default: '/var/run/secrets/kubernetes.io/serviceaccount'
54
52
  config_param :de_dot, :bool, default: true
55
53
  config_param :de_dot_separator, :string, default: '_'
@@ -237,10 +235,10 @@ module Fluent
237
235
  end
238
236
  end
239
237
  if @use_journal
240
- @merge_json_log_key = 'MESSAGE'
238
+ log.debug "Will stream from the journal"
241
239
  self.class.class_eval { alias_method :filter_stream, :filter_stream_from_journal }
242
240
  else
243
- @merge_json_log_key = 'log'
241
+ log.debug "Will stream from the files"
244
242
  self.class.class_eval { alias_method :filter_stream, :filter_stream_from_files }
245
243
  end
246
244
 
@@ -299,13 +297,10 @@ module Fluent
299
297
  }
300
298
  end
301
299
 
302
- es.each { |time, record|
303
- record = merge_json_log(record) if @merge_json_log
304
-
300
+ es.each do |time, record|
305
301
  record = record.merge(Marshal.load(Marshal.dump(metadata))) if metadata
306
-
307
302
  new_es.add(time, record)
308
- }
303
+ end
309
304
  dump_stats
310
305
  new_es
311
306
  end
@@ -313,8 +308,7 @@ module Fluent
313
308
  def filter_stream_from_journal(tag, es)
314
309
  new_es = MultiEventStream.new
315
310
  batch_miss_cache = {}
316
- es.each { |time, record|
317
- record = merge_json_log(record) if @merge_json_log
311
+ es.each do |time, record|
318
312
  metadata = nil
319
313
  if record.has_key?('CONTAINER_NAME') && record.has_key?('CONTAINER_ID_FULL')
320
314
  metadata = record['CONTAINER_NAME'].match(@container_name_to_kubernetes_regexp_compiled) do |match_data|
@@ -337,35 +331,15 @@ module Fluent
337
331
  @stats.bump(:container_name_id_missing)
338
332
  end
339
333
 
340
- if metadata
341
- record = record.merge(metadata)
342
- end
334
+ record = record.merge(metadata) if metadata
343
335
 
344
336
  new_es.add(time, record)
345
- }
337
+ end
346
338
 
347
339
  dump_stats
348
340
  new_es
349
341
  end
350
342
 
351
- def merge_json_log(record)
352
- if record.has_key?(@merge_json_log_key)
353
- value = record[@merge_json_log_key].strip
354
- if value[0].eql?('{') && value[-1].eql?('}')
355
- begin
356
- record = JSON.parse(value).merge(record)
357
- unless @preserve_json_log
358
- record.delete(@merge_json_log_key)
359
- end
360
- rescue JSON::ParserError=>e
361
- @stats.bump(:merge_json_parse_errors)
362
- log.debug(e)
363
- end
364
- end
365
- end
366
- record
367
- end
368
-
369
343
  def de_dot!(h)
370
344
  h.keys.each do |ref|
371
345
  if h[ref] && ref =~ /\./
@@ -397,45 +397,6 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
397
397
  assert_false(es.instance_variable_get(:@record_array)[0].has_key?(:kubernetes))
398
398
  end
399
399
 
400
- test 'merges json log data' do
401
- json_log = {
402
- 'hello' => 'world'
403
- }
404
- msg = {
405
- 'log' => "#{json_log.to_json}"
406
- }
407
- es = emit_with_tag('non-kubernetes', msg, '')
408
- assert_equal(msg.merge(json_log), es.instance_variable_get(:@record_array)[0])
409
- end
410
-
411
- test 'merges json log data in MESSAGE' do
412
- json_log = {
413
- 'hello' => 'world'
414
- }
415
- msg = {
416
- 'MESSAGE' => "#{json_log.to_json}"
417
- }
418
- es = emit_with_tag('non-kubernetes', msg, 'use_journal true')
419
- assert_equal(msg.merge(json_log), es.instance_variable_get(:@record_array)[0])
420
- end
421
-
422
- test 'merges json log data with message field' do
423
- json_log = {
424
- 'timeMillis' => 1459853347608,
425
- 'thread' => 'main',
426
- 'level' => 'INFO',
427
- 'loggerName' => 'org.apache.camel.spring.SpringCamelContext',
428
- 'message' => 'Total 1 routes, of which 1 is started.',
429
- 'endOfBatch' => false,
430
- 'loggerFqcn' => 'org.apache.logging.slf4j.Log4jLogger'
431
- }
432
- msg = {
433
- 'log' => "#{json_log.to_json}"
434
- }
435
- es = emit_with_tag('non-kubernetes', msg, '')
436
- assert_equal(msg.merge(json_log), es.instance_variable_get(:@record_array)[0])
437
- end
438
-
439
400
  test 'ignores invalid json in log field' do
440
401
  json_log = "{'foo':123}"
441
402
  msg = {
@@ -445,50 +406,6 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
445
406
  assert_equal(msg, es.instance_variable_get(:@record_array)[0])
446
407
  end
447
408
 
448
- test 'merges json log data with message field in MESSAGE' do
449
- json_log = {
450
- 'timeMillis' => 1459853347608,
451
- 'thread' => 'main',
452
- 'level' => 'INFO',
453
- 'loggerName' => 'org.apache.camel.spring.SpringCamelContext',
454
- 'message' => 'Total 1 routes, of which 1 is started.',
455
- 'endOfBatch' => false,
456
- 'loggerFqcn' => 'org.apache.logging.slf4j.Log4jLogger'
457
- }
458
- msg = {
459
- 'MESSAGE' => "#{json_log.to_json}"
460
- }
461
- es = emit_with_tag('non-kubernetes', msg, 'use_journal true')
462
- assert_equal(msg.merge(json_log), es.instance_variable_get(:@record_array)[0])
463
- end
464
-
465
- test 'emit individual fields from json, throw out whole original string' do
466
- json_log = {
467
- 'hello' => 'world',
468
- 'more' => 'data'
469
- }
470
- msg = {
471
- 'log' => "#{json_log.to_json}"
472
- }
473
- es = emit_with_tag('non-kubernetes', msg, 'preserve_json_log false')
474
- assert_equal(json_log, es.instance_variable_get(:@record_array)[0])
475
- end
476
-
477
- test 'emit individual fields from json, throw out whole original string in MESSAGE' do
478
- json_log = {
479
- 'hello' => 'world',
480
- 'more' => 'data'
481
- }
482
- msg = {
483
- 'MESSAGE' => "#{json_log.to_json}"
484
- }
485
- es = emit_with_tag('non-kubernetes', msg, '
486
- preserve_json_log false
487
- use_journal true
488
- ')
489
- assert_equal(json_log, es.instance_variable_get(:@record_array)[0])
490
- end
491
-
492
409
  test 'with kubernetes dotted labels, de_dot enabled' do
493
410
  VCR.use_cassette('kubernetes_docker_metadata_dotted_labels') do
494
411
  es = emit({}, '
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-kubernetes_metadata_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmi Dyson