rails_performance 1.2.3 → 1.3.1
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 +4 -4
- data/README.md +5 -13
- data/Rakefile +14 -14
- data/app/assets/images/download.svg +3 -0
- data/app/controllers/rails_performance/base_controller.rb +21 -21
- data/app/controllers/rails_performance/concerns/csv_exportable.rb +29 -0
- data/app/controllers/rails_performance/rails_performance_controller.rb +96 -49
- data/app/helpers/rails_performance/rails_performance_helper.rb +152 -156
- data/app/views/rails_performance/javascripts/app.js +2 -2
- data/app/views/rails_performance/rails_performance/_export.html.erb +3 -0
- data/app/views/rails_performance/rails_performance/crashes.html.erb +8 -1
- data/app/views/rails_performance/rails_performance/index.html.erb +29 -0
- data/app/views/rails_performance/rails_performance/recent.html.erb +8 -6
- data/app/views/rails_performance/rails_performance/requests.html.erb +15 -1
- data/app/views/rails_performance/rails_performance/slow.html.erb +3 -0
- data/app/views/rails_performance/shared/_header.html.erb +0 -1
- data/app/views/rails_performance/stylesheets/style.css +10 -0
- data/config/routes.rb +16 -18
- data/lib/generators/rails_performance/install/install_generator.rb +1 -1
- data/lib/generators/rails_performance/install/templates/initializer.rb +56 -42
- data/lib/rails_performance/data_source.rb +120 -121
- data/lib/rails_performance/engine.rb +8 -8
- data/lib/rails_performance/extensions/trace.rb +32 -33
- data/lib/rails_performance/gems/custom_ext.rb +31 -34
- data/lib/rails_performance/gems/delayed_job_ext.rb +50 -54
- data/lib/rails_performance/gems/grape_ext.rb +33 -35
- data/lib/rails_performance/gems/rake_ext.rb +41 -44
- data/lib/rails_performance/gems/sidekiq_ext.rb +34 -37
- data/lib/rails_performance/instrument/metrics_collector.rb +50 -50
- data/lib/rails_performance/models/base_record.rb +33 -36
- data/lib/rails_performance/models/collection.rb +35 -36
- data/lib/rails_performance/models/custom_record.rb +47 -48
- data/lib/rails_performance/models/delayed_job_record.rb +61 -62
- data/lib/rails_performance/models/grape_record.rb +60 -61
- data/lib/rails_performance/models/rake_record.rb +48 -49
- data/lib/rails_performance/models/request_record.rb +128 -120
- data/lib/rails_performance/models/sidekiq_record.rb +65 -66
- data/lib/rails_performance/models/trace_record.rb +18 -19
- data/lib/rails_performance/rails/middleware.rb +75 -76
- data/lib/rails_performance/rails/query_builder.rb +18 -20
- data/lib/rails_performance/reports/base_report.rb +60 -60
- data/lib/rails_performance/reports/breakdown_report.rb +15 -18
- data/lib/rails_performance/reports/crash_report.rb +15 -17
- data/lib/rails_performance/reports/percentile_report.rb +14 -0
- data/lib/rails_performance/reports/recent_requests_report.rb +24 -24
- data/lib/rails_performance/reports/requests_report.rb +30 -27
- data/lib/rails_performance/reports/response_time_report.rb +17 -17
- data/lib/rails_performance/reports/slow_requests_report.rb +4 -4
- data/lib/rails_performance/reports/throughput_report.rb +15 -17
- data/lib/rails_performance/reports/trace_report.rb +16 -18
- data/lib/rails_performance/thread/current_request.rb +33 -34
- data/lib/rails_performance/utils.rb +64 -54
- data/lib/rails_performance/version.rb +2 -2
- data/lib/rails_performance.rb +35 -36
- metadata +21 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3252836acfb4bfe1d62ace64e6c49633df64761b41f8aedf7286f41d9f11e889
|
4
|
+
data.tar.gz: 234011eabad7794de9d5fc6c367a3cd74d6db14db48907e8f0552f67229b4160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
248
|
-
|
249
|
-
|
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
|
2
|
+
require "bundler/setup"
|
3
3
|
rescue LoadError
|
4
|
-
puts
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
5
|
end
|
6
6
|
|
7
|
-
require
|
7
|
+
require "rdoc/task"
|
8
8
|
|
9
9
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir =
|
11
|
-
rdoc.title
|
12
|
-
rdoc.options <<
|
13
|
-
rdoc.rdoc_files.include(
|
14
|
-
rdoc.rdoc_files.include(
|
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
|
18
|
+
load "rails/tasks/engine.rake"
|
19
19
|
|
20
|
-
load
|
20
|
+
load "rails/tasks/statistics.rake"
|
21
21
|
|
22
|
-
require
|
22
|
+
require "bundler/gem_tasks"
|
23
23
|
|
24
|
-
require
|
24
|
+
require "rake/testtask"
|
25
25
|
|
26
26
|
Rake::TestTask.new(:test) do |t|
|
27
|
-
t.libs <<
|
28
|
-
t.pattern =
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
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
|
11
|
-
|
9
|
+
@datasource = RailsPerformance::DataSource.new(
|
10
|
+
**prepare_query, type: :requests
|
11
|
+
)
|
12
|
+
db = @datasource.db
|
12
13
|
|
13
|
-
@throughput_report_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
|
19
|
-
|
20
|
+
@datasource = RailsPerformance::DataSource.new(
|
21
|
+
**prepare_query, type: :requests
|
22
|
+
)
|
23
|
+
db = @datasource.db
|
20
24
|
|
21
|
-
@throughput_report_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
|
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
|
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
|
40
|
+
@data = RailsPerformance::Reports::TraceReport.new(request_id: params[:id]).data
|
34
41
|
respond_to do |format|
|
35
42
|
format.js {}
|
36
|
-
format.any
|
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
|
42
|
-
|
43
|
-
|
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,
|
48
|
-
|
49
|
-
|
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,
|
54
|
-
|
55
|
-
|
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 |
|
77
|
-
|
78
|
-
|
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,
|
84
|
-
|
85
|
-
|
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
|
90
|
-
|
91
|
-
|
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
|
133
|
+
@recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
|
94
134
|
end
|
95
135
|
|
96
136
|
def delayed_job
|
97
|
-
@datasource
|
98
|
-
|
99
|
-
|
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
|
143
|
+
@recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
|
102
144
|
end
|
103
145
|
|
104
146
|
def custom
|
105
|
-
@datasource
|
106
|
-
|
107
|
-
|
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
|
153
|
+
@recent_report_data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
|
110
154
|
end
|
111
155
|
|
112
156
|
def grape
|
113
|
-
@datasource
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|