fluent-plugin-timestamper 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6af72ca1bbf8a29b8ff8497ef45a6113774cb92
4
+ data.tar.gz: 6c81a92960780aa22c39e22cd8e5f45262568bbe
5
+ SHA512:
6
+ metadata.gz: 34a3fe22d05f26f268095a865d2baee9095e561cc9653412656c996b79e2cb06d0ef0c5d571f700c9ee02bc470bc8d825c050d3c8b87708af84278c8a9468eb1
7
+ data.tar.gz: 5cadededb4609aca79fb2d9f4d71d1786b94939cef206ea82d19d6787bb9ff8ea441b6f5fb9a9cb011ad540e97e383c70681e938ee4fa50561d64476ab436be0
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-timestamper.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Masaki Matsushita
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # fluent-plugin-timestamper
2
+
3
+ Fluentd output plugin which adds timestamp field to record.
4
+ Timestamp format can be seconds and milliseconds from epoch, iso8601 and you can also use strftime() format.
5
+
6
+ ## Installation
7
+
8
+ $ gem install fluent-plugin-timestamper
9
+
10
+ ## Usage
11
+
12
+ Put your configuration in /etc/fluent/fluent.conf
13
+
14
+ ```xml:fluent.conf
15
+ <match foo>
16
+ type timestamper
17
+ tag tag.to.rewrite
18
+ key name_of_key
19
+ format milliseconds # or "seconds", "iso8601", "%Y-%m-%d"
20
+ </match>
21
+ ```
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/fluent-plugin-timestamper/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,23 @@
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-timestamper"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Masaki Matsushita"]
9
+ spec.email = ["glass.saga@gmail.com"]
10
+ spec.summary = %q{Fluentd output plugin which adds timestamp field to record in various formats.}
11
+ spec.homepage = "https://github.com/Glasssaga/fluent-plugin-timestamper"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.7"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "timecop"
22
+ spec.add_runtime_dependency "fluentd"
23
+ end
@@ -0,0 +1,34 @@
1
+ module Fluent
2
+ class Timestamper < Output
3
+ Fluent::Plugin.register_output('timestamper', self)
4
+
5
+ config_param :tag, :string
6
+ config_param :key, :string
7
+ config_param :format, :string
8
+
9
+ def configure(conf)
10
+ super
11
+ end
12
+
13
+ def emit(tag, es, chain)
14
+ now = Time.now
15
+
16
+ es.each do |time, record|
17
+ case @format
18
+ when "seconds"
19
+ record[@key] = now.to_i
20
+ when "milliseconds"
21
+ record[@key] = (now.to_i * 1000) + (now.usec / 1000.0).round
22
+ when "iso8601"
23
+ record[@key] = now.iso8601
24
+ else
25
+ record[@key] = now.strftime(@format)
26
+ end
27
+
28
+ Fluent::Engine.emit(@tag, time, record)
29
+ end
30
+
31
+ chain.next
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ require 'bundler'
2
+
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_timestamper'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,79 @@
1
+ require 'helper'
2
+ require 'timecop'
3
+
4
+ class TimestamperOutputTest < Test::Unit::TestCase
5
+ def setup
6
+ @time = Time.parse("2011-01-02 13:14:15 UTC")
7
+ @tag = "foo"
8
+ @key = "timestamp"
9
+ Timecop.freeze(@time)
10
+ Fluent::Test.setup
11
+ end
12
+
13
+ def create_driver(conf, tag='test')
14
+ Fluent::Test::OutputTestDriver.new(Fluent::Timestamper, tag).configure(conf)
15
+ end
16
+
17
+ def test_format_seconds
18
+ d = create_driver %[
19
+ tag #{@tag}
20
+ key #{@key}
21
+ format seconds
22
+ ]
23
+
24
+ seconds = @time.to_i
25
+ timestamp = pick_timestamp(d)
26
+ assert_equal seconds, timestamp
27
+ end
28
+
29
+ def test_format_milliseconds
30
+ d = create_driver %[
31
+ tag #{@tag}
32
+ key #{@key}
33
+ format milliseconds
34
+ ]
35
+
36
+ milliseconds = (@time.to_i * 1000) + (@time.usec / 1000.0).round
37
+ timestamp = pick_timestamp(d)
38
+ assert_equal milliseconds, timestamp
39
+ end
40
+
41
+ def test_format_iso8601
42
+ d = create_driver %[
43
+ tag #{@tag}
44
+ key #{@key}
45
+ format iso8601
46
+ ]
47
+
48
+ iso8601 = Time.now.iso8601
49
+ timestamp = pick_timestamp(d)
50
+ assert_equal iso8601, timestamp
51
+ end
52
+
53
+ def test_format_strftime
54
+ d = create_driver %[
55
+ tag #{@tag}
56
+ key #{@key}
57
+ format %X
58
+ ]
59
+
60
+ formatted = Time.now.strftime("%X")
61
+ timestamp = pick_timestamp(d)
62
+ assert_equal formatted, timestamp
63
+ end
64
+
65
+ private
66
+
67
+ def pick_timestamp(d)
68
+ d.run do
69
+ d.emit({"a"=>1}, @time.to_i)
70
+ end
71
+
72
+ record = d.emits.first.last
73
+ return record[@key]
74
+ end
75
+
76
+ def teardown
77
+ Timecop.return
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-timestamper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masaki Matsushita
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: timecop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fluentd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - glass.saga@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - fluent-plugin-timestamper.gemspec
82
+ - lib/fluent/plugin/out_timestamper.rb
83
+ - test/helper.rb
84
+ - test/plugin/test_out_timestamper.rb
85
+ homepage: https://github.com/Glasssaga/fluent-plugin-timestamper
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.4
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Fluentd output plugin which adds timestamp field to record in various formats.
109
+ test_files:
110
+ - test/helper.rb
111
+ - test/plugin/test_out_timestamper.rb