rails_performance 1.3.2 → 1.3.3

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
2
  SHA256:
3
- metadata.gz: ce8db107a23bdd7c902fa8edcc2ebe260998e1cf7712f0a710131983b28c3fa9
4
- data.tar.gz: 82e818c24db06fb74d6d477aba06f0841174894c23f45fab785dd6dd0f808aa8
3
+ metadata.gz: 0a55d30b55b9b21648f47e913b5fc80277338d64265c4b652dd7c3b66080f7a2
4
+ data.tar.gz: d402afddcd43f8328dcb12b4749657d4ed2e60159722a73524cf81aa3b91dff3
5
5
  SHA512:
6
- metadata.gz: 49d48df321943a17cd226f68ace96bbebca96ab6b47dde70e6cc95fd21276338562d3e0dbe365d1133aa6cd93981d2dd0980790cac8f52512ac2fbdb3558263d
7
- data.tar.gz: 6c3ec9d24045abc760cba57d2f3d12fe6c3ea0e35a49a138bad3bfec06ae9c8a0ebc11721c5a3c92a9f3dcad6dc80ac98d1b0d6e3fd0a2a8063b11a715dfb5e8
6
+ metadata.gz: 7497bf5420d086bb8ea1f18cee0ff029f50d5df03065f3866456560912f4cb07207c1abeb94a1c3df0f117df083e24cc118938012241f911631e5bfff0868751
7
+ data.tar.gz: 895b554629a924b4afcfb7c3e1b18126ec7e56bad780f1a95d8ab3a80bd2e8dcb17ee5782b6566d930e0937770e00d8624d5a04960de65e5021841455f9085c2
data/README.md CHANGED
@@ -51,7 +51,7 @@ Create `config/initializers/rails_performance.rb` in your app:
51
51
 
52
52
  ```ruby
53
53
  RailsPerformance.setup do |config|
54
- config.redis = Redis::Namespace.new("#{Rails.env}-rails-performance", redis: Redis.new(url: ENV["REDIS_URL"].presence || "redis://127.0.0.1:6379/0"))
54
+ config.redis = Redis.new(url: ENV["REDIS_URL"].presence || "redis://127.0.0.1:6379/0") # or Redis::Namespace.new("rails-performance", redis: Redis.new), see below in README
55
55
  config.duration = 4.hours
56
56
 
57
57
  config.debug = false # currently not used>
@@ -173,6 +173,18 @@ RailsPerformance.measure("some label", "some namespace") do
173
173
  end
174
174
  ```
175
175
 
176
+ ## Using with Rails Namespace
177
+
178
+ ```ruby
179
+ config.redis = Redis::Namespace.new("#{Rails.env}-rails-performance", redis: Redis.new(url: ENV["REDIS_URL"].presence || "redis://127.0.0.1:6379/0"))
180
+ ```
181
+
182
+ and add a gem dependency to the Gemfile:
183
+
184
+ ```ruby
185
+ gem 'redis-namespace'
186
+ ```
187
+
176
188
  ## How it works
177
189
 
178
190
  ![Schema](docs/rails_performance.png)
@@ -6,9 +6,7 @@ module RailsPerformance
6
6
 
7
7
  if RailsPerformance.enabled
8
8
  def index
9
- @datasource = RailsPerformance::DataSource.new(
10
- **prepare_query, type: :requests
11
- )
9
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :requests)
12
10
  db = @datasource.db
13
11
 
14
12
  @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
@@ -17,16 +15,12 @@ module RailsPerformance
17
15
  end
18
16
 
19
17
  def summary
20
- @datasource = RailsPerformance::DataSource.new(
21
- **prepare_query, type: :requests
22
- )
18
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :requests)
23
19
  db = @datasource.db
24
20
 
25
21
  @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
26
22
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
27
- @data = RailsPerformance::Reports::BreakdownReport.new(
28
- db, title: "Requests"
29
- ).data
23
+ @data = RailsPerformance::Reports::BreakdownReport.new(db, title: "Requests").data
30
24
  respond_to do |format|
31
25
  format.js {}
32
26
  format.any do
@@ -47,9 +41,7 @@ module RailsPerformance
47
41
  end
48
42
 
49
43
  def crashes
50
- @datasource = RailsPerformance::DataSource.new(
51
- **prepare_query({status_eq: 500}), type: :requests
52
- )
44
+ @datasource = RailsPerformance::DataSource.new(**prepare_query({status_eq: 500}), type: :requests)
53
45
  db = @datasource.db
54
46
  @data = RailsPerformance::Reports::CrashReport.new(db).data
55
47
 
@@ -62,11 +54,9 @@ module RailsPerformance
62
54
  end
63
55
 
64
56
  def requests
65
- @datasource = RailsPerformance::DataSource.new(**prepare_query,
66
- type: :requests)
57
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :requests)
67
58
  db = @datasource.db
68
- @data = RailsPerformance::Reports::RequestsReport.new(db,
69
- group: :controller_action_format, sort: :count).data
59
+ @data = RailsPerformance::Reports::RequestsReport.new(db, group: :controller_action_format, sort: :count).data
70
60
  respond_to do |format|
71
61
  format.html
72
62
  format.csv do
@@ -76,8 +66,7 @@ type: :requests)
76
66
  end
77
67
 
78
68
  def recent
79
- @datasource = RailsPerformance::DataSource.new(**prepare_query,
80
- type: :requests)
69
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :requests)
81
70
  db = @datasource.db
82
71
  @data = RailsPerformance::Reports::RecentRequestsReport.new(db).data(params[:from_timei])
83
72
 
@@ -110,8 +99,7 @@ type: :requests)
110
99
  end
111
100
 
112
101
  def slow
113
- @datasource = RailsPerformance::DataSource.new(**prepare_query,
114
- type: :requests)
102
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :requests)
115
103
  db = @datasource.db
116
104
  @data = RailsPerformance::Reports::SlowRequestsReport.new(db).data
117
105
 
@@ -124,9 +112,7 @@ type: :requests)
124
112
  end
125
113
 
126
114
  def sidekiq
127
- @datasource = RailsPerformance::DataSource.new(
128
- **prepare_query, type: :sidekiq
129
- )
115
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :sidekiq)
130
116
  db = @datasource.db
131
117
  @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
132
118
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
@@ -134,9 +120,7 @@ type: :requests)
134
120
  end
135
121
 
136
122
  def delayed_job
137
- @datasource = RailsPerformance::DataSource.new(
138
- **prepare_query, type: :delayed_job
139
- )
123
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :delayed_job)
140
124
  db = @datasource.db
141
125
  @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
142
126
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
@@ -144,9 +128,7 @@ type: :requests)
144
128
  end
145
129
 
146
130
  def custom
147
- @datasource = RailsPerformance::DataSource.new(
148
- **prepare_query, type: :custom
149
- )
131
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :custom)
150
132
  db = @datasource.db
151
133
  @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
152
134
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
@@ -154,18 +136,14 @@ type: :requests)
154
136
  end
155
137
 
156
138
  def grape
157
- @datasource = RailsPerformance::DataSource.new(
158
- **prepare_query, type: :grape
159
- )
139
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :grape)
160
140
  db = @datasource.db
161
141
  @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
162
142
  @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
163
143
  end
164
144
 
165
145
  def rake
166
- @datasource = RailsPerformance::DataSource.new(
167
- **prepare_query, type: :rake
168
- )
146
+ @datasource = RailsPerformance::DataSource.new(**prepare_query(params), type: :rake)
169
147
  db = @datasource.db
170
148
  @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
171
149
  @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
@@ -173,7 +151,7 @@ type: :requests)
173
151
 
174
152
  private
175
153
 
176
- def prepare_query(query = params)
154
+ def prepare_query(query)
177
155
  RailsPerformance::Rails::QueryBuilder.compose_from(query)
178
156
  end
179
157
  end
@@ -1,7 +1,7 @@
1
1
  if defined?(RailsPerformance)
2
2
  RailsPerformance.setup do |config|
3
3
  # Redis configuration
4
- config.redis = Redis::Namespace.new("#{Rails.env}-rails-performance", redis: Redis.new(url: ENV["REDIS_URL"].presence || "redis://127.0.0.1:6379/0"))
4
+ config.redis = Redis.new(url: ENV["REDIS_URL"].presence || "redis://127.0.0.1:6379/0")
5
5
 
6
6
  # All data we collect
7
7
  config.duration = 4.hours
@@ -36,7 +36,7 @@ if defined?(RailsPerformance)
36
36
 
37
37
  # You can ignore request paths by specifying the beginning of the path.
38
38
  # For example, all routes starting with '/admin' can be ignored:
39
- config.ignored_paths = ['/rails/performance']
39
+ config.ignored_paths = ["/rails/performance"]
40
40
 
41
41
  # store custom data for the request
42
42
  # config.custom_data_proc = proc do |env|
@@ -30,7 +30,11 @@ module RailsPerformance
30
30
  def self.from_db(key, value)
31
31
  items = key.split("|")
32
32
 
33
- parsed_value = JSON.parse(value) rescue {}
33
+ parsed_value = begin
34
+ JSON.parse(value)
35
+ rescue
36
+ {}
37
+ end
34
38
 
35
39
  RequestRecord.new(
36
40
  controller: items[2],
@@ -45,7 +49,7 @@ module RailsPerformance
45
49
  json: value,
46
50
  duration: parsed_value["duration"],
47
51
  view_runtime: parsed_value["view_runtime"],
48
- db_runtime: parsed_value["db_runtime"],
52
+ db_runtime: parsed_value["db_runtime"]
49
53
  )
50
54
  end
51
55
 
@@ -2,7 +2,7 @@ module RailsPerformance
2
2
  module Reports
3
3
  class PercentileReport < BaseReport
4
4
  def data
5
- durations = db.data.collect(&:duration)
5
+ durations = db.data.collect(&:duration).compact
6
6
  {
7
7
  p50: RailsPerformance::Utils.percentile(durations, 50),
8
8
  p95: RailsPerformance::Utils.percentile(durations, 95),
@@ -21,7 +21,7 @@ module RailsPerformance
21
21
  db_runtime_slowest: db_runtimes.max,
22
22
  p50_duration: RailsPerformance::Utils.percentile(durations, 50),
23
23
  p95_duration: RailsPerformance::Utils.percentile(durations, 95),
24
- p99_duration: RailsPerformance::Utils.percentile(durations, 99),
24
+ p99_duration: RailsPerformance::Utils.percentile(durations, 99)
25
25
  }
26
26
  end.sort_by { |e| -e[sort].to_f } # to_f because could ne NaN or nil
27
27
  end
@@ -1,4 +1,4 @@
1
1
  module RailsPerformance
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  SCHEMA = "1.0.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-08 00:00:00.000000000 Z
11
+ date: 2024-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties