inner_performance 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6fb86a53413ef53d7256b526e4b75dd7d910473fc8d047b97976285ad82a91f
4
- data.tar.gz: 60147dd06fb7069a809c402e3cd9aeebf18df7d4921d1df52f0733159390ec22
3
+ metadata.gz: 761ab8ec52713467243aa93a5b2f82804f4d70f5fcbe8a571f1873e38ad289af
4
+ data.tar.gz: b05a53a01997aee49f40e0bfc488d34d5257e2edb9c26fac038461b13a811190
5
5
  SHA512:
6
- metadata.gz: 71ffe8d954c92f5736d9a57d161657dbca3cbbea5303fb42f31a5f007af962096f8a9709a190eb21bb10cfd78004ff628f7548317fc90505971d2f0893a3477b
7
- data.tar.gz: cc4a9176b3d7c787f0bd9636c294ffc554471fd3466c1a10c92eb267dd67d273152df7e00fbdb21eee520157b7cdf11a40fa1738b9762eeed8d551fc2648e293
6
+ metadata.gz: 6754adf03e924da656a5b0c44b492071a8f28772919b989ca5581ea21d82530485f0a9edfc71e8c6609002fcc881ee07670ce5b5bd42adaa04e14b2a99683649
7
+ data.tar.gz: f6805d89fa9b98230567799fd3db2e4217c99fd36d535938cbd5390908a5f1cb0bca16f001663e734d42d3a733a4d266b161cc0094960b2f60cdb41a7fdb8abc
data/README.md CHANGED
@@ -17,6 +17,11 @@ $ rails inner_performance:install:migrations
17
17
  $ rails db:migrate
18
18
  ```
19
19
 
20
+ Add inner_performance to `app/assets/config/manifest.js`
21
+ ```javascript
22
+ //= link inner_performance/application.css
23
+ ```
24
+
20
25
  Mount UI in `routes.rb` (don't forget to protect it!)
21
26
 
22
27
  ```ruby
@@ -38,7 +43,7 @@ InnerPerformance.configure do |config|
38
43
  # approx. 170 requests per minute, keeping it at default 2%
39
44
  # provides me more than enough data to analyze and locate the
40
45
  # bottlenecks.
41
- 'process_action.action_controller' => 2,
46
+ 'process_action.action_controller' => (Rails.env.production? ? 2 : 100),
42
47
 
43
48
  # 100% of all the jobs will be stored and analyzed.
44
49
  'perform.active_job' => 100
@@ -67,9 +72,12 @@ InnerPerformance.configure do |config|
67
72
  end
68
73
  ```
69
74
 
70
- `InnerPerformance` will produce an infinite amount of event records so in order
71
- to clean them up, you should periodically run
72
- `InnerPerformance::CleanupJob.perform_later`.
75
+ ## Regular Housekeeping
76
+ To ensure optimal performance and avoid data bloat, remember to schedule the cleanup job:
77
+
78
+ ```ruby
79
+ InnerPerformance::CleanupJob.perform_later
80
+ ```
73
81
 
74
82
  # Alternatives
75
83
 
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
- require "bundler/setup"
1
+ # frozen_string_literal: true
2
2
 
3
- APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
4
- load "rails/tasks/engine.rake"
3
+ require 'bundler/setup'
5
4
 
6
- load "rails/tasks/statistics.rake"
5
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
6
+ load 'rails/tasks/engine.rake'
7
7
 
8
- require "bundler/gem_tasks"
8
+ load 'rails/tasks/statistics.rake'
9
+
10
+ require 'bundler/gem_tasks'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class ApplicationController < ActionController::Base
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class DashboardController < ApplicationController
3
5
  def index
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class EventsController < ApplicationController
3
5
  include Pagy::Backend
4
6
 
5
7
  def index
6
8
  @q = InnerPerformance::Event.all.ransack(params[:q])
7
- @q.sorts = "created_at desc" if @q.sorts.empty?
9
+ @q.sorts = 'created_at desc' if @q.sorts.empty?
8
10
  @pagy, @events = pagy(@q.result)
9
11
  end
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  module ApplicationHelper
3
5
  include Pagy::Frontend
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class ApplicationJob < ActiveJob::Base
3
5
  end
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class CleanupJob < ApplicationJob
3
5
  def perform
4
- InnerPerformance::Event.where('created_at >= ?', InnerPerformance.configuration.events_retention)
6
+ InnerPerformance::Event
7
+ .where('created_at < ?', InnerPerformance.configuration.events_retention.ago)
8
+ .destroy_all
5
9
  end
6
10
  end
7
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class SaveEventJob < ApplicationJob
3
5
  def perform(type:, created_at:, event:, name:, duration:, db_runtime:, properties: {})
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class ApplicationMailer < ActionMailer::Base
3
- default from: "from@example.com"
4
- layout "mailer"
5
+ default from: 'from@example.com'
6
+ layout 'mailer'
5
7
  end
6
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class ApplicationRecord < ActiveRecord::Base
3
5
  self.abstract_class = true
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class Event < ApplicationRecord
3
5
  serialize :properties, coder: JSON
4
6
 
5
- def self.ransackable_attributes(auth_object = nil)
6
- ["created_at", "db_runtime", "duration", "event", "format", "id", "name"]
7
+ def self.ransackable_attributes(_auth_object = nil)
8
+ %w[created_at db_runtime duration event format id name]
7
9
  end
8
10
 
9
- def self.ransackable_associations(auth_object = nil)
11
+ def self.ransackable_associations(_auth_object = nil)
10
12
  []
11
13
  end
12
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  module Events
3
5
  class PerformActiveJob < InnerPerformance::Event
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  module Events
3
5
  class ProcessActionActionController < InnerPerformance::Event
data/config/routes.rb CHANGED
@@ -1,7 +1,7 @@
1
- InnerPerformance::Engine.routes.draw do
2
- mount InnerPerformance::Engine, at: '/performance'
1
+ # frozen_string_literal: true
3
2
 
3
+ InnerPerformance::Engine.routes.draw do
4
4
  resources :events, only: [:index]
5
5
 
6
- root to: "dashboard#index"
6
+ root to: 'dashboard#index'
7
7
  end
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateInnerPerformanceEvents < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :inner_performance_events, force: :cascade do |t|
4
- t.string "event"
5
- t.string "name"
6
- t.decimal "duration"
7
- t.decimal "db_runtime"
8
- t.datetime "created_at", null: false
9
- t.datetime "updated_at", null: false
10
- t.text "properties", default: "{}"
6
+ t.string 'event'
7
+ t.string 'name'
8
+ t.decimal 'duration'
9
+ t.decimal 'db_runtime'
10
+ t.datetime 'created_at', null: false
11
+ t.datetime 'updated_at', null: false
12
+ t.text 'properties', default: '{}'
11
13
  end
12
14
  end
13
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddTypeToInnerPerformanceEvents < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  add_column :inner_performance_events, :type, :string
@@ -1,9 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class Configuration
3
- attr_accessor :sample_rates
4
- attr_accessor :events_retention
5
- attr_accessor :medium_duration_range
6
- attr_accessor :ignore_rules
5
+ attr_accessor :sample_rates, :events_retention, :medium_duration_range, :ignore_rules
7
6
 
8
7
  def initialize
9
8
  @sample_rates = {
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
4
  class Engine < ::Rails::Engine
3
5
  isolate_namespace InnerPerformance
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InnerPerformance
2
- VERSION = "0.1.2"
4
+ VERSION = '0.1.4'
3
5
  end
@@ -1,9 +1,11 @@
1
- require "inner_performance/version"
2
- require "inner_performance/engine"
3
- require "inner_performance/configuration"
1
+ # frozen_string_literal: true
4
2
 
5
- require "ransack"
6
- require "pagy"
3
+ require 'inner_performance/version'
4
+ require 'inner_performance/engine'
5
+ require 'inner_performance/configuration'
6
+
7
+ require 'ransack'
8
+ require 'pagy'
7
9
 
8
10
  module InnerPerformance
9
11
  class << self
@@ -16,7 +18,7 @@ module InnerPerformance
16
18
  end
17
19
 
18
20
  def install!
19
- ActiveSupport::Notifications.subscribe "process_action.action_controller" do |event|
21
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |event|
20
22
  if save_event?(event)
21
23
  InnerPerformance::SaveEventJob.perform_later(
22
24
  type: InnerPerformance::Events::ProcessActionActionController.name,
@@ -32,7 +34,7 @@ module InnerPerformance
32
34
  end
33
35
  end
34
36
 
35
- ActiveSupport::Notifications.subscribe "perform.active_job" do |event|
37
+ ActiveSupport::Notifications.subscribe 'perform.active_job' do |event|
36
38
  if save_event?(event)
37
39
  InnerPerformance::SaveEventJob.perform_later(
38
40
  type: InnerPerformance::Events::PerformActiveJob.name,
@@ -46,12 +48,11 @@ module InnerPerformance
46
48
  end
47
49
  end
48
50
 
49
- # Iterate throug the ignored_rules array and return false on first rule
50
- # that returns `true`
51
+ # Check if all the ignore_rules returns false. If so, save the event.
51
52
  def save_event?(event)
52
- InnerPerformance.configuration.ignore_rules.each_with_object([]) do |rule, arr|
53
- arr << rule.call(event)
54
- end.find { |r| r == true }
53
+ InnerPerformance.configuration.ignore_rules.find do |rule|
54
+ rule.call(event) == true
55
+ end.nil?
55
56
  end
56
57
  end
57
58
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # desc "Explaining what the task does"
2
4
  # task :inner_performance do
3
5
  # # Task goes here
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inner_performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mbajur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-24 00:00:00.000000000 Z
11
+ date: 2024-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activejob
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 7.1.5
27
27
  - !ruby/object:Gem::Dependency
28
- name: activejob
28
+ name: pagy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 9.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 9.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -53,19 +67,19 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: 4.2.1
55
69
  - !ruby/object:Gem::Dependency
56
- name: pagy
70
+ name: factory_bot
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: 9.3.1
62
- type: :runtime
75
+ version: '0'
76
+ type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: 9.3.1
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec-rails
71
85
  requirement: !ruby/object:Gem::Requirement