rails_performance 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -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 +95 -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/recent.html.erb +8 -6
  13. data/app/views/rails_performance/rails_performance/requests.html.erb +8 -1
  14. data/app/views/rails_performance/rails_performance/slow.html.erb +4 -1
  15. data/app/views/rails_performance/shared/_header.html.erb +0 -1
  16. data/app/views/rails_performance/stylesheets/style.css +6 -0
  17. data/config/routes.rb +16 -18
  18. data/lib/generators/rails_performance/install/install_generator.rb +1 -1
  19. data/lib/generators/rails_performance/install/templates/initializer.rb +56 -38
  20. data/lib/rails_performance/data_source.rb +120 -121
  21. data/lib/rails_performance/engine.rb +8 -8
  22. data/lib/rails_performance/extensions/trace.rb +32 -33
  23. data/lib/rails_performance/gems/custom_ext.rb +31 -34
  24. data/lib/rails_performance/gems/delayed_job_ext.rb +50 -54
  25. data/lib/rails_performance/gems/grape_ext.rb +33 -35
  26. data/lib/rails_performance/gems/rake_ext.rb +41 -44
  27. data/lib/rails_performance/gems/sidekiq_ext.rb +34 -37
  28. data/lib/rails_performance/instrument/metrics_collector.rb +50 -49
  29. data/lib/rails_performance/models/base_record.rb +33 -36
  30. data/lib/rails_performance/models/collection.rb +35 -36
  31. data/lib/rails_performance/models/custom_record.rb +47 -48
  32. data/lib/rails_performance/models/delayed_job_record.rb +61 -62
  33. data/lib/rails_performance/models/grape_record.rb +60 -61
  34. data/lib/rails_performance/models/rake_record.rb +48 -49
  35. data/lib/rails_performance/models/request_record.rb +123 -120
  36. data/lib/rails_performance/models/sidekiq_record.rb +65 -66
  37. data/lib/rails_performance/models/trace_record.rb +18 -19
  38. data/lib/rails_performance/rails/middleware.rb +75 -76
  39. data/lib/rails_performance/rails/query_builder.rb +18 -20
  40. data/lib/rails_performance/reports/base_report.rb +60 -60
  41. data/lib/rails_performance/reports/breakdown_report.rb +15 -18
  42. data/lib/rails_performance/reports/crash_report.rb +15 -17
  43. data/lib/rails_performance/reports/recent_requests_report.rb +24 -24
  44. data/lib/rails_performance/reports/requests_report.rb +27 -27
  45. data/lib/rails_performance/reports/response_time_report.rb +17 -17
  46. data/lib/rails_performance/reports/slow_requests_report.rb +4 -4
  47. data/lib/rails_performance/reports/throughput_report.rb +15 -17
  48. data/lib/rails_performance/reports/trace_report.rb +16 -18
  49. data/lib/rails_performance/thread/current_request.rb +33 -34
  50. data/lib/rails_performance/utils.rb +53 -54
  51. data/lib/rails_performance/version.rb +2 -2
  52. data/lib/rails_performance.rb +38 -33
  53. metadata +20 -3
@@ -1,61 +1,60 @@
1
- module RailsPerformance
2
- module Models
3
- class GrapeRecord < BaseRecord
4
- attr_accessor :datetime, :datetimei, :format, :status, :path, :method, :request_id, :json
5
- attr_accessor :endpoint_render_grape, :endpoint_run_grape, :format_response_grape
6
-
7
- # key = grape|datetime|20210409T1115|datetimei|1617992134|format|json|path|/api/users|status|200|method|GET|request_id|1122|END|1.0.0
8
- # value = {"endpoint_render.grape"=>0.000643989, "endpoint_run.grape"=>0.002000907, "format_response.grape"=>0.0348967}
9
- def GrapeRecord.from_db(key, value)
10
- items = key.split("|")
11
-
12
- GrapeRecord.new(
13
- datetime: items[2],
14
- datetimei: items[4],
15
- format: items[6],
16
- path: items[8],
17
- status: items[10],
18
- method: items[12],
19
- request_id: items[14],
20
- json: value
21
- )
22
- end
23
-
24
- def initialize(datetime: nil, datetimei: nil, format: nil, path: nil, status: nil, method: nil, request_id:, endpoint_render_grape: nil, endpoint_run_grape: nil, format_response_grape: nil, json: '{}')
25
- @datetime = datetime
26
- @datetimei = datetimei.to_i unless datetimei.nil?
27
- @format = format
28
- @path = path
29
- @status = status
30
- @method = method
31
- @request_id = request_id
32
-
33
- @endpoint_render_grape = endpoint_render_grape
34
- @endpoint_run_grape = endpoint_run_grape
35
- @format_response_grape = format_response_grape
36
-
37
- @json = json
38
- end
39
-
40
- def record_hash
41
- {
42
- format: self.format,
43
- status: self.status,
44
- method: self.method,
45
- path: self.path,
46
- datetime: Time.at(self.datetimei.to_i),
47
- datetimei: datetimei.to_i,
48
- request_id: self.request_id,
49
- }.merge(self.value)
50
- end
51
-
52
- def save
53
- key = "grape|datetime|#{datetime}|datetimei|#{datetimei}|format|#{format}|path|#{path}|status|#{status}|method|#{method}|request_id|#{request_id}|END|#{RailsPerformance::SCHEMA}"
54
- value = { "endpoint_render.grape" => endpoint_render_grape, "endpoint_run.grape" => endpoint_run_grape, "format_response.grape" => format_response_grape }
55
-
56
- Utils.save_to_redis(key, value)
57
- end
58
-
59
- end
60
- end
61
- end
1
+ module RailsPerformance
2
+ module Models
3
+ class GrapeRecord < BaseRecord
4
+ attr_accessor :datetime, :datetimei, :format, :status, :path, :method, :request_id, :json
5
+ attr_accessor :endpoint_render_grape, :endpoint_run_grape, :format_response_grape
6
+
7
+ # key = grape|datetime|20210409T1115|datetimei|1617992134|format|json|path|/api/users|status|200|method|GET|request_id|1122|END|1.0.0
8
+ # value = {"endpoint_render.grape"=>0.000643989, "endpoint_run.grape"=>0.002000907, "format_response.grape"=>0.0348967}
9
+ def self.from_db(key, value)
10
+ items = key.split("|")
11
+
12
+ GrapeRecord.new(
13
+ datetime: items[2],
14
+ datetimei: items[4],
15
+ format: items[6],
16
+ path: items[8],
17
+ status: items[10],
18
+ method: items[12],
19
+ request_id: items[14],
20
+ json: value
21
+ )
22
+ end
23
+
24
+ def initialize(request_id:, datetime: nil, datetimei: nil, format: nil, path: nil, status: nil, method: nil, endpoint_render_grape: nil, endpoint_run_grape: nil, format_response_grape: nil, json: "{}")
25
+ @datetime = datetime
26
+ @datetimei = datetimei.to_i unless datetimei.nil?
27
+ @format = format
28
+ @path = path
29
+ @status = status
30
+ @method = method
31
+ @request_id = request_id
32
+
33
+ @endpoint_render_grape = endpoint_render_grape
34
+ @endpoint_run_grape = endpoint_run_grape
35
+ @format_response_grape = format_response_grape
36
+
37
+ @json = json
38
+ end
39
+
40
+ def record_hash
41
+ {
42
+ format: self.format,
43
+ status: status,
44
+ method: method,
45
+ path: path,
46
+ datetime: Time.at(datetimei.to_i),
47
+ datetimei: datetimei.to_i,
48
+ request_id: request_id
49
+ }.merge(value)
50
+ end
51
+
52
+ def save
53
+ key = "grape|datetime|#{datetime}|datetimei|#{datetimei}|format|#{format}|path|#{path}|status|#{status}|method|#{method}|request_id|#{request_id}|END|#{RailsPerformance::SCHEMA}"
54
+ value = {"endpoint_render.grape" => endpoint_render_grape, "endpoint_run.grape" => endpoint_run_grape, "format_response.grape" => format_response_grape}
55
+
56
+ Utils.save_to_redis(key, value)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,49 +1,48 @@
1
- module RailsPerformance
2
- module Models
3
- class RakeRecord < BaseRecord
4
- attr_accessor :task, :duration, :datetime, :datetimei, :status
5
-
6
- # rake|task|["task3"]|datetime|20210416T1254|datetimei|1618602843|status|error|END|1.0.0
7
- # {"duration":0.00012442}
8
- def RakeRecord.from_db(key, value)
9
- items = key.split("|")
10
-
11
- RakeRecord.new(
12
- task: JSON.parse(items[2]),
13
- datetime: items[4],
14
- datetimei: items[6],
15
- status: items[8],
16
- json: value
17
- )
18
- end
19
-
20
- def initialize(task:, duration: nil, datetime:, datetimei:, status:, json: '{}')
21
- @task = Array.wrap(task)
22
- @datetime = datetime
23
- @datetimei = datetimei.to_i
24
- @status = status
25
- @duration = duration
26
- @json = json
27
-
28
- @duration ||= value['duration']
29
- end
30
-
31
- def record_hash
32
- {
33
- task: task,
34
- datetime: Time.at(datetimei),
35
- datetimei: datetimei,
36
- duration: duration,
37
- status: status,
38
- }
39
- end
40
-
41
- def save
42
- key = "rake|task|#{task.to_json}|datetime|#{datetime}|datetimei|#{datetimei}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
43
- value = { duration: duration }
44
- Utils.save_to_redis(key, value)
45
- end
46
-
47
- end
48
- end
49
- end
1
+ module RailsPerformance
2
+ module Models
3
+ class RakeRecord < BaseRecord
4
+ attr_accessor :task, :duration, :datetime, :datetimei, :status
5
+
6
+ # rake|task|["task3"]|datetime|20210416T1254|datetimei|1618602843|status|error|END|1.0.0
7
+ # {"duration":0.00012442}
8
+ def self.from_db(key, value)
9
+ items = key.split("|")
10
+
11
+ RakeRecord.new(
12
+ task: JSON.parse(items[2]),
13
+ datetime: items[4],
14
+ datetimei: items[6],
15
+ status: items[8],
16
+ json: value
17
+ )
18
+ end
19
+
20
+ def initialize(task:, datetime:, datetimei:, status:, duration: nil, json: "{}")
21
+ @task = Array.wrap(task)
22
+ @datetime = datetime
23
+ @datetimei = datetimei.to_i
24
+ @status = status
25
+ @duration = duration
26
+ @json = json
27
+
28
+ @duration ||= value["duration"]
29
+ end
30
+
31
+ def record_hash
32
+ {
33
+ task: task,
34
+ datetime: Time.at(datetimei),
35
+ datetimei: datetimei,
36
+ duration: duration,
37
+ status: status
38
+ }
39
+ end
40
+
41
+ def save
42
+ key = "rake|task|#{task.to_json}|datetime|#{datetime}|datetimei|#{datetimei}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
43
+ value = {duration: duration}
44
+ Utils.save_to_redis(key, value)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,120 +1,123 @@
1
- module RailsPerformance
2
- module Models
3
- class RequestRecord < BaseRecord
4
- attr_accessor :controller, :action, :format, :status, :datetime, :datetimei, :method, :path, :request_id, :json
5
- attr_accessor :view_runtime, :db_runtime, :duration, :http_referer, :custom_data
6
- attr_accessor :exception, :exception_object
7
-
8
- def RequestRecord.find_by(request_id:)
9
- keys, values = RailsPerformance::Utils.fetch_from_redis("performance|*|request_id|#{request_id}|*")
10
-
11
- return nil if keys.blank?
12
- return nil if values.blank?
13
-
14
- RailsPerformance::Models::RequestRecord.from_db(keys[0], values[0])
15
- end
16
-
17
- # key = performance|
18
- # controller|HomeController|
19
- # action|index|
20
- # format|html|
21
- # status|200|
22
- # datetime|20200124T0523|
23
- # datetimei|1579861423|
24
- # method|GET|
25
- # path|/|
26
- # request_id|454545454545454545|
27
- # END|1.0.0
28
- # = {"view_runtime":null,"db_runtime":0,"duration":27.329741000000002,"http_referer":null,"custom_data":null,"exception":"ZeroDivisionError divided by 0","backtrace":["/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `/'","/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `crash'","/usr/local/rvm/gems/ruby-2.6.3/gems/actionpack-6.1.3.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"]}
29
- # value = JSON
30
- def RequestRecord.from_db(key, value)
31
- items = key.split("|")
32
-
33
- RequestRecord.new(
34
- controller: items[2],
35
- action: items[4],
36
- format: items[6],
37
- status: items[8],
38
- datetime: items[10],
39
- datetimei: items[12],
40
- method: items[14],
41
- path: items[16],
42
- request_id: items[18],
43
- json: value
44
- )
45
- end
46
-
47
- def initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, custom_data: nil, exception: nil, exception_object: nil, json: '{}')
48
- @controller = controller
49
- @action = action
50
- @format = format
51
- @status = status
52
- @datetime = datetime
53
- @datetimei = datetimei.to_i
54
- @method = method
55
- @path = path
56
- @request_id = request_id
57
-
58
- @view_runtime = view_runtime
59
- @db_runtime = db_runtime
60
- @duration = duration
61
- @http_referer = http_referer
62
- @custom_data = custom_data
63
-
64
- @exception = Array.wrap(exception).compact.join(" ")
65
- @exception_object = exception_object
66
-
67
- @json = json
68
- end
69
-
70
- def controller_action
71
- "#{controller}##{action}"
72
- end
73
-
74
- def controller_action_format
75
- "#{controller}##{action}|#{format}"
76
- end
77
-
78
- # show on UI in the right panel
79
- def record_hash
80
- {
81
- controller: self.controller,
82
- action: self.action,
83
- format: self.format,
84
- status: self.status,
85
- method: self.method,
86
- path: self.path,
87
- request_id: self.request_id,
88
- datetime: Time.at(self.datetimei.to_i),
89
- datetimei: datetimei,
90
- duration: self.value['duration'],
91
- db_runtime: self.value['db_runtime'],
92
- view_runtime: self.value['view_runtime'],
93
- exception: self.value['exception'],
94
- backtrace: self.value['backtrace'],
95
- http_referer: self.value['http_referer']
96
- }.tap do |h|
97
- custom_data = JSON.parse(self.value['custom_data']) rescue nil
98
- if custom_data.is_a?(Hash)
99
- h.merge!(custom_data)
100
- end
101
- end
102
- end
103
-
104
- def save
105
- key = "performance|controller|#{controller}|action|#{action}|format|#{format}|status|#{status}|datetime|#{datetime}|datetimei|#{datetimei}|method|#{method}|path|#{path}|request_id|#{request_id}|END|#{RailsPerformance::SCHEMA}"
106
- value = {
107
- view_runtime: view_runtime,
108
- db_runtime: db_runtime,
109
- duration: duration,
110
- http_referer: http_referer,
111
- custom_data: custom_data.to_json
112
- }
113
- value[:exception] = exception if exception.present?
114
- value[:backtrace] = exception_object.backtrace.take(3) if exception_object
115
- Utils.save_to_redis(key, value)
116
- end
117
-
118
- end
119
- end
120
- end
1
+ module RailsPerformance
2
+ module Models
3
+ class RequestRecord < BaseRecord
4
+ attr_accessor :controller, :action, :format, :status, :datetime, :datetimei, :method, :path, :request_id, :json
5
+ attr_accessor :view_runtime, :db_runtime, :duration, :http_referer, :custom_data
6
+ attr_accessor :exception, :exception_object
7
+
8
+ def self.find_by(request_id:)
9
+ keys, values = RailsPerformance::Utils.fetch_from_redis("performance|*|request_id|#{request_id}|*")
10
+
11
+ return nil if keys.blank?
12
+ return nil if values.blank?
13
+
14
+ RailsPerformance::Models::RequestRecord.from_db(keys[0], values[0])
15
+ end
16
+
17
+ # key = performance|
18
+ # controller|HomeController|
19
+ # action|index|
20
+ # format|html|
21
+ # status|200|
22
+ # datetime|20200124T0523|
23
+ # datetimei|1579861423|
24
+ # method|GET|
25
+ # path|/|
26
+ # request_id|454545454545454545|
27
+ # END|1.0.0
28
+ # = {"view_runtime":null,"db_runtime":0,"duration":27.329741000000002,"http_referer":null,"custom_data":null,"exception":"ZeroDivisionError divided by 0","backtrace":["/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `/'","/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `crash'","/usr/local/rvm/gems/ruby-2.6.3/gems/actionpack-6.1.3.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"]}
29
+ # value = JSON
30
+ def self.from_db(key, value)
31
+ items = key.split("|")
32
+
33
+ RequestRecord.new(
34
+ controller: items[2],
35
+ action: items[4],
36
+ format: items[6],
37
+ status: items[8],
38
+ datetime: items[10],
39
+ datetimei: items[12],
40
+ method: items[14],
41
+ path: items[16],
42
+ request_id: items[18],
43
+ json: value
44
+ )
45
+ end
46
+
47
+ def initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, custom_data: nil, exception: nil, exception_object: nil, json: "{}")
48
+ @controller = controller
49
+ @action = action
50
+ @format = format
51
+ @status = status
52
+ @datetime = datetime
53
+ @datetimei = datetimei.to_i
54
+ @method = method
55
+ @path = path
56
+ @request_id = request_id
57
+
58
+ @view_runtime = view_runtime
59
+ @db_runtime = db_runtime
60
+ @duration = duration
61
+ @http_referer = http_referer
62
+ @custom_data = custom_data
63
+
64
+ @exception = Array.wrap(exception).compact.join(" ")
65
+ @exception_object = exception_object
66
+
67
+ @json = json
68
+ end
69
+
70
+ def controller_action
71
+ "#{controller}##{action}"
72
+ end
73
+
74
+ def controller_action_format
75
+ "#{controller}##{action}|#{format}"
76
+ end
77
+
78
+ # show on UI in the right panel
79
+ def record_hash
80
+ {
81
+ controller: controller,
82
+ action: action,
83
+ format: self.format,
84
+ status: status,
85
+ method: method,
86
+ path: path,
87
+ request_id: request_id,
88
+ datetime: Time.at(datetimei.to_i),
89
+ datetimei: datetimei,
90
+ duration: value["duration"],
91
+ db_runtime: value["db_runtime"],
92
+ view_runtime: value["view_runtime"],
93
+ exception: value["exception"],
94
+ backtrace: value["backtrace"],
95
+ http_referer: value["http_referer"]
96
+ }.tap do |h|
97
+ custom_data = begin
98
+ JSON.parse(value["custom_data"])
99
+ rescue
100
+ nil
101
+ end
102
+ if custom_data.is_a?(Hash)
103
+ h.merge!(custom_data)
104
+ end
105
+ end
106
+ end
107
+
108
+ def save
109
+ key = "performance|controller|#{controller}|action|#{action}|format|#{format}|status|#{status}|datetime|#{datetime}|datetimei|#{datetimei}|method|#{method}|path|#{path}|request_id|#{request_id}|END|#{RailsPerformance::SCHEMA}"
110
+ value = {
111
+ view_runtime: view_runtime,
112
+ db_runtime: db_runtime,
113
+ duration: duration,
114
+ http_referer: http_referer,
115
+ custom_data: custom_data.to_json
116
+ }
117
+ value[:exception] = exception if exception.present?
118
+ value[:backtrace] = exception_object.backtrace.take(3) if exception_object
119
+ Utils.save_to_redis(key, value)
120
+ end
121
+ end
122
+ end
123
+ end
@@ -1,66 +1,65 @@
1
- module RailsPerformance
2
- module Models
3
- class SidekiqRecord < BaseRecord
4
- attr_accessor :queue, :worker, :jid, :datetimei, :enqueued_ati, :datetime, :start_timei, :status, :duration, :message
5
-
6
- # key = job-performance
7
- # |queue|default
8
- # |worker|SimpleWorker
9
- # |jid|7d48fbf20976c224510dbc60
10
- # |datetime|20200124T0523
11
- # |datetimei|1583146613
12
- # |enqueued_ati|1583146613
13
- # |start_timei|1583146614
14
- # |status|success|END|1.0.0
15
- # value = JSON
16
- def SidekiqRecord.from_db(key, value)
17
- items = key.split("|")
18
-
19
- SidekiqRecord.new(
20
- queue: items[2],
21
- worker: items[4],
22
- jid: items[6],
23
- datetime: items[8],
24
- datetimei: items[10],
25
- enqueued_ati: items[12],
26
- start_timei: items[14],
27
- status: items[16],
28
- json: value
29
- )
30
- end
31
-
32
- def initialize(queue:, worker:, jid:, datetime:, datetimei:, enqueued_ati:, start_timei:, status: nil, duration: nil, json: "{}")
33
- @queue = queue
34
- @worker = worker
35
- @jid = jid
36
- @datetime = datetime
37
- @datetimei = datetimei.to_i
38
- @enqueued_ati = enqueued_ati
39
- @start_timei = start_timei
40
- @status = status
41
- @duration = duration
42
- @json = json
43
- end
44
-
45
- def record_hash
46
- {
47
- worker: self.worker,
48
- queue: self.queue,
49
- jid: self.jid,
50
- status: self.status,
51
- datetimei: datetimei,
52
- datetime: Time.at(self.start_timei.to_i),
53
- duration: self.value['duration'],
54
- message: value['message']
55
- }
56
- end
57
-
58
- def save
59
- key = "sidekiq|queue|#{queue}|worker|#{worker}|jid|#{jid}|datetime|#{datetime}|datetimei|#{datetimei}|enqueued_ati|#{enqueued_ati}|start_timei|#{start_timei}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
60
- value = { message: message, duration: duration }
61
- Utils.save_to_redis(key, value)
62
- end
63
-
64
- end
65
- end
66
- end
1
+ module RailsPerformance
2
+ module Models
3
+ class SidekiqRecord < BaseRecord
4
+ attr_accessor :queue, :worker, :jid, :datetimei, :enqueued_ati, :datetime, :start_timei, :status, :duration, :message
5
+
6
+ # key = job-performance
7
+ # |queue|default
8
+ # |worker|SimpleWorker
9
+ # |jid|7d48fbf20976c224510dbc60
10
+ # |datetime|20200124T0523
11
+ # |datetimei|1583146613
12
+ # |enqueued_ati|1583146613
13
+ # |start_timei|1583146614
14
+ # |status|success|END|1.0.0
15
+ # value = JSON
16
+ def self.from_db(key, value)
17
+ items = key.split("|")
18
+
19
+ SidekiqRecord.new(
20
+ queue: items[2],
21
+ worker: items[4],
22
+ jid: items[6],
23
+ datetime: items[8],
24
+ datetimei: items[10],
25
+ enqueued_ati: items[12],
26
+ start_timei: items[14],
27
+ status: items[16],
28
+ json: value
29
+ )
30
+ end
31
+
32
+ def initialize(queue:, worker:, jid:, datetime:, datetimei:, enqueued_ati:, start_timei:, status: nil, duration: nil, json: "{}")
33
+ @queue = queue
34
+ @worker = worker
35
+ @jid = jid
36
+ @datetime = datetime
37
+ @datetimei = datetimei.to_i
38
+ @enqueued_ati = enqueued_ati
39
+ @start_timei = start_timei
40
+ @status = status
41
+ @duration = duration
42
+ @json = json
43
+ end
44
+
45
+ def record_hash
46
+ {
47
+ worker: worker,
48
+ queue: queue,
49
+ jid: jid,
50
+ status: status,
51
+ datetimei: datetimei,
52
+ datetime: Time.at(start_timei.to_i),
53
+ duration: value["duration"],
54
+ message: value["message"]
55
+ }
56
+ end
57
+
58
+ def save
59
+ key = "sidekiq|queue|#{queue}|worker|#{worker}|jid|#{jid}|datetime|#{datetime}|datetimei|#{datetimei}|enqueued_ati|#{enqueued_ati}|start_timei|#{start_timei}|status|#{status}|END|#{RailsPerformance::SCHEMA}"
60
+ value = {message: message, duration: duration}
61
+ Utils.save_to_redis(key, value)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,19 +1,18 @@
1
- module RailsPerformance
2
- module Models
3
- class TraceRecord < BaseRecord
4
- attr_accessor :request_id, :value
5
-
6
- def initialize(request_id:, value:)
7
- @request_id = request_id
8
- @value = value
9
- end
10
-
11
- def save
12
- return if value.empty?
13
-
14
- Utils.save_to_redis("trace|#{request_id}|END|#{RailsPerformance::SCHEMA}", value, RailsPerformance.recent_requests_time_window.to_i)
15
- end
16
-
17
- end
18
- end
19
- end
1
+ module RailsPerformance
2
+ module Models
3
+ class TraceRecord < BaseRecord
4
+ attr_accessor :request_id, :value
5
+
6
+ def initialize(request_id:, value:)
7
+ @request_id = request_id
8
+ @value = value
9
+ end
10
+
11
+ def save
12
+ return if value.empty?
13
+
14
+ Utils.save_to_redis("trace|#{request_id}|END|#{RailsPerformance::SCHEMA}", value, RailsPerformance.recent_requests_time_window.to_i)
15
+ end
16
+ end
17
+ end
18
+ end