rails_performance 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +95 -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/recent.html.erb +8 -6
- data/app/views/rails_performance/rails_performance/requests.html.erb +8 -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 +6 -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 +123 -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/recent_requests_report.rb +24 -24
- data/lib/rails_performance/reports/requests_report.rb +27 -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 +53 -54
- data/lib/rails_performance/version.rb +2 -2
- data/lib/rails_performance.rb +33 -34
- metadata +20 -3
@@ -1,121 +1,120 @@
|
|
1
|
-
module RailsPerformance
|
2
|
-
class DataSource
|
3
|
-
KLASSES = {
|
4
|
-
requests: RailsPerformance::Models::RequestRecord,
|
5
|
-
sidekiq: RailsPerformance::Models::SidekiqRecord,
|
6
|
-
delayed_job: RailsPerformance::Models::DelayedJobRecord,
|
7
|
-
grape: RailsPerformance::Models::GrapeRecord,
|
8
|
-
rake: RailsPerformance::Models::RakeRecord,
|
9
|
-
custom: RailsPerformance::Models::CustomRecord
|
10
|
-
}
|
11
|
-
|
12
|
-
attr_reader :q, :klass, :type
|
13
|
-
|
14
|
-
def initialize(q: {}
|
15
|
-
@type
|
16
|
-
@klass
|
17
|
-
q[:on] ||= Date.today
|
18
|
-
@q
|
19
|
-
end
|
20
|
-
|
21
|
-
def db
|
22
|
-
result = RailsPerformance::Models::Collection.new
|
23
|
-
(0..(RailsPerformance::Utils.days + 1)).to_a.
|
24
|
-
RailsPerformance::DataSource.new(q:
|
25
|
-
end
|
26
|
-
result
|
27
|
-
end
|
28
|
-
|
29
|
-
def default?
|
30
|
-
@q.keys == [:on]
|
31
|
-
end
|
32
|
-
|
33
|
-
def add_to(storage = RailsPerformance::Models::Collection.new)
|
34
|
-
store do |record|
|
35
|
-
storage.add(record)
|
36
|
-
end
|
37
|
-
storage
|
38
|
-
end
|
39
|
-
|
40
|
-
def store
|
41
|
-
keys, values = Utils.fetch_from_redis(query)
|
42
|
-
|
43
|
-
return [] if keys.blank?
|
44
|
-
|
45
|
-
keys.each_with_index do |key, index|
|
46
|
-
yield klass.from_db(key, values[index])
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def query
|
53
|
-
case type
|
54
|
-
when :requests
|
55
|
-
"performance|*#{compile_requests_query}*|END|#{RailsPerformance::SCHEMA}"
|
56
|
-
when :sidekiq
|
57
|
-
"sidekiq|*#{compile_sidekiq_query}*|END|#{RailsPerformance::SCHEMA}"
|
58
|
-
when :delayed_job
|
59
|
-
"delayed_job|*#{compile_delayed_job_query}*|END|#{RailsPerformance::SCHEMA}"
|
60
|
-
when :grape
|
61
|
-
"grape|*#{compile_grape_query}*|END|#{RailsPerformance::SCHEMA}"
|
62
|
-
when :rake
|
63
|
-
"rake|*#{compile_rake_query}*|END|#{RailsPerformance::SCHEMA}"
|
64
|
-
when :custom
|
65
|
-
"custom|*#{compile_custom_query}*|END|#{RailsPerformance::SCHEMA}"
|
66
|
-
else
|
67
|
-
raise "wrong type for datasource query builder"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def compile_requests_query
|
72
|
-
str = []
|
73
|
-
str << "controller|#{q[:controller]}|" if q[:controller].present?
|
74
|
-
str << "action|#{q[:action]}|" if q[:action].present?
|
75
|
-
str << "format|#{q[:format]}|" if q[:format].present?
|
76
|
-
str << "status|#{q[:status]}|" if q[:status].present?
|
77
|
-
str << "datetime|#{q[:on].strftime(
|
78
|
-
str << "method|#{q[:method]}|" if q[:method].present?
|
79
|
-
str << "path|#{q[:path]}|" if q[:path].present?
|
80
|
-
str.join("*")
|
81
|
-
end
|
82
|
-
|
83
|
-
def compile_sidekiq_query
|
84
|
-
str = []
|
85
|
-
str << "queue|#{q[:queue]}|" if q[:queue].present?
|
86
|
-
str << "worker|#{q[:worker]}|" if q[:worker].present?
|
87
|
-
str << "datetime|#{q[:on].strftime(
|
88
|
-
str << "status|#{q[:status]}|" if q[:status].present?
|
89
|
-
str.join("*")
|
90
|
-
end
|
91
|
-
|
92
|
-
def compile_delayed_job_query
|
93
|
-
str = []
|
94
|
-
str << "datetime|#{q[:on].strftime(
|
95
|
-
str << "status|#{q[:status]}|" if q[:status].present?
|
96
|
-
str.join("*")
|
97
|
-
end
|
98
|
-
|
99
|
-
def compile_rake_query
|
100
|
-
str = []
|
101
|
-
str << "datetime|#{q[:on].strftime(
|
102
|
-
str << "status|#{q[:status]}|" if q[:status].present?
|
103
|
-
str.join("*")
|
104
|
-
end
|
105
|
-
|
106
|
-
def compile_custom_query
|
107
|
-
str = []
|
108
|
-
str << "datetime|#{q[:on].strftime(
|
109
|
-
str << "status|#{q[:status]}|" if q[:status].present?
|
110
|
-
str.join("*")
|
111
|
-
end
|
112
|
-
|
113
|
-
def compile_grape_query
|
114
|
-
str = []
|
115
|
-
str << "datetime|#{q[:on].strftime(
|
116
|
-
str << "status|#{q[:status]}|" if q[:status].present?
|
117
|
-
str.join("*")
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
end
|
1
|
+
module RailsPerformance
|
2
|
+
class DataSource
|
3
|
+
KLASSES = {
|
4
|
+
requests: RailsPerformance::Models::RequestRecord,
|
5
|
+
sidekiq: RailsPerformance::Models::SidekiqRecord,
|
6
|
+
delayed_job: RailsPerformance::Models::DelayedJobRecord,
|
7
|
+
grape: RailsPerformance::Models::GrapeRecord,
|
8
|
+
rake: RailsPerformance::Models::RakeRecord,
|
9
|
+
custom: RailsPerformance::Models::CustomRecord
|
10
|
+
}
|
11
|
+
|
12
|
+
attr_reader :q, :klass, :type
|
13
|
+
|
14
|
+
def initialize(type:, q: {})
|
15
|
+
@type = type
|
16
|
+
@klass = KLASSES[type]
|
17
|
+
q[:on] ||= Date.today
|
18
|
+
@q = q
|
19
|
+
end
|
20
|
+
|
21
|
+
def db
|
22
|
+
result = RailsPerformance::Models::Collection.new
|
23
|
+
(0..(RailsPerformance::Utils.days + 1)).to_a.reverse_each do |e|
|
24
|
+
RailsPerformance::DataSource.new(q: q.merge({on: (Time.current - e.days).to_date}), type: type).add_to(result)
|
25
|
+
end
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
def default?
|
30
|
+
@q.keys == [:on]
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_to(storage = RailsPerformance::Models::Collection.new)
|
34
|
+
store do |record|
|
35
|
+
storage.add(record)
|
36
|
+
end
|
37
|
+
storage
|
38
|
+
end
|
39
|
+
|
40
|
+
def store
|
41
|
+
keys, values = Utils.fetch_from_redis(query)
|
42
|
+
|
43
|
+
return [] if keys.blank?
|
44
|
+
|
45
|
+
keys.each_with_index do |key, index|
|
46
|
+
yield klass.from_db(key, values[index])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def query
|
53
|
+
case type
|
54
|
+
when :requests
|
55
|
+
"performance|*#{compile_requests_query}*|END|#{RailsPerformance::SCHEMA}"
|
56
|
+
when :sidekiq
|
57
|
+
"sidekiq|*#{compile_sidekiq_query}*|END|#{RailsPerformance::SCHEMA}"
|
58
|
+
when :delayed_job
|
59
|
+
"delayed_job|*#{compile_delayed_job_query}*|END|#{RailsPerformance::SCHEMA}"
|
60
|
+
when :grape
|
61
|
+
"grape|*#{compile_grape_query}*|END|#{RailsPerformance::SCHEMA}"
|
62
|
+
when :rake
|
63
|
+
"rake|*#{compile_rake_query}*|END|#{RailsPerformance::SCHEMA}"
|
64
|
+
when :custom
|
65
|
+
"custom|*#{compile_custom_query}*|END|#{RailsPerformance::SCHEMA}"
|
66
|
+
else
|
67
|
+
raise "wrong type for datasource query builder"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def compile_requests_query
|
72
|
+
str = []
|
73
|
+
str << "controller|#{q[:controller]}|" if q[:controller].present?
|
74
|
+
str << "action|#{q[:action]}|" if q[:action].present?
|
75
|
+
str << "format|#{q[:format]}|" if q[:format].present?
|
76
|
+
str << "status|#{q[:status]}|" if q[:status].present?
|
77
|
+
str << "datetime|#{q[:on].strftime("%Y%m%d")}*|" if q[:on].present?
|
78
|
+
str << "method|#{q[:method]}|" if q[:method].present?
|
79
|
+
str << "path|#{q[:path]}|" if q[:path].present?
|
80
|
+
str.join("*")
|
81
|
+
end
|
82
|
+
|
83
|
+
def compile_sidekiq_query
|
84
|
+
str = []
|
85
|
+
str << "queue|#{q[:queue]}|" if q[:queue].present?
|
86
|
+
str << "worker|#{q[:worker]}|" if q[:worker].present?
|
87
|
+
str << "datetime|#{q[:on].strftime("%Y%m%d")}*|" if q[:on].present?
|
88
|
+
str << "status|#{q[:status]}|" if q[:status].present?
|
89
|
+
str.join("*")
|
90
|
+
end
|
91
|
+
|
92
|
+
def compile_delayed_job_query
|
93
|
+
str = []
|
94
|
+
str << "datetime|#{q[:on].strftime("%Y%m%d")}*|" if q[:on].present?
|
95
|
+
str << "status|#{q[:status]}|" if q[:status].present?
|
96
|
+
str.join("*")
|
97
|
+
end
|
98
|
+
|
99
|
+
def compile_rake_query
|
100
|
+
str = []
|
101
|
+
str << "datetime|#{q[:on].strftime("%Y%m%d")}*|" if q[:on].present?
|
102
|
+
str << "status|#{q[:status]}|" if q[:status].present?
|
103
|
+
str.join("*")
|
104
|
+
end
|
105
|
+
|
106
|
+
def compile_custom_query
|
107
|
+
str = []
|
108
|
+
str << "datetime|#{q[:on].strftime("%Y%m%d")}*|" if q[:on].present?
|
109
|
+
str << "status|#{q[:status]}|" if q[:status].present?
|
110
|
+
str.join("*")
|
111
|
+
end
|
112
|
+
|
113
|
+
def compile_grape_query
|
114
|
+
str = []
|
115
|
+
str << "datetime|#{q[:on].strftime("%Y%m%d")}*|" if q[:on].present?
|
116
|
+
str << "status|#{q[:status]}|" if q[:status].present?
|
117
|
+
str.join("*")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
1
|
+
require "action_view/log_subscriber"
|
2
|
+
require_relative "rails/middleware"
|
3
|
+
require_relative "models/collection"
|
4
|
+
require_relative "instrument/metrics_collector"
|
5
5
|
|
6
6
|
module RailsPerformance
|
7
7
|
class Engine < ::Rails::Engine
|
@@ -23,7 +23,7 @@ module RailsPerformance
|
|
23
23
|
app.middleware.insert_before RailsPerformance::Rails::Middleware, RailsPerformance::Rails::MiddlewareTraceStorerAndCleanup
|
24
24
|
|
25
25
|
if defined?(::Sidekiq)
|
26
|
-
require_relative
|
26
|
+
require_relative "gems/sidekiq_ext"
|
27
27
|
Sidekiq.configure_server do |config|
|
28
28
|
config.server_middleware do |chain|
|
29
29
|
chain.add RailsPerformance::Gems::SidekiqExt
|
@@ -32,12 +32,12 @@ module RailsPerformance
|
|
32
32
|
end
|
33
33
|
|
34
34
|
if defined?(::Grape)
|
35
|
-
require_relative
|
35
|
+
require_relative "gems/grape_ext"
|
36
36
|
RailsPerformance::Gems::GrapeExt.init
|
37
37
|
end
|
38
38
|
|
39
39
|
if defined?(::Delayed::Job)
|
40
|
-
require_relative
|
40
|
+
require_relative "gems/delayed_job_ext"
|
41
41
|
RailsPerformance::Gems::DelayedJobExt.init
|
42
42
|
end
|
43
43
|
end
|
@@ -58,7 +58,7 @@ module RailsPerformance
|
|
58
58
|
ActiveRecord::LogSubscriber.send :prepend, RailsPerformance::Extensions::Db if defined?(ActiveRecord)
|
59
59
|
|
60
60
|
if defined?(::Rake::Task) && RailsPerformance.include_rake_tasks
|
61
|
-
require_relative
|
61
|
+
require_relative "gems/rake_ext"
|
62
62
|
RailsPerformance::Gems::RakeExt.init
|
63
63
|
end
|
64
64
|
end
|
@@ -1,33 +1,32 @@
|
|
1
|
-
module RailsPerformance
|
2
|
-
module Extensions
|
3
|
-
module View
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module RailsPerformance
|
18
|
-
module Extensions
|
19
|
-
module Db
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
1
|
+
module RailsPerformance
|
2
|
+
module Extensions
|
3
|
+
module View
|
4
|
+
# in env
|
5
|
+
# this works if config.log_level = :info
|
6
|
+
def info(&block)
|
7
|
+
CurrentRequest.current.trace({
|
8
|
+
group: :view,
|
9
|
+
message: block.call
|
10
|
+
})
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module RailsPerformance
|
18
|
+
module Extensions
|
19
|
+
module Db
|
20
|
+
# in env
|
21
|
+
# this works if config.log_level = :debug
|
22
|
+
def sql(event)
|
23
|
+
CurrentRequest.current.trace({
|
24
|
+
group: :db,
|
25
|
+
duration: event.duration.round(2),
|
26
|
+
sql: event.payload[:sql]
|
27
|
+
})
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,34 +1,31 @@
|
|
1
|
-
module RailsPerformance
|
2
|
-
module Gems
|
3
|
-
module CustomExtension
|
4
|
-
extend self
|
5
|
-
|
6
|
-
def measure(tag_name, namespace_name = nil)
|
7
|
-
return yield unless RailsPerformance.enabled
|
8
|
-
return yield unless RailsPerformance.include_custom_events
|
9
|
-
|
10
|
-
begin
|
11
|
-
now
|
12
|
-
status =
|
13
|
-
result = yield
|
14
|
-
result
|
15
|
-
rescue Exception => ex
|
16
|
-
status =
|
17
|
-
raise(ex)
|
18
|
-
ensure
|
19
|
-
RailsPerformance::Models::CustomRecord.new(
|
20
|
-
tag_name: tag_name,
|
21
|
-
namespace_name: namespace_name,
|
22
|
-
status: status,
|
23
|
-
duration: (Time.current - now) * 1000,
|
24
|
-
datetime: now.strftime(RailsPerformance::FORMAT),
|
25
|
-
datetimei: now.to_i
|
26
|
-
).save
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
module RailsPerformance
|
2
|
+
module Gems
|
3
|
+
module CustomExtension
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def measure(tag_name, namespace_name = nil)
|
7
|
+
return yield unless RailsPerformance.enabled
|
8
|
+
return yield unless RailsPerformance.include_custom_events
|
9
|
+
|
10
|
+
begin
|
11
|
+
now = Time.current
|
12
|
+
status = "success"
|
13
|
+
result = yield
|
14
|
+
result
|
15
|
+
rescue Exception => ex # rubocop:disable Lint/RescueException
|
16
|
+
status = "error"
|
17
|
+
raise(ex)
|
18
|
+
ensure
|
19
|
+
RailsPerformance::Models::CustomRecord.new(
|
20
|
+
tag_name: tag_name,
|
21
|
+
namespace_name: namespace_name,
|
22
|
+
status: status,
|
23
|
+
duration: (Time.current - now) * 1000,
|
24
|
+
datetime: now.strftime(RailsPerformance::FORMAT),
|
25
|
+
datetimei: now.to_i
|
26
|
+
).save
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,54 +1,50 @@
|
|
1
|
-
module RailsPerformance
|
2
|
-
module Gems
|
3
|
-
class DelayedJobExt
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
1
|
+
module RailsPerformance
|
2
|
+
module Gems
|
3
|
+
class DelayedJobExt
|
4
|
+
class Plugin < ::Delayed::Plugin
|
5
|
+
callbacks do |lifecycle|
|
6
|
+
lifecycle.around(:invoke_job) do |job, *args, &block|
|
7
|
+
now = Time.current
|
8
|
+
block.call(job, *args)
|
9
|
+
status = "success"
|
10
|
+
rescue Exception => error # rubocop:disable Lint/RescueException
|
11
|
+
status = "error"
|
12
|
+
raise error
|
13
|
+
ensure
|
14
|
+
meta_data = RailsPerformance::Gems::DelayedJobExt::Plugin.meta(job.payload_object)
|
15
|
+
record = RailsPerformance::Models::DelayedJobRecord.new(
|
16
|
+
jid: job.id,
|
17
|
+
duration: (Time.current - now) * 1000,
|
18
|
+
datetime: now.strftime(RailsPerformance::FORMAT),
|
19
|
+
datetimei: now.to_i,
|
20
|
+
source_type: meta_data[0],
|
21
|
+
class_name: meta_data[1],
|
22
|
+
method_name: meta_data[2],
|
23
|
+
status: status
|
24
|
+
)
|
25
|
+
record.save
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# [source_type, class_name, method_name, duration]
|
30
|
+
def self.meta(payload_object)
|
31
|
+
if payload_object.is_a?(::Delayed::PerformableMethod)
|
32
|
+
if payload_object.object.is_a?(Module)
|
33
|
+
[:class_method, payload_object.object.name, payload_object.method_name.to_s]
|
34
|
+
else
|
35
|
+
[:instance_method, payload_object.object.class.name, payload_object.method_name.to_s]
|
36
|
+
end
|
37
|
+
else
|
38
|
+
[:instance_method, payload_object.class.name, "perform"]
|
39
|
+
end
|
40
|
+
rescue
|
41
|
+
[:unknown, :unknown, :unknown]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.init
|
46
|
+
::Delayed::Worker.plugins += [::RailsPerformance::Gems::DelayedJobExt::Plugin]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,35 +1,33 @@
|
|
1
|
-
module RailsPerformance
|
2
|
-
module Gems
|
3
|
-
class GrapeExt
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
CurrentRequest.current.
|
12
|
-
CurrentRequest.current.record
|
13
|
-
CurrentRequest.current.record.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
CurrentRequest.current.record.
|
22
|
-
CurrentRequest.current.record.
|
23
|
-
CurrentRequest.current.record.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
1
|
+
module RailsPerformance
|
2
|
+
module Gems
|
3
|
+
class GrapeExt
|
4
|
+
def self.init
|
5
|
+
ActiveSupport::Notifications.subscribe(/grape/) do |name, start, finish, id, payload|
|
6
|
+
# TODO change to set
|
7
|
+
CurrentRequest.current.ignore.add(:performance)
|
8
|
+
|
9
|
+
now = Time.current
|
10
|
+
CurrentRequest.current.data ||= {}
|
11
|
+
CurrentRequest.current.record ||= RailsPerformance::Models::GrapeRecord.new(request_id: CurrentRequest.current.request_id)
|
12
|
+
CurrentRequest.current.record.datetimei ||= now.to_i
|
13
|
+
CurrentRequest.current.record.datetime ||= now.strftime(RailsPerformance::FORMAT)
|
14
|
+
|
15
|
+
if ["endpoint_render.grape", "endpoint_run.grape", "format_response.grape"].include?(name)
|
16
|
+
CurrentRequest.current.record.send(name.tr(".", "_") + "=", (finish - start) * 1000)
|
17
|
+
end
|
18
|
+
|
19
|
+
if payload[:env]
|
20
|
+
CurrentRequest.current.record.status = payload[:env]["api.endpoint"].status
|
21
|
+
CurrentRequest.current.record.format = payload[:env]["api.format"]
|
22
|
+
CurrentRequest.current.record.method = payload[:env]["REQUEST_METHOD"]
|
23
|
+
CurrentRequest.current.record.path = payload[:env]["PATH_INFO"]
|
24
|
+
end
|
25
|
+
|
26
|
+
if name == "format_response.grape"
|
27
|
+
CurrentRequest.current.record.save
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|