diff --git a/lib/fluent/plugin/out_scalyr.rb b/lib/fluent/plugin/out_scalyr.rb index 716e2e7..550dfda 100644 --- a/lib/fluent/plugin/out_scalyr.rb +++ b/lib/fluent/plugin/out_scalyr.rb @@ -107,7 +107,7 @@ def start #the following variables are all under the control of the above mutex @thread_ids = Hash.new #hash of tags -> id @next_id = 1 #incrementing thread id for the session - @last_timestamp = 0 #timestamp of most recent event + @last_timestamp = 0 #timestamp of most recent event in nanoseconds since epoch end @@ -130,7 +130,7 @@ def format( tag, time, record ) record["message"].force_encoding( @message_encoding ) end end - [tag, time, record].to_msgpack + [tag, time.sec, time.nsec, record].to_msgpack rescue JSON::GeneratorError $log.warn "Unable to format message due to JSON::GeneratorError. Record is:\n\t#{record.to_s}" @@ -169,17 +169,16 @@ def write( chunk ) end - #explicit function to convert to nanoseconds #will make things easier to maintain if/when fluentd supports higher than second resolutions - def to_nanos( seconds ) - seconds * 10**9 + def to_nanos( seconds, nsec ) + (seconds * 10**9) + nsec end #explicit function to convert to milliseconds #will make things easier to maintain if/when fluentd supports higher than second resolutions - def to_millis( seconds ) - seconds * 10**6 + def to_millis( timestamp ) + (timestamp.sec * 10**3) + (timestamp.nsec / 10**6) end def post_request( uri, body ) @@ -255,9 +254,10 @@ def build_add_events_body( chunk ) #create a Scalyr event object for each record in the chunk events = Array.new - chunk.msgpack_each {|(tag,time,record)| + chunk.msgpack_each {|(tag, sec, nsec, record)| + + timestamp = self.to_nanos( sec, nsec ) - timestamp = self.to_nanos( time ) thread_id = 0 @sync.synchronize { @@ -285,7 +285,7 @@ def build_add_events_body( chunk ) #append to list of events event = { :thread => thread_id.to_s, - :ts => timestamp.to_s, + :ts => timestamp, :attrs => record } diff --git a/test/helper.rb b/test/helper.rb index 5b23677..f060f34 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -27,6 +27,7 @@ def setup CONFIG = %[ api_write_token test_token + ssl_ca_bundle_path /etc/ssl/certs/ca-certificates.crt ] def create_driver( conf = CONFIG )