fluent-plugin-elasticsearch-timestamp-check 0.2.5 → 0.2.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cd7b06f7edb4ce3f72d1c6dccf21929046ceb51
|
4
|
+
data.tar.gz: 9ef81ffc2b011bd4e8a06fbdf66b38562c59711f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a091f77db169760a13a1838c2d6e2a68b50f97274902f4506b467568f3c279f9b5e0763be181a9259ff7a5051a0ffd9ae8db5e06ef08534d85f20ecaa09a5fe8
|
7
|
+
data.tar.gz: 0da8c759f7c0d29b5970ccd0d3c06ac2317e2d411cd159321c178cea88bd8e9c538b80442a7c8cf83a9cf7b903ba9620bf43b28a83126cdf89e0bf0e8f45ea08
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "fluent-plugin-elasticsearch-timestamp-check"
|
3
|
-
spec.version = "0.2.
|
3
|
+
spec.version = "0.2.6"
|
4
4
|
spec.authors = ["Richard Li"]
|
5
5
|
spec.email = ["evilcat@wisewolfsolutions.com"]
|
6
6
|
spec.description = %q{fluent filter plugin to ensure @timestamp is in proper format}
|
@@ -4,9 +4,13 @@ module Fluent::Plugin
|
|
4
4
|
class ElasticsearchTimestampCheckFilter < Filter
|
5
5
|
Fluent::Plugin.register_filter('elasticsearch_timestamp_check', self)
|
6
6
|
|
7
|
+
config_param :subsecond_precision, :integer, default: 3
|
8
|
+
|
7
9
|
def configure(conf)
|
8
10
|
super
|
9
11
|
require 'date'
|
12
|
+
raise Fluent::ConfigError, "specify 1 or bigger number." if subsecond_precision < 1
|
13
|
+
@strftime_format = "%Y-%m-%dT%H:%M:%S.%#{@subsecond_precision}N%z".freeze
|
10
14
|
end
|
11
15
|
|
12
16
|
def start
|
@@ -32,13 +36,13 @@ module Fluent::Plugin
|
|
32
36
|
record['@timestamp'] = record['fluent_converted_timestamp'] =
|
33
37
|
Time.at(
|
34
38
|
num / (10 ** ((Math.log10(num).to_i + 1) - 10))
|
35
|
-
).strftime(
|
39
|
+
).strftime(@strftime_format)
|
36
40
|
break
|
37
41
|
end
|
38
42
|
|
39
43
|
# normal timestamp string processing
|
40
44
|
record['@timestamp'] = record['fluent_converted_timestamp'] =
|
41
|
-
DateTime.parse(timestamp).strftime(
|
45
|
+
DateTime.parse(timestamp).strftime(@strftime_format)
|
42
46
|
$log.debug("Timestamp parsed: #{record['@timestamp']}")
|
43
47
|
break
|
44
48
|
rescue ArgumentError
|
@@ -47,7 +51,7 @@ module Fluent::Plugin
|
|
47
51
|
|
48
52
|
unless record['fluent_converted_timestamp']
|
49
53
|
record['@timestamp'] = record['fluent_added_timestamp'] =
|
50
|
-
Time.now.strftime(
|
54
|
+
Time.now.strftime(@strftime_format)
|
51
55
|
$log.debug("Timestamp added: #{record['@timestamp']}")
|
52
56
|
end
|
53
57
|
|
@@ -9,6 +9,18 @@ class TestElasticsearchTimestampCheckFilter < Test::Unit::TestCase
|
|
9
9
|
Fluent::Test::Driver::Filter.new(Fluent::Plugin::ElasticsearchTimestampCheckFilter).configure(conf)
|
10
10
|
end
|
11
11
|
|
12
|
+
def test_configure
|
13
|
+
assert_raise(Fluent::ConfigError) do
|
14
|
+
create_driver(%[subsecond_precision -3])
|
15
|
+
end
|
16
|
+
assert_raise(Fluent::ConfigError) do
|
17
|
+
create_driver(%[subsecond_precision 0])
|
18
|
+
end
|
19
|
+
assert_nothing_raised do
|
20
|
+
create_driver(%[subsecond_precision 1])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
12
24
|
def test_added_timestamp
|
13
25
|
d = create_driver
|
14
26
|
d.run(default_tag: 'test') do
|
@@ -51,7 +63,29 @@ class TestElasticsearchTimestampCheckFilter < Test::Unit::TestCase
|
|
51
63
|
num = timestamp.to_f
|
52
64
|
formatted_time = Time.at(
|
53
65
|
num / (10 ** ((Math.log10(num).to_i + 1) - 10))
|
54
|
-
).strftime('%Y-%m-%dT%H:%M:%S.%
|
66
|
+
).strftime('%Y-%m-%dT%H:%M:%S.%3N%z')
|
67
|
+
assert_true(filtered.key?("@timestamp"))
|
68
|
+
assert_true(filtered.key?("fluent_converted_timestamp"))
|
69
|
+
assert_equal(formatted_time, filtered["fluent_converted_timestamp"])
|
70
|
+
end
|
71
|
+
|
72
|
+
data('@timestamp' => '@timestamp',
|
73
|
+
'timestamp' => 'timestamp',
|
74
|
+
'time' => 'time',
|
75
|
+
'syslog_timestamp' => 'syslog_timestamp')
|
76
|
+
def test_timestamp_with_digit_and_nano_precision(data)
|
77
|
+
timekey = data
|
78
|
+
precision = 9
|
79
|
+
d = create_driver(%[subsecond_precision #{precision}])
|
80
|
+
timestamp = '1505800348899'
|
81
|
+
d.run(default_tag: 'test') do
|
82
|
+
d.feed({'test' => 'notime'}.merge(timekey => timestamp))
|
83
|
+
end
|
84
|
+
filtered = d.filtered.map{|e| e.last}.first
|
85
|
+
num = timestamp.to_f
|
86
|
+
formatted_time = Time.at(
|
87
|
+
num / (10 ** ((Math.log10(num).to_i + 1) - 10))
|
88
|
+
).strftime("%Y-%m-%dT%H:%M:%S.%#{precision}N%z")
|
55
89
|
assert_true(filtered.key?("@timestamp"))
|
56
90
|
assert_true(filtered.key?("fluent_converted_timestamp"))
|
57
91
|
assert_equal(formatted_time, filtered["fluent_converted_timestamp"])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-elasticsearch-timestamp-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.6.14
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: fluent timestamp checker filter
|