optics-agent 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmZmOWU0ZjllNzk5YzI5ZDU4ZGQ3ZjQ2ZmQzNGQxYTE1OWYyMDFiYw==
4
+ YjIwMWU1NjYxNGYzNzhhMzk1Y2IwODMxZTE1NjZkYjUwNTY1NTQ5YQ==
5
5
  data.tar.gz: !binary |-
6
- MzkyZTYyNDJlZjZlNmYwZTk4ODIyMGQyZjk0ZGRjNjE0MzdlZDllMg==
6
+ MTNkMjcxMjAyNWJlY2E1OTc4NTVkY2NmMTZjMGZiODdkNDg4ZTFkMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjZlNTA4NTZjMTRmMDAxMmUzOTgyNGE5YWJlOTM1YjdiNTlmNmZjMTA3MmYw
10
- NTAyZWI5OTRjMGMwYThlM2JkY2JhNzE0NmRiODQ4MjQ3ZTUzNDA0Yzc2NDU4
11
- Y2VmOGRjYWQyOGNiM2YxZTQ4OTVkM2JjMWE2ZGYxNzRiZDExMDE=
9
+ OTRkYTZlZDlhMDNmMjQ5OGU5MTliNDVkNWRhYzUzMjIzMDMwNTNjYjQ4NTg2
10
+ OTNkOWRmOWM1YmE2YWViNzE2MGExZDliNzQwZjcxZjFkYmNmNjA2MGM5OWMz
11
+ ZjhmOGFmODM2MWFjMDM5Njc3OTU2YzFmMDgyN2FiYmUwMmVmYWI=
12
12
  data.tar.gz: !binary |-
13
- MmI1NjhiNzI4YTNiOGJkMmY2NGY5ZTYwMTExMmFlMDA1YTAyNWRhMzllYWVm
14
- ZDgzMGQzYTM2OTU5MzcxZjIzN2UxODhmYzQ1NDgyZWQ2NDUyMDZiZTRkZGI5
15
- OWI2MGMyMWEyNzcyYTM1NThiZmRiNTZjODA5M2YzMmZiYmNjZDY=
13
+ NWM4ZDQwOGU5MTZjYTVhY2MwZjg4NWQ4MjA5Zjc2OGZjZWUyZTlkMTc2YTI1
14
+ MTk4YzQzZWEyNGY1YmUwMDUzZTg2Mjg3NTk4MTIyNGNiMjA4ZGNhNjQwYWE1
15
+ ZGE0ZjEyMTdiNmJlZTM3NDFlN2E3YTEyOTNhZmUyZTJkYzQ4NTM=
data/README.md CHANGED
@@ -59,12 +59,12 @@ end
59
59
 
60
60
  ## Rails
61
61
 
62
- The equivalent of the above for Rails is (I welcome better solutions!)
62
+ The equivalent of the above for Rails is:
63
63
 
64
64
  Create an agent in `config/apllication.rb`, and register the rack middleware:
65
65
 
66
66
  ```ruby
67
- module XXXRails
67
+ module YourApplicationRails
68
68
  class Application < Rails::Application
69
69
  # ...
70
70
 
@@ -81,7 +81,7 @@ Register the Graphql middleware when you create your schema:
81
81
  Rails.application.config.optics_agent.instrument_schema(YourSchema)
82
82
  ```
83
83
 
84
- Add something like this to your `graphql` action:
84
+ Register Optics Agent on the GraphQL context within your `graphql` action as below:
85
85
 
86
86
  ```ruby
87
87
  def create
@@ -19,7 +19,6 @@ module OpticsAgent
19
19
  def initialize
20
20
  @query_queue = []
21
21
  @semaphone = Mutex.new
22
- ReportJob.perform_in(60, self)
23
22
  end
24
23
 
25
24
  def instrument_schema(schema)
@@ -28,6 +27,11 @@ module OpticsAgent
28
27
 
29
28
  puts 'scheduling schema job'
30
29
  SchemaJob.perform_in(10, self)
30
+ schedule_report
31
+ end
32
+
33
+ def schedule_report
34
+ ReportJob.perform_in(60, self)
31
35
  end
32
36
 
33
37
  def add_query(query, rack_env, start_time, end_time)
@@ -6,7 +6,7 @@ module OpticsAgent
6
6
 
7
7
  # see https://github.com/apollostack/optics-agent/blob/master/docs/histograms.md
8
8
  def latency_bucket(micros)
9
- bucket = Math.log(micros) / Math.log(1.1)
9
+ bucket = Math.log([0, micros].max) / Math.log(1.1)
10
10
 
11
11
  [255, [0, bucket].max].min.ceil.to_i
12
12
  end
@@ -18,7 +18,7 @@ module OpticsAgent::Reporting
18
18
  report.decorate_from_schema(agent.schema)
19
19
  report.send
20
20
 
21
- self.class.perform_in(60, agent)
21
+ agent.schedule_report
22
22
  end
23
23
  end
24
24
  end
@@ -14,15 +14,30 @@ describe 'latency helpers' do
14
14
  describe 'latency_bucket' do
15
15
  it 'returns the right values' do
16
16
  tests = [
17
+ [-1, 0],
18
+ [0, 0],
19
+ # 1 nanosecond
20
+ [0.001, 0],
17
21
  [0.1, 0],
18
22
  [0.9, 0],
23
+ [0.999, 0],
24
+ # 1 microsecond
19
25
  [1, 0],
26
+ [1.001, 1],
20
27
  [1.1, 1],
28
+ [1.101, 2],
21
29
  [1.21, 2],
30
+ [10, 25],
31
+ [10.834, 25],
32
+ [10.835, 26],
22
33
  [100, 49],
34
+ # 1 millisecond
23
35
  [1000, 73],
36
+ # 1 second
24
37
  [1000 * 1000, 145],
25
38
  [1.1**254, 255],
39
+ # 5 days
40
+ [5 * 24 * 60 * 60 * 1000 * 1000, 255],
26
41
  [1000 * 1000 * 1000 * 1000, 255]
27
42
  ]
28
43
 
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ! 'Tom Coleman '