class OpticsAgent::Reporting::Query
This is a convenience class that enables us to fairly blindly pass in data as we resolve a query
Attributes
document[RW]
end_time[R]
reports[R]
start_time[R]
Public Class Methods
new()
click to toggle source
# File lib/optics-agent/reporting/query.rb, line 23 def initialize @reports = [] @document = nil @signature = nil @start_time = Time.now @interval = Hitimes::Interval.now end
Public Instance Methods
add_to_stats(stats_per_signature)
click to toggle source
add our results to an existing StatsPerSignature
# File lib/optics-agent/reporting/query.rb, line 60 def add_to_stats(stats_per_signature) each_report do |type_name, field_name, start_offset, duration| type_stat = stats_per_signature.per_type.find { |ts| ts.name == type_name } unless type_stat type_stat = TypeStat.new({ name: type_name }) stats_per_signature.per_type << type_stat end field_stat = type_stat.field.find { |fs| fs.name == field_name } unless field_stat field_stat = FieldStat.new({ name: field_name, latency_count: empty_latency_count }) type_stat.field << field_stat end add_latency(field_stat.latency_count, duration) end end
each_report() { |*report| ... }
click to toggle source
# File lib/optics-agent/reporting/query.rb, line 53 def each_report @reports.each do |report| yield *report end end
finish!()
click to toggle source
# File lib/optics-agent/reporting/query.rb, line 33 def finish! @end_time = Time.now @interval.stop end
report_field(type_name, field_name, start_offset, duration)
click to toggle source
we do nothing when reporting to minimize impact
# File lib/optics-agent/reporting/query.rb, line 49 def report_field(type_name, field_name, start_offset, duration) @reports << [type_name, field_name, start_offset, duration] end
signature()
click to toggle source
# File lib/optics-agent/reporting/query.rb, line 38 def signature # Note this isn't actually possible but would be a sensible spot to throw # if the user forgets to call `.with_document` unless @document throw "You must call .with_document on the optics context" end @signature ||= normalize(document.to_s) end