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

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: caf11889f096c3937908340a59ff69af610e80a9
4
- data.tar.gz: 5fec5fb248ae90cae895942b8d1fb6544e5a233c
3
+ metadata.gz: dddb0ad42d2491532c832ae7d7e1a447c65431cd
4
+ data.tar.gz: 09b846178a4d199a69cced307fc4b9a489c790f7
5
5
  SHA512:
6
- metadata.gz: 4904d97b3143926d00c313bef06a1e3e2f79413f6c867ca2e3cde2bbbf6db46b68960bab98abd0e28c702e849377bd15b5ee2c56a0c5640ece68f77204138c6d
7
- data.tar.gz: 3d3e8575835bdb4a9d9e28e70c9abbb7a58ea8cee7a6fc0e97dff92b3ecfb09afd728c928a47b3dbd115d54a5661e1a821ec55ef9c603169a3d2dae7d30bae76
6
+ metadata.gz: 1d0d3fcb7ff42f8da5c38e3c2fc264a09de5a42178af961a06ed83c817608e08dfce337b1eea453c6a0ffcc1a87602536e9bdafaf9844ba0ec1d330e1427a3b2
7
+ data.tar.gz: 92fd025a3111678ea4d6351e0d1707f5eb6a85c585662fdfc32888033bf494640455c7ab9d657014d0c4d92a1c8eececdd155c71c5391e62dc4cc3f4d4548653
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
data/README.md CHANGED
@@ -14,7 +14,10 @@ record which is necessary for the record to be indexed properly by
14
14
  elasticsearch.
15
15
 
16
16
  * If *@timestamp* field already exists, it will ensure the format is correct
17
- by parse and convert to format '%Y-%m-%dT%H:%M:%S%z'.
17
+ by parse and convert to format '%Y-%m-%dT%H:%M:%S%z'. **As of version 0.2.4, it
18
+ will support epoch second / epoch millis format as a valid timestamp value. If
19
+ such value is detected, it will be converted to iso8601 format for easier
20
+ consumption of elasticsearch when dynamic mapping is used.**
18
21
 
19
22
  * If a field named *timestamp* or *time* or *syslog_timestamp* exists, it will
20
23
  parse that field and conver it to format '%Y-%m-%dT%H:%M:%S%z' then store it
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ test.warning = false
9
+ end
10
+
11
+ task :default => :test
@@ -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.4"
3
+ spec.version = "0.2.5"
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}
@@ -13,5 +13,8 @@ Gem::Specification.new do |spec|
13
13
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
14
  spec.require_paths = ["lib"]
15
15
 
16
+ spec.add_runtime_dependency "fluentd", [">= 0.14.0", "< 2"]
17
+ spec.add_development_dependency "rake", "~> 11.0"
16
18
  spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "test-unit", "~> 3.2"
17
20
  end
@@ -24,14 +24,14 @@ module Fluent::Plugin
24
24
  begin
25
25
  # all digit entry would be treated as epoch seconds or epoch millis
26
26
  if !!(timestamp =~ /\A[-+]?\d+\z/)
27
- num = timestamp.to_i
27
+ num = timestamp.to_f
28
28
  # epoch second or epoch millis should be either 10 or 13 digits
29
29
  # other length should be considered invalid (until the next digit
30
30
  # rollover at 2286-11-20 17:46:40 Z
31
- next unless [10, 13].include?(num.to_s.length)
31
+ next unless [10, 13].include?(Math.log10(num).to_i + 1)
32
32
  record['@timestamp'] = record['fluent_converted_timestamp'] =
33
33
  Time.at(
34
- num / (10 ** (num.to_s.length - 10))
34
+ num / (10 ** ((Math.log10(num).to_i + 1) - 10))
35
35
  ).strftime('%Y-%m-%dT%H:%M:%S.%L%z')
36
36
  break
37
37
  end
data/test/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'fluent/test'
2
+ require 'fluent/test/helpers'
3
+ require 'fluent/test/driver/filter'
4
+ require 'fluent/plugin/filter_elasticsearch_timestamp_check'
5
+
6
+ class Test::Unit::TestCase
7
+ include Fluent::Test::Helpers
8
+ end
@@ -0,0 +1,60 @@
1
+ require 'helper'
2
+
3
+ class TestElasticsearchTimestampCheckFilter < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ def create_driver(conf='')
9
+ Fluent::Test::Driver::Filter.new(Fluent::Plugin::ElasticsearchTimestampCheckFilter).configure(conf)
10
+ end
11
+
12
+ def test_added_timestamp
13
+ d = create_driver
14
+ d.run(default_tag: 'test') do
15
+ d.feed({'test' => 'notime'})
16
+ end
17
+ filtered = d.filtered.map {|e| e.last}.first
18
+ assert_true(filtered.key?("@timestamp"))
19
+ assert_true(filtered.key?("fluent_added_timestamp"))
20
+ end
21
+
22
+ data('@timestamp' => '@timestamp',
23
+ 'timestamp' => 'timestamp',
24
+ 'time' => 'time',
25
+ 'syslog_timestamp' => 'syslog_timestamp')
26
+ def test_timestamp_with_normal(data)
27
+ timekey = data
28
+ d = create_driver
29
+ timestamp = '2017-09-19T14:40:08.321+0900'
30
+ d.run(default_tag: 'test') do
31
+ d.feed({'test' => 'notime'}.merge(timekey => timestamp))
32
+ end
33
+ filtered = d.filtered.map{|e| e.last}.first
34
+ assert_true(filtered.key?("@timestamp"))
35
+ assert_true(filtered.key?("fluent_converted_timestamp"))
36
+ assert_equal(timestamp, filtered["fluent_converted_timestamp"])
37
+ end
38
+
39
+ data('@timestamp' => '@timestamp',
40
+ 'timestamp' => 'timestamp',
41
+ 'time' => 'time',
42
+ 'syslog_timestamp' => 'syslog_timestamp')
43
+ def test_timestamp_with_digit(data)
44
+ timekey = data
45
+ d = create_driver
46
+ timestamp = '1505800348899'
47
+ d.run(default_tag: 'test') do
48
+ d.feed({'test' => 'notime'}.merge(timekey => timestamp))
49
+ end
50
+ filtered = d.filtered.map{|e| e.last}.first
51
+ num = timestamp.to_f
52
+ formatted_time = Time.at(
53
+ num / (10 ** ((Math.log10(num).to_i + 1) - 10))
54
+ ).strftime('%Y-%m-%dT%H:%M:%S.%L%z')
55
+ assert_true(filtered.key?("@timestamp"))
56
+ assert_true(filtered.key?("fluent_converted_timestamp"))
57
+ assert_equal(formatted_time, filtered["fluent_converted_timestamp"])
58
+ end
59
+
60
+ end
metadata CHANGED
@@ -1,15 +1,49 @@
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
4
+ version: 0.2.5
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-06-20 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
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: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '11.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '11.0'
13
47
  - !ruby/object:Gem::Dependency
14
48
  name: bundler
15
49
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +58,20 @@ dependencies:
24
58
  - - "~>"
25
59
  - !ruby/object:Gem::Version
26
60
  version: '1.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: test-unit
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.2'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.2'
27
75
  description: fluent filter plugin to ensure @timestamp is in proper format
28
76
  email:
29
77
  - evilcat@wisewolfsolutions.com
@@ -32,10 +80,14 @@ extensions: []
32
80
  extra_rdoc_files: []
33
81
  files:
34
82
  - ".gitignore"
83
+ - Gemfile
35
84
  - LICENSE
36
85
  - README.md
86
+ - Rakefile
37
87
  - fluent-plugin-elasticsearch-timestamp-check.gemspec
38
88
  - lib/fluent/plugin/filter_elasticsearch_timestamp_check.rb
89
+ - test/helper.rb
90
+ - test/plugin/test_filter_elasticsearch_timestamp_check.rb
39
91
  homepage: https://github.com/ecwws/fluent-plugin-elasticsearch-timestamp-check
40
92
  licenses:
41
93
  - MIT
@@ -56,9 +108,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
108
  version: '0'
57
109
  requirements: []
58
110
  rubyforge_project:
59
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.2.5
60
112
  signing_key:
61
113
  specification_version: 4
62
114
  summary: fluent timestamp checker filter
63
- test_files: []
64
- has_rdoc:
115
+ test_files:
116
+ - test/helper.rb
117
+ - test/plugin/test_filter_elasticsearch_timestamp_check.rb