fluent-plugin-tai64n_parser 0.1.0 → 0.2.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: 1f47b272961f4be0457ff8ef982c0f29fa396f74
4
- data.tar.gz: 0863699cd861ef18b4b999681cfeb7383c100841
3
+ metadata.gz: 98eeadeabea7c5c15b15b840c1d8d6b9ade095ce
4
+ data.tar.gz: 0a03ab28e47f559559422470cd0f07573a9694a7
5
5
  SHA512:
6
- metadata.gz: 0225747aa31a264174f99c84e63372e37227a28a3a2863f09b2d34030497b3ca32baa703170b6487838a9eb688fbcf2aa2c793d1ba25c82c1e016e3469598def
7
- data.tar.gz: d7506a97b2d672c990e9ea9701e831e9b20684199d286220eda0de7b8ae78c0e1e90f72d86720ffce5054bfcf7af115143feb8d87e40b0447197f6e5abe39a3c
6
+ metadata.gz: ee877722ddb16ce7162959e1b12bc3a475324f9244adbeaade7e6584fbf112ff1a16bf87067ea54ce14f8bf56ce4c37b04fa1c133ee48402a3e477a811b148f2
7
+ data.tar.gz: 204d311a6c71145c83aa716376956dd9d4e7a8f090e8ab1f717bcb1cb43d2483df4681efde2a4f47ab33b538c28e33a446d7c09f3ae247db67c4a3d2ea5410d8
@@ -1,18 +1,15 @@
1
1
  # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
2
  language: ruby
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
-
4
+ - 2.1.*
5
+ - 2.2.*
6
+ - 2.3.*
7
+ gemfile:
8
+ - Gemfile
9
+ - Gemfile.fluentd.v0.12
10
+ - Gemfile.fluentd.v0.10
7
11
  before_install:
8
12
  - gem update bundler
9
-
10
- matrie:
11
- allow_failures:
12
- - rvm: 1.9.3
13
- - rvm: 2.0.0
14
-
15
13
  env:
16
14
  - TZ="Asia/Tokyo"
17
-
18
15
  script: bundle exec rake test
@@ -0,0 +1,5 @@
1
+ # 0.2.0 (2016-09-24)
2
+
3
+ Enhancements
4
+
5
+ * Add filter plugin
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
1
  source 'https://rubygems.org'
2
+
2
3
  gemspec
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'fluentd', '~> 0.10.43'
4
+ gemspec
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'fluentd', '~> 0.12.0'
4
+ gemspec
data/README.md CHANGED
@@ -14,15 +14,39 @@ gem install fluent-plugin-tai64n_parser
14
14
 
15
15
  ## Configuration
16
16
 
17
- ### Basic Example:
17
+ ### Filter Plugin
18
18
 
19
19
  ```
20
- <match test.**>
21
- type tai64n_parser
20
+ <filter test.**>
21
+ @type tai64n_parser
22
+ key message
23
+ </match>
24
+ ```
22
25
 
23
- key tai64n
24
- output_key parsed_time
25
- add_tag_prefix parsed.
26
+ Assume following input is coming (indented):
27
+
28
+ ``` js
29
+ "test" => {
30
+ "message" => "@4000000052f88ea32489532c [FATAL] blah blah"
31
+ }
32
+ ```
33
+
34
+ then output becomes as below (indented):
35
+
36
+ ``` js
37
+ "test" => {
38
+ "message" => "2014-02-10 17:32:25.612979500 [FATAL] blah blah"
39
+ }
40
+ ```
41
+
42
+ ### Output Plugin (Old Style)
43
+
44
+ ```
45
+ <match test.**>
46
+ @type tai64n_parser
47
+
48
+ key message
49
+ add_tag_prefix parsed.
26
50
  </match>
27
51
  ```
28
52
 
@@ -30,7 +54,7 @@ Assume following input is coming (indented):
30
54
 
31
55
  ``` js
32
56
  "test" => {
33
- "tai64n" => "@4000000052f88ea32489532c"
57
+ "message" => "@4000000052f88ea32489532c [FATAL] blah blah"
34
58
  }
35
59
  ```
36
60
 
@@ -38,8 +62,7 @@ then output becomes as below (indented):
38
62
 
39
63
  ``` js
40
64
  "parsed.test" => {
41
- "tai64n" => "@4000000052f88ea32489532c"
42
- "parsed_time" => "2014-02-10 17:32:25.612979500",
65
+ "message" => "2014-02-10 17:32:25.612979500 [FATAL] blah blah"
43
66
  }
44
67
  ```
45
68
 
@@ -93,6 +116,52 @@ delivery_id":"9","parsed_time":"2014-02-12 13:50:11.947211500"}
93
116
  2014-02-12T13:50:11+09:00 parsed.qmail.sent {"tai64n":"@4000000052fafd8d387554bc","message":"end msg 3890","key":"3890","parsed_time":"2014-02-12 13:50:11.947213500"}
94
117
  ```
95
118
 
119
+ ## Parameters
120
+
121
+ ### Filter Plugin
122
+
123
+ - key *field\_key*
124
+
125
+ The target field key to parse tai64n. The first 25 characters are tried to parse.
126
+ If the characters are of tail64n format, convert to the time format as of `tai64nlocal` command.
127
+ If the characters are not of tai64n format, just pass through the input with info level messages on the log.
128
+
129
+ - output\_key *field\_key*
130
+
131
+ The target field to output the parsed result. The default is equivalent with `key` which means to overwrite the `key` field.
132
+
133
+ ### Output Plugin (Old Style)
134
+
135
+ - key *field\_key*
136
+
137
+ The target field key to parse tai64n. The first 25 characters are tried to parse.
138
+ If the characters are of tail64n format, convert to the time format as of `tai64nlocal` command.
139
+ If the characters are not of tai64n format, just pass through the input with info level messages on the log.
140
+
141
+ - output\_key *field\_key*
142
+
143
+ The target field to output the parsed result. The default is equivalent with `key` which means to overwrite the `key` field.
144
+
145
+ - add_tag_prefix
146
+
147
+ Add tag prefix for output message
148
+
149
+ - remove_tag_prefix
150
+
151
+ Remove tag prefix for output message
152
+
153
+ - add_tag_suffix
154
+
155
+ Add tag suffix for output message
156
+
157
+ - remove_tag_suffix
158
+
159
+ Remove tag suffix for output message
160
+
161
+ ## ChangeLog
162
+
163
+ [CHANGELOG.md](./CHANGELOG.md)
164
+
96
165
  ## Contributing
97
166
 
98
167
  1. Fork it
data/Rakefile CHANGED
@@ -6,4 +6,5 @@ Rake::TestTask.new(:test) do |test|
6
6
  test.libs << 'lib' << 'test'
7
7
  test.pattern = 'test/**/test_*.rb'
8
8
  test.verbose = true
9
+ test.warning = false
9
10
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'fluent-plugin-tai64n_parser'
3
- gem.version = '0.1.0'
3
+ gem.version = '0.2.0'
4
4
  gem.authors = ['Akira Maeda','Naotoshi Seo']
5
5
  gem.email = ['glidenote+github@gmail.com','sonots@gmail.com']
6
6
  gem.homepage = 'https://github.com/glidenote/fluent-plugin-tai64n_parser'
@@ -12,9 +12,8 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.require_paths = ['lib']
14
14
 
15
+ gem.add_runtime_dependency 'fluentd'
16
+
15
17
  gem.add_development_dependency 'rake'
16
- gem.add_development_dependency 'fluentd'
17
18
  gem.add_development_dependency 'test-unit'
18
-
19
- gem.add_runtime_dependency 'fluentd'
20
19
  end
@@ -0,0 +1,35 @@
1
+ require_relative 'tai64n_parser_mixin'
2
+
3
+ module Fluent
4
+ class Tai64nParserFilter < Filter
5
+ include Fluent::Tai64nParserMixin
6
+ Fluent::Plugin.register_filter('tai64n_parser', self)
7
+
8
+ config_param :key, :string, :default => 'tai64n'
9
+ config_param :output_key, :string, :default => nil
10
+
11
+ def configure(conf)
12
+ super
13
+ @output_key ||= @key
14
+ end
15
+
16
+ def start
17
+ super
18
+ end
19
+
20
+ def shutdown
21
+ super
22
+ end
23
+
24
+ def filter(tag, time, record)
25
+ begin
26
+ record[output_key] = try_replace_tai64n(record[key])
27
+ rescue => e
28
+ log.warn("filter_tai64n_parser: #{e.class} #{e.message}")
29
+ log.warn_backtrace
30
+ end
31
+ record
32
+ end
33
+
34
+ end
35
+ end if defined?(Fluent::Filter) # Support only >= v0.12
@@ -1,6 +1,9 @@
1
+ require_relative 'tai64n_parser_mixin'
2
+
1
3
  module Fluent
2
4
  class Tai64nParserOutput < Output
3
5
  include Fluent::HandleTagNameMixin
6
+ include Fluent::Tai64nParserMixin
4
7
  Fluent::Plugin.register_output('tai64n_parser', self)
5
8
 
6
9
  # Define `log` method for v0.10.42 or earlier
@@ -8,6 +11,11 @@ module Fluent
8
11
  define_method("log") { $log }
9
12
  end
10
13
 
14
+ # Define `router` method of v0.12 to support v0.10 or earlier
15
+ unless method_defined?(:router)
16
+ define_method("router") { Fluent::Engine }
17
+ end
18
+
11
19
  config_param :key, :string, :default => 'tai64n'
12
20
  config_param :output_key, :string, :default => nil
13
21
 
@@ -36,41 +44,20 @@ module Fluent
36
44
  es.each {|time,record|
37
45
  t = tag.dup
38
46
  filter_record(t, time, record)
39
- Engine.emit(t, time, record)
47
+ router.emit(t, time, record)
40
48
  }
41
49
  chain.next
42
50
  end
43
51
 
44
52
  def filter_record(tag, time, record)
45
53
  begin
46
- record[output_key] = replace_tai64n(record[key])
47
- rescue => error
48
- log.warn("out_tai64n_parser: #{error.class} #{error.message} #{error.backtrace.first}")
54
+ record[output_key] = try_replace_tai64n(record[key])
55
+ rescue => e
56
+ log.warn("out_tai64n_parser: #{e.class} #{e.message}")
57
+ log.warn_backtrace
49
58
  end
50
- super(tag, time, record)
59
+ super(tag, time, record) # HandleTagNameMixin
51
60
  end
52
61
 
53
- def replace_tai64n(str)
54
- tai64n, rest = str[0,25], str[25..-1]
55
- parsed = parse_tai64n(tai64n)
56
- if parsed
57
- "#{parsed}#{rest}"
58
- else
59
- log.info("out_tai64n_parser: record['#{key}']='#{str}' does not start with valid tai64n")
60
- str
61
- end
62
- end
63
-
64
- def parse_tai64n(tai64n)
65
- # @4000000052f88ea32489532c
66
- # 0123456789012345678901234
67
- # 0 1 2
68
- # |-------------||------|
69
- return nil unless tai64n[0,2] == '@4'
70
- ts = tai64n[2,15].hex
71
- tf = tai64n[17,8].hex
72
- t = Time.at(ts-10,tf/1000.0)
73
- t.strftime("%Y-%m-%d %X.%9N")
74
- end
75
62
  end
76
63
  end
@@ -0,0 +1,26 @@
1
+ module Fluent
2
+ module Tai64nParserMixin
3
+ def try_replace_tai64n(str)
4
+ tai64n, rest = str[0,25], str[25..-1]
5
+ parsed = parse_tai64n(tai64n)
6
+ if parsed
7
+ "#{parsed}#{rest}"
8
+ else
9
+ log.info("tai64n_parser: record['#{key}']='#{str}' does not start with valid tai64n")
10
+ str
11
+ end
12
+ end
13
+
14
+ def parse_tai64n(tai64n)
15
+ # @4000000052f88ea32489532c
16
+ # 0123456789012345678901234
17
+ # 0 1 2
18
+ # |-------------||------|
19
+ return nil unless tai64n[0,2] == '@4'
20
+ ts = tai64n[2,15].hex
21
+ tf = tai64n[17,8].hex
22
+ t = Time.at(ts-10,tf/1000.0)
23
+ t.strftime("%Y-%m-%d %X.%9N")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ require_relative '../test_helper'
2
+ require 'fluent/plugin/filter_tai64n_parser'
3
+
4
+ class Tai64nParserFilterTest < Test::Unit::TestCase
5
+
6
+ TAI64N_TIME = "@4000000052f88ea32489532c"
7
+ PARSED_TIME = "2014-02-10 17:32:25.612979500"
8
+
9
+ def setup
10
+ Fluent::Test.setup
11
+ @time = Fluent::Engine.now
12
+ end
13
+
14
+ def create_driver(conf)
15
+ Fluent::Test::FilterTestDriver.new(
16
+ Fluent::Tai64nParserFilter
17
+ ).configure(conf)
18
+ end
19
+
20
+ def filter(config, msgs)
21
+ d = create_driver(config)
22
+ d.run {
23
+ msgs.each {|msg|
24
+ d.filter(msg, @time)
25
+ }
26
+ }
27
+ filtered = d.filtered_as_array
28
+ filtered.map {|m| m[2] }
29
+ end
30
+
31
+ def test_configure
32
+ d = create_driver(%[
33
+ key test
34
+ output_key parsed_time
35
+ ])
36
+ assert_equal 'test', d.instance.key
37
+ assert_equal 'parsed_time', d.instance.output_key
38
+
39
+ #Default Key
40
+ d = create_driver(%[
41
+ ])
42
+ assert_equal 'tai64n', d.instance.key
43
+ assert_equal 'tai64n', d.instance.output_key
44
+ end
45
+
46
+ def test_filter
47
+ d = create_driver(%[
48
+ key tai64n
49
+ output_key parsed_time
50
+ ])
51
+ record = {'tai64n' => TAI64N_TIME}
52
+ d.run { d.filter(record, @time) }
53
+
54
+ filtered_record = d.filtered_as_array.first[2]
55
+ assert_equal PARSED_TIME, filtered_record['parsed_time']
56
+ end
57
+
58
+ end if defined?(Fluent::Filter)
@@ -1,11 +1,10 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'test_helper'
1
+ require_relative '../test_helper'
2
+ require 'fluent/plugin/out_tai64n_parser'
3
3
 
4
4
  class Tai64nParserOutputTest < Test::Unit::TestCase
5
5
 
6
6
  TAI64N_TIME = "@4000000052f88ea32489532c"
7
7
  PARSED_TIME = "2014-02-10 17:32:25.612979500"
8
- BAD_TAI64N_TIME = "4000000052f88ea32489"
9
8
 
10
9
  def setup
11
10
  Fluent::Test.setup
@@ -50,23 +49,6 @@ class Tai64nParserOutputTest < Test::Unit::TestCase
50
49
  assert_equal record['parsed_time'], '2014-02-10 17:32:25.612979500'
51
50
  end
52
51
 
53
- def test_filter_record_bad_parameters
54
- d = create_driver(%[
55
- key tai64n
56
- output_key parsed_time
57
- add_tag_prefix parsed.
58
- ])
59
- tag = 'test'
60
- record = {'tai64n' => BAD_TAI64N_TIME}
61
-
62
- d.instance.filter_record('test', Time.now, record)
63
- assert_equal record['parsed_time'], BAD_TAI64N_TIME
64
-
65
- record = {'tai64n' => "this is not a date"}
66
- d.instance.filter_record('test', Time.now, record)
67
- assert_equal record['parsed_time'], "this is not a date"
68
- end
69
-
70
52
  def test_emit
71
53
  d = create_driver(%[
72
54
  key tai64n
@@ -103,34 +85,4 @@ class Tai64nParserOutputTest < Test::Unit::TestCase
103
85
  end
104
86
  end
105
87
 
106
- def test_emit_with_invalid_tai64n
107
- d = create_driver(%[
108
- key tai64n
109
- output_key parsed_time
110
- add_tag_prefix parsed.
111
- ])
112
- wrong_time = 'wrong time'
113
- d.run { d.emit('tai64n' => wrong_time) }
114
- emits = d.emits
115
-
116
- assert_equal 1, emits.count
117
- assert_equal 'parsed.test', emits[0][0]
118
- assert_equal wrong_time, emits[0][2]['tai64n']
119
- end
120
-
121
- def test_emit_with_replace
122
- d = create_driver(%[
123
- key message
124
- parsed_time_tag message
125
- add_tag_prefix parsed.
126
- ])
127
-
128
- d.run { d.emit('message' => "#{TAI64N_TIME}foobar") }
129
- emits = d.emits
130
-
131
- assert_equal 1, emits.count
132
- assert_equal 'parsed.test', emits[0][0]
133
- assert_equal "#{PARSED_TIME}foobar", emits[0][2]['message']
134
- end
135
-
136
88
  end
@@ -0,0 +1,38 @@
1
+ require_relative '../test_helper'
2
+ require 'fluent/plugin/tai64n_parser_mixin'
3
+ require 'logger'
4
+
5
+ class Tai64nParserTest < Test::Unit::TestCase
6
+
7
+ class Tai64nParser
8
+ include Fluent::Tai64nParserMixin
9
+
10
+ def log
11
+ @log ||= Logger.new(logdev)
12
+ end
13
+
14
+ def logdev
15
+ @logdev ||= StringIO.new
16
+ end
17
+
18
+ def key
19
+ 'foo'
20
+ end
21
+ end
22
+
23
+ def parser
24
+ @parser ||= Tai64nParser.new
25
+ end
26
+
27
+ def test_try_replace_tai64n
28
+ good_tai64n = "@4000000052f88ea32489532c"
29
+ expected_time = "2014-02-10 17:32:25.612979500"
30
+ assert_equal expected_time, parser.try_replace_tai64n(good_tai64n)
31
+ assert_equal "#{expected_time} foo", parser.try_replace_tai64n("#{good_tai64n} foo")
32
+
33
+ bad_tai64n = "4000000052f88ea32489"
34
+ assert_equal bad_tai64n, parser.try_replace_tai64n(bad_tai64n)
35
+ assert_true parser.logdev.tap {|d| d.rewind }.read.include?('does not start with valid tai64n')
36
+ end
37
+
38
+ end
@@ -15,7 +15,5 @@ unless ENV.has_key?('VERBOSE')
15
15
  $log = nulllogger
16
16
  end
17
17
 
18
- require 'fluent/plugin/out_tai64n_parser'
19
-
20
18
  class Test::Unit::TestCase
21
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-tai64n_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Maeda
@@ -9,62 +9,48 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-19 00:00:00.000000000 Z
12
+ date: 2016-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rake
15
+ name: fluentd
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
- type: :development
21
+ type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: fluentd
29
+ name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: test-unit
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: fluentd
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - '>='
53
+ - - ">="
68
54
  - !ruby/object:Gem::Version
69
55
  version: '0'
70
56
  description: Fluentd plugin to parse the tai64n format log.
@@ -75,15 +61,22 @@ executables: []
75
61
  extensions: []
76
62
  extra_rdoc_files: []
77
63
  files:
78
- - .gitignore
79
- - .travis.yml
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - CHANGELOG.md
80
67
  - Gemfile
68
+ - Gemfile.fluentd.v0.10
69
+ - Gemfile.fluentd.v0.12
81
70
  - LICENSE
82
71
  - README.md
83
72
  - Rakefile
84
73
  - fluent-plugin-tai64n_parser.gemspec
74
+ - lib/fluent/plugin/filter_tai64n_parser.rb
85
75
  - lib/fluent/plugin/out_tai64n_parser.rb
76
+ - lib/fluent/plugin/tai64n_parser_mixin.rb
77
+ - test/plugin/test_filter_tai64n_parser.rb
86
78
  - test/plugin/test_out_tai64n_parser.rb
79
+ - test/plugin/test_tai64n_parser_mixin.rb
87
80
  - test/test_helper.rb
88
81
  homepage: https://github.com/glidenote/fluent-plugin-tai64n_parser
89
82
  licenses: []
@@ -94,20 +87,22 @@ require_paths:
94
87
  - lib
95
88
  required_ruby_version: !ruby/object:Gem::Requirement
96
89
  requirements:
97
- - - '>='
90
+ - - ">="
98
91
  - !ruby/object:Gem::Version
99
92
  version: '0'
100
93
  required_rubygems_version: !ruby/object:Gem::Requirement
101
94
  requirements:
102
- - - '>='
95
+ - - ">="
103
96
  - !ruby/object:Gem::Version
104
97
  version: '0'
105
98
  requirements: []
106
99
  rubyforge_project:
107
- rubygems_version: 2.0.14
100
+ rubygems_version: 2.5.1
108
101
  signing_key:
109
102
  specification_version: 4
110
103
  summary: Fluentd plugin to parse the tai64n format log.
111
104
  test_files:
105
+ - test/plugin/test_filter_tai64n_parser.rb
112
106
  - test/plugin/test_out_tai64n_parser.rb
107
+ - test/plugin/test_tai64n_parser_mixin.rb
113
108
  - test/test_helper.rb