diff --git a/Gemfile b/Gemfile index 844cdd82..01004e83 100644 --- a/Gemfile +++ b/Gemfile @@ -81,6 +81,9 @@ gem "rack-mini-profiler" gem "memory_profiler" gem "flamegraph" +# Rails Performance monitoring dashboard +gem "rails_performance" + gem "skylight" # Ahoy analytics diff --git a/Gemfile.lock b/Gemfile.lock index 8856dca0..cd8aee18 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,7 @@ GEM msgpack (~> 1.2) brakeman (7.0.2) racc + browser (6.2.0) builder (3.3.0) bullet (8.0.8) activesupport (>= 3.0.0) @@ -385,6 +386,10 @@ GEM rails-html-sanitizer (1.6.2) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + rails_performance (1.4.2) + browser + railties + redis railties (8.0.2) actionpack (= 8.0.2) activesupport (= 8.0.2) @@ -403,6 +408,10 @@ GEM erb psych (>= 4.0.0) redcarpet (3.6.1) + redis (5.4.0) + redis-client (>= 0.22.0) + redis-client (0.25.0) + connection_pool regexp_parser (2.10.0) reline (0.6.1) io-console (~> 0.5) @@ -587,6 +596,7 @@ DEPENDENCIES rack-cors rack-mini-profiler rails (~> 8.0.2) + rails_performance redcarpet rubocop-rails-omakase selenium-webdriver diff --git a/config/initializers/rails_performance.rb b/config/initializers/rails_performance.rb new file mode 100644 index 00000000..6387a843 --- /dev/null +++ b/config/initializers/rails_performance.rb @@ -0,0 +1,40 @@ +if defined?(RailsPerformance) + RailsPerformance.setup do |config| + # Redis is required for rails_performance + config.redis = Redis.new(url: ENV["REDIS_URL"].presence || "redis://127.0.0.1:6379/0") + config.duration = 4.hours + + # Custom data to track + config.custom_data_proc = lambda do |env| + request = Rack::Request.new(env) + data = {} + + # Track current user if available + if request.session && request.session["user_id"] + user = User.find_by(id: request.session["user_id"]) + if user + data[:user_id] = user.id + data[:username] = user.username + data[:user_admin] = user.admin? + end + end + + # Track HTTP User Agent + data[:user_agent] = request.user_agent + + # Track IP address + data[:remote_ip] = request.ip + + # Track referer + data[:referer] = request.referer + + data + end + + # Skip certain paths + config.ignored_paths = [ "/good_job", "/rails/health", "/assets", "/rails/performance" ] + + # Enable monitoring for all environments (you might want to restrict this) + config.enabled = true + end +end diff --git a/config/routes.rb b/config/routes.rb index 4cba4551..2a82667d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,7 @@ def self.matches?(request) mount GoodJob::Engine => "good_job" mount AhoyCaptain::Engine => "/ahoy_captain" mount Flipper::UI.app(Flipper) => "flipper", as: :flipper + mount RailsPerformance::Engine => "rails_performance", as: :rails_performance get "/impersonate/:id", to: "sessions#impersonate", as: :impersonate_user end diff --git a/docker-compose.yml b/docker-compose.yml index 232f1c21..2cda6d1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,11 +11,13 @@ services: environment: - RAILS_ENV=development - DATABASE_URL=postgres://postgres:secureorpheus123@db:5432/app_development + - REDIS_URL=redis://redis:6379/0 - POSTGRES_HOST=db - POSTGRES_USER=postgres - POSTGRES_PASSWORD=secureorpheus123 depends_on: - db + - redis db: image: postgres:16 @@ -28,6 +30,14 @@ services: ports: - "5432:5432" + redis: + image: redis:7.0 + ports: + - "6379:6379" + volumes: + - harbor_redis_data:/data + volumes: harbor_postgres_data: + harbor_redis_data: bundle_cache: \ No newline at end of file