rails_performance 1.2.3 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -13
  3. data/Rakefile +14 -14
  4. data/app/assets/images/download.svg +3 -0
  5. data/app/controllers/rails_performance/base_controller.rb +21 -21
  6. data/app/controllers/rails_performance/concerns/csv_exportable.rb +29 -0
  7. data/app/controllers/rails_performance/rails_performance_controller.rb +96 -49
  8. data/app/helpers/rails_performance/rails_performance_helper.rb +152 -156
  9. data/app/views/rails_performance/javascripts/app.js +2 -2
  10. data/app/views/rails_performance/rails_performance/_export.html.erb +3 -0
  11. data/app/views/rails_performance/rails_performance/crashes.html.erb +8 -1
  12. data/app/views/rails_performance/rails_performance/index.html.erb +29 -0
  13. data/app/views/rails_performance/rails_performance/recent.html.erb +8 -6
  14. data/app/views/rails_performance/rails_performance/requests.html.erb +15 -1
  15. data/app/views/rails_performance/rails_performance/slow.html.erb +3 -0
  16. data/app/views/rails_performance/shared/_header.html.erb +0 -1
  17. data/app/views/rails_performance/stylesheets/style.css +10 -0
  18. data/config/routes.rb +16 -18
  19. data/lib/generators/rails_performance/install/install_generator.rb +1 -1
  20. data/lib/generators/rails_performance/install/templates/initializer.rb +56 -42
  21. data/lib/rails_performance/data_source.rb +120 -121
  22. data/lib/rails_performance/engine.rb +8 -8
  23. data/lib/rails_performance/extensions/trace.rb +32 -33
  24. data/lib/rails_performance/gems/custom_ext.rb +31 -34
  25. data/lib/rails_performance/gems/delayed_job_ext.rb +50 -54
  26. data/lib/rails_performance/gems/grape_ext.rb +33 -35
  27. data/lib/rails_performance/gems/rake_ext.rb +41 -44
  28. data/lib/rails_performance/gems/sidekiq_ext.rb +34 -37
  29. data/lib/rails_performance/instrument/metrics_collector.rb +50 -50
  30. data/lib/rails_performance/models/base_record.rb +33 -36
  31. data/lib/rails_performance/models/collection.rb +35 -36
  32. data/lib/rails_performance/models/custom_record.rb +47 -48
  33. data/lib/rails_performance/models/delayed_job_record.rb +61 -62
  34. data/lib/rails_performance/models/grape_record.rb +60 -61
  35. data/lib/rails_performance/models/rake_record.rb +48 -49
  36. data/lib/rails_performance/models/request_record.rb +128 -120
  37. data/lib/rails_performance/models/sidekiq_record.rb +65 -66
  38. data/lib/rails_performance/models/trace_record.rb +18 -19
  39. data/lib/rails_performance/rails/middleware.rb +75 -76
  40. data/lib/rails_performance/rails/query_builder.rb +18 -20
  41. data/lib/rails_performance/reports/base_report.rb +60 -60
  42. data/lib/rails_performance/reports/breakdown_report.rb +15 -18
  43. data/lib/rails_performance/reports/crash_report.rb +15 -17
  44. data/lib/rails_performance/reports/percentile_report.rb +14 -0
  45. data/lib/rails_performance/reports/recent_requests_report.rb +24 -24
  46. data/lib/rails_performance/reports/requests_report.rb +30 -27
  47. data/lib/rails_performance/reports/response_time_report.rb +17 -17
  48. data/lib/rails_performance/reports/slow_requests_report.rb +4 -4
  49. data/lib/rails_performance/reports/throughput_report.rb +15 -17
  50. data/lib/rails_performance/reports/trace_report.rb +16 -18
  51. data/lib/rails_performance/thread/current_request.rb +33 -34
  52. data/lib/rails_performance/utils.rb +64 -54
  53. data/lib/rails_performance/version.rb +2 -2
  54. data/lib/rails_performance.rb +35 -36
  55. metadata +21 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f62ed6d90c59a10854568fb3cbfc0ad3b6aa4335be471b9b44d2512a1e517bd8
4
- data.tar.gz: 48660eb209b4d1ad1824e73e3766e9e5b15e6391d687d617162babdd1c4df4f1
3
+ metadata.gz: 3252836acfb4bfe1d62ace64e6c49633df64761b41f8aedf7286f41d9f11e889
4
+ data.tar.gz: 234011eabad7794de9d5fc6c367a3cd74d6db14db48907e8f0552f67229b4160
5
5
  SHA512:
6
- metadata.gz: 232da3c634a49b94aab7c934a22df9583b12785c7cd5b880bceaa055207367fe615d41c6bf5e314e548877bbb16280a732ee4863a402dd306f68b684a8f89001
7
- data.tar.gz: 89980a1267b46b18548545837041abdaa2544c88fc0f7343fb9d3d8e825a5f69fd33e5f56662c5852c7dd4b6c33edac323a6e08d90f14254543689fd1718c896
6
+ metadata.gz: c6b3e38a15d53cf1518542972fb5d5dfcaffff218ef325d97b6bb776d987c699936fa6237de1b0f191370185dad2ecbcc52821e0d13bd0fb21b0200c063e3f51
7
+ data.tar.gz: e7e77fb6229377c2550e70813f7276041c542b2bf0fa2c2c0ef00edca95d6ab82cc9802dfde0a995f4374559f0159c5224c4b21452e74fd392d9c91e9552ae69
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)
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"))
55
55
  config.duration = 4.hours
56
56
 
57
57
  config.debug = false # currently not used>
@@ -85,7 +85,7 @@ RailsPerformance.setup do |config|
85
85
 
86
86
  # You can ignore request paths by specifying the beginning of the path.
87
87
  # For example, all routes starting with '/admin' can be ignored:
88
- # config.ignored_paths = ['/admin']
88
+ config.ignored_paths = ['/rails/performance', '/admin']
89
89
 
90
90
  # store custom data for the request
91
91
  # config.custom_data_proc = proc do |env|
@@ -244,17 +244,9 @@ If "schema" how records are stored i Redis is changed, and this is a breaking ch
244
244
 
245
245
  ## Big thanks to contributors
246
246
 
247
- - https://github.com/synth
248
- - https://github.com/alagos
249
- - https://github.com/klondaiker
250
- - https://github.com/jules2689
251
- - https://github.com/PedroAugustoRamalhoDuarte
252
- - https://github.com/haffla
253
- - https://github.com/D1ceWard
254
- - https://github.com/carl-printreleaf
255
- - https://github.com/langalex
256
- - https://github.com/olleolleolle
257
- - https://github.com/desheikh
247
+ https://github.com/igorkasyanchuk/rails_performance/graphs/contributors
248
+
249
+ ## Other
258
250
 
259
251
  [<img src="https://opensource-heroes.com/svg/embed/igorkasyanchuk/rails_performance"
260
252
  />](https://opensource-heroes.com/r/igorkasyanchuk/rails_performance)
data/Rakefile CHANGED
@@ -1,31 +1,31 @@
1
1
  begin
2
- require 'bundler/setup'
2
+ require "bundler/setup"
3
3
  rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
5
  end
6
6
 
7
- require 'rdoc/task'
7
+ require "rdoc/task"
8
8
 
9
9
  RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'RailsPerformance'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "RailsPerformance"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.md")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
15
15
  end
16
16
 
17
17
  APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
- load 'rails/tasks/engine.rake'
18
+ load "rails/tasks/engine.rake"
19
19
 
20
- load 'rails/tasks/statistics.rake'
20
+ load "rails/tasks/statistics.rake"
21
21
 
22
- require 'bundler/gem_tasks'
22
+ require "bundler/gem_tasks"
23
23
 
24
- require 'rake/testtask'
24
+ require "rake/testtask"
25
25
 
26
26
  Rake::TestTask.new(:test) do |t|
27
- t.libs << 'test'
28
- t.pattern = 'test/**/*_test.rb'
27
+ t.libs << "test"
28
+ t.pattern = "test/**/*_test.rb"
29
29
  t.verbose = false
30
30
  end
31
31
 
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
2
+ <path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" />
3
+ </svg>
@@ -1,21 +1,21 @@
1
- module RailsPerformance
2
- class BaseController < ActionController::Base
3
- layout 'rails_performance/layouts/rails_performance'
4
-
5
- before_action :verify_access
6
-
7
- if RailsPerformance.http_basic_authentication_enabled
8
- http_basic_authenticate_with \
9
- name: RailsPerformance.http_basic_authentication_user_name,
10
- password: RailsPerformance.http_basic_authentication_password
11
- end
12
-
13
- private
14
-
15
- def verify_access
16
- result = RailsPerformance.verify_access_proc.call(self)
17
- redirect_to('/', error: 'Access Denied', status: 401) unless result
18
- end
19
-
20
- end
21
- end
1
+ module RailsPerformance
2
+ class BaseController < ActionController::Base
3
+ include RailsPerformance::Concerns::CsvExportable
4
+ layout "rails_performance/layouts/rails_performance"
5
+
6
+ before_action :verify_access
7
+
8
+ if RailsPerformance.http_basic_authentication_enabled
9
+ http_basic_authenticate_with \
10
+ name: RailsPerformance.http_basic_authentication_user_name,
11
+ password: RailsPerformance.http_basic_authentication_password
12
+ end
13
+
14
+ private
15
+
16
+ def verify_access
17
+ result = RailsPerformance.verify_access_proc.call(self)
18
+ redirect_to("/", error: "Access Denied", status: 401) unless result
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ require "csv"
2
+ module RailsPerformance
3
+ module Concerns
4
+ module CsvExportable
5
+ extend ActiveSupport::Concern
6
+
7
+ def export_to_csv(filename, data)
8
+ return if data.blank?
9
+
10
+ send_data generate_csv(data),
11
+ filename: "#{filename}_#{Time.zone.today}.csv",
12
+ type: "text/csv",
13
+ disposition: "attachment"
14
+ end
15
+
16
+ private
17
+
18
+ def generate_csv(data)
19
+ CSV.generate(headers: true) do |csv|
20
+ headers = data.first.keys
21
+ csv << headers.map(&:to_s)
22
+ data.each do |entry|
23
+ csv << headers.map { |header| entry[header].to_s }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,58 +1,85 @@
1
- require_relative './base_controller.rb'
1
+ require_relative "base_controller"
2
2
 
3
3
  module RailsPerformance
4
4
  class RailsPerformanceController < RailsPerformance::BaseController
5
-
6
5
  protect_from_forgery except: :recent
7
6
 
8
7
  if RailsPerformance.enabled
9
8
  def index
10
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :requests)
11
- db = @datasource.db
9
+ @datasource = RailsPerformance::DataSource.new(
10
+ **prepare_query, type: :requests
11
+ )
12
+ db = @datasource.db
12
13
 
13
- @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
14
+ @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
14
15
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
16
+ @percentile_report_data = RailsPerformance::Reports::PercentileReport.new(db).data
15
17
  end
16
18
 
17
19
  def summary
18
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :requests)
19
- db = @datasource.db
20
+ @datasource = RailsPerformance::DataSource.new(
21
+ **prepare_query, type: :requests
22
+ )
23
+ db = @datasource.db
20
24
 
21
- @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
25
+ @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
22
26
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
23
- @data = RailsPerformance::Reports::BreakdownReport.new(db, title: "Requests").data
24
-
27
+ @data = RailsPerformance::Reports::BreakdownReport.new(
28
+ db, title: "Requests"
29
+ ).data
25
30
  respond_to do |format|
26
31
  format.js {}
27
- format.any { render plain: "Doesn't open in new window. Wait until full page load." }
32
+ format.any do
33
+ render plain: "Doesn't open in new window. Wait until full page load."
34
+ end
28
35
  end
29
36
  end
30
37
 
31
38
  def trace
32
39
  @record = RailsPerformance::Models::RequestRecord.find_by(request_id: params[:id])
33
- @data = RailsPerformance::Reports::TraceReport.new(request_id: params[:id]).data
40
+ @data = RailsPerformance::Reports::TraceReport.new(request_id: params[:id]).data
34
41
  respond_to do |format|
35
42
  format.js {}
36
- format.any { render plain: "Doesn't open in new window. Wait until full page load." }
43
+ format.any do
44
+ render plain: "Doesn't open in new window. Wait until full page load."
45
+ end
37
46
  end
38
47
  end
39
48
 
40
49
  def crashes
41
- @datasource = RailsPerformance::DataSource.new(**prepare_query({status_eq: 500}), type: :requests)
42
- db = @datasource.db
43
- @data = RailsPerformance::Reports::CrashReport.new(db).data
50
+ @datasource = RailsPerformance::DataSource.new(
51
+ **prepare_query({status_eq: 500}), type: :requests
52
+ )
53
+ db = @datasource.db
54
+ @data = RailsPerformance::Reports::CrashReport.new(db).data
55
+
56
+ respond_to do |format|
57
+ format.html
58
+ format.csv do
59
+ export_to_csv "error_report", @data
60
+ end
61
+ end
44
62
  end
45
63
 
46
64
  def requests
47
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :requests)
48
- db = @datasource.db
49
- @data = RailsPerformance::Reports::RequestsReport.new(db, group: :controller_action_format, sort: :count).data
65
+ @datasource = RailsPerformance::DataSource.new(**prepare_query,
66
+ type: :requests)
67
+ db = @datasource.db
68
+ @data = RailsPerformance::Reports::RequestsReport.new(db,
69
+ group: :controller_action_format, sort: :count).data
70
+ respond_to do |format|
71
+ format.html
72
+ format.csv do
73
+ export_to_csv "requests_report", @data
74
+ end
75
+ end
50
76
  end
51
77
 
52
78
  def recent
53
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :requests)
54
- db = @datasource.db
55
- @data = RailsPerformance::Reports::RecentRequestsReport.new(db).data(params[:from_timei])
79
+ @datasource = RailsPerformance::DataSource.new(**prepare_query,
80
+ type: :requests)
81
+ db = @datasource.db
82
+ @data = RailsPerformance::Reports::RecentRequestsReport.new(db).data(params[:from_timei])
56
83
 
57
84
  # example
58
85
  # :controller=>"HomeController",
@@ -73,54 +100,75 @@ module RailsPerformance
73
100
  # "email"=>nil,
74
101
  # "user_agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}]
75
102
 
76
- respond_to do |page|
77
- page.html
78
- page.js
103
+ respond_to do |format|
104
+ format.html
105
+ format.js
106
+ format.csv do
107
+ export_to_csv "recent_requests_report", @data
108
+ end
79
109
  end
80
110
  end
81
111
 
82
112
  def slow
83
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :requests)
84
- db = @datasource.db
85
- @data = RailsPerformance::Reports::SlowRequestsReport.new(db).data
113
+ @datasource = RailsPerformance::DataSource.new(**prepare_query,
114
+ type: :requests)
115
+ db = @datasource.db
116
+ @data = RailsPerformance::Reports::SlowRequestsReport.new(db).data
117
+
118
+ respond_to do |format|
119
+ format.html
120
+ format.csv do
121
+ export_to_csv "slow_requests_report", @data
122
+ end
123
+ end
86
124
  end
87
125
 
88
126
  def sidekiq
89
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :sidekiq)
90
- db = @datasource.db
91
- @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
127
+ @datasource = RailsPerformance::DataSource.new(
128
+ **prepare_query, type: :sidekiq
129
+ )
130
+ db = @datasource.db
131
+ @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
92
132
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
93
- @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
133
+ @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
94
134
  end
95
135
 
96
136
  def delayed_job
97
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :delayed_job)
98
- db = @datasource.db
99
- @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
137
+ @datasource = RailsPerformance::DataSource.new(
138
+ **prepare_query, type: :delayed_job
139
+ )
140
+ db = @datasource.db
141
+ @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
100
142
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
101
- @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
143
+ @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
102
144
  end
103
145
 
104
146
  def custom
105
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :custom)
106
- db = @datasource.db
107
- @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
147
+ @datasource = RailsPerformance::DataSource.new(
148
+ **prepare_query, type: :custom
149
+ )
150
+ db = @datasource.db
151
+ @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
108
152
  @response_time_report_data = RailsPerformance::Reports::ResponseTimeReport.new(db).data
109
- @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
153
+ @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
110
154
  end
111
155
 
112
156
  def grape
113
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :grape)
114
- db = @datasource.db
115
- @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
116
- @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
157
+ @datasource = RailsPerformance::DataSource.new(
158
+ **prepare_query, type: :grape
159
+ )
160
+ db = @datasource.db
161
+ @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
162
+ @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
117
163
  end
118
164
 
119
165
  def rake
120
- @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :rake)
121
- db = @datasource.db
122
- @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
123
- @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
166
+ @datasource = RailsPerformance::DataSource.new(
167
+ **prepare_query, type: :rake
168
+ )
169
+ db = @datasource.db
170
+ @throughput_report_data = RailsPerformance::Reports::ThroughputReport.new(db).data
171
+ @recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
124
172
  end
125
173
 
126
174
  private
@@ -129,6 +177,5 @@ module RailsPerformance
129
177
  RailsPerformance::Rails::QueryBuilder.compose_from(query)
130
178
  end
131
179
  end
132
-
133
180
  end
134
181
  end