Class: OpticsAgent::Reporting::Query
- Inherits:
-
Object
- Object
- OpticsAgent::Reporting::Query
- Extended by:
- Forwardable
- Defined in:
- lib/optics-agent/reporting/query.rb
Overview
This is a convenience class that enables us to fairly blindly pass in data as we resolve a query
Constant Summary
Constants included from Apollo::Optics::Proto
Apollo::Optics::Proto::Error, Apollo::Optics::Proto::Field, Apollo::Optics::Proto::FieldStat, Apollo::Optics::Proto::Id128, Apollo::Optics::Proto::ReportHeader, Apollo::Optics::Proto::SchemaReport, Apollo::Optics::Proto::StatsPerClientName, Apollo::Optics::Proto::StatsPerSignature, Apollo::Optics::Proto::StatsReport, Apollo::Optics::Proto::Timestamp, Apollo::Optics::Proto::Trace, Apollo::Optics::Proto::TracesReport, Apollo::Optics::Proto::Type, Apollo::Optics::Proto::TypeStat
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#reports ⇒ Object
readonly
Returns the value of attribute reports.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#add_to_stats(stats_per_signature) ⇒ Object
add our results to an existing StatsPerSignature.
- #each_report ⇒ Object
- #finish! ⇒ Object
-
#initialize ⇒ Query
constructor
A new instance of Query.
-
#report_field(type_name, field_name, start_offset, duration) ⇒ Object
we do nothing when reporting to minimize impact.
- #signature ⇒ Object
Methods included from Normalization::Query
Methods included from Normalization
#empty_latency_count, #latency_bucket
Methods included from OpticsAgent::Reporting
#add_latency, #client_info, #duration_micros, #duration_nanos, #generate_report_header, #generate_timestamp, #latency_bucket_for_duration
Constructor Details
#initialize ⇒ Query
Returns a new instance of Query.
23 24 25 26 27 28 29 30 31 |
# 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 |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
19 20 21 |
# File 'lib/optics-agent/reporting/query.rb', line 19 def document @document end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
20 21 22 |
# File 'lib/optics-agent/reporting/query.rb', line 20 def end_time @end_time end |
#reports ⇒ Object (readonly)
Returns the value of attribute reports.
20 21 22 |
# File 'lib/optics-agent/reporting/query.rb', line 20 def reports @reports end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
20 21 22 |
# File 'lib/optics-agent/reporting/query.rb', line 20 def start_time @start_time end |
Instance Method Details
#add_to_stats(stats_per_signature) ⇒ Object
add our results to an existing StatsPerSignature
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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 ⇒ Object
53 54 55 56 57 |
# File 'lib/optics-agent/reporting/query.rb', line 53 def each_report @reports.each do |report| yield *report end end |
#finish! ⇒ Object
33 34 35 36 |
# 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) ⇒ Object
we do nothing when reporting to minimize impact
49 50 51 |
# 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 ⇒ Object
38 39 40 41 42 43 44 45 46 |
# 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 |