fluent-plugin-gelf-best 1.3.0 → 1.3.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: b3d0be1e13c195cc69d517d9678fd9ed15128700a203f6fcded95a8acf26ffa5
4
- data.tar.gz: b5f48294ede888f480c827fcfeb635ae0769631c8e77b0329773927ca64a0aef
3
+ metadata.gz: dc3a134e34dfdc0c22a93f90ca53b655bbb9133f787726adb478ffdb6b74bba3
4
+ data.tar.gz: f65ca691ac9b2e7046878b1b8b6315a21c6a3d575408ece21aff885c0f3c3add
5
5
  SHA512:
6
- metadata.gz: 1d0a6549e8a686fca58906ca27fd153e7e6d84cac711c59a7e0312f039ad591815567d08d55724d1a88c1d7ef3ae3acef214a652fae50aac09a3fc6145aae24d
7
- data.tar.gz: 60bebae56b82025efa2f141be0842d1fe966d47d0d633fbe2e18bce7dbb7718635425150ae4bce2c69713b6a6b814efd6a63af508599ea16b293c2086d74c7dc
6
+ metadata.gz: f2adf1721b08d85f7a191d7121eb0a0190aee674f70159c828a475a4f717a90594307e116b1a88212d0095c9b546d48134c596e7fb186f6dba9cc0476905e616
7
+ data.tar.gz: 7bca600938707cda06ce79d798d11dd3dd3756ee7a0a3016b2770aa9a63d1133f0a7bcb745d8e14699d6503099cced2d6ff2a63b008731e8aa8a4fc3b6a652a4
@@ -1,39 +1,24 @@
1
- require 'oj'
2
- require 'date'
3
- require 'gelf'
4
-
5
1
  module Fluent
6
2
  module GelfPluginUtil
3
+ require "gelf"
4
+ require "date"
7
5
 
8
6
  LEVEL_MAP = {
9
- '0' => GELF::UNKNOWN, '1' => GELF::UNKNOWN, 'a' => GELF::UNKNOWN,
10
- '2' => GELF::FATAL, 'c' => GELF::FATAL,
11
- '3' => GELF::ERROR,
12
- '4' => GELF::WARN, 'w' => GELF::WARN,
13
- '5' => GELF::INFO, 'n' => GELF::INFO,
14
- '6' => GELF::INFO, 'i' => GELF::INFO,
15
- '7' => GELF::DEBUG, 'd' => GELF::DEBUG,
16
- 'e' => GELF::ERROR
7
+ "0" => GELF::UNKNOWN, "1" => GELF::UNKNOWN, "a" => GELF::UNKNOWN,
8
+ "2" => GELF::FATAL, "c" => GELF::FATAL,
9
+ "3" => GELF::ERROR,
10
+ "4" => GELF::WARN, "w" => GELF::WARN,
11
+ "5" => GELF::INFO, "n" => GELF::INFO,
12
+ "6" => GELF::INFO, "i" => GELF::INFO,
13
+ "7" => GELF::DEBUG, "d" => GELF::DEBUG,
14
+ "e" => GELF::ERROR # assuming 'e' stands typically for 'error'
17
15
  }.freeze
18
16
 
19
- def get_internal_json_out(record, key)
20
- json_data = parse_json_field(record[key])
21
- return record unless json_data
22
-
23
- record.delete(key)
24
- merge_record_with_json(record, json_data)
25
- rescue Oj::ParseError, EncodingError
26
- # Return original record if JSON parsing fails
27
- record
28
- end
29
-
30
17
  def make_gelfentry(tag, time, record, conf = {})
31
- record = get_internal_json_out(record, "message")
32
- record = get_internal_json_out(record, "log")
33
- gelfentry = {"_fluentd_tag" => tag, "timestamp" => calculate_timestamp(time)}
18
+ gelfentry = {'_fluentd_tag' => tag, 'timestamp' => calculate_timestamp(time)}
34
19
 
35
- record.each do |k, v|
36
- process_record_entry(k, v, conf, gelfentry)
20
+ record.each_pair do |k, v|
21
+ gelfentry.merge!(process_record_entry(k, v, conf, gelfentry))
37
22
  end
38
23
 
39
24
  ensure_short_message(gelfentry)
@@ -42,13 +27,6 @@ module Fluent
42
27
 
43
28
  private
44
29
 
45
- def parse_json_field(json_field)
46
- return nil unless json_field
47
- json = Oj.load(json_field.strip)
48
- return nil unless json.is_a?(Hash)
49
- json
50
- end
51
-
52
30
  def calculate_timestamp(time)
53
31
  if defined?(Fluent::EventTime) && time.is_a?(Fluent::EventTime)
54
32
  time.sec + (time.nsec.to_f / 1_000_000_000).round(3)
@@ -60,29 +38,43 @@ module Fluent
60
38
  def process_record_entry(k, v, conf, gelfentry)
61
39
  case k
62
40
  when 'host', 'hostname'
63
- gelfentry['host'] = conf[:use_record_host] ? v : (gelfentry['_host'] = v)
41
+ return {'host' => (conf[:use_record_host] ? v : gelfentry['_host'] = v)}
64
42
  when 'timestamp', 'time'
65
- gelfentry['timestamp'] = parse_timestamp(v)
43
+ { 'timestamp' => parse_timestamp(v) }
66
44
  when 'level'
67
- gelfentry['level'] = LEVEL_MAP[v.to_s.downcase[0]] || GELF::UNKNOWN
45
+ {'level' => LEVEL_MAP[v.to_s.downcase[0]] || (v.to_s.length >= 2 && v.to_s.downcase[1] != "r" ? GELF::UNKNOWN : v)}
68
46
  when 'msec'
69
- gelfentry['timestamp'] = conf[:add_msec_time] ? "#{time.to_s}.#{v}".to_f : (gelfentry['_msec'] = v)
47
+ conf[:add_msec_time] ? {'timestamp' => "#{time.to_s}.#{v}".to_f} : {'_msec' => v}
70
48
  when 'short_message', 'version', 'full_message', 'facility', 'file', 'line'
71
- gelfentry[k] = v
49
+ {k => v}
72
50
  else
73
- gelfentry[k.start_with?('_') ? k : "_#{k}"] = v
51
+ {k.start_with?('_') ? k : "_#{k}" => v}
74
52
  end
75
53
  end
76
54
 
77
55
  def parse_timestamp(v)
78
- return v if v.is_a?(Integer) || v.is_a?(Float)
79
-
80
- DateTime.parse(v).strftime("%Q").to_f / 1_000 rescue v
56
+ if v.is_a?(Integer) || v.is_a?(Float)
57
+ v
58
+ else
59
+ begin
60
+ (DateTime.parse(v).strftime("%Q").to_f / 1_000).round(3)
61
+ rescue ArgumentError
62
+ v
63
+ end
64
+ end
81
65
  end
82
66
 
83
67
  def ensure_short_message(gelfentry)
84
- default_key = ['_message', '_msg', '_log', '_record'].find { |key| gelfentry[key]&.strip&.empty? == false }
85
- gelfentry['short_message'] = default_key ? gelfentry.delete(default_key) : '(no message)'
68
+ return if gelfentry['short_message'] && !gelfentry['short_message'].to_s.strip.empty?
69
+
70
+ ['_message', '_msg', '_log', '_record'].each do |key|
71
+ if gelfentry[key] && !gelfentry[key].to_s.strip.empty?
72
+ gelfentry['short_message'] = gelfentry.delete(key)
73
+ return
74
+ end
75
+ end
76
+
77
+ gelfentry['short_message'] = '(no message)' unless gelfentry['short_message']
86
78
  end
87
79
  end
88
80
  end
@@ -1,3 +1,3 @@
1
1
  module FluentPluginGelfBest
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-gelf-best
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Yamauchi