New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add busted_tracer middleware #16
Conversation
README.md
Outdated
@@ -162,6 +162,22 @@ $ ruby start_finish_trace.rb | |||
|
|||
**Busted** includes an [example `dtrace` probe](/dtrace/probes/examples/method-cache-clear.d) for use on the command line or an application. See the [probe](/dtrace/probes/examples/method-cache-clear.d) for usage. | |||
|
|||
# Rails Usage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, let's make this a subheadline via ## Rails Usage
, so it matches the rest of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
test/middleware/busted_tracer.rb
Outdated
@@ -0,0 +1,26 @@ | |||
require "logger" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/middleware/busted_tracer.rb
is the same as lib/busted/middleware/busted_tracer.rb
. Why must we copy the file into the test
directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I totally missed that I had the file twice.
That was some bad git hygiene on my part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries 😄
after PR simeonwillbanks#15 merged, this is the only test that uses the old minitest test syntax. We can also eliminate some "ambiguous first argument; put parentheses or a space even after `/' operator" by adding parentheses after assert_equal methods in tests
The "coming soon" link in the readme now points to the rails docs. The Rails Usage header is now the proper "##" depth
test/middleware_test.rb
Outdated
middleware.call({}) | ||
end | ||
|
||
assert_match(/methods=0 constants=0/, log.messages.last) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method's name is test_it_logs_cache_invalidations
, but we aren't asserting on "[Cache Invalidations]"
. Why don't we add "[Cache Invalidations]"
to this tests and maybe the others?
lib/busted/profiler.rb
Outdated
@@ -2,6 +2,7 @@ | |||
require "busted/countable" | |||
require "busted/tracer" | |||
require "busted/traceable" | |||
require "busted/middleware/busted_tracer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I realized that we probably don't need to require the middleware in all cases. Do you think it would be worth it try to load it dynamically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you have in mind for dynamically loading?
@simeonwillbanks do you think you could take another look? I think I resolved everything we discussed. |
README.md
Outdated
In rails you can use the `BustedTracer` middleware to log the method and constant cache invalidations. You can configure BustedTracer using, | ||
|
||
```ruby | ||
config.middleware.insert_after(ActionDispatch::Static, BustedTracer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we test BustedTracer
comes before the rest of the middleware stack:
config.middleware.insert_before(0, BustedTracer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean test if it works first in the middleware stack, or specifically require the middleware to be first in the stack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HParker My thoughts are config.middleware.insert_before 0
makes sure BustedTracer
runs at the beginning of the stack.
Why did you suggest ActionDispatch::Static
? I've got a Rails 5.0 app handy, and here's its out-of-the-box middleware stack.
~/Code/rails_5
❯ rails --version
Rails 5.0.1
~/Code/rails_5
❯ rake middleware
Running via Spring preloader in process 63804
use Rack::Sendfile
use ActionDispatch::Static
use ActionDispatch::Executor
use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Sprockets::Rails::QuietAssets
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use WebConsole::Middleware
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
run Rails5::Application.routes
@@ -0,0 +1,26 @@ | |||
require "logger" | |||
|
|||
class BustedTracer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at a few other middlewares, and they are using a different class name and file structure.
I think we should adopt this pattern.
Busted::Middleware
./lib/busted/middleware.rb
Thoughts @HParker ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@HParker have you tested the new middleware in a few Rails apps? We should test in at least one Rails 4 and one Rails 5 app. Also, maybe we can spin up some vanilla Rails 4 and 5 apps then define some invalidations in application code. That way, we can test out middleware insertion and compare the expected log messages with actual log messages. Thoughts? |
I have only tested in a rails 5 app, though I think the middleware API is rack version specific not rails version specific right? |
i'm using it on rails 4.1 and 4.2 and seems ok! |
@simeonwillbanks Let me know if theres anything else I can do to move this along. |
Putting the middleware after the ActionDispatch::Static middleware assumes something about what you are trying to trace.
@alepore Are you using the gem or the middleware in this Pull Request? @HParker I tried out Here's
Maybe something with Spring preloader? Here's
I don't understand why the In an app, I tried the middleware. I fiddled with
class HomeController < ApplicationController
class Hello
end
def index
end
end
Using class HomeController < ApplicationController
Busted.start
class Hello
def wat
puts 'wat'
end
end
report = Busted.finish
Rails.logger.info "[Cache Invalidations From Inside App] methods=#{report[:invalidations][:method]} constants=#{report[:invalidations][:constant]}"
def index
end
end
Overall, it feels like we might go down a rabbit hole understanding how the middleware is working within Rails. To respect your time (now and in the future when Rails changes), I don't think we should go down that rabbit hole, and we should keep |
I agree the numbers are confusing. If we end up providing a tool like this, it probably will need to change with rails version, this tool does not need to care about rails, so we should probably keep that part separate from this gem no matter what. I'll close and see if I can find a way to get sane numbers from rails another time and place. |
@HParker Sounds good and agreed. Thank you very much for your contributions and patience! 🍻 |
Fixes #2
adds logging for use in a rails/rack app.