diff --git a/app/controllers/redis_log_controller.rb b/app/controllers/redis_log_controller.rb index 1b5427c04..b74647035 100644 --- a/app/controllers/redis_log_controller.rb +++ b/app/controllers/redis_log_controller.rb @@ -110,6 +110,19 @@ def by_status end.reject(&:empty?) end + def by_path + redis = redis(logger: true) + @method = params[:method] + @path = params[:path] + @format = params[:format] + si, ei = page + @requests = redis.zrevrange("requests/by_path/#{@method}/#{@path}.#{@format}", si, ei, with_scores: true).to_a.map do |request_id, timestamp| + r = get_request(timestamp, request_id) + redis.zrem "requests/by_path/#{@method}/#{@path}.#{@format}", request_id if r.empty? + r + end.reject(&:empty?) + end + private def get_request(timestamp, request_id) diff --git a/app/views/redis_log/_row.html.erb b/app/views/redis_log/_row.html.erb index ec0256bd2..b62e7624e 100644 --- a/app/views/redis_log/_row.html.erb +++ b/app/views/redis_log/_row.html.erb @@ -12,6 +12,8 @@ <%= req['user_id'].nil? ? "No User" : link_to("user", redis_log_by_user_path(id: req['user_id'])) %> · <%= link_to("request", redis_log_request_path(req.slice(:request_id, :timestamp))) %> + · + <%= %w[method path format].all? { |i| req[i].present? } ? link_to("path", redis_log_by_path_path(method: req['method'], format: req['format'], path: Rails.sensible_routes.match_for(req['path'])&.path || req['path'].split('?').first)) : 'No Path' %>

<%= req['controller'] %>#<%= req['action'] %> (<%= req['path'] %>.<%= req['format'] %>)

<% if !req[:logs].nil? %> diff --git a/app/views/redis_log/by_path.html.erb b/app/views/redis_log/by_path.html.erb new file mode 100644 index 000000000..f001d6b2c --- /dev/null +++ b/app/views/redis_log/by_path.html.erb @@ -0,0 +1,3 @@ +

<%= @method %> <%= @path %>.<%= @format %>

+ +<%= render 'table', requests: @requests %> diff --git a/config/initializers/redis_logging.rb b/config/initializers/redis_logging.rb index 634417361..c9549b827 100644 --- a/config/initializers/redis_logging.rb +++ b/config/initializers/redis_logging.rb @@ -4,7 +4,7 @@ REDIS_LOG_EXPIRATION = 1.day.seconds.to_i -def log_timestamps(ts, status:, action:, controller:, format:, method:, view_runtime:, db_runtime:, path:) # rubocop:disable Metrics/ParameterLists +def log_timestamps(ts, status:, action:, controller:, format:, method:, view_runtime:, db_runtime:, path:, uuid:) # rubocop:disable Metrics/ParameterLists redis = redis(logger: true) return if path.nil? path = Rails.sensible_routes.match_for(path)&.path || path.split('?').first @@ -20,6 +20,9 @@ def log_timestamps(ts, status:, action:, controller:, format:, method:, view_run redis.zadd "request_timings/status_counts/by_action/#{controller}##{action}", ts, status redis.zadd 'request_timings/status_counts', ts, status + redis.zadd "requests/by_path/#{method.upcase}/#{path}.#{format}", ts, uuid + redis.zadd "requests/by_action/#{controller}##{action}", ts, uuid + redis.zadd 'request_timings/sha', ts, CurrentCommit, nx: true end @@ -46,7 +49,7 @@ def log_timestamps(ts, status:, action:, controller:, format:, method:, view_run :action, :controller, :view_runtime, :db_runtime, :method, :format, :status - ), path: redis.hget(redis_log_key, 'path')) + ), path: redis.hget(redis_log_key, 'path'), uuid: request_id) end end end diff --git a/config/routes.rb b/config/routes.rb index 0ed41e603..4b6d42a01 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -212,6 +212,7 @@ root to: 'redis_log#index' get 'user/:id', to: 'redis_log#by_user', as: :redis_log_by_user get 'status/:status', to: 'redis_log#by_status', as: :redis_log_by_status + get 'by_path/:method/:path', to: 'redis_log#by_path', as: :redis_log_by_path get 'session/:id', to: 'redis_log#by_session', as: :redis_log_by_session scope 'request/:timestamp/:request_id', constraints: {:timestamp => /[^\/]+/ } do root to: 'redis_log#show', as: :redis_log_request