Identify unused routes within your rails routes.rb file by reading in a csv file of all controllers hit within a given time period. The csv file can most easily be generated with New Relic.
This gem is inspired by newrelic_route_check
Add this line to your application's Gemfile:
gem 'rake_unused_routes'
And then execute:
$ bundle
In order to see unused routes, we need an export of all controller actions that are still in use. An easy way of generating the export is with either the basic NewRelic RPM or NewRelic Insights.
The easiest way to generate a CSV file is by exporting all controllers from the all transactions page within newrelic. To get there:
- Navigate to Transactions
- Select "Last 7 Days ending now" within time picker
- Pick type Web
- Click "Show all transactions table"
- Click "Export as CSV"
Copy exported file to $RAILS_ROOT/tmp/controller_summary.csv
Run:
rake unused_routes
The advantage of using NewRelic Insights export is that dependening on your retention policies, Insights can generate a report for a much great length of time than 7 days. Our current NewRelic policies allow for pulling usage data from 9 weeks ago.
Navigate to Insights and run the following query:
SELECT count(*)
from Transaction
where transactionSubType ='Controller'
facet name
since 9 weeks ago
limit 1000
Export the results to a csv file:
Copy the results to $RAILS_ROOT/tmp/insights_controllers.csv .
Then run:
rake unused_routes:from_insights
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/viewthespace/rake_unused_routes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.