peek 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bbed54bce4732314dfcdd567b7dc6a6e1a9239d8
4
- data.tar.gz: 1f88f52c9afe97f73d1eed6b92146ee052d638f8
2
+ SHA256:
3
+ metadata.gz: 77d9b2433cb9d59f8ffd5046e1b24fd58d143325caeeba2e6c23ee89305fb354
4
+ data.tar.gz: 920c924d24b16c6d98ff16c57390a452f3dc6ef292bac266f37c1a0b2b5524ea
5
5
  SHA512:
6
- metadata.gz: b8c62b3b22c484f9b9df0de921df6419f66b3aeb81cea9574cbb217776c5e0d6ed7db4753d33e9933cf6446232e717a48056272acedbde3fe5a9db4691408d7d
7
- data.tar.gz: a68133cfbbc341dbb4fe1518df040748fb2882c8ff326ef14b786ea88db930a0ab0c13e5c48fcaa70560253d724732ce16d69ec0e553f18deca6f2a28945a97c
6
+ metadata.gz: e8085a7e2920485828c3bf9fdf12339cd607d89ca289f37d7788a622b1df7918fbd39efeb098e179454b31c2a46c492712515a27f999d8f1023fe83d8dcf88f7
7
+ data.tar.gz: 3095c6b9baf4f8e620ca2b9fbf7fe8a7da7cb7ecab6e92cbffc1939186cc7d1c017d8f126de766c44bfef8511363e0d066c7abff46042c18e434ca2d0e4e4994
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  /bin
20
+ .ruby-version
@@ -90,3 +90,8 @@
90
90
  - Replace GIFs with colors @tarebyte
91
91
  - Remove CoffeeScript @dewski
92
92
  - Use Ruby JSON syntax for hashes
93
+
94
+ # 1.1.0
95
+
96
+ - Ensure that Peek can handle concurrent requests with a multithreaded application server - [#113](https://github.com/peek/peek/pull/113) [@smcgivern](https://github.com/smcgivern)
97
+ - Don't store metrics if no request ID is present - [#112](https://github.com/peek/peek/pull/112) [@rymai](https://github.com/rymai)
data/Gemfile CHANGED
@@ -6,7 +6,10 @@ gemspec
6
6
  gem 'rake'
7
7
  gem 'json', '~> 2.0', '>= 2.0.2'
8
8
 
9
+ # For the test application
9
10
  gem 'rails', '~> 5.0', '>= 5.0.0.1'
11
+ gem 'concurrent-ruby', '>= 0.9.0'
12
+ gem 'concurrent-ruby-ext', '>= 0.9.0'
10
13
 
11
14
  # Use SCSS for stylesheets
12
15
  gem 'sass-rails', '~> 5.0'
data/README.md CHANGED
@@ -6,11 +6,11 @@ Take a peek into your Rails application.
6
6
 
7
7
  ![Preview](https://f.cloud.github.com/assets/79995/244991/03cee1fa-8a74-11e2-8e33-283cf1298a60.png)
8
8
 
9
- This is a profiling tool originally built at GitHub to help us get an insight into our application. Now, we have extracted this into Peek, so that other Rails application can experience the same benefit.
9
+ This is a profiling tool originally built at GitHub to help us get an insight into our application. Now, we have extracted this into Peek, so that other Rails applications can experience the same benefit.
10
10
 
11
11
  Peek puts a little bar on top of your application to show you all sorts of helpful information about your application. From the screenshot above, you can see that Peek provides information about database queries, cache, Resque workers and more. However, this is only part of Peek's beauty.
12
12
 
13
- The true beauty of Peek lies in the fact that it is an extensible platform. If there are some performance metrics that you need but are not available on Peek, you can find it from the list of available [Peek Views](#available-peek-views) and integrate it into Peek. Even if you do not find what you want on Peek Views, you can always [create your own](#creating-your-own-peek-item).
13
+ The true beauty of Peek lies in the fact that it is an extensible platform. If there are some performance metrics that you need but are not available on Peek, you can find them in the list of available [Peek Views](#available-peek-views) and integrate them into Peek. Even if you do not find what you want on Peek Views, you can always [create your own](#creating-your-own-peek-item).
14
14
 
15
15
  ## Installation
16
16
 
@@ -49,9 +49,9 @@ Peek.into Peek::Views::Dalli
49
49
  ```
50
50
 
51
51
  Feel free to pick and install from the [list](https://github.com/peek/peek#available-peek-views) or create your own. The order they
52
- are added to Peek, the order they will appear in your bar.
52
+ are added to Peek is the order they will appear in your bar.
53
53
 
54
- Next, to render the Peek bar in your application just add the following snippet
54
+ Next, to render the Peek bar in your application, add the following snippet
55
55
  just after the opening `<body>` tag in your application layout.
56
56
 
57
57
  ```erb
@@ -102,9 +102,9 @@ For Peek to work, it keeps track of all requests made in your application
102
102
  so it can report back and display that information in the Peek bar. By default
103
103
  it stores this information in memory, which is not recommended for production environments.
104
104
 
105
- In production environments you may have application servers on multiple hosts,
106
- at which Peek will not be able to access the request data if it was saved in memory on
107
- another host. Peek provides 2 additional adapters for multi server environments.
105
+ In production environments you may have application servers on multiple hosts.
106
+ Peek will not be able to access the request data if it was saved in memory on
107
+ another host. Peek provides additional adapters for multi server environments.
108
108
 
109
109
  You can configure which adapter Peek uses by updating your application
110
110
  config or an individual environment config file. We'll use production as an example.
@@ -153,10 +153,10 @@ Peeked::Application.configure do
153
153
  end
154
154
  ```
155
155
 
156
- Peek doesn't persist the request data forever. It uses a safe 30 minute
157
- cache length that way data will be available if you'd like to aggregate it or
156
+ Peek doesn't persist the request data forever. It uses a safe 30 minute cache
157
+ length so that data will be available if you'd like to aggregate it or
158
158
  use it for other Peek views. You can update this to be 30 seconds if you don't
159
- want the data to be available to stick around.
159
+ want the data to be available for these or other uses.
160
160
 
161
161
  ### Customizing the bar
162
162
 
@@ -202,6 +202,7 @@ end
202
202
  - [peek-alt-routes](https://github.com/mkcode/peek-alt-routes)
203
203
  - [peek-dalli](https://github.com/peek/peek-dalli)
204
204
  - [peek-delayed_job](https://github.com/18F/peek-delayed_job)
205
+ - [peek-devise](https://github.com/gencer/peek-devise)
205
206
  - [peek-faraday](https://github.com/grk/peek-faraday)
206
207
  - [peek-flexirest](https://github.com/andyjeffries/peek-flexirest)
207
208
  - [peek-gc](https://github.com/peek/peek-gc)
@@ -229,7 +230,7 @@ report it back to the Peek bar. A Peek item is just a custom class that
229
230
  is responsible for fetching and building the data that should be reported back
230
231
  to the user.
231
232
 
232
- There are still some docs to be written, but if you'd like to checkout a simple
233
+ There are still some docs to be written, but if you'd like to check out a simple
233
234
  example of how to create your own, just checkout [peek-git](https://github.com/peek/peek-git).
234
235
  To just look at an example view, there is [Peek::Views::Git](https://github.com/peek/peek-git/blob/master/lib/peek/views/git.rb).
235
236
 
@@ -1,5 +1,5 @@
1
1
  <% if peek_enabled? %>
2
- <div id="peek" class="<%= Peek.env %><%= ' disabled' if cookies[:peek] == 'false' %>" data-request-id="<%= Peek.request_id %>">
2
+ <div id="peek" class="<%= Peek.env %><%= ' disabled' if cookies[:peek] == 'false' %>" data-request-id="<%= peek_request_id %>">
3
3
  <div class="wrapper">
4
4
  <% Peek.views.each do |view| %>
5
5
  <div id="<%= view.dom_id %>" class="view">
@@ -1,6 +1,5 @@
1
1
  require 'peek/version'
2
2
  require 'rails'
3
- require 'concurrent/atomics'
4
3
 
5
4
  require 'peek/adapters/memory'
6
5
  require 'peek/views/view'
@@ -8,18 +7,6 @@ require 'peek/views/view'
8
7
  module Peek
9
8
  ALLOWED_ENVS = ['development', 'staging'].freeze
10
9
 
11
- def self._request_id
12
- @_request_id ||= Concurrent::AtomicReference.new
13
- end
14
-
15
- def self.request_id
16
- _request_id.get
17
- end
18
-
19
- def self.request_id=(id)
20
- _request_id.update { id }
21
- end
22
-
23
10
  def self.adapter
24
11
  @adapter
25
12
  end
@@ -96,14 +83,6 @@ module Peek
96
83
  @cached_views = nil
97
84
  end
98
85
 
99
- # Hook that happens after every request. It is expected to reset
100
- # any state that Peek managed throughout the requests lifecycle.
101
- #
102
- # Returns nothing.
103
- def self.clear
104
- _request_id.update { '' }
105
- end
106
-
107
86
  def self.setup
108
87
  ActiveSupport::Deprecation.warn "'Peek.setup' is deprecated and does nothing.", caller
109
88
  end
@@ -18,10 +18,12 @@ module Peek
18
18
  # pass
19
19
  end
20
20
 
21
- def save
21
+ def save(request_id)
22
+ return false if request_id.blank?
23
+
22
24
  @client.index index: @index,
23
25
  type: @type,
24
- id: "#{Peek.request_id}",
26
+ id: "#{request_id}",
25
27
  body: Peek.results.to_json,
26
28
  ttl: @expires_in
27
29
  rescue ::Elasticsearch::Transport::Transport::Errors::BadRequest
@@ -15,8 +15,10 @@ module Peek
15
15
  Rails.logger.error "#{e.class.name}: #{e.message}"
16
16
  end
17
17
 
18
- def save
19
- @client.add("peek:requests:#{Peek.request_id}", Peek.results.to_json, @expires_in)
18
+ def save(request_id)
19
+ return false if request_id.blank?
20
+
21
+ @client.add("peek:requests:#{request_id}", Peek.results.to_json, @expires_in)
20
22
  rescue ::Dalli::DalliError => e
21
23
  Rails.logger.error "#{e.class.name}: #{e.message}"
22
24
  end
@@ -13,8 +13,10 @@ module Peek
13
13
  @requests[request_id]
14
14
  end
15
15
 
16
- def save
17
- @requests[Peek.request_id] = Peek.results
16
+ def save(request_id)
17
+ return false if request_id.blank?
18
+
19
+ @requests[request_id] = Peek.results
18
20
  end
19
21
 
20
22
  def reset
@@ -13,8 +13,10 @@ module Peek
13
13
  @client.get("peek:requests:#{request_id}")
14
14
  end
15
15
 
16
- def save
17
- @client.setex("peek:requests:#{Peek.request_id}", @expires_in, Peek.results.to_json)
16
+ def save(request_id)
17
+ return false if request_id.blank?
18
+
19
+ @client.setex("peek:requests:#{request_id}", @expires_in, Peek.results.to_json)
18
20
  end
19
21
  end
20
22
  end
@@ -3,18 +3,20 @@ module Peek
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- prepend_before_action :set_peek_request_id, if: :peek_enabled?
7
- helper_method :peek_enabled? if respond_to? :helper_method
6
+ if respond_to? :helper_method
7
+ helper_method :peek_enabled?
8
+ helper_method :peek_request_id
9
+ end
8
10
  end
9
11
 
10
12
  protected
11
13
 
12
- def set_peek_request_id
13
- Peek.request_id = request.env['action_dispatch.request_id']
14
- end
15
-
16
14
  def peek_enabled?
17
15
  Peek.enabled?
18
16
  end
17
+
18
+ def peek_request_id
19
+ request.env['action_dispatch.request_id']
20
+ end
19
21
  end
20
22
  end
@@ -19,9 +19,10 @@ module Peek
19
19
  end
20
20
 
21
21
  initializer 'peek.persist_request_data' do
22
- ActiveSupport::Notifications.subscribe('process_action.action_controller') do
23
- Peek.adapter.save
24
- Peek.clear
22
+ ActiveSupport::Notifications.subscribe('process_action.action_controller') do |_name, _start, _finish, _id, payload|
23
+ if request_id = payload[:headers].env['action_dispatch.request_id']
24
+ Peek.adapter.save(request_id)
25
+ end
25
26
  end
26
27
  end
27
28
 
@@ -1,3 +1,3 @@
1
1
  module Peek
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -19,6 +19,4 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ['lib']
20
20
 
21
21
  gem.add_dependency 'railties', '>= 4.0.0'
22
- gem.add_dependency 'concurrent-ruby', '>= 0.9.0'
23
- gem.add_dependency 'concurrent-ruby-ext', '>= 0.9.0'
24
22
  end
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require_relative '../dummy/lib/test_view'
2
3
 
3
4
  class RequestsTest < ActionDispatch::IntegrationTest
4
5
  setup do
@@ -8,7 +9,25 @@ class RequestsTest < ActionDispatch::IntegrationTest
8
9
 
9
10
  test "the request id is set" do
10
11
  assert_empty Peek.adapter.requests
12
+
11
13
  get '/'
14
+
12
15
  assert_not_empty Peek.adapter.requests
13
16
  end
17
+
18
+ test "the request ID and data are set correctly for concurrent requests" do
19
+ Peek.into TestView
20
+ concurrent_requests = 10
21
+
22
+ assert_empty Peek.adapter.requests
23
+
24
+ concurrent_requests.times.map do
25
+ Thread.new { get '/' }
26
+ end.map(&:join)
27
+
28
+ result_sequence = Peek.adapter.requests.values.map { |value| value[:data]['test-view'][:number] }
29
+
30
+ assert_equal Peek.adapter.requests.length, concurrent_requests
31
+ assert_equal result_sequence, 1.upto(concurrent_requests).to_a
32
+ end
14
33
  end
@@ -4,13 +4,11 @@ class TestView < Peek::Views::View
4
4
  class << self
5
5
  attr_accessor :counter
6
6
  end
7
- self.counter = Concurrent::AtomicReference.new(0)
7
+ self.counter = Concurrent::AtomicFixnum.new
8
8
 
9
9
  def results
10
- self.class.counter.update { |value| value + 1 }
11
-
12
10
  {
13
- number: self.class.counter.value
11
+ number: self.class.counter.increment
14
12
  }
15
13
  end
16
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peek
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Bjerkhoel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2019-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.0.0
27
- - !ruby/object:Gem::Dependency
28
- name: concurrent-ruby
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.9.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 0.9.0
41
- - !ruby/object:Gem::Dependency
42
- name: concurrent-ruby-ext
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 0.9.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 0.9.0
55
27
  description: Take a peek into your Rails application.
56
28
  email:
57
29
  - me@garrettbjerkhoel.com
@@ -143,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
115
  - !ruby/object:Gem::Version
144
116
  version: '0'
145
117
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.5.1
118
+ rubygems_version: 3.0.3
148
119
  signing_key:
149
120
  specification_version: 4
150
121
  summary: Take a peek into your Rails application.
@@ -188,4 +159,3 @@ test_files:
188
159
  - test/peek/views/view_test.rb
189
160
  - test/peek_test.rb
190
161
  - test/test_helper.rb
191
- has_rdoc: