Skip to content

Commit 701a6ec

Browse files
committed
Enable millisecond precision for timestamps
Use raw Time.now.to_f instead of Engine.now until fluent/fluentd@c9be93c is merged or fluent/fluentd#461 resolved
1 parent 2c7ecbb commit 701a6ec

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

clean_and_test.sh

100755100644
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
rm Gemfile.lock
22
bundle install
3-
rake
3+
rake

fluent-plugin-logtank-http.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |gem|
44
gem.name = "fluent-plugin-logtank-http"
5-
gem.version = '0.0.4'
5+
gem.version = '0.0.5'
66

77
gem.authors = ["Peter Grman"]
88
gem.email = ["[email protected]"]
@@ -26,4 +26,4 @@ Gem::Specification.new do |gem|
2626

2727
gem.add_development_dependency("rake")
2828
gem.add_development_dependency("simplecov")
29-
end
29+
end

lib/fluent/plugin/in_logtank_http.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ def on_request(path_info, params)
134134

135135
time = if param_time = params['time']
136136
param_time = param_time.to_i
137-
param_time.zero? ? Engine.now : param_time
137+
# Engine.now has only second-precision, use Time.now.to_f to get millisecond precision
138+
# param_time.zero? ? Engine.now : param_time
139+
param_time.zero? ? Time.now.to_f : param_time
138140
else
139-
record_time.nil? ? Engine.now : record_time
141+
# Engine.now has only second-precision, use Time.now.to_f to get millisecond precision
142+
# record_time.nil? ? Engine.now : record_time
143+
record_time.nil? ? Time.now.to_f : record_time
140144
end
141145
rescue
142146
return ["400 Bad Request", {'Content-type'=>'text/plain'}, "400 Bad Request\n#{$!}\n"]

test/plugin/test_in_logtank_http.rb

+20-16
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,26 @@ def test_configure
2929
assert_equal false, d.instance.add_http_headers
3030
end
3131

32-
def test_time
33-
d = create_driver
34-
35-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
36-
Fluent::Engine.now = time
37-
38-
d.expect_emit "tag1", time, {"a"=>1}
39-
d.expect_emit "tag2", time, {"a"=>2}
40-
41-
d.run do
42-
d.expected_emits.each {|tag,time,record|
43-
res = post("/#{tag}", {"json"=>record.to_json})
44-
assert_equal "200", res.code
45-
}
46-
end
47-
end
32+
# TODO: this plugin doesn't use Engine.now because it isn't precise enough.
33+
# Change back to Engine.now and uncomment this test, when
34+
# https://github.com/fluent/fluentd/commit/c9be93cfc5c6905e7b18720709e6c8d835859941
35+
# will be merged or https://github.com/fluent/fluentd/issues/461 resolved
36+
# def test_time
37+
# d = create_driver
38+
39+
# time = Time.parse("2011-01-02 13:14:15 UTC").to_i
40+
# Fluent::Engine.now = time
41+
42+
# d.expect_emit "tag1", time, {"a"=>1}
43+
# d.expect_emit "tag2", time, {"a"=>2}
44+
45+
# d.run do
46+
# d.expected_emits.each {|tag,time,record|
47+
# res = post("/#{tag}", {"json"=>record.to_json})
48+
# assert_equal "200", res.code
49+
# }
50+
# end
51+
# end
4852

4953
def test_json
5054
d = create_driver

0 commit comments

Comments
 (0)