fluent-plugin-parser 0.3.2 → 0.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
  SHA1:
3
- metadata.gz: 77aa844930416c72ecbe0f6836c6550b2fd6b822
4
- data.tar.gz: e1c0b6119d98cd6c2e61cbc45eaeda94326116cb
3
+ metadata.gz: 2326d0682f48ee2aa993c41114c4b6135cf610e5
4
+ data.tar.gz: aa40d1f259c0781492004e21a79c64118d5ae2cf
5
5
  SHA512:
6
- metadata.gz: 44b28f43b84125697f69596c1d308db160c3488b2a599ad150dd3bcdd9cf2c0f69d226bf86099baa13c7e18bd1c2399eac0180cb9c72dad340759b8cfc1596a4
7
- data.tar.gz: 3e547b358059d88f59a1484d44e27164043d52fc4f0d3e2254ffbd5f38e61e517206e3bd8eedc79db3e1caf691526f383bf987583ba96cdf018b0025c0bf18ad
6
+ metadata.gz: 10d523349d0c40468ce83b886e74bcbb2d89d3138cf36d09858c3302d398d67b0114e8b1693407b8fcc774ea9b2114d3b94cc8d560fcd4045a885f62f15d598b
7
+ data.tar.gz: cc0a2694b738d268faff7bdf3d7da786da0ffd785662ff130da252aa18b3c1cf0e6931b5417dae4047cae5ef5ee34b60163fbf6da26f505f60a6acbb2543aa3f
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-parser"
4
- gem.version = "0.3.2"
4
+ gem.version = "0.3.3"
5
5
  gem.authors = ["TAGOMORI Satoshi"]
6
6
  gem.email = ["tagomoris@gmail.com"]
7
7
  gem.description = %q{fluentd plugin to parse single field, or to combine log structure into single field}
@@ -11,6 +11,11 @@ class FluentExt::TextParser
11
11
  config_param :time_format, :string, :default => nil
12
12
  config_param :time_parse, :bool, :default => true
13
13
 
14
+ @cache1_key = nil
15
+ @cache1_time = nil
16
+ @cache2_key = nil
17
+ @cache2_time = nil
18
+
14
19
  def parse_time(record)
15
20
  time = nil
16
21
 
@@ -19,15 +24,25 @@ class FluentExt::TextParser
19
24
  end
20
25
 
21
26
  if value = record.delete(@time_key)
22
- begin
23
- time = if @time_format
24
- Time.strptime(value, @time_format).to_i
25
- else
26
- Time.parse(value).to_i
27
- end
28
- rescue TypeError, ArgumentError => e
29
- $log.warn "Failed to parse time", :key => @time_key, :value => value
30
- record[@time_key] = value
27
+ if @cache1_key == value
28
+ time = @cache1_time
29
+ elsif @cache2_key == value
30
+ time = @cache2_time
31
+ else
32
+ begin
33
+ time = if @time_format
34
+ Time.strptime(value, @time_format).to_i
35
+ else
36
+ Time.parse(value).to_i
37
+ end
38
+ @cache1_key = @cache2_key
39
+ @cache1_time = @cache2_time
40
+ @cache2_key = value
41
+ @cache2_time = time
42
+ rescue TypeError, ArgumentError => e
43
+ $log.warn "Failed to parse time", :key => @time_key, :value => value
44
+ record[@time_key] = value
45
+ end
31
46
  end
32
47
  end
33
48
 
@@ -112,9 +112,12 @@ class ParserOutputTest < Test::Unit::TestCase
112
112
  d1.run do
113
113
  d1.emit({'message' => '12 20120402182059'}, time)
114
114
  d1.emit({'message' => '34 20120402182100'}, time)
115
+ d1.emit({'message' => '56 20120402182100'}, time)
116
+ d1.emit({'message' => '78 20120402182101'}, time)
117
+ d1.emit({'message' => '90 20120402182100'}, time)
115
118
  end
116
119
  emits = d1.emits
117
- assert_equal 2, emits.length
120
+ assert_equal 5, emits.length
118
121
 
119
122
  first = emits[0]
120
123
  assert_equal 'parsed.in', first[0]
@@ -129,6 +132,24 @@ class ParserOutputTest < Test::Unit::TestCase
129
132
  assert_equal '3', second[2]['x']
130
133
  assert_equal '4', second[2]['y']
131
134
 
135
+ third = emits[2]
136
+ assert_equal 'parsed.in', third[0]
137
+ assert_equal Time.parse("2012-04-02 18:21:00").to_i, third[1]
138
+ assert_equal '5', third[2]['x']
139
+ assert_equal '6', third[2]['y']
140
+
141
+ fourth = emits[3]
142
+ assert_equal 'parsed.in', fourth[0]
143
+ assert_equal Time.parse("2012-04-02 18:21:01").to_i, fourth[1]
144
+ assert_equal '7', fourth[2]['x']
145
+ assert_equal '8', fourth[2]['y']
146
+
147
+ fifth = emits[4]
148
+ assert_equal 'parsed.in', fifth[0]
149
+ assert_equal Time.parse("2012-04-02 18:21:00").to_i, fifth[1]
150
+ assert_equal '9', fifth[2]['x']
151
+ assert_equal '0', fifth[2]['y']
152
+
132
153
  d2 = create_driver(%[
133
154
  tag parsed
134
155
  key_name data
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake