fluent-plugin-elasticsearch-timestamp-check 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dddb0ad42d2491532c832ae7d7e1a447c65431cd
4
- data.tar.gz: 09b846178a4d199a69cced307fc4b9a489c790f7
3
+ metadata.gz: 5cd7b06f7edb4ce3f72d1c6dccf21929046ceb51
4
+ data.tar.gz: 9ef81ffc2b011bd4e8a06fbdf66b38562c59711f
5
5
  SHA512:
6
- metadata.gz: 1d0d3fcb7ff42f8da5c38e3c2fc264a09de5a42178af961a06ed83c817608e08dfce337b1eea453c6a0ffcc1a87602536e9bdafaf9844ba0ec1d330e1427a3b2
7
- data.tar.gz: 92fd025a3111678ea4d6351e0d1707f5eb6a85c585662fdfc32888033bf494640455c7ab9d657014d0c4d92a1c8eececdd155c71c5391e62dc4cc3f4d4548653
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.5"
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('%Y-%m-%dT%H:%M:%S.%L%z')
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('%Y-%m-%dT%H:%M:%S.%L%z')
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('%Y-%m-%dT%H:%M:%S.%L%z')
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.%L%z')
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.5
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: 2017-09-20 00:00:00.000000000 Z
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.2.5
111
+ rubygems_version: 2.6.14
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: fluent timestamp checker filter