fluent-plugin-set-timezone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1fb96f5bb40f462f657e71b3f277214685d10071ce664440415526f9de7633ab
4
+ data.tar.gz: da5bf5f19a59f863cfe7d8cbdba3479c2281598dbedc9d67738a11e7417dcd40
5
+ SHA512:
6
+ metadata.gz: 86e4e29fb8f3ae1fc3c6f128b3b4f32a172d2b72b976acbac4b2f7e167e749f990b543d61a2dccab57756899deebab0afd45fee85bea76603c40ad8983db5667
7
+ data.tar.gz: 66c41d124f7c7db34cdbd902a72278fe582fddbf95046932a23e782ec4d08dca8b613d338ee33bb503bf7ae2a3e1fce2300cd24426ff5dd0515194205d1b8975
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-set-timezone (0.0.1)
5
+ fluentd (>= 0.14.0, < 2)
6
+ tzinfo-data (>= 0.3.6)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ concurrent-ruby (1.1.8)
12
+ cool.io (1.7.1)
13
+ fluentd (1.12.0)
14
+ bundler
15
+ cool.io (>= 1.4.5, < 2.0.0)
16
+ http_parser.rb (>= 0.5.1, < 0.7.0)
17
+ msgpack (>= 1.3.1, < 2.0.0)
18
+ serverengine (>= 2.2.2, < 3.0.0)
19
+ sigdump (~> 0.2.2)
20
+ strptime (>= 0.2.2, < 1.0.0)
21
+ tzinfo (>= 1.0, < 3.0)
22
+ tzinfo-data (~> 1.0)
23
+ yajl-ruby (~> 1.0)
24
+ http_parser.rb (0.6.0)
25
+ msgpack (1.4.2)
26
+ power_assert (2.0.0)
27
+ rake (12.3.3)
28
+ serverengine (2.2.2)
29
+ sigdump (~> 0.2.2)
30
+ sigdump (0.2.4)
31
+ strptime (0.2.5)
32
+ test-unit (3.1.9)
33
+ power_assert
34
+ tzinfo (2.0.4)
35
+ concurrent-ruby (~> 1.0)
36
+ tzinfo-data (1.2021.1)
37
+ tzinfo (>= 1.0.0)
38
+ yajl-ruby (1.4.1)
39
+
40
+ PLATFORMS
41
+ x86_64-linux
42
+
43
+ DEPENDENCIES
44
+ bundler
45
+ fluent-plugin-set-timezone!
46
+ rake (~> 12.0)
47
+ test-unit
48
+
49
+ BUNDLED WITH
50
+ 2.2.11
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/**/test_*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => [:test]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-set-timezone"
7
+ spec.description = "Filter plugin for modifying event record"
8
+ spec.homepage = "https://github.com/orbit-online/fluent-plugin-set-timezone"
9
+ spec.summary = spec.description
10
+ spec.version = File.read("VERSION").strip
11
+ spec.authors = ["Anders Ingemann"]
12
+ spec.email = "aim@orbit.online"
13
+ spec.license = 'MIT'
14
+ spec.files = Dir['**/*']
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.add_runtime_dependency "fluentd", ">= 0.14.0", "< 2"
18
+ spec.add_dependency "tzinfo-data", [">= 0.3.6"]
19
+ spec.add_development_dependency "bundler"
20
+ spec.add_development_dependency "rake", "~> 12.0"
21
+ spec.add_development_dependency "test-unit"
22
+ end
@@ -0,0 +1,37 @@
1
+ require 'time'
2
+ require 'tzinfo'
3
+ require 'fluent/plugin/filter'
4
+ require 'fluent/plugin_helper'
5
+
6
+ module Fluent::Plugin
7
+ class SetTimezoneFilter < Filter
8
+ Fluent::Plugin.register_filter('set_timezone', self)
9
+ helpers :record_accessor
10
+
11
+ config_param :timezone_key, :string, :desc => 'The name of the key containing the timezone'
12
+
13
+ def configure(conf)
14
+ super
15
+ if !@timezone_key
16
+ raise Fluent::ConfigError, "timezone_key is required"
17
+ end
18
+ @accessor = record_accessor_create(@timezone_key)
19
+ end
20
+
21
+ def filter_with_time(tag, event_time, record)
22
+ timezone = @accessor.call(record)
23
+ return event_time, record unless timezone and !timezone.empty?
24
+ time = event_time.to_time.utc
25
+ begin
26
+ tz = TZInfo::Timezone.get(timezone)
27
+ adjusted = tz.local_time(time.year, time.month, time.day, time.hour, time.min, time.sec, Rational(time.nsec, 1000000000))
28
+ rescue TZInfo::InvalidTimezoneIdentifier
29
+ offset = Time.zone_offset(timezone)
30
+ raise "Unable to parse timezone '#{timezone}'" unless !offset.nil?
31
+ adjusted = time - offset
32
+ end
33
+
34
+ return Fluent::EventTime.from_time(adjusted), record
35
+ end
36
+ end
37
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/setup"
2
+ require "test-unit"
3
+ require "fluent/test"
4
+ require 'fluent/plugin/filter_set_timezone'
@@ -0,0 +1,79 @@
1
+ # coding: utf-8
2
+ require 'helper'
3
+ require "fluent/test/helpers"
4
+ require "fluent/test/driver/filter"
5
+
6
+ class SetTimezoneFilterTest < Test::Unit::TestCase
7
+
8
+ include Fluent::Test::Helpers
9
+
10
+ def setup
11
+ Fluent::Test.setup
12
+ @log = Logger.new(STDOUT)
13
+ @log.level = Logger::DEBUG
14
+ end
15
+
16
+ CONFIG = %q!
17
+ timezone_key tz
18
+ !
19
+
20
+ def create_driver(conf)
21
+ Fluent::Test::Driver::Filter.new(Fluent::Plugin::SetTimezoneFilter).configure(conf)
22
+ end
23
+
24
+ def create_filter(conf)
25
+ f = Fluent::Plugin::SetTimezoneFilter.new
26
+ f.configure(Fluent::Config.parse(conf, "(test)", "(test_dir)", syntax: :v1))
27
+ f
28
+ end
29
+
30
+ def filter(filter, time, source_zone, offset_diff, tz_overwrite)
31
+ result = filter.filter_with_time('filter.test', event_time("#{time} #{source_zone}"), {'tz' => tz_overwrite})
32
+ expect = event_time("#{time} #{offset_diff}")
33
+ return expect, result[0]
34
+ end
35
+
36
+ sub_test_case 'configured with invalid configuration' do
37
+ test 'empty configuration' do
38
+ assert_raise(Fluent::ConfigError) do
39
+ create_driver('')
40
+ end
41
+ end
42
+ end
43
+
44
+ test 'set to Europe/Copenhagen' do
45
+ f = create_filter(CONFIG)
46
+ assert_equal_event_time(*filter(f, '2016-11-03 15:58:09', 'UTC', '+01:00', 'Europe/Copenhagen'))
47
+ assert_equal_event_time(*filter(f, '2020-10-03 09:45:19', 'UTC', '+02:00', 'Europe/Copenhagen'))
48
+ assert_equal_event_time(*filter(f, '1985-01-15 10:05:01', 'EST', '-04:00', 'Europe/Copenhagen'))
49
+ assert_equal_event_time(*filter(f, '1998-08-15 10:05:01', 'Z', '+02:00', 'CET'))
50
+ end
51
+
52
+ test 'match subsec' do
53
+ f = create_filter(CONFIG)
54
+ assert_equal_event_time(*filter(f, '2016-11-03 15:58:09.00013', 'UTC', '-04:00', 'America/New_York'))
55
+ assert_equal_event_time(*filter(f, '2020-10-03 09:45:19.123', 'UTC', '+02:00', 'Europe/Copenhagen'))
56
+ assert_equal_event_time(*filter(f, '1985-01-15 10:05:01.16548413', 'EST', '-04:00', 'Europe/Copenhagen'))
57
+ end
58
+
59
+ test 'set to offset' do
60
+ f = create_filter(CONFIG)
61
+ assert_equal_event_time(*filter(f, '2016-11-03 15:58:09.016824', 'UTC', '+02:00', '+0200'))
62
+ assert_equal_event_time(*filter(f, '2020-10-03 09:45:19.4882', 'UTC', '-11:30', '-11:30'))
63
+ assert_equal_event_time(*filter(f, '1985-01-15 10:05:01.1357444680', 'EST', '-05:00', 'Z'))
64
+ end
65
+
66
+ test 'return same on no tz' do
67
+ f = create_filter(CONFIG)
68
+ assert_equal_event_time(*filter(f, '2016-11-03 15:58:09.016824', 'UTC', '+00:00', ''))
69
+ assert_equal_event_time(*filter(f, '2016-11-03 15:58:09.016824', 'UTC', '+00:00', nil))
70
+ end
71
+
72
+ test 'fail on invalid tz' do
73
+ assert_raise(RuntimeError.new('Unable to parse timezone \'Sokovia/Novi_Grad\'')) do
74
+ f = create_filter(CONFIG)
75
+ filter(f, '2016-11-03 15:58:09.016824', 'UTC', '+00:00', 'Sokovia/Novi_Grad')
76
+ end
77
+ end
78
+
79
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-set-timezone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anders Ingemann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.14.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.14.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: tzinfo-data
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.3.6
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.3.6
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '12.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '12.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Filter plugin for modifying event record
90
+ email: aim@orbit.online
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - Rakefile
98
+ - VERSION
99
+ - fluent-plugin-set-timezone.gemspec
100
+ - lib/fluent/plugin/filter_set_timezone.rb
101
+ - pkg/fluent-plugin-set-timezone-0.0.1.gem
102
+ - test/helper.rb
103
+ - test/plugin/test_filter_set_timezone.rb
104
+ homepage: https://github.com/orbit-online/fluent-plugin-set-timezone
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.0.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Filter plugin for modifying event record
127
+ test_files: []