Skip to content

Commit 4cc9f94

Browse files
committed
Fixes #1 support for epoch seconds and epoch millis
1 parent f7eca3c commit 4cc9f94

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/fluent/plugin/filter_elasticsearch_timestamp_check.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ def filter(tag, time, record)
2222
record[field]
2323
end.compact.each do |timestamp|
2424
begin
25+
# all digit entry would be treated as epoch seconds or epoch millis
26+
if !!(timestamp =~ /\A[-+]?\d+\z/)
27+
num = timestamp.to_i
28+
# epoch second or epoch millis should be either 10 or 13 digits
29+
# other length should be considered invalid (until the next digit
30+
# rollover at 2286-11-20 17:46:40 Z
31+
next unless [10, 13].include?(num.to_s.length)
32+
record['@timestamp'] = record['fluent_converted_timestamp'] =
33+
Time.at(
34+
num / (10 ** (num.to_s.length - 10))
35+
).strftime('%Y-%m-%dT%H:%M:%S.%L%z')
36+
break
37+
end
38+
39+
# normal timestamp string processing
2540
record['@timestamp'] = record['fluent_converted_timestamp'] =
2641
DateTime.parse(timestamp).strftime('%Y-%m-%dT%H:%M:%S.%L%z')
2742
$log.debug("Timestamp parsed: #{record['@timestamp']}")

0 commit comments

Comments
 (0)