fluent-plugin-dockergelf 0.1.5 → 0.2.0

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: 844e49c9984c07d68c6a2295817af4725092cf480399940d2aafbbaea7278cd4
4
- data.tar.gz: 766867ba26d2d66200b9b0c8990da50d0d5e66bb5681b65bc3f9791c9af04295
3
+ metadata.gz: feff450bcb796cff98adfcb03a064c8e95464aaafc1f3719dc2b25c240cfa08a
4
+ data.tar.gz: 55a274b720520b6ef6fe28b55c227b18cb62398d322c2abf844e52224dfcda21
5
5
  SHA512:
6
- metadata.gz: 4dd97d20c1d3eea9ba59ad62ec20fa2fe205411811c8b88ec885a4a2d6ac9800d01f5c6bf43865ff3b86837f36629b0e0fa453dab9b472a2750250ee3c1ea6ee
7
- data.tar.gz: 8707d5031aae26092b7adc3c84c54eae52cda4603b0e65c6ea3d2184a0fd44aa351e7306f8fe8b39296b3d378a970313e40c35ad446a580239a10e23642ac231
6
+ metadata.gz: 9b3864c3df3257e36824a128eb8c21ca8885138fb3ba650ee505ff26a8ff10b7ac98f31cdaa2aff47bcc4cd64ca35bc7e7f20d042e91202822028874cf8921be
7
+ data.tar.gz: 868cefaf9b75722dbacd5e6c3b8cb0b27387cf30ce93ce212ef2c325ab144a6c41dc4ee797795749886ef277c9a6bc995638a9bd3cb30bee8ecf1788f9007390
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg/
2
+ .idea/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-dockergelf (0.1.1)
4
+ fluent-plugin-dockergelf (0.2.0)
5
5
  fluentd (>= 0.14.10, < 2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,8 +1,19 @@
1
1
  # fluent-plugin-dockergelf
2
2
 
3
- [Fluentd](https://fluentd.org/) filter plugin to do something.
3
+ [Fluentd](https://fluentd.org/) filter plugin to handle gelf format log in docker(kubenetes)
4
4
 
5
- TODO: write description for you plugin.
5
+ The log looks like
6
+ ```
7
+ {"log":"{"_instance_id":"","_microservice_id":"","host":"","level":4,"short_message":"Some log information.","timestamp":1539143207.2754333,"version":"1.1"}","stream":"stderr","time":"2018-10-10T05:05:17.102912076Z"}
8
+ ```
9
+ This filter will use the timestamp inside as the timestamp. create a new field called logtime as the timestamp from the docker. move the short_message to the log field.
10
+
11
+ The latest kubernetes_metadata filter does not support the inner json process anymore. So this filter is recommended to put between detect_exceptions and kubernetes_metadata.
12
+ ```clickhouse
13
+ <filter kubernetes.**>
14
+ @type dockergelf
15
+ </filter>
16
+ ```
6
17
 
7
18
  ## Installation
8
19
 
@@ -26,12 +37,12 @@ And then execute:
26
37
  $ bundle
27
38
  ```
28
39
 
29
- ## Configuration
40
+ ## Release new version
30
41
 
31
- You can generate configuration template:
42
+ You can release new version of this plugin:
32
43
 
33
44
  ```
34
- $ fluent-plugin-config-format filter dockergelf
45
+ $ rake release
35
46
  ```
36
47
 
37
48
  You can copy and paste generated documents here.
@@ -3,14 +3,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-dockergelf"
6
- spec.version = "0.1.5"
6
+ spec.version = "0.2.0"
7
7
  spec.authors = ["Bo Zhang"]
8
- spec.email = ["bo.zhang@inoviagroup.se"]
8
+ spec.email = ["bo.b.zhang@ericsson.com"]
9
9
 
10
- spec.summary = %q{rrr}
11
- spec.description = %q{ttt}
12
- spec.homepage = "http://google.com"
13
- spec.license = ""
10
+ spec.summary = %q{Handles gelf log in docker/kubenetes}
11
+ spec.description = %q{Will put docker log time as new field logtime, and use the timestamp in gelf}
12
+ spec.homepage = "https://gitlab.apphub.ericsson.net/bo-test-group/fluent-plugin-dockergelf"
13
+ spec.license = "Ericsson"
14
14
 
15
15
  test_files, files = `git ls-files -z`.split("\x0").partition do |f|
16
16
  f.match(%r{^(test|spec|features)/})
@@ -1,17 +1,39 @@
1
1
  require "fluent/plugin/filter"
2
-
2
+ require "json"
3
+ require "pp"
3
4
  module Fluent
4
5
  module Plugin
5
6
  class DockergelfFilter < Fluent::Plugin::Filter
6
7
  Fluent::Plugin.register_filter("dockergelf", self)
8
+
7
9
  def configure(conf)
8
10
  super
9
11
  end
10
- def filter(tag, time, record)
11
- record["ttttt"] = tag.to_s
12
- record["mmmmm"] = time.to_s
13
- record["ddddd"] = record.to_s
14
- record
12
+
13
+ def filter_with_time(tag, time, record)
14
+ record["logtime"] = Time.at(time.to_f).iso8601(3).to_s
15
+ content = record["log"].strip
16
+ rettime = time
17
+ if (content =~ /^[{](.*)[}]$/)
18
+ content_hash = JSON.parse(content)
19
+ if content_hash["version"].to_s == "1.1" && content_hash["short_message"] != nil #check if gelf format
20
+ content_hash.delete("version")
21
+ msg = content_hash["short_message"]
22
+ content_hash.delete("short_message")
23
+ content_hash.each do |key ,value|
24
+ if key == "timestamp"
25
+ rettime = Fluent::EventTime.from_time(Time.at(value))
26
+ else
27
+ record[key]=value
28
+ end
29
+ end
30
+ record["log"] = msg
31
+ end
32
+ end
33
+ rescue
34
+ ensure
35
+ puts "returning "+ (Time.at(rettime.to_f).iso8601(3).to_s )+" "+record.to_s
36
+ return rettime, record
15
37
  end
16
38
  end
17
39
  end
@@ -16,12 +16,10 @@ class DockergelfFilterTest < Test::Unit::TestCase
16
16
  Fluent::Test::Driver::Filter.new(Fluent::Plugin::DockergelfFilter).configure(conf)
17
17
  end
18
18
 
19
- def filter(config, messages)
19
+ def filterWithTime(config, time, message)
20
20
  d = create_driver(config)
21
- d.run(default_tag: "input.access") do
22
- messages.each do |message|
23
- d.feed(message)
24
- end
21
+ d.run() do
22
+ d.feed("tag.input",time, message)
25
23
  end
26
24
  d.filtered_records
27
25
  end
@@ -44,31 +42,63 @@ class DockergelfFilterTest < Test::Unit::TestCase
44
42
  # # ...
45
43
  # end
46
44
 
47
- sub_test_case 'plugin will add some fields' do
48
- test 'add hostname to record' do
45
+ sub_test_case 'plugin will handle gelf' do
46
+ test 'parse gel log' do
49
47
  conf = CONFIG
50
- messages = [
51
- {"message" => "This is test message"}
52
- ]
53
- expected = [
54
- {"message" => "This is test message"}
55
- ]
56
- filtered_records = filter(conf, messages)
57
- assert_equal(expected, filtered_records)
48
+ time = event_time('2018-10-20T00:00:00.123Z')
49
+ logtime=Time.at(time.to_f).iso8601(3).to_s
50
+ message = {"log" => '{"_instance_id":"","_microservice_id":"","host":"","level":4,"short_message":"somemsg","timestamp":1539143207.2754333,"version":"1.1"}',
51
+ "stream" => 'stderr'
52
+ }
53
+ filtered_record = filterWithTime(conf, time, message)[0]
54
+ puts filtered_record
55
+ assert_equal(logtime, filtered_record["logtime"])
56
+ assert_equal(4, filtered_record["level"])
57
+ assert_equal("stderr", filtered_record["stream"])
58
+ assert_equal("somemsg", filtered_record["log"])
58
59
  end
59
60
  end
60
61
 
61
- sub_test_case 'plugin will add some fields' do
62
- test 'add hostname to record' do
62
+ sub_test_case 'plugin will handle nongelf' do
63
+ test 'parse nonegelf log' do
63
64
  conf = CONFIG
64
- messages = [
65
- { "message" => "This is test message" }
66
- ]
67
- expected = [
68
- { "message" => "This is test message"}
69
- ]
70
- filtered_records = filter(conf, messages)
71
- assert_equal(expected, filtered_records)
65
+ time = event_time('2018-10-20T00:00:00.123Z')
66
+ logtime=Time.at(time.to_f).iso8601(3).to_s
67
+ message = {"log" => 'abc',
68
+ "stream" => 'stderr'
69
+ }
70
+ filtered_record = filterWithTime(conf, time, message)[0]
71
+ puts filtered_record
72
+ assert_equal(logtime, filtered_record["logtime"])
73
+ assert_equal("stderr", filtered_record["stream"])
74
+ assert_equal("abc", filtered_record["log"])
75
+ end
76
+ test 'parse bad json log' do
77
+ conf = CONFIG
78
+ time = event_time('2018-10-20T00:00:00.123Z')
79
+ logtime=Time.at(time.to_f).iso8601(3).to_s
80
+ message = {"log" => '{"asdf":"aa",[}',
81
+ "stream" => 'stderr'
82
+ }
83
+ filtered_record = filterWithTime(conf, time, message)[0]
84
+ puts filtered_record
85
+ assert_equal(logtime, filtered_record["logtime"])
86
+ assert_equal("stderr", filtered_record["stream"])
87
+ assert_equal('{"asdf":"aa",[}', filtered_record["log"])
72
88
  end
73
89
  end
90
+ #
91
+ # sub_test_case 'plugin will add some fields' do
92
+ # test 'add hostname to record' do
93
+ # conf = CONFIG
94
+ # messages = [
95
+ # { "message" => "This is test message" }
96
+ # ]
97
+ # expected = [
98
+ # { "message" => "This is test message"}
99
+ # ]
100
+ # filtered_records = filter(conf, messages)
101
+ # assert_equal(expected, filtered_records)
102
+ # end
103
+
74
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-dockergelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bo Zhang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2018-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,25 +72,26 @@ dependencies:
72
72
  - - "<"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2'
75
- description: ttt
75
+ description: Will put docker log time as new field logtime, and use the timestamp
76
+ in gelf
76
77
  email:
77
- - bo.zhang@inoviagroup.se
78
+ - bo.b.zhang@ericsson.com
78
79
  executables: []
79
80
  extensions: []
80
81
  extra_rdoc_files: []
81
82
  files:
83
+ - ".gitignore"
82
84
  - Gemfile
83
85
  - Gemfile.lock
84
86
  - README.md
85
87
  - Rakefile
86
88
  - fluent-plugin-dockergelf.gemspec
87
89
  - lib/fluent/plugin/filter_dockergelf.rb
88
- - pkg/fluent-plugin-dockergelf-0.1.1.gem
89
90
  - test/helper.rb
90
91
  - test/plugin/test_filter_dockergelf.rb
91
- homepage: http://google.com
92
+ homepage: https://gitlab.apphub.ericsson.net/bo-test-group/fluent-plugin-dockergelf
92
93
  licenses:
93
- - ''
94
+ - Ericsson
94
95
  metadata: {}
95
96
  post_install_message:
96
97
  rdoc_options: []
@@ -111,7 +112,7 @@ rubyforge_project:
111
112
  rubygems_version: 2.7.7
112
113
  signing_key:
113
114
  specification_version: 4
114
- summary: rrr
115
+ summary: Handles gelf log in docker/kubenetes
115
116
  test_files:
116
117
  - test/helper.rb
117
118
  - test/plugin/test_filter_dockergelf.rb
Binary file