fluent-plugin-better-timestamp-timekey 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/ChangeLog +3 -0
- data/Gemfile +3 -0
- data/README.md +45 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/fluent-plugin-better-timestamp.gemspec +23 -0
- data/lib/fluent/plugin/out_better_timestamp.rb +49 -0
- data/test/out_better_timestamp.rb +42 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d77280f829ab1d3a679b571af8fd882e839840e6
|
4
|
+
data.tar.gz: 1334762f5f1d33684c8c7d1980561e6e79cf644c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 270893a0d605c2f4a5ad681acd9678f27a689b77b4febc428fb28de1be1ee75022adb28fc433f13cfcdad496bfbd6abfcd2fabc2082ce2a7d792e5850cea5d35
|
7
|
+
data.tar.gz: 43540b5dbb8e8e1b649684bd357ba02dc10f28326446cbd54a2e0257257dd78aaec8ee80e54ab5e18d07b601fddd0f7510dda2a1d422bfb4e2ef179ab8fedef0
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/ChangeLog
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
fluent-plugin-better-timestamp
|
2
|
+
==============================
|
3
|
+
|
4
|
+
fluentd plugin to store timestamp with millisecond to elasticsearch
|
5
|
+
|
6
|
+
### fluent-plugin-elasticsearch
|
7
|
+
fluentd uses unixtime as 'time' and fluent-plugin-elasticsearch inserts the 'time' to elasticsearch as @timestamp. Therefore, it's not easy to store more detailed time data like millisec. But fluentd-plugin-elasticsearch provides another way to store timestamp to elasticsearch. if record has '@timestamp', that will be stored in elasticsearh.
|
8
|
+
|
9
|
+
### fluent-plugin-better-timestamp
|
10
|
+
this plugin works as a filter that creates '@timestamp' with proper format from 'time' and one more field which have 'msec' data
|
11
|
+
|
12
|
+
## install
|
13
|
+
```
|
14
|
+
gem install fluent-plugin-better-timestamp
|
15
|
+
```
|
16
|
+
|
17
|
+
### configuration
|
18
|
+
'better-timestamp' plugin has only 3 config parameters
|
19
|
+
|
20
|
+
* tag
|
21
|
+
* msec_key - specifies the key name for msec (default: msec)
|
22
|
+
* timestamp_key - specifies the key name for output (default: @timestamp)
|
23
|
+
|
24
|
+
### example
|
25
|
+
|
26
|
+
```
|
27
|
+
<source>
|
28
|
+
type tail
|
29
|
+
format
|
30
|
+
format /^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).(?<msec>\d{3}) .....
|
31
|
+
...
|
32
|
+
tag log
|
33
|
+
</source>
|
34
|
+
<match log>
|
35
|
+
type better_timestamp
|
36
|
+
tag log.with_msec
|
37
|
+
</match>
|
38
|
+
<match tag log.with_msec>
|
39
|
+
type elasticsearch
|
40
|
+
...
|
41
|
+
</match
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.test_files = FileList['test/*.rb']
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:build]
|
14
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-better-timestamp-timekey"
|
6
|
+
gem.description = "Output filter plugin which put timestamp with configurable time_key"
|
7
|
+
gem.homepage = "https://github.com/spynode/fluent-plugin-better-timestamp"
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.version = File.read("VERSION").strip
|
10
|
+
gem.authors = ["Kenichi Otsuka"]
|
11
|
+
gem.email = "shivaken@gmail.com"
|
12
|
+
gem.has_rdoc = false
|
13
|
+
#gem.platform = Gem::Platform::RUBY
|
14
|
+
gem.license = 'MIT'
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency "fluentd", "~> 0.10.17"
|
21
|
+
gem.add_dependency "fluent-mixin-config-placeholders", ">= 0.3.0"
|
22
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'fluent/mixin/config_placeholders'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
class BetterTimestampOutput < Output
|
5
|
+
Fluent::Plugin.register_output('better_timestamp', self)
|
6
|
+
|
7
|
+
config_param :tag, :string
|
8
|
+
config_param :time_key, :string, :default => 'time'
|
9
|
+
config_param :msec_key, :string, :default => 'msec'
|
10
|
+
config_param :timestamp_key, :string, :default => '@timestamp'
|
11
|
+
|
12
|
+
include SetTagKeyMixin
|
13
|
+
include Fluent::Mixin::ConfigPlaceholders
|
14
|
+
|
15
|
+
BUILTIN_CONFIGURATIONS = %W(type tag timestamp_key msec_key)
|
16
|
+
|
17
|
+
def configure(conf)
|
18
|
+
super
|
19
|
+
|
20
|
+
@map = {}
|
21
|
+
conf.each_pair { |k, v|
|
22
|
+
unless BUILTIN_CONFIGURATIONS.include?(k)
|
23
|
+
conf.has_key?(k)
|
24
|
+
@map[k] = v
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def emit(tag, es, chain)
|
31
|
+
es.each { |time, record|
|
32
|
+
filter_record(tag, time, record)
|
33
|
+
Engine.emit(@tag, time, modify_record(time, record))
|
34
|
+
}
|
35
|
+
|
36
|
+
chain.next
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def modify_record(time, record)
|
42
|
+
if record[@msec_key] then
|
43
|
+
record[@timestamp_key] = Time.at(record[@time_key], record[@msec_key].to_i * 1000).strftime("%Y-%m-%dT%H:%M:%S.%L%z")
|
44
|
+
record.delete(@msec_key)
|
45
|
+
end
|
46
|
+
record
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
require 'fluent/plugin/out_better_timestamp'
|
3
|
+
|
4
|
+
class BetterTimestampOutputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
CONFIG = %[
|
10
|
+
type better_timestamp
|
11
|
+
tag foo.filtered
|
12
|
+
msec_key msec
|
13
|
+
timestamp_key
|
14
|
+
]
|
15
|
+
|
16
|
+
def create_driver(conf = CONFIG)
|
17
|
+
Fluent::Test::OutputTestDriver.new(Fluent::BetterTimestampOutput, tag='test_tag').configure(conf)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_configure
|
21
|
+
d = create_driver
|
22
|
+
map = d.instance.instance_variable_get(:@map)
|
23
|
+
|
24
|
+
#assert_equal 'msec', map['msec_key']
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_remove_one_key
|
28
|
+
d = create_driver %[
|
29
|
+
type record_modifier
|
30
|
+
tag foo.filtered
|
31
|
+
msec_key msec
|
32
|
+
]
|
33
|
+
|
34
|
+
mapped = {}
|
35
|
+
|
36
|
+
d.run do
|
37
|
+
d.emit("msec" => '1', "k1" => 'v')
|
38
|
+
end
|
39
|
+
|
40
|
+
assert d.records[0]['@timestamp']
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-better-timestamp-timekey
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kenichi Otsuka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-25 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.10.17
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.17
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fluent-mixin-config-placeholders
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.2
|
55
|
+
description: Output filter plugin which put timestamp with configurable time_key
|
56
|
+
email: shivaken@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- ChangeLog
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- fluent-plugin-better-timestamp.gemspec
|
68
|
+
- lib/fluent/plugin/out_better_timestamp.rb
|
69
|
+
- pkg/fluent-plugin-better-timestamp-0.1.0.gem
|
70
|
+
- test/out_better_timestamp.rb
|
71
|
+
homepage: https://github.com/spynode/fluent-plugin-better-timestamp
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.5.1
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Output filter plugin which put timestamp with configurable time_key
|
95
|
+
test_files:
|
96
|
+
- test/out_better_timestamp.rb
|