Skip to content

Commit

Permalink
added nanosecond support
Browse files Browse the repository at this point in the history
  • Loading branch information
Imron Alston committed Dec 15, 2017
1 parent b054b50 commit c9d50fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/fluent/plugin/out_scalyr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}"
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit c9d50fb

Please sign in to comment.