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

handle recent Rack v3 changes in tests & example #209

Merged
merged 14 commits into from
Sep 27, 2022
Merged

Conversation

emilyashley
Copy link
Contributor

@emilyashley emilyashley commented Sep 26, 2022

Which problem is this PR solving?

Short description of the changes

  • Rack::Lobster moved to Rackup::Lobster in newest versions, we removed lobster.
  • Build a Rack 2 and a Rack 3 and use in appraisals and CI
  • conditionally catch which version of rack is being used and use appropriate code
  • Rack Session also moved rack 3 as well ( and longer secret is required)
  • replace ::Rack::VERSION with ::Rack.release

@emilyashley emilyashley marked this pull request as ready for review September 26, 2022 19:26
@emilyashley emilyashley requested a review from a team September 26, 2022 19:26
@emilyashley emilyashley requested a review from pkanal September 26, 2022 19:26
@emilyashley emilyashley self-assigned this Sep 26, 2022
require "rack/lobster"
rescue LoadError
require "rack/session"
require "rackup"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

on second thought, I'm not sure if this line is needed. @robbkidd ?

Copy link
Member

Choose a reason for hiding this comment

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

🤔 I think you may be right. I will check!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't ✨ Just pushed a commit removing the duplicate "rackup" and also adding the rack-session dep to the appraisals file (not just directly in the .gemfile for rack_3)

@MikeGoldsmith MikeGoldsmith added the type: maintenance The necessary chores to keep the dust off. label Sep 27, 2022
@robbkidd robbkidd self-assigned this Sep 27, 2022
@emilyashley emilyashley added status: oncall Flagged for awareness from Honeycomb Telemetry Oncall version: no bump A PR with maintenance or doc changes that aren't included in a release. labels Sep 27, 2022
Copy link
Contributor

@JamieDanielson JamieDanielson left a comment

Choose a reason for hiding this comment

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

Nice work! I'm not super familiar with Ruby, so I'll add my notes here from trying things out with this PR:

These changes worked for running bundle exec appraisal rake test. This makes sense - it worked in Circle! But when I tried bundle install, it was failing with this error:

[!] There was an error parsing ``rack.gemfile``: No such file or directory @ rb_sysopen - /Users/jamiedanielson/code/beeline-ruby/gemfiles/rack.gemfile. Bundler cannot continue.

I believe this was actually because of the rack example app, which should maybe be updated with this change? In examples/rack/Gemfile I added gem "rackup"; in examples/rack/main.rb I added require "rackup" to the top, and updated the handler to handler = Rackup::Handler::WEBrick (previously Rack::).

Now I can run bundle install successfully, and from examples/rack/ I can run bundle exec ruby main.rb, which starts the server. Then I curl localhost:8080 to get aHello from Honeycomb reply, and see trace data in the console {"meta.beeline_version":"2.11.0","meta.local_hostname":"jamiedanielson","meta.instrumentations_count":10,"meta.instrumentations":"[\"active_support\"...

::Rack::VERSION was deprecated in v3.0[1]. Also, turns out, it's the
Rack *protocol* version, not the version of the Rack gem.

[1] rack/rack@856934f

::Rack.release is the gem version, has existed since at least v0.4,[2]
and--bonus!--is already a dotted-string version number.

[2] https://github.com/rack/rack/blob/rack-0.4/lib/rack.rb#L24-L27
With some commentary thrown in because I didn't know what the heck
Lobster was before this blew up the nightly, an if-else makes explicit
our expectation that one way works with older Rack and the other way
works with newer Rack.
@emilyashley emilyashley changed the title Make Rack builds happy Handle recent Rack v3 changes (Lobster, Session) in Beeline examples, tests, and CI Sep 27, 2022
@emilyashley emilyashley changed the title Handle recent Rack v3 changes (Lobster, Session) in Beeline examples, tests, and CI Handle recent Rack v3 changes (Lobster, Session) in examples and CI tests Sep 27, 2022
def call(_env)
[200, { "content-type" => "text/plain" }, ["Hello world!"]]
end
end
Copy link
Member

@robbkidd robbkidd Sep 27, 2022

Choose a reason for hiding this comment

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

Huge fan of replacing Rack::Lobster—as cute at it is—with a simple test app of our own to reduce dependencies.

require "warden"

class AnApp
def call(_env)
Copy link
Member

Choose a reason for hiding this comment

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

Starting the unused variable with an underscore will appease the Lint/UnusedMethodArgument Rubocop cop.

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL

We don't use it for any assertions, only to create the session. Simplify
for future humans reading these tests.
@robbkidd
Copy link
Member

Longer secret required for Rack 3
@emilyashley

Ooops

end
let(:auth) { Authenticate.new(honeycomb) }
let(:warden) do
Warden::Manager.new(auth) do |manager|
manager.default_strategies :test
end
end
let(:session) { Rack::Session::Cookie.new(warden, secret: "honeycomb") }
let(:secret) { "honeycombsecretneedstobe64characterslongforrack3sonowitslongeryay" }
Copy link
Member

Choose a reason for hiding this comment

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

🎉

Copy link
Member

@robbkidd robbkidd left a comment

Choose a reason for hiding this comment

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

It wasn't a rock! It was a rack lobster!

@robbkidd robbkidd changed the title Handle recent Rack v3 changes (Lobster, Session) in examples and CI tests maint: handle recent Rack v3 changes in tests & example Sep 27, 2022
@robbkidd robbkidd changed the title maint: handle recent Rack v3 changes in tests & example handle recent Rack v3 changes in tests & example Sep 27, 2022
Copy link
Contributor

@JamieDanielson JamieDanielson left a comment

Choose a reason for hiding this comment

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

thats amazing

@emilyashley emilyashley merged commit b550f7d into main Sep 27, 2022
@emilyashley emilyashley deleted the emash-rack-test branch September 27, 2022 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: oncall Flagged for awareness from Honeycomb Telemetry Oncall type: maintenance The necessary chores to keep the dust off. version: no bump A PR with maintenance or doc changes that aren't included in a release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failing nightly build - Rack is unhappy
4 participants