optics-agent 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDY0NThhZDNkNTNhNGYwOWEyMmFlMDhjOGFkNGVlNjM0MjAzYWNkNw==
4
+ YmZmOWU0ZjllNzk5YzI5ZDU4ZGQ3ZjQ2ZmQzNGQxYTE1OWYyMDFiYw==
5
5
  data.tar.gz: !binary |-
6
- YWIzNWIxMzNhMGRkMTA3ZGZjMWRiODNjYWVmNTY3OTY4ODA1ZmIxNg==
6
+ MzkyZTYyNDJlZjZlNmYwZTk4ODIyMGQyZjk0ZGRjNjE0MzdlZDllMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Yzk3ODZjY2UzNWRlMzExMGEyMmY1MmRmNDBhNDA3MzVkYzg4ZjRkMWY1NTU3
10
- ZjUwNzU1OWJhNjVhOGQ0OTYxZTk0YmQ0NWMzMDdmYzM4N2M3ZTdmMDQyMDMx
11
- NWUyMDY4NmE1ODVlYjk1MWM4ZDY2MzY0Y2U1ZTM3ODljMzIzY2Q=
9
+ MjZlNTA4NTZjMTRmMDAxMmUzOTgyNGE5YWJlOTM1YjdiNTlmNmZjMTA3MmYw
10
+ NTAyZWI5OTRjMGMwYThlM2JkY2JhNzE0NmRiODQ4MjQ3ZTUzNDA0Yzc2NDU4
11
+ Y2VmOGRjYWQyOGNiM2YxZTQ4OTVkM2JjMWE2ZGYxNzRiZDExMDE=
12
12
  data.tar.gz: !binary |-
13
- NGVlZGUyNTRmM2E3OGRjMWE1MGJkNmQ4ODQ2MjQ3MWIxOTY1YWM0ZDI1NDJi
14
- NzUzYTk2MTc4ZDNmNzJmZDdkZjFiOWZmNDM2MzQwOGZhYzM4ZjExZWFkYjM3
15
- ZmUxZjM0NDZkYjJmMDc2ODFiMjUyMTI2M2NiYzY5ZGY5MmFiOWM=
13
+ MmI1NjhiNzI4YTNiOGJkMmY2NGY5ZTYwMTExMmFlMDA1YTAyNWRhMzllYWVm
14
+ ZDgzMGQzYTM2OTU5MzcxZjIzN2UxODhmYzQ1NDgyZWQ2NDUyMDZiZTRkZGI5
15
+ OWI2MGMyMWEyNzcyYTM1NThiZmRiNTZjODA5M2YzMmZiYmNjZDY=
data/README.md CHANGED
@@ -3,7 +3,8 @@ Optics Agent for GraphQL Monitoring in Ruby.
3
3
 
4
4
  This is an alpha release, suitable for use in development contexts. There are still some outstanding improvements to make it ready for production contexts; see the [known limitations](#known-limitations) section below.
5
5
 
6
- [![Build Status](https://travis-ci.org/apollostack/optics-agent-ruby.svg?branch=master)](https://travis-ci.org/apollostack/optics-agent-ruby)
6
+ [![Gem Version](https://badge.fury.io/rb/optics-agent.svg)](https://badge.fury.io/rb/optics-agent) [![Build Status](https://travis-ci.org/apollostack/optics-agent-ruby.svg?branch=master)](https://travis-ci.org/apollostack/optics-agent-ruby)
7
+
7
8
 
8
9
  ## Installing
9
10
 
@@ -19,7 +20,7 @@ To your `Gemfile`
19
20
 
20
21
  ### API key
21
22
 
22
- You'll need to run your app with the `OPTICS_API_KEY` environment variable set to the name of your Apollo Optics service; at the moment Optics is in early access alpha--[get in touch](http://www.apollostack.com/optics) if you want to be part of our early access program.
23
+ You'll need to run your app with the `OPTICS_API_KEY` environment variable set to the API key of your Apollo Optics service; at the moment Optics is in early access alpha--[get in touch](http://www.apollostack.com/optics) if you want to be part of our early access program.
23
24
 
24
25
  ### Basic Rack/Sinatra
25
26
 
@@ -135,5 +136,5 @@ bundle install
135
136
  Compile the `.proto` definitions with
136
137
 
137
138
  ```bash
138
- bundle exec rake proto:compile
139
+ bundle exec rake protobuf:compile
139
140
  ```
@@ -19,6 +19,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
19
19
  optional :server_id, :message, 1, "apollo.optics.proto.Id128"
20
20
  optional :client_id, :message, 2, "apollo.optics.proto.Id128"
21
21
  optional :start_time, :message, 4, "apollo.optics.proto.Timestamp"
22
+ optional :end_time, :message, 3, "apollo.optics.proto.Timestamp"
23
+ optional :duration_ns, :uint64, 11
22
24
  optional :signature, :string, 5
23
25
  optional :details, :message, 6, "apollo.optics.proto.Trace.Details"
24
26
  optional :client_name, :string, 7
@@ -15,6 +15,11 @@ module OpticsAgent::Reporting
15
15
  });
16
16
  end
17
17
 
18
+ def duration_nanos(start_time, end_time)
19
+ throw "start_time before end_time" if (start_time > end_time)
20
+ ((end_time - start_time) * 1e9).to_i
21
+ end
22
+
18
23
  # XXX: implement
19
24
  def client_info(rack_env)
20
25
  {
@@ -14,6 +14,8 @@ module OpticsAgent::Reporting
14
14
  def initialize(query, rack_env, start_time, end_time)
15
15
  trace = Trace.new({
16
16
  start_time: generate_timestamp(start_time),
17
+ end_time: generate_timestamp(end_time),
18
+ duration_ns: duration_nanos(start_time, end_time),
17
19
  signature: query.signature
18
20
  })
19
21
 
@@ -33,8 +35,8 @@ module OpticsAgent::Reporting
33
35
  query.each_report do |type_name, field_name, field_start_time, field_end_time|
34
36
  nodes << Trace::Node.new({
35
37
  field_name: "#{type_name}.#{field_name}",
36
- start_time: ((field_start_time - start_time) * 1e9).to_i,
37
- end_time: ((field_end_time - start_time) * 1e9).to_i
38
+ start_time: duration_nanos(start_time, field_start_time),
39
+ end_time: duration_nanos(start_time, field_end_time)
38
40
  })
39
41
  end
40
42
  trace.execute = Trace::Node.new({
@@ -1,6 +1,7 @@
1
1
  require 'apollo/optics/proto/reports_pb'
2
2
  require 'optics-agent/reporting/helpers'
3
3
  require 'optics-agent/normalization/latency'
4
+ require 'optics-agent/normalization/query'
4
5
 
5
6
  module OpticsAgent::Reporting
6
7
  # This is a convenience class that enables us to fairly blindly
@@ -9,6 +10,7 @@ module OpticsAgent::Reporting
9
10
  include Apollo::Optics::Proto
10
11
  include OpticsAgent::Reporting
11
12
  include OpticsAgent::Normalization
13
+ include OpticsAgent::Normalization::Query
12
14
 
13
15
  attr_accessor :document
14
16
 
@@ -16,6 +18,7 @@ module OpticsAgent::Reporting
16
18
  @reports = []
17
19
 
18
20
  @document = nil
21
+ @signature
19
22
  end
20
23
 
21
24
  def signature
@@ -25,8 +28,7 @@ module OpticsAgent::Reporting
25
28
  throw "You must call .with_document on the optics context"
26
29
  end
27
30
 
28
- # TODO: query normalization here
29
- return document["query"].to_s
31
+ @signature ||= normalize(document["query"].to_s)
30
32
  end
31
33
 
32
34
  # we do nothing when reporting to minimize impact
@@ -20,20 +20,13 @@ module OpticsAgent::Reporting
20
20
  header: ReportHeader.new({
21
21
  agent_version: '1'
22
22
  }),
23
- start_time: Timestamp.new({
24
- # XXX pass this in?
25
- seconds: Time.now.to_i,
26
- nanos: 0
27
- })
23
+ start_time: generate_timestamp(Time.now)
28
24
  })
29
25
  end
30
26
 
31
27
  def finish!
32
- @report.end_time ||= Timestamp.new({
33
- # XXX pass this in?
34
- seconds: Time.now.to_i,
35
- nanos: 0
36
- })
28
+ @report.end_time ||= generate_timestamp(Time.now)
29
+ @report.realtime_duration || duration_nanos(@report.start_time, @report.end_time)
37
30
  end
38
31
 
39
32
  def send
@@ -23,7 +23,7 @@ describe QueryTrace do
23
23
  query.report_field 'Person', 'firstName', 1, 1.1
24
24
  query.report_field 'Person', 'lastName', 1, 1.1
25
25
  query.report_field 'Query', 'person', 1, 1.22
26
- query.document = DocumentMock.new('key')
26
+ query.document = DocumentMock.new('{field}')
27
27
 
28
28
  trace = QueryTrace.new(query, {}, 1, 1.25)
29
29
 
@@ -23,7 +23,7 @@ describe Report do
23
23
  query.report_field 'Person', 'firstName', 1, 1.1
24
24
  query.report_field 'Person', 'lastName', 1, 1.1
25
25
  query.report_field 'Query', 'person', 1, 1.22
26
- query.document = DocumentMock.new('key')
26
+ query.document = DocumentMock.new('{field}')
27
27
 
28
28
  report = Report.new
29
29
  report.add_query query, {}, 1, 1.25
@@ -31,7 +31,7 @@ describe Report do
31
31
 
32
32
  expect(report.report).to be_an_instance_of(StatsReport)
33
33
  stats_report = report.report
34
- expect(stats_report.per_signature.keys).to match_array(['key'])
34
+ expect(stats_report.per_signature.keys).to match_array(['{field}'])
35
35
 
36
36
  signature_stats = stats_report.per_signature.values.first
37
37
  expect(signature_stats.per_type.length).to equal(2)
@@ -52,13 +52,13 @@ describe Report do
52
52
  queryOne.report_field 'Person', 'firstName', 1, 1.1
53
53
  queryOne.report_field 'Person', 'lastName', 1, 1.1
54
54
  queryOne.report_field 'Query', 'person', 1, 1.22
55
- queryOne.document = DocumentMock.new('key')
55
+ queryOne.document = DocumentMock.new('{field}')
56
56
 
57
57
  queryTwo = Query.new
58
58
  queryTwo.report_field 'Person', 'firstName', 1, 1.05
59
59
  queryTwo.report_field 'Person', 'lastName', 1, 1.05
60
60
  queryTwo.report_field 'Query', 'person', 1, 1.2
61
- queryTwo.document = DocumentMock.new('key')
61
+ queryTwo.document = DocumentMock.new('{field}')
62
62
 
63
63
  report = Report.new
64
64
  report.add_query queryOne, {}, 1, 1.1
@@ -67,7 +67,7 @@ describe Report do
67
67
 
68
68
  expect(report.report).to be_an_instance_of(StatsReport)
69
69
  stats_report = report.report
70
- expect(stats_report.per_signature.keys).to match_array(['key'])
70
+ expect(stats_report.per_signature.keys).to match_array(['{field}'])
71
71
 
72
72
  signature_stats = stats_report.per_signature.values.first
73
73
  expect(signature_stats.per_type.length).to equal(2)
@@ -88,13 +88,13 @@ describe Report do
88
88
  queryOne.report_field 'Person', 'firstName', 1, 1.1
89
89
  queryOne.report_field 'Person', 'lastName', 1, 1.1
90
90
  queryOne.report_field 'Query', 'person', 1, 1.22
91
- queryOne.document = DocumentMock.new('keyOne')
91
+ queryOne.document = DocumentMock.new('{fieldOne}')
92
92
 
93
93
  queryTwo = Query.new
94
94
  queryTwo.report_field 'Person', 'firstName', 1, 1.05
95
95
  queryTwo.report_field 'Person', 'lastName', 1, 1.05
96
96
  queryTwo.report_field 'Query', 'person', 1, 1.02
97
- queryTwo.document = DocumentMock.new('keyTwo')
97
+ queryTwo.document = DocumentMock.new('{fieldTwo}')
98
98
 
99
99
  report = Report.new
100
100
  report.add_query queryOne, {}, 1, 1.1
@@ -103,9 +103,9 @@ describe Report do
103
103
 
104
104
  expect(report.report).to be_an_instance_of(StatsReport)
105
105
  stats_report = report.report
106
- expect(stats_report.per_signature.keys).to match_array(['keyOne', 'keyTwo'])
106
+ expect(stats_report.per_signature.keys).to match_array(['{fieldOne}', '{fieldTwo}'])
107
107
 
108
- signature_stats = stats_report.per_signature['keyOne']
108
+ signature_stats = stats_report.per_signature['{fieldOne}']
109
109
  expect(signature_stats.per_type.length).to equal(2)
110
110
  expect(signature_stats.per_type.map &:name).to match_array(['Person', 'Query'])
111
111
 
@@ -123,7 +123,7 @@ describe Report do
123
123
  query = Query.new
124
124
  query.report_field 'Person', 'firstName', 1, 1.1
125
125
  query.report_field 'Person', 'age', 1, 1.1
126
- query.document = DocumentMock.new('key')
126
+ query.document = DocumentMock.new('{field}')
127
127
 
128
128
  report = Report.new
129
129
  report.add_query query, {}, 1, 1.25
@@ -161,7 +161,7 @@ describe Report do
161
161
  query.report_field 'Query', '__schema', 1, 1.1
162
162
  query.report_field 'Query', '__typename', 1, 1.1
163
163
  query.report_field 'Query', '__type', 1, 1.1
164
- query.document = DocumentMock.new('key')
164
+ query.document = DocumentMock.new('{field}')
165
165
 
166
166
  report = Report.new
167
167
  report.add_query query, {}, 1, 1.25
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optics-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ! 'Tom Coleman '