rails_performance 1.4.3 → 1.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60fc2568e878c07db112623ef55985422852996f3eea18fd972c9ccc0288fd1a
4
- data.tar.gz: 3ff0036deb507e91fd9ac1ab63cafac95e98aeb59646ca566dff403a2bcdc1d6
3
+ metadata.gz: 10d13bdf7ddb45da1783c3665a64a89730639a3b13061c496e4502a59158c329
4
+ data.tar.gz: 738313bc41c6af0d1cfee519679519639acda8781dd4dd74602e3c55a6b1f6de
5
5
  SHA512:
6
- metadata.gz: 28a6b7d3918eaabb97a4cabcdbc95e66cca45dba61c416f90ed083e6508df79333a0e2c209fb3d1d1654a1516587dda5387eb88a42518a4b602cb77b4c83922e
7
- data.tar.gz: '0179ca0fdece9492e9053820aa025d0210391957d9eee2cac714bc0e8611003b467ff8d06bf91cb27d0eb8024bc4a8d77a56410aa7879a701be0d9df59ed8ee1'
6
+ metadata.gz: 33dcfe7183c335961e7716acc301b7c38877c9409c911ff0b6dfa0f5046ed40fc3f36fd9994cb8053367e467cb8c427eb042c218731cf7ada935fc6857c70b8d
7
+ data.tar.gz: e5e07d09bac167200fda9ff4e5b8d1bcd2e9558e4bc4a7bc9bf9c78d15f76d829f049c83793e7ef89c057bd83eda2ee2613ef6a01265a92aa6834dd891721047
data/README.md CHANGED
@@ -34,6 +34,7 @@ It allows you to track:
34
34
  - total duration of time spent per request, views rendering, DB
35
35
  - SQL queries, rendering logs in "Recent Requests" section
36
36
  - simple 500-crashes reports
37
+ - deployment events (or custom events)
37
38
  - Sidekiq jobs
38
39
  - Delayed Job jobs
39
40
  - Grape API inside Rails app
@@ -237,6 +238,31 @@ More information here: `lib/rails_performance/engine.rb`.
237
238
 
238
239
  PS: right now it can only distinguish between web app servers and the sidekiq servers.
239
240
 
241
+ #### Deployment Events + Custom Events on the Charts
242
+
243
+ ![Deployments](docs/deploys.png)
244
+
245
+ #### For Kamal
246
+
247
+ - edit `.kamal/hooks/post-deploy` (rename .sample if needed)
248
+ - add `kamal app exec -p './bin/rails runner "RailsPerformance.create_event(name: \"Deploy\")"'`
249
+ - kamal deploy
250
+
251
+ #### Custom Events on the Charts
252
+
253
+ You can specify colors, orientation for the event label.
254
+
255
+ ```ruby
256
+ RailsPerformance.create_event(name: "Deploy", options: {
257
+ borderColor: "#00E396",
258
+ label: {
259
+ borderColor: "#00E396",
260
+ orientation: "horizontal",
261
+ text: "Deploy"
262
+ }
263
+ })
264
+ ```
265
+
240
266
  ### Custom events
241
267
 
242
268
  ```ruby
@@ -79,7 +79,8 @@ function showTIRChart(element_id, data, addon, name) {
79
79
  series: [{
80
80
  name: name,
81
81
  data: data
82
- }]
82
+ }],
83
+ annotations: window?.annotationsData || {}
83
84
  });
84
85
  }
85
86
 
@@ -90,6 +91,7 @@ function showRTChart(element_id, data) {
90
91
  name: 'Response Time',
91
92
  data: data,
92
93
  }],
94
+ annotations: window?.annotationsData || {}
93
95
  });
94
96
  }
95
97
 
@@ -8,6 +8,9 @@
8
8
  <%= csp_meta_tag if ::Rails::VERSION::STRING.to_f >= 5.2 %>
9
9
  <%= render '/rails_performance/stylesheets/stylesheets' %>
10
10
  <link rel="shortcut icon" href="/favicon.ico">
11
+ <script>
12
+ window.annotationsData = <%= raw RailsPerformance::Reports::AnnotationsReport.new.data.to_json %>;
13
+ </script>
11
14
  </head>
12
15
 
13
16
  <body class="has-sticky-footer">
@@ -22,7 +22,7 @@ module RailsPerformance
22
22
 
23
23
  def db
24
24
  result = RailsPerformance::Models::Collection.new
25
- now = RailsPerformance::Utils.time
25
+ now = RailsPerformance::Utils.kind_of_now
26
26
  (0..days).to_a.reverse_each do |e|
27
27
  RailsPerformance::DataSource.new(q: q.merge({on: (now - e.days).to_date}), type: type).add_to(result)
28
28
  end
@@ -0,0 +1,62 @@
1
+ module RailsPerformance
2
+ module Events
3
+ class Record
4
+ attr_reader :name, :datetimei, :options
5
+
6
+ DEFAULT_COLOR = "#FF00FF"
7
+ DEFAULT_LABEL_COLOR = "#FF00FF"
8
+ DEFAULT_LABEL_ORIENTATION = "horizontal"
9
+
10
+ class << self
11
+ def create(name:, datetimei: Time.now.to_i, options: {})
12
+ instance = new(name: name, datetimei: datetimei, options: options)
13
+ instance.save
14
+ instance
15
+ end
16
+
17
+ def all
18
+ _, values = RailsPerformance::Utils.fetch_from_redis("rails_performance:records:events:*")
19
+ Array(values).map do |value|
20
+ json = JSON.parse(value)
21
+ new(name: json["name"], datetimei: json["datetimei"], options: Hash(json["options"]))
22
+ end
23
+ end
24
+ end
25
+
26
+ def initialize(name:, datetimei:, options: {})
27
+ @name = name
28
+ @datetimei = datetimei
29
+ @options = options
30
+ end
31
+
32
+ def save
33
+ RailsPerformance::Utils.save_to_redis(rails_performance_key, value)
34
+ end
35
+
36
+ def rails_performance_key
37
+ "rails_performance:records:events:#{datetimei}|#{RailsPerformance::EVENTS_SCHEMA}"
38
+ end
39
+
40
+ def value
41
+ {
42
+ name: name,
43
+ datetime: RailsPerformance::Utils.from_datetimei(datetimei.to_i),
44
+ datetimei: datetimei,
45
+ options: options
46
+ }
47
+ end
48
+
49
+ def to_annotation
50
+ {
51
+ x: datetimei * 1000,
52
+ borderColor: options.dig("borderColor") || DEFAULT_COLOR,
53
+ label: {
54
+ borderColor: options.dig("label", "borderColor") || DEFAULT_LABEL_COLOR,
55
+ orientation: options.dig("label", "orientation") || DEFAULT_LABEL_ORIENTATION,
56
+ text: options.dig("label", "text") || name
57
+ }
58
+ }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -24,6 +24,7 @@ module RailsPerformance
24
24
  datetime: now.strftime(RailsPerformance::FORMAT),
25
25
  datetimei: now.to_i
26
26
  ).save
27
+ CurrentRequest.cleanup
27
28
  end
28
29
  end
29
30
  end
@@ -23,6 +23,7 @@ module RailsPerformance
23
23
  status: status
24
24
  )
25
25
  record.save
26
+ CurrentRequest.cleanup
26
27
  end
27
28
  end
28
29
 
@@ -25,6 +25,7 @@ module RailsPerformance
25
25
 
26
26
  if name == "format_response.grape"
27
27
  CurrentRequest.current.record.save
28
+ CurrentRequest.cleanup
28
29
  end
29
30
  end
30
31
  end
@@ -23,6 +23,7 @@ module RailsPerformance
23
23
  duration: (RailsPerformance::Utils.time - now) * 1000,
24
24
  status: status
25
25
  ).save
26
+ CurrentRequest.cleanup
26
27
  end
27
28
  end
28
29
 
@@ -27,6 +27,7 @@ module RailsPerformance
27
27
  # store in ms instead of seconds
28
28
  record.duration = (RailsPerformance::Utils.time - now) * 1000
29
29
  record.save
30
+ CurrentRequest.cleanup
30
31
  end
31
32
  end
32
33
  end
@@ -0,0 +1,7 @@
1
+ module RailsPerformance
2
+ module Interface
3
+ def create_event(name:, datetime: RailsPerformance::Utils.time, options: {})
4
+ RailsPerformance::Events::Record.create(name: name, datetimei: datetime.to_i, options: options)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ class RailsPerformance::Reports::AnnotationsReport
2
+ def data
3
+ {
4
+ xaxis: xaxis
5
+ }
6
+ end
7
+
8
+ private
9
+
10
+ def xaxis
11
+ RailsPerformance::Events::Record.all.map(&:to_annotation)
12
+ end
13
+ end
@@ -32,7 +32,7 @@ module RailsPerformance
32
32
 
33
33
  # TODO: simplify this method, and combine with nullify_data
34
34
  def calculate_data
35
- now = RailsPerformance::Utils.time
35
+ now = RailsPerformance::Utils.kind_of_now
36
36
  now = now.change(sec: 0, usec: 0)
37
37
  stop = now # Time.at(60 * (now.to_i / 60), in:)
38
38
  offset = 0 # RailsPerformance::Reports::BaseReport.time_in_app_time_zone(now).utc_offset
@@ -66,7 +66,7 @@ module RailsPerformance
66
66
  def nil_data(duration = RailsPerformance.duration)
67
67
  @nil_data ||= begin
68
68
  result = {}
69
- now = RailsPerformance::Utils.time
69
+ now = RailsPerformance::Utils.kind_of_now
70
70
  now = now.change(sec: 0, usec: 0)
71
71
  stop = now # Time.at(60 * (now.to_i / 60))
72
72
  offset = 0 # RailsPerformance::Reports::BaseReport.time_in_app_time_zone(now).utc_offset
@@ -60,7 +60,7 @@ module RailsPerformance
60
60
  def store_data(data)
61
61
  ::Rails.logger.info("Server: #{server_id}, Context: #{context}, Role: #{role}, data: #{data}")
62
62
 
63
- now = RailsPerformance::Utils.time
63
+ now = RailsPerformance::Utils.kind_of_now
64
64
  now = now.change(sec: 0, usec: 0)
65
65
  RailsPerformance::Models::ResourceRecord.new(
66
66
  server: server_id,
@@ -1,9 +1,15 @@
1
1
  module RailsPerformance
2
2
  class Utils
3
+ DEFAULT_TIME_OFFSET = 1.minute
4
+
3
5
  def self.time
4
6
  Time.now.utc
5
7
  end
6
8
 
9
+ def self.kind_of_now
10
+ time + DEFAULT_TIME_OFFSET
11
+ end
12
+
7
13
  def self.from_datetimei(datetimei)
8
14
  Time.at(datetimei, in: "+00:00")
9
15
  end
@@ -1,4 +1,5 @@
1
1
  module RailsPerformance
2
- VERSION = "1.4.3"
2
+ VERSION = "1.5.0"
3
3
  SCHEMA = "1.0.2"
4
+ EVENTS_SCHEMA = "1.0.0"
4
5
  end
@@ -26,10 +26,15 @@ require_relative "rails_performance/reports/breakdown_report"
26
26
  require_relative "rails_performance/reports/trace_report"
27
27
  require_relative "rails_performance/reports/percentile_report"
28
28
  require_relative "rails_performance/reports/resources_report"
29
+ require_relative "rails_performance/reports/annotations_report"
30
+ require_relative "rails_performance/events/record"
29
31
  require_relative "rails_performance/extensions/trace"
30
32
  require_relative "rails_performance/thread/current_request"
33
+ require_relative "rails_performance/interface"
31
34
 
32
35
  module RailsPerformance
36
+ extend RailsPerformance::Interface
37
+
33
38
  FORMAT = "%Y%m%dT%H%M"
34
39
 
35
40
  mattr_accessor :redis
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -347,6 +347,7 @@ files:
347
347
  - lib/rails_performance.rb
348
348
  - lib/rails_performance/data_source.rb
349
349
  - lib/rails_performance/engine.rb
350
+ - lib/rails_performance/events/record.rb
350
351
  - lib/rails_performance/extensions/trace.rb
351
352
  - lib/rails_performance/gems/custom_ext.rb
352
353
  - lib/rails_performance/gems/delayed_job_ext.rb
@@ -354,6 +355,7 @@ files:
354
355
  - lib/rails_performance/gems/rake_ext.rb
355
356
  - lib/rails_performance/gems/sidekiq_ext.rb
356
357
  - lib/rails_performance/instrument/metrics_collector.rb
358
+ - lib/rails_performance/interface.rb
357
359
  - lib/rails_performance/models/base_record.rb
358
360
  - lib/rails_performance/models/collection.rb
359
361
  - lib/rails_performance/models/custom_record.rb
@@ -366,6 +368,7 @@ files:
366
368
  - lib/rails_performance/models/trace_record.rb
367
369
  - lib/rails_performance/rails/middleware.rb
368
370
  - lib/rails_performance/rails/query_builder.rb
371
+ - lib/rails_performance/reports/annotations_report.rb
369
372
  - lib/rails_performance/reports/base_report.rb
370
373
  - lib/rails_performance/reports/breakdown_report.rb
371
374
  - lib/rails_performance/reports/crash_report.rb