inner_performance 0.1.4 → 0.2.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -9
  3. data/Rakefile +5 -5
  4. data/app/controllers/inner_performance/dashboard_controller.rb +5 -5
  5. data/app/controllers/inner_performance/events_controller.rb +6 -1
  6. data/app/controllers/inner_performance/frontends_controller.rb +32 -0
  7. data/app/frontend/inner_performance/vendor/bootstrap.min.css +5 -0
  8. data/app/helpers/inner_performance/application_helper.rb +2 -2
  9. data/app/jobs/inner_performance/cleanup_job.rb +7 -2
  10. data/app/jobs/inner_performance/save_event_job.rb +13 -3
  11. data/app/mailers/inner_performance/application_mailer.rb +2 -2
  12. data/app/models/inner_performance/event.rb +3 -1
  13. data/app/models/inner_performance/trace.rb +7 -0
  14. data/app/models/inner_performance/traces/db.rb +22 -0
  15. data/app/models/inner_performance/traces/view.rb +22 -0
  16. data/app/services/inner_performance/trace_for_insert_initializer.rb +19 -0
  17. data/app/views/inner_performance/events/_event.html.erb +1 -1
  18. data/app/views/inner_performance/events/index.html.erb +15 -4
  19. data/app/views/inner_performance/events/show.html.erb +32 -0
  20. data/app/views/inner_performance/traces/dbs/_db.html.erb +10 -0
  21. data/app/views/inner_performance/traces/views/_view.html.erb +9 -0
  22. data/app/views/layouts/inner_performance/application.html.erb +1 -3
  23. data/config/routes.rb +6 -2
  24. data/db/migrate/20241123121600_create_inner_performance_events.rb +8 -8
  25. data/db/migrate/20241124111458_add_type_to_inner_performance_events.rb +1 -1
  26. data/db/migrate/20241218082041_remove_default_value_from_inner_performance_events_properties.rb +5 -0
  27. data/db/migrate/20250214162622_create_inner_performance_traces.rb +13 -0
  28. data/lib/inner_performance/configuration.rb +19 -5
  29. data/lib/inner_performance/current_request.rb +37 -0
  30. data/lib/inner_performance/engine.rb +7 -2
  31. data/lib/inner_performance/version.rb +1 -1
  32. data/lib/inner_performance.rb +47 -10
  33. metadata +16 -6
  34. data/app/assets/config/inner_performance_manifest.js +0 -1
  35. data/app/assets/stylesheets/inner_performance/application.css +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 761ab8ec52713467243aa93a5b2f82804f4d70f5fcbe8a571f1873e38ad289af
4
- data.tar.gz: b05a53a01997aee49f40e0bfc488d34d5257e2edb9c26fac038461b13a811190
3
+ metadata.gz: c96a8facfe3fbb37d213b6b2a4b4e2050b3f253c0ec18f2d4aff77f9faed5360
4
+ data.tar.gz: ddf1874585533fd13b73baa82ae7f7daa4546d5256f091914d37739856c28434
5
5
  SHA512:
6
- metadata.gz: 6754adf03e924da656a5b0c44b492071a8f28772919b989ca5581ea21d82530485f0a9edfc71e8c6609002fcc881ee07670ce5b5bd42adaa04e14b2a99683649
7
- data.tar.gz: f6805d89fa9b98230567799fd3db2e4217c99fd36d535938cbd5390908a5f1cb0bca16f001663e734d42d3a733a4d266b161cc0094960b2f60cdb41a7fdb8abc
6
+ metadata.gz: b761eb747aab13b1b54701d84ac2ab8f68bc6cfebe38b6283dc2608ac3716788112b8434fda349650f806f151342b39c3b18ff2e7dd79fb9522e9de16df017b0
7
+ data.tar.gz: 7993f0d2013eee24b56e43e2c33e2ab123ed4efaff3cedc2db60cad4afa7c05e76d2c201a5070a777f636de799fac66f8551675d73eda24b3d0d7ad3cba70c1b
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # ☯️ InnerPerformance [![Gem Version](https://badge.fury.io/rb/inner_performance.svg)](https://badge.fury.io/rb/inner_performance)
2
- Database-backed modest performance monitoring tool for your Rails app.
2
+ Simple database-backed performance monitoring for your Rails app.
3
3
 
4
4
  <img width="1188" alt="image" src="https://github.com/user-attachments/assets/cb659c76-8139-4ee0-b683-d6acef227dc6">
5
+ <img width="1239" alt="image" src="https://github.com/user-attachments/assets/3d15f993-4575-4a5c-977c-5983d3af13c9" />
5
6
 
6
7
  ## Installation
7
8
  Add `inner_performance` gem to your bundle
@@ -17,11 +18,6 @@ $ rails inner_performance:install:migrations
17
18
  $ rails db:migrate
18
19
  ```
19
20
 
20
- Add inner_performance to `app/assets/config/manifest.js`
21
- ```javascript
22
- //= link inner_performance/application.css
23
- ```
24
-
25
21
  Mount UI in `routes.rb` (don't forget to protect it!)
26
22
 
27
23
  ```ruby
@@ -42,7 +38,7 @@ InnerPerformance.configure do |config|
42
38
  # your app's performance. As an example: In a Spree shop with
43
39
  # approx. 170 requests per minute, keeping it at default 2%
44
40
  # provides me more than enough data to analyze and locate the
45
- # bottlenecks.
41
+ # bottlenecks. Value can be both decimal and integer.
46
42
  'process_action.action_controller' => (Rails.env.production? ? 2 : 100),
47
43
 
48
44
  # 100% of all the jobs will be stored and analyzed.
@@ -60,15 +56,21 @@ InnerPerformance.configure do |config|
60
56
  # be considered slow.
61
57
  config.medium_duration_range = [200, 999]
62
58
 
59
+ # Set it to true to enable tracing of SQL queries and views rendering
60
+ config.traces_enabled = false
61
+
63
62
  # Rules for ignoring an event. There are two rules applied by default:
64
63
  # * sample_rates - operates on configured sample rate and drops events
65
64
  # which do not got lucky when drawing a random number
66
65
  # * InnerPerformance job namespace - we don't want to save events for
67
66
  # the job that saves the events because that leeds to infinite loop.
68
67
  # Better not remove this rule as it will lead to stack overflow.
69
- config.ignore_rules.push(
68
+ config.ignore_rules.unshift(
70
69
  proc { |event| !event.is_a?(ActiveSupport::Notifications::Event) }
71
70
  )
71
+
72
+ # Set it to true if you want to cleanup old events right after saving the event
73
+ config.cleanup_immediately = false
72
74
  end
73
75
  ```
74
76
 
@@ -81,7 +83,9 @@ InnerPerformance::CleanupJob.perform_later
81
83
 
82
84
  # Alternatives
83
85
 
84
- * [rails_performance](https://github.com/igorkasyanchuk/rails_performance) - much better but depends on Redis
86
+ * [rails_performance](https://github.com/igorkasyanchuk/rails_performance) - much
87
+ more robust but depends on Redis. Operates on `ActiveSupport::LogSubscriber`
88
+ instead of `ActiveSupport::Notifications`
85
89
 
86
90
  ## License
87
91
  The gem is available as open source under the terms of the
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/setup'
3
+ require "bundler/setup"
4
4
 
5
- APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
6
- load 'rails/tasks/engine.rake'
5
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
6
+ load "rails/tasks/engine.rake"
7
7
 
8
- load 'rails/tasks/statistics.rake'
8
+ load "rails/tasks/statistics.rake"
9
9
 
10
- require 'bundler/gem_tasks'
10
+ require "bundler/gem_tasks"
@@ -6,11 +6,11 @@ module InnerPerformance
6
6
  @recent_events = InnerPerformance::Event.all.order(id: :desc).limit(25)
7
7
  @average_req_duration = InnerPerformance::Events::ProcessActionActionController.all.average(:duration)
8
8
  @average_job_duration = InnerPerformance::Events::PerformActiveJob.average(:duration) || 0
9
- @biggest_events = \
10
- InnerPerformance::Event.select('SUM(duration) as duration, name, COUNT(*) as count, AVG(duration) as avg_duration')
11
- .group(:name)
12
- .order('duration DESC')
13
- .limit(10)
9
+ @biggest_events =
10
+ InnerPerformance::Event.select("SUM(duration) as duration, name, COUNT(*) as count, AVG(duration) as avg_duration")
11
+ .group(:name)
12
+ .order("duration DESC")
13
+ .limit(10)
14
14
  end
15
15
  end
16
16
  end
@@ -6,8 +6,13 @@ module InnerPerformance
6
6
 
7
7
  def index
8
8
  @q = InnerPerformance::Event.all.ransack(params[:q])
9
- @q.sorts = 'created_at desc' if @q.sorts.empty?
9
+ @q.sorts = "created_at desc" if @q.sorts.empty?
10
10
  @pagy, @events = pagy(@q.result)
11
11
  end
12
+
13
+ def show
14
+ @event = InnerPerformance::Event.find(params[:id])
15
+ @traces = @event.traces.order(created_at: :asc)
16
+ end
12
17
  end
13
18
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InnerPerformance
4
+ class FrontendsController < ApplicationController
5
+ protect_from_forgery with: :exception
6
+ skip_after_action :verify_same_origin_request, raise: false
7
+
8
+ before_action do
9
+ expires_in 1.year, public: true
10
+ end
11
+
12
+ class << self
13
+ def asset_path(path)
14
+ Engine.root.join("app/frontend/inner_performance", path)
15
+ end
16
+ end
17
+
18
+ STATIC_ASSETS = {
19
+ css: {
20
+ bootstrap: asset_path("vendor/bootstrap.min.css"),
21
+ },
22
+ }.freeze
23
+
24
+ def static
25
+ file_stem = params[:stem]&.to_sym
26
+ file_format = params[:format]&.to_sym
27
+
28
+ file_path = STATIC_ASSETS.dig(file_format, file_stem) || raise(ActionController::RoutingError, "Not Found")
29
+ send_file(file_path, disposition: "inline")
30
+ end
31
+ end
32
+ end