class Slimy::Context
This is a group of metadata that exists for the duration of some request to be measured as part of an SLI.
Attributes
Public Class Methods
Create a new context sets the `start_time` to now
Parameters¶ ↑
An overriden Time at which the event started. Defaults to now.
- deadline
-
ms that this context should be finished in to be considered acceptable
# File lib/slimy/context.rb, line 19 def initialize(start_time: nil, type: "request", deadline: nil) @start_time = start_time || Time.now @deadline = deadline @result_status = :success @end_time = nil @tags = {} @reportable = true @type = type end
Public Instance Methods
Did the request finish before the deadline (or was there no deadline)
# File lib/slimy/context.rb, line 83 def deadline_success? return true if @deadline.nil? || !finished? duration < @deadline end
tool for debugging
# File lib/slimy/context.rb, line 99 def debug_format "slimy_ctx:\n\tfinished: #{finished?}\n" \ + "\tduration: #{duration}\n" \ + "\tresult_success: #{result_success?}\n" \ + "\tduration_success: #{deadline_success?}\n" \ + "\tsuccess: #{success?}\n" \ + "\tdeadline: #{deadline}\n" \ + "\ttags: #{tags.inspect}\n" end
# File lib/slimy/context.rb, line 94 def do_not_report! @reportable = false end
duration in ms of the event
# File lib/slimy/context.rb, line 76 def duration return -1 unless finished? [@end_time - @start_time, 0].max * 1000.0 end
Whether or not an end time has been set
# File lib/slimy/context.rb, line 44 def finished? !@end_time.nil? end
Whether or not this context should be reported
# File lib/slimy/context.rb, line 90 def reportable? @reportable end
mark request as having an error, or otherwise unacceptable for users
# File lib/slimy/context.rb, line 49 def result_error! @result_status = :error end
was the result of the request an error?
# File lib/slimy/context.rb, line 54 def result_error? @result_status == :error end
mark the result as being successful. This will not override deadline failure
# File lib/slimy/context.rb, line 60 def result_success! @result_status = :success end
Was the execution path of this request normal (not an error)? This does not include deadline failures
# File lib/slimy/context.rb, line 66 def result_success? @result_status == :success end
Returns true if there was no error and if the deadline was not reached.
# File lib/slimy/context.rb, line 71 def success? result_success? && deadline_success? end