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

fix: RubyGems Fallback #1161

Merged
merged 3 commits into from
Apr 12, 2022

Conversation

arielvalentin
Copy link
Contributor

@arielvalentin arielvalentin commented Mar 25, 2022

The GitHub Monolith bypasses RubyGems when loading dependencies, which results in a nil variable being returned by Gem.loaded_specs.

This change fallsback to using Gem::Version.new(<VERSION>) where possible.

See #947

Related open-telemetry/opentelemetry-ruby-contrib#373

@arielvalentin arielvalentin self-assigned this Mar 25, 2022
@arielvalentin arielvalentin changed the title fix: Bypass RubyGems loaded_specs fix: RubyGems Fallback Mar 28, 2022
@arielvalentin arielvalentin force-pushed the use-gem-versions branch 3 times, most recently from 5cb7fc6 to 0ed52f7 Compare March 28, 2022 14:46
@arielvalentin arielvalentin marked this pull request as ready for review March 28, 2022 15:55
@arielvalentin arielvalentin marked this pull request as draft March 29, 2022 16:55
@arielvalentin
Copy link
Contributor Author

Summarizing our conversation on 2022-03-29 we prefer to rely on gem specific constants over Gem.loaded_specs

@@ -27,6 +27,8 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
private

def gem_version
# Version is hardcoded in the gemspec
# https://github.com/collectiveidea/delayed_job/blob/master/delayed_job.gemspec#L16
Gem.loaded_specs['delayed_job'].version
Copy link
Member

@robbkidd robbkidd Mar 29, 2022

Choose a reason for hiding this comment

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

Did we want to rub some try (&.) on this? Or leave as-is for an exception instead of a nil?

Or maybe …

Suggested change
Gem.loaded_specs['delayed_job'].version
Gem.loaded_specs.fetch('delayed_job').version

… for a different exception? KeyError (key not found: "delayed_job") as opposed to NoMethodError (undefined method 'version' for nil:NilClass)

(I am indeed trying to make fetch happen.)

Copy link
Member

Choose a reason for hiding this comment

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

Or even …

Suggested change
Gem.loaded_specs['delayed_job'].version
Gem
.loaded_specs
.fetch('delayed_job') { raise KeyError.new("'delayed_job' not
found among Gem.loaded_specs") }
.version

… for KeyError ('delayed_job' not found among Gem.loaded_specs).

🤔 Maybe that's too much fetch?

Copy link
Contributor Author

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 Mar 30, 2022

Choose a reason for hiding this comment

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

I think that's how flow is controlled with the existing implementation.

Gem.loaded_specs['delayed_job'].version

If it can't find 'delayed_job' in Gem.loaded_specs, aNoMethodError (undefined method 'version' for nil:NilClass) exception would be thrown (right?) which I think is less clear about what the true error is.

Update: yep.

irb(main):001:0> Gem.loaded_specs['no_such_gem'].version
Traceback (most recent call last):
       … blah blah blah
NoMethodError (undefined method `version' for nil:NilClass)

irb(main):002:0> Gem.loaded_specs.fetch('no_such_gem'){raise KeyError.new("'no_such_gem' not found among Gem.loaded_specs")}.version
Traceback (most recent call last):
        … blah blah blah
KeyError ('no_such_gem' not found among Gem.loaded_specs)

@arielvalentin arielvalentin marked this pull request as ready for review March 30, 2022 00:36
@arielvalentin arielvalentin requested a review from robbkidd March 30, 2022 00:36
@arielvalentin arielvalentin marked this pull request as draft March 30, 2022 13:18
@arielvalentin
Copy link
Contributor Author

Got a failing test for AWS v2.11 after removing mocks/stubs in my last commit.

@NathanielRN does the SDK team have a Timeline for EoL since v2 is deprecated?

@arielvalentin
Copy link
Contributor Author

NVM @NathanielRN I read STDERR

Version 2 of the Ruby SDK will enter maintenance mode as of November 20, 2020. To continue receiving service updates and new features, please upgrade to Version 3. More information can be found here: https://aws.amazon.com/blogs/developer/deprecation-schedule-for-aws-sdk-for-ruby-v2/

@arielvalentin
Copy link
Contributor Author

@YanivD I am going to drop support for AWS SDK 2.0 since it is no longer under maintenance since 2021-11. I will open a separate PR.

Please let me know if you have any concerns.

@arielvalentin
Copy link
Contributor Author

cc: #1166

@arielvalentin arielvalentin force-pushed the use-gem-versions branch 2 times, most recently from 258198d to 689d7db Compare April 1, 2022 15:13
@arielvalentin arielvalentin marked this pull request as ready for review April 1, 2022 16:28
Copy link
Member

@mwear mwear left a comment

Choose a reason for hiding this comment

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

LGTM

The GitHub Monolith bypasses RubyGems when loading dependencies, which results in a `nil` variable being returned by `Gem.loaded_specs`.

This change fallsback to using `Gem::Version.new(<VERSION>)` where possible.

See open-telemetry#947

Related https://github.com/open-telemetry/opentelemetry-ruby/issues/988#issuecomment-1018676853
Prior to this commit developers had to either run tests from within a container,
or independently run services from their host machine.

Developers may now use docker-compose for all services and run tests from their host machine.
@arielvalentin
Copy link
Contributor Author

Two unexpected errors in the test suites suite

Ruby 2.5 https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true

The Gemfile's dependencies are satisfied
[4972](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4972)
opentelemetry-instrumentation-rdkafka: test
[4973](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4973)
Your RubyGems version (2.7.6.3) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3`
[4974](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4974)
>> BUNDLE_GEMFILE=/home/runner/work/opentelemetry-ruby/opentelemetry-ruby/instrumentation/rdkafka/gemfiles/rdkafka_0.10.0.gemfile bundle exec rake test
[4975](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4975)
Your RubyGems version (2.7.6.3) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3`
[4976](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4976)
Run options: --seed 8271
[4977](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4977)

[4978](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4978)
# Running:
[4979](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4979)

[4980](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4980)
......
[4981](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4981)

[4982](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4982)
Finished in 11.175682s, 0.5369 runs/s, 3.1318 assertions/s.
[4983](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4983)

[4984](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4984)
6 runs, 35 assertions, 0 failures, 0 errors, 0 skips
[4985](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4985)
Segmentation fault (core dumped)
[4986](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4986)
rake aborted!
[4987](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4987)
Command failed with status (139)
[4988](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4988)
/opt/hostedtoolcache/Ruby/2.5.9/x64/bin/bundle:23:in `load'
[4989](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4989)
/opt/hostedtoolcache/Ruby/2.5.9/x64/bin/bundle:23:in `<main>'
[4990](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4990)
Tasks: TOP => test
[4991](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998961?check_suite_focus=true#step:6:4991)
(See full trace by running task with --trace)

Ruby 2.6 https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true

# Running:
[994](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:994)

[995](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:995)
.......................................F..
[996](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:996)

[997](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:997)
Finished in 0.044692s, 939.7698 runs/s, 2080.9188 assertions/s.
[998](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:998)

[999](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:999)
  1) Failure:
[1000](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1000)
OpenTelemetry::Instrumentation::ActiveJob::Patches::ActiveJobCallbacks::attributes::messaging.active_job.executions#test_0002_tracks correctly for jobs that do retry [/home/runner/work/opentelemetry-ruby/opentelemetry-ruby/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb:218]:
[1001](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1001)
Expected: 2
[1002](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1002)
  Actual: 1
[1003](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1003)

[1004](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1004)
42 runs, 93 assertions, 1 failures, 0 errors, 0 skips
[1005](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1005)
rake aborted!
[1006](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1006)
Command failed with status (1)
[1007](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1007)
/opt/hostedtoolcache/Ruby/2.6.9/x64/bin/bundle:23:in `load'
[1008](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1008)
/opt/hostedtoolcache/Ruby/2.6.9/x64/bin/bundle:23:in `<main>'
[1009](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1009)
Tasks: TOP => test
[1010](https://github.com/open-telemetry/opentelemetry-ruby/runs/5799998978?check_suite_focus=true#step:6:1010)
(See full trace by running task with --trace)

@arielvalentin
Copy link
Contributor Author

@open-telemetry/ruby-maintainers thoughts?

@ericmustin
Copy link
Contributor

@arielvalentin the tests appear to have magically fixed themselves, fwiw.

@robertlaurin robertlaurin merged commit 3b03ff7 into open-telemetry:main Apr 12, 2022
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.

5 participants