Class: OpticsAgent::Reporting::Query

Inherits:
Object
  • Object
show all
Includes:
Apollo::Optics::Proto, Normalization, Normalization::Query, OpticsAgent::Reporting
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 OpticsAgent::Reporting

OPTICS_URL

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

Instance Method Summary collapse

Methods included from Normalization::Query

#normalize

Methods included from Normalization

#empty_latency_count, #latency_bucket

Methods included from OpticsAgent::Reporting

#add_latency, #client_info, #duration_nanos, #generate_report_header, #generate_timestamp, #send_message

Constructor Details

#initializeQuery

Returns a new instance of Query.



17
18
19
20
21
22
# File 'lib/optics-agent/reporting/query.rb', line 17

def initialize
  @reports = []

  @document = nil
  @signature
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



15
16
17
# File 'lib/optics-agent/reporting/query.rb', line 15

def document
  @document
end

Instance Method Details

#add_to_stats(stats_per_signature) ⇒ Object

add our results to an existing StatsPerSignature



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/optics-agent/reporting/query.rb', line 46

def add_to_stats(stats_per_signature)
  each_report do |type_name, field_name, start_time, end_time|
    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, start_time, end_time)
  end
end

#each_reportObject



39
40
41
42
43
# File 'lib/optics-agent/reporting/query.rb', line 39

def each_report
  @reports.each do |report|
    yield *report
  end
end

#report_field(type_name, field_name, start_time, end_time) ⇒ Object

we do nothing when reporting to minimize impact



35
36
37
# File 'lib/optics-agent/reporting/query.rb', line 35

def report_field(type_name, field_name, start_time, end_time)
  @reports << [type_name, field_name, start_time, end_time]
end

#signatureObject



24
25
26
27
28
29
30
31
32
# File 'lib/optics-agent/reporting/query.rb', line 24

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["query"].to_s)
end