fluent-plugin-time_parser 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## Component
4
4
  TimeParserOutput
5
5
 
6
- Based on the great extract-query-params plugin by @Kentaro (https://github.com/kentaro/fluent-plugin-extract_query_params).
6
+ Based on the great extract-query-params plugin by [@Kentaro](https://github.com/kentaro/fluent-plugin-extract_query_params).
7
7
  Will take a time attribute and will extract the date and the hour for a given time zone.
8
8
 
9
9
  ## wat?!
@@ -14,7 +14,7 @@ Will take a time attribute and will extract the date and the hour for a given ti
14
14
 
15
15
  key time
16
16
  add_tag_prefix extracted.
17
- time_zone Tokyo
17
+ time_zone Asia/Tokyo
18
18
  </match>
19
19
  ```
20
20
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'fluent-plugin-time_parser'
3
- gem.version = '0.0.2'
3
+ gem.version = '0.0.3'
4
4
  gem.authors = ['Carlos Donderis']
5
5
  gem.email = ['cdonderis@gmail.com']
6
6
  gem.homepage = 'http://github.com/cads/fluent-plugin-time_parser'
@@ -8,6 +8,9 @@ module Fluent
8
8
 
9
9
  config_param :key, :string, :default => 'time'
10
10
  config_param :time_zone, :string
11
+ config_param :parsed_time_tag, :string, :default => 'parsed_time'
12
+ config_param :parsed_hour_tag, :string, :default => 'parsed_hour'
13
+ config_param :parsed_date_tag, :string, :default => 'parsed_date'
11
14
 
12
15
  def configure(conf)
13
16
  super
@@ -41,21 +44,27 @@ module Fluent
41
44
 
42
45
  def filter_record(tag, time, record)
43
46
  begin
44
- original_time = Time.parse(record[key])
47
+ original_time = DateTime.parse(record[key])
45
48
  tz = TZInfo::Timezone.get(time_zone.capitalize)
46
49
 
47
- converted_time = tz.utc_to_local(original_time)
50
+ period = tz.period_for_utc(original_time)
51
+ rational_offset = period.utc_total_offset_rational
52
+
53
+ converted_time = tz.utc_to_local(original_time).new_offset(rational_offset) -
54
+ period.utc_total_offset_rational
48
55
 
49
56
  date = converted_time.to_date.to_s
50
57
  hour = converted_time.hour.to_s
51
- record['date'] = date
52
- record['hour'] = hour
58
+
59
+ record[parsed_time_tag] = converted_time.to_s
60
+ record[parsed_date_tag] = date
61
+ record[parsed_hour_tag] = hour
62
+
53
63
  rescue ArgumentError => error
54
64
  $log.warn("out_extract_query_params: #{error.message}")
55
65
  rescue TZInfo::InvalidTimezoneIdentifier
56
66
  $log.warn("Timezone Not Valid, please refer to http://tzinfo.rubyforge.org/doc/classes/TZInfo/Timezone.html for valid timezones")
57
67
  end
58
-
59
68
  super(tag, time, record)
60
69
  end
61
70
  end
@@ -6,6 +6,7 @@ require 'tzinfo'
6
6
  class TimeParserOutputTest < Test::Unit::TestCase
7
7
 
8
8
  TIME = "2013-04-14T06:14:36Z"
9
+ GIRIGIRI_TIME = "2013-04-14T15:14:36Z"
9
10
 
10
11
  def setup
11
12
  Fluent::Test.setup
@@ -60,11 +61,25 @@ class TimeParserOutputTest < Test::Unit::TestCase
60
61
  tag = 'test'
61
62
  record = {'time' => TIME}
62
63
  d.instance.filter_record('test', Time.now, record)
63
- tz = TZInfo::Timezone.get('Japan')
64
- converted_time = tz.utc_to_local(Time.parse(TIME))
65
64
 
66
- assert_equal record['date'], converted_time.to_date.to_s
67
- assert_equal record['hour'], converted_time.hour.to_s
65
+ assert_equal record['parsed_time'], "2013-04-14T15:14:36+09:00"
66
+ assert_equal record['parsed_date'], "2013-04-14"
67
+ assert_equal record['parsed_hour'], "15"
68
+ end
69
+
70
+ def test_girigiri_records
71
+ d = create_driver(%[
72
+ key time
73
+ add_tag_prefix extracted.
74
+ time_zone Japan
75
+ ])
76
+ tag = 'test'
77
+ record = {'time' => GIRIGIRI_TIME}
78
+ d.instance.filter_record('test', Time.now, record)
79
+
80
+ assert_equal record['parsed_time'], "2013-04-15T00:14:36+09:00"
81
+ assert_equal record['parsed_date'], "2013-04-15"
82
+ assert_equal record['parsed_hour'], "0"
68
83
  end
69
84
 
70
85
  def test_filter_record_bad_parameters
@@ -77,13 +92,15 @@ class TimeParserOutputTest < Test::Unit::TestCase
77
92
  record = {'time' => TIME}
78
93
 
79
94
  d.instance.filter_record('test', Time.now, record)
80
- assert_equal record['date'], nil
81
- assert_equal record['hour'], nil
95
+ assert_equal record['parsed_time'], nil
96
+ assert_equal record['parsed_date'], nil
97
+ assert_equal record['parsed_hour'], nil
82
98
 
83
99
  record = {'time' => "this is not a date"}
84
100
  d.instance.filter_record('test', Time.now, record)
85
- assert_equal record['date'], nil
86
- assert_equal record['hour'], nil
101
+ assert_equal record['parsed_time'], nil
102
+ assert_equal record['parsed_date'], nil
103
+ assert_equal record['parsed_hour'], nil
87
104
  end
88
105
 
89
106
  def test_emit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-time_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-01 00:00:00.000000000 Z
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70338037769140 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70338037769140
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: fluentd
27
- requirement: &70338037768700 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70338037768700
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: tzinfo
38
- requirement: &70338037768280 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70338037768280
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: tzinfo
49
- requirement: &70338037784180 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *70338037784180
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: fluentd
60
- requirement: &70338037783740 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '0'
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *70338037783740
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description: Fluentd plugin to parse the time parameter.
70
95
  email:
71
96
  - cdonderis@gmail.com
@@ -102,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
127
  version: '0'
103
128
  requirements: []
104
129
  rubyforge_project:
105
- rubygems_version: 1.8.11
130
+ rubygems_version: 1.8.25
106
131
  signing_key:
107
132
  specification_version: 3
108
133
  summary: Fluentd plugin to parse the time parameter.