rails_performance 0.9.9 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -3
  3. data/app/controllers/rails_performance/rails_performance_controller.rb +47 -35
  4. data/app/helpers/rails_performance/application_helper.rb +25 -7
  5. data/app/views/rails_performance/javascripts/app.js +2 -2
  6. data/app/views/rails_performance/rails_performance/_summary.html.erb +1 -1
  7. data/app/views/rails_performance/rails_performance/custom.html.erb +83 -0
  8. data/app/views/rails_performance/rails_performance/delayed_job.html.erb +74 -0
  9. data/app/views/rails_performance/rails_performance/grape.html.erb +64 -0
  10. data/app/views/rails_performance/rails_performance/rake.html.erb +55 -0
  11. data/app/views/rails_performance/rails_performance/recent.html.erb +3 -1
  12. data/app/views/rails_performance/rails_performance/{jobs.html.erb → sidekiq.html.erb} +5 -4
  13. data/app/views/rails_performance/rails_performance/summary.js.erb +1 -1
  14. data/app/views/rails_performance/rails_performance/trace.js.erb +1 -1
  15. data/app/views/rails_performance/shared/_header.html.erb +9 -1
  16. data/app/views/rails_performance/stylesheets/style.css +5 -0
  17. data/config/routes.rb +5 -1
  18. data/lib/rails_performance.rb +29 -6
  19. data/lib/rails_performance/data_source.rb +52 -13
  20. data/lib/rails_performance/engine.rb +20 -3
  21. data/lib/rails_performance/extensions/{capture_everything.rb → trace.rb} +2 -2
  22. data/lib/rails_performance/gems/custom_ext.rb +33 -0
  23. data/lib/rails_performance/gems/delayed_job_ext.rb +54 -0
  24. data/lib/rails_performance/gems/grape_ext.rb +35 -0
  25. data/lib/rails_performance/gems/rake_ext.rb +40 -0
  26. data/lib/rails_performance/gems/{sidekiq.rb → sidekiq_ext.rb} +13 -12
  27. data/lib/rails_performance/instrument/metrics_collector.rb +3 -2
  28. data/lib/rails_performance/models/base_record.rb +12 -0
  29. data/lib/rails_performance/models/custom_record.rb +48 -0
  30. data/lib/rails_performance/models/delayed_job_record.rb +62 -0
  31. data/lib/rails_performance/models/grape_record.rb +61 -0
  32. data/lib/rails_performance/models/rake_record.rb +49 -0
  33. data/lib/rails_performance/models/request_record.rb +98 -0
  34. data/lib/rails_performance/models/sidekiq_record.rb +66 -0
  35. data/lib/rails_performance/models/trace_record.rb +19 -0
  36. data/lib/rails_performance/rails/middleware.rb +42 -16
  37. data/lib/rails_performance/rails/query_builder.rb +1 -1
  38. data/lib/rails_performance/reports/breakdown_report.rb +4 -16
  39. data/lib/rails_performance/reports/crash_report.rb +4 -15
  40. data/lib/rails_performance/reports/recent_requests_report.rb +7 -44
  41. data/lib/rails_performance/reports/trace_report.rb +1 -1
  42. data/lib/rails_performance/{models → thread}/current_request.rb +9 -4
  43. data/lib/rails_performance/utils.rb +15 -28
  44. data/lib/rails_performance/version.rb +1 -1
  45. metadata +79 -10
  46. data/lib/rails_performance/models/job_record.rb +0 -48
  47. data/lib/rails_performance/models/record.rb +0 -68
@@ -1,6 +1,7 @@
1
1
  module RailsPerformance
2
2
  class CurrentRequest
3
- attr_reader :request_id, :storage
3
+ attr_reader :request_id, :tracings, :ignore
4
+ attr_accessor :data
4
5
  attr_accessor :record
5
6
 
6
7
  def CurrentRequest.init
@@ -12,17 +13,21 @@ module RailsPerformance
12
13
  end
13
14
 
14
15
  def CurrentRequest.cleanup
16
+ RailsPerformance.log "----------------------------------------------------> CurrentRequest.cleanup !!!!!!!!!!!! -------------------------\n\n"
17
+ RailsPerformance.skip = false
15
18
  Thread.current[:rp_current_request] = nil
16
19
  end
17
20
 
18
21
  def initialize(request_id)
19
22
  @request_id = request_id
20
- @storage = []
23
+ @tracings = []
24
+ @ignore = Set.new
25
+ @data = nil
21
26
  @record = nil
22
27
  end
23
28
 
24
- def store(options = {})
25
- @storage << options.merge(time: Time.now.to_i)
29
+ def trace(options = {})
30
+ @tracings << options.merge(time: Time.now.to_i)
26
31
  end
27
32
 
28
33
  end
@@ -12,35 +12,29 @@ module RailsPerformance
12
12
  now.strftime("%H:%M")
13
13
  end
14
14
 
15
- def Utils.log_job_in_redis(e)
16
- key = "jobs|queue|#{e[:queue]}|worker|#{e[:worker]}|jid|#{e[:jid]}|datetime|#{e[:datetime]}|created_ati|#{e[:created_ati]}|enqueued_ati|#{e[:enqueued_ati]}|start_timei|#{e[:start_timei]}|status|#{e[:status]}|END"
17
- value = { message: e[:message], duration: e[:duration] }
18
- Utils.save_to_redis(key, value)
19
- end
20
-
21
- def Utils.log_request_in_redis(e)
22
- value = e.slice(:view_runtime, :db_runtime, :duration, :HTTP_REFERER)
23
- key = "performance|controller|#{e[:controller]}|action|#{e[:action]}|format|#{e[:format]}|status|#{e[:status]}|datetime|#{e[:datetime]}|datetimei|#{e[:datetimei]}|method|#{e[:method]}|path|#{e[:path]}|request_id|#{e[:request_id]}|END"
24
- Utils.save_to_redis(key, value)
25
- end
26
-
27
- def Utils.log_trace_in_redis(request_id, value)
28
- key = "trace|#{request_id}"
29
- Utils.save_to_redis(key, value, RailsPerformance::Reports::RecentRequestsReport::TIME_WINDOW.to_i)
30
- end
31
-
32
15
  def Utils.fetch_from_redis(query)
33
- #puts "\n\n [REDIS QUERY] --> #{query}\n\n"
16
+ RailsPerformance.log "\n\n [REDIS QUERY] --> #{query}\n\n"
34
17
 
35
- keys = RP.redis.keys(query)
18
+ keys = RailsPerformance.redis.keys(query)
36
19
  return [] if keys.blank?
37
- values = RP.redis.mget(keys)
20
+ values = RailsPerformance.redis.mget(keys)
21
+
22
+ RailsPerformance.log "\n\n [FOUND] --> #{values.size}\n\n"
38
23
 
39
24
  [keys, values]
40
25
  end
41
26
 
27
+ def Utils.save_to_redis(key, value, expire = RailsPerformance.duration.to_i)
28
+ # TODO think here if add return
29
+ #return if value.empty?
30
+
31
+ RailsPerformance.log " [SAVE] key ---> #{key}\n"
32
+ RailsPerformance.log " [SAVE] value ---> #{value.to_json}\n\n"
33
+ RailsPerformance.redis.set(key, value.to_json, ex: expire.to_i)
34
+ end
35
+
42
36
  def Utils.days
43
- (RP.duration / 1.day) + 1
37
+ (RailsPerformance.duration / 1.day) + 1
44
38
  end
45
39
 
46
40
  def Utils.median(array)
@@ -56,12 +50,5 @@ module RailsPerformance
56
50
  sorted[center]
57
51
  end
58
52
  end
59
-
60
- def Utils.save_to_redis(key, value, expire = RP.duration.to_i)
61
- # puts " [SAVE] key ---> #{key}\n"
62
- # puts " value ---> #{value.to_json}\n\n"
63
- RP.redis.set(key, value.to_json, ex: expire.to_i)
64
- end
65
-
66
53
  end
67
54
  end
@@ -1,3 +1,3 @@
1
1
  module RailsPerformance
2
- VERSION = '0.9.9'
2
+ VERSION = '1.0.0.beta1'
3
3
  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: 0.9.9
4
+ version: 1.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: grape
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: otr-activerecord
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: sidekiq
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +136,34 @@ dependencies:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: delayed_job_active_record
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: daemons
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
111
167
  description: 3rd party dependency-free solution how to monitor performance of your
112
168
  Rails applications.
113
169
  email:
@@ -144,10 +200,14 @@ files:
144
200
  - app/views/rails_performance/rails_performance/_summary.html.erb
145
201
  - app/views/rails_performance/rails_performance/_trace.html.erb
146
202
  - app/views/rails_performance/rails_performance/crashes.html.erb
203
+ - app/views/rails_performance/rails_performance/custom.html.erb
204
+ - app/views/rails_performance/rails_performance/delayed_job.html.erb
205
+ - app/views/rails_performance/rails_performance/grape.html.erb
147
206
  - app/views/rails_performance/rails_performance/index.html.erb
148
- - app/views/rails_performance/rails_performance/jobs.html.erb
207
+ - app/views/rails_performance/rails_performance/rake.html.erb
149
208
  - app/views/rails_performance/rails_performance/recent.html.erb
150
209
  - app/views/rails_performance/rails_performance/requests.html.erb
210
+ - app/views/rails_performance/rails_performance/sidekiq.html.erb
151
211
  - app/views/rails_performance/rails_performance/summary.js.erb
152
212
  - app/views/rails_performance/rails_performance/trace.js.erb
153
213
  - app/views/rails_performance/shared/_header.html.erb
@@ -162,14 +222,22 @@ files:
162
222
  - lib/rails_performance.rb
163
223
  - lib/rails_performance/data_source.rb
164
224
  - lib/rails_performance/engine.rb
165
- - lib/rails_performance/extensions/capture_everything.rb
166
- - lib/rails_performance/gems/sidekiq.rb
225
+ - lib/rails_performance/extensions/trace.rb
226
+ - lib/rails_performance/gems/custom_ext.rb
227
+ - lib/rails_performance/gems/delayed_job_ext.rb
228
+ - lib/rails_performance/gems/grape_ext.rb
229
+ - lib/rails_performance/gems/rake_ext.rb
230
+ - lib/rails_performance/gems/sidekiq_ext.rb
167
231
  - lib/rails_performance/instrument/metrics_collector.rb
168
232
  - lib/rails_performance/models/base_record.rb
169
233
  - lib/rails_performance/models/collection.rb
170
- - lib/rails_performance/models/current_request.rb
171
- - lib/rails_performance/models/job_record.rb
172
- - lib/rails_performance/models/record.rb
234
+ - lib/rails_performance/models/custom_record.rb
235
+ - lib/rails_performance/models/delayed_job_record.rb
236
+ - lib/rails_performance/models/grape_record.rb
237
+ - lib/rails_performance/models/rake_record.rb
238
+ - lib/rails_performance/models/request_record.rb
239
+ - lib/rails_performance/models/sidekiq_record.rb
240
+ - lib/rails_performance/models/trace_record.rb
173
241
  - lib/rails_performance/rails/middleware.rb
174
242
  - lib/rails_performance/rails/query_builder.rb
175
243
  - lib/rails_performance/reports/base_report.rb
@@ -180,6 +248,7 @@ files:
180
248
  - lib/rails_performance/reports/response_time_report.rb
181
249
  - lib/rails_performance/reports/throughput_report.rb
182
250
  - lib/rails_performance/reports/trace_report.rb
251
+ - lib/rails_performance/thread/current_request.rb
183
252
  - lib/rails_performance/utils.rb
184
253
  - lib/rails_performance/version.rb
185
254
  homepage: https://github.com/igorkasyanchuk/rails_performance
@@ -197,9 +266,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
266
  version: '0'
198
267
  required_rubygems_version: !ruby/object:Gem::Requirement
199
268
  requirements:
200
- - - ">="
269
+ - - ">"
201
270
  - !ruby/object:Gem::Version
202
- version: '0'
271
+ version: 1.3.1
203
272
  requirements: []
204
273
  rubygems_version: 3.0.3
205
274
  signing_key:
@@ -1,48 +0,0 @@
1
- module RailsPerformance
2
- module Models
3
- class JobRecord < BaseRecord
4
- attr_reader :queue, :worker, :jid, :created_ati, :enqueued_ati, :datetime, :start_timei, :status
5
-
6
- # key = job-performance
7
- # |queue|default
8
- # |worker|SimpleWorker
9
- # |jid|7d48fbf20976c224510dbc60
10
- # |datetime|20200124T0523
11
- # |created_ati|1583146613
12
- # |enqueued_ati|1583146613
13
- # |start_timei|1583146614
14
- # |status|success|END
15
- # value = JSON
16
- def initialize(key, value)
17
- @json = value
18
-
19
- items = key.split("|")
20
-
21
- @queue = items[2]
22
- @worker = items[4]
23
- @jid = items[6]
24
- @datetime = items[8]
25
- @created_ati = items[10]
26
- @enqueued_ati = items[12]
27
- @start_timei = items[14]
28
- @status = items[16]
29
- end
30
-
31
- def to_h
32
- {
33
- queue: queue,
34
- worker: worker,
35
- jid: jid,
36
- datetime: datetime,
37
- created_ati: created_ati,
38
- enqueued_ati: enqueued_ati,
39
- start_timei: start_timei,
40
- duration: duration,
41
- status: status,
42
- message: value['message']
43
- }
44
- end
45
-
46
- end
47
- end
48
- end
@@ -1,68 +0,0 @@
1
- module RailsPerformance
2
- module Models
3
- class Record < BaseRecord
4
- attr_reader :controller, :action, :format, :status, :datetime, :datetimei, :method, :path, :request_id
5
-
6
- def Record.find_by(request_id:)
7
- keys, values = RP::Utils.fetch_from_redis("performance|*|request_id|#{request_id}|*")
8
-
9
- return nil if keys.blank?
10
- return nil if values.blank?
11
-
12
- RP::Models::Record.new(keys[0], values[0])
13
- end
14
-
15
- # key = performance|
16
- # controller|HomeController|
17
- # action|index|
18
- # format|html|
19
- # status|200|
20
- # datetime|20200124T0523|
21
- # datetimei|1579861423|
22
- # method|GET|
23
- # path|/|
24
- # request_id|454545454545454545|
25
- # END
26
- # = {"view_runtime":8.444603008683771,"db_runtime":0,"duration":9.216095000000001}
27
- # value = JSON
28
- def initialize(key, value)
29
- @json = value
30
-
31
- items = key.split("|")
32
-
33
- @controller = items[2]
34
- @action = items[4]
35
- @format = items[6]
36
- @status = items[8]
37
- @datetime = items[10]
38
- @datetimei = items[12]
39
- @method = items[14]
40
- @path = items[16]
41
- @request_id = items[18]
42
- end
43
-
44
- def controller_action
45
- "#{controller}##{action}"
46
- end
47
-
48
- def controller_action_format
49
- "#{controller}##{action}|#{format}"
50
- end
51
-
52
- def to_h
53
- {
54
- controller: controller,
55
- action: action,
56
- format: format,
57
- method: method,
58
- path: path,
59
- duration: ms(duration),
60
- view_runtime: ms(value['view_runtime']),
61
- db_runtime: ms(value['db_runtime']),
62
- HTTP_REFERER: value['HTTP_REFERER']
63
- }
64
- end
65
-
66
- end
67
- end
68
- end