Skip to content
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 Roda instrumentation #2144

Merged
merged 32 commits into from
Aug 10, 2023
Merged

Add Roda instrumentation #2144

merged 32 commits into from
Aug 10, 2023

Conversation

hannahramadan
Copy link
Contributor

@hannahramadan hannahramadan commented Jul 25, 2023

Adds instrumentation for Roda versions 3.19.0+. Roda will be automatically detected and instrumented.

closes #1783

@hannahramadan hannahramadan changed the title Initial commit Roda instrumentation Roda instrumentation Jul 26, 2023
newrelic.yml Outdated Show resolved Hide resolved
@hannahramadan hannahramadan marked this pull request as ready for review August 7, 2023 22:48
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@fallwith fallwith self-requested a review August 8, 2023 00:53
@fallwith fallwith dismissed their stale review August 8, 2023 00:54

Original change not required (I didn't catch the ||), but the refactor looks great so we'll keep it.

Co-authored-by: James Bunch <fallwith@gmail.com>
Co-authored-by: James Bunch <fallwith@gmail.com>
Co-authored-by: Kayla Reopelle (she/her) <87386821+kaylareopelle@users.noreply.github.com>
hannahramadan and others added 2 commits August 8, 2023 09:45
@hannahramadan hannahramadan changed the title Roda instrumentation Add Roda instrumentation Aug 8, 2023
lib/new_relic/agent/instrumentation/roda.rb Outdated Show resolved Hide resolved
lib/new_relic/agent/instrumentation/roda.rb Outdated Show resolved Hide resolved
lib/new_relic/agent/transaction.rb Outdated Show resolved Hide resolved
test/multiverse/lib/multiverse/runner.rb Outdated Show resolved Hide resolved
test/multiverse/suites/roda/Envfile Outdated Show resolved Hide resolved
test/multiverse/suites/roda/roda_instrumentation_test.rb Outdated Show resolved Hide resolved
test/multiverse/suites/roda_agent_disabled/Envfile Outdated Show resolved Hide resolved
Co-authored-by: James Bunch <fallwith@gmail.com>
NewRelic::Agent.stub(:logger, NewRelic::Agent::MemoryLogger.new) do
# Have the #params call made on the request raise an exception to test
# the error handling
RodaTestApp::RodaRequest.any_instance.stubs(:params).raises(StandardError.new)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on offline discussions on this one...

  • Minitest doesn't support (and one might even infer it discourages) the stubbing of any instance
  • The any_instance here is provided by the Mocha testing gem
  • Personally I think introducing Mocha to a Minitest based project detracts from the Minitest experience as much as it adds to it. Perhaps it's like adding a sidecar to a motorcycle. It's clear that the sidecar offers a distinct advantage over a motorcycle without a sidecar. But there are also fundamental changes to the motorcycling experience that could be considered as drawbacks.
  • Testing any instance is well known anti-pattern given the risk of having stubbing behavior bleed over to other instances in play in a testing context where the stubbing behavior would be problematic.
    • The risk is mitigated here in two ways:
      • We are assured of only having one Rack request in play during the test.
      • We do not (currently) make use of parallelized, concurrent tests.
  • Typically the best practice is to have a handle on the specific instance under test. The need to reach for the stubbing of any instance could itself indicate complexity of code. This complexity might come from not following TDD or could indicate a focus / prioritization on performance over testability. For whatever reason, tests that require stubbing any instance might indicate difficulties in maintainability.
  • We use this any_instance method quite a lot in this project. It is completely acceptable to use it again here from a PR approval standpoint. The maintainers may at one point decide to dissuade future usage or refactor out existing usage of any_instance, but for now there's a green light.
    • We bring in a RuboCop gem specific to Minitest, but unfortunately given that any_instance comes from Mocha, its usage is not flagged by any cops.
  • Looking at the context for this exact line of code, the benefit of using any_instance is pretty clear. We invoke the Rack::Test get method, which via Forwardable goes through the Rack::Test flow of calling the user defined app method to get an app class. An instance of that class is instantiated and the request params object is prepped. For us to be able to get at the exact single instance of the class (as opposed to any instance) that will field the web request, we would need to change the overall flow of this test and have it be different from all the others. Perhaps we could stub new on the Rack app and use that stubbing for a foothold while retaining the Rack test integration style of using get. Alternatively, we could have this test not leverage Rack::Test and we could instead directly invoke the rack_request_params method being tested. (We'd use a unit test instead of an integration test). The benefits of having this test look and act like the others is a pretty clear advantage of any_instance.

Copy link
Contributor Author

@hannahramadan hannahramadan Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed thoughts—loving the motorcycle analogy. I agree it's weird to mix Mocha and Minitest. I've updated this and to go with the unit-style test— just calling rack_request_params directly, which is going to fail since no Rack request will be in existence.

Updating our codebase to get rid of any_instance would be a fun project. I think it would help with learning.

…r.rb

Co-authored-by: James Bunch <fallwith@gmail.com>
@github-actions
Copy link

github-actions bot commented Aug 9, 2023

SimpleCov Report

Coverage Threshold
Line 94.29% 94%
Branch 85.78% 85%

Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, Hannah!

@hannahramadan hannahramadan merged commit b6acbfd into dev Aug 10, 2023
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add instrumentation for Roda
4 participants