mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
reject invalid UNIX timestamp
This commit is contained in:
parent
f8e00994fe
commit
95abfdebe8
2 changed files with 31 additions and 7 deletions
|
@ -133,14 +133,20 @@ class LogStash::Filters::Date < LogStash::Filters::Base
|
|||
end
|
||||
parser = lambda { |date| joda_parser.parseMillis(date) }
|
||||
when "UNIX" # unix epoch
|
||||
joda_instant = org.joda.time.Instant.java_class.constructor(Java::long).method(:new_instance)
|
||||
#parser = lambda { |date| joda_instant.call((date.to_f * 1000).to_i).to_java.toDateTime }
|
||||
parser = lambda { |date| (date.to_f * 1000).to_i }
|
||||
when "UNIX_MS" # unix epoch in ms
|
||||
joda_instant = org.joda.time.Instant.java_class.constructor(Java::long).method(:new_instance)
|
||||
parser = lambda do |date|
|
||||
#return joda_instant.call(date.to_i).to_java.toDateTime
|
||||
return date.to_i
|
||||
if /\d+/ === date || date.is_a?(Numeric)
|
||||
(date.to_f * 1000).to_i
|
||||
else
|
||||
raise "Invalid UNIX epoch value '#{date}'"
|
||||
end
|
||||
end
|
||||
when "UNIX_MS" # unix epoch in ms
|
||||
parser = lambda do |date|
|
||||
if /\d+/ === date || date.is_a?(Numeric)
|
||||
date.to_i
|
||||
else
|
||||
raise "Invalid UNIX epoch value '#{date}'"
|
||||
end
|
||||
end
|
||||
when "TAI64N" # TAI64 with nanoseconds, -10000 accounts for leap seconds
|
||||
joda_instant = org.joda.time.Instant.java_class.constructor(Java::long).method(:new_instance)
|
||||
|
|
|
@ -112,6 +112,12 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
|
|||
insist { subject["@timestamp"].time } == Time.iso8601(output).utc
|
||||
end
|
||||
end # times.each
|
||||
|
||||
#Invalid value should not be evaluated to zero (String#to_i madness)
|
||||
sample("mydate" => "%{bad_value}") do
|
||||
insist { subject["mydate"] } == "%{bad_value}"
|
||||
insist { subject["@timestamp"] } != Time.iso8601("1970-01-01T00:00:00.000Z").utc
|
||||
end
|
||||
end
|
||||
|
||||
describe "parsing microsecond-precise times with UNIX (#213)" do
|
||||
|
@ -128,6 +134,18 @@ RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
|
|||
# Joda time only supports milliseconds :\
|
||||
insist { subject.timestamp.time } == Time.iso8601("2012-10-16T12:15:44.123-07:00").utc
|
||||
end
|
||||
|
||||
#Support float values
|
||||
sample("mydate" => 1350414944.123456) do
|
||||
insist { subject["mydate"] } == 1350414944.123456
|
||||
insist { subject.timestamp } == Time.iso8601("2012-10-16T12:15:44.123-07:00").utc
|
||||
end
|
||||
|
||||
#Invalid value should not be evaluated to zero (String#to_i madness)
|
||||
sample("mydate" => "%{bad_value}") do
|
||||
insist { subject["mydate"] } == "%{bad_value}"
|
||||
insist { subject["@timestamp"] } != Time.iso8601("1970-01-01T00:00:00.000Z").utc
|
||||
end
|
||||
end
|
||||
|
||||
describe "parsing with UNIX_MS" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue