Skip to content

Commit 9e4a1fa

Browse files
committed
[PROF-2585] Warn on incompatible rollbar version
Rollbar gem versions <= 3.1.1 have an incompatibility with ddtrace's CPU profiling. This was ack'd and fixed upstream in <rollbar/rollbar-gem#1018>. This commit adds code to detect when customers are still using a legacy version of rollbar, printing a warning to ask them to upgrade. Note: Because the fixed version of rollbar has not yet been released, the tests that validate that the warning is not shown on unpatched versions are disabled and tagged with a FIXME. See the "FIXME NEW ROLLBAR NEEDED" note in the setup_spec.rb for more details on what's disabled and what steps we need to take once the new version gets released. First commit @ Datadog 🎉
1 parent 54e51bd commit 9e4a1fa

File tree

4 files changed

+207
-0
lines changed

4 files changed

+207
-0
lines changed

Appraisals

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ elsif Gem::Version.new('2.0.0') <= Gem::Version.new(RUBY_VERSION) \
7373
gem 'lograge', '< 0.4'
7474
end
7575

76+
appraise 'rollbar-incompatible' do
77+
gem 'rollbar', '= 3.1.1'
78+
end
79+
80+
appraise 'rollbar-compatible' do
81+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
82+
#gem 'rollbar', '= 3.1.2'
83+
end
84+
7685
appraise 'contrib-old' do
7786
gem 'active_model_serializers', '~> 0.9.0'
7887
gem 'activerecord', '3.2.22.5'
@@ -201,6 +210,15 @@ elsif Gem::Version.new('2.1.0') <= Gem::Version.new(RUBY_VERSION) \
201210
gem 'lograge'
202211
end
203212

213+
appraise 'rollbar-incompatible' do
214+
gem 'rollbar', '= 3.1.1'
215+
end
216+
217+
appraise 'rollbar-compatible' do
218+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
219+
#gem 'rollbar', '= 3.1.2'
220+
end
221+
204222
appraise 'contrib-old' do
205223
gem 'active_model_serializers', '~> 0.9.0'
206224
gem 'activerecord', '3.2.22.5'
@@ -386,6 +404,15 @@ elsif Gem::Version.new('2.2.0') <= Gem::Version.new(RUBY_VERSION) \
386404
gem 'mimemagic', '0.3.9' # Pinned until https://github.com/mimemagicrb/mimemagic/issues/142 is resolved.
387405
end
388406

407+
appraise 'rollbar-incompatible' do
408+
gem 'rollbar', '= 3.1.1'
409+
end
410+
411+
appraise 'rollbar-compatible' do
412+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
413+
#gem 'rollbar', '= 3.1.2'
414+
end
415+
389416
appraise 'contrib' do
390417
gem 'actionpack'
391418
gem 'actionview'
@@ -585,6 +612,15 @@ elsif Gem::Version.new('2.3.0') <= Gem::Version.new(RUBY_VERSION) \
585612

586613
(3..4).each { |v| gem_cucumber(v) }
587614

615+
appraise 'rollbar-incompatible' do
616+
gem 'rollbar', '= 3.1.1'
617+
end
618+
619+
appraise 'rollbar-compatible' do
620+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
621+
#gem 'rollbar', '= 3.1.2'
622+
end
623+
588624
appraise 'contrib' do
589625
gem 'actionpack'
590626
gem 'actionview'
@@ -693,6 +729,15 @@ elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) \
693729

694730
(3..4).each { |v| gem_cucumber(v) }
695731

732+
appraise 'rollbar-incompatible' do
733+
gem 'rollbar', '= 3.1.1'
734+
end
735+
736+
appraise 'rollbar-compatible' do
737+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
738+
#gem 'rollbar', '= 3.1.2'
739+
end
740+
696741
appraise 'contrib' do
697742
gem 'actionpack'
698743
gem 'actionview'
@@ -898,6 +943,15 @@ elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
898943

899944
(3..5).each { |v| gem_cucumber(v) }
900945

946+
appraise 'rollbar-incompatible' do
947+
gem 'rollbar', '= 3.1.1'
948+
end
949+
950+
appraise 'rollbar-compatible' do
951+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
952+
#gem 'rollbar', '= 3.1.2'
953+
end
954+
901955
appraise 'contrib' do
902956
gem 'actionpack'
903957
gem 'actionview'
@@ -1078,6 +1132,15 @@ elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION) \
10781132

10791133
(3..5).each { |v| gem_cucumber(v) }
10801134

1135+
appraise 'rollbar-incompatible' do
1136+
gem 'rollbar', '= 3.1.1'
1137+
end
1138+
1139+
appraise 'rollbar-compatible' do
1140+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
1141+
#gem 'rollbar', '= 3.1.2'
1142+
end
1143+
10811144
appraise 'contrib' do
10821145
gem 'actionpack'
10831146
gem 'actionview'
@@ -1259,6 +1322,15 @@ elsif Gem::Version.new('2.7.0') <= Gem::Version.new(RUBY_VERSION) \
12591322

12601323
(3..5).each { |v| gem_cucumber(v) }
12611324

1325+
appraise 'rollbar-incompatible' do
1326+
gem 'rollbar', '= 3.1.1'
1327+
end
1328+
1329+
appraise 'rollbar-compatible' do
1330+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
1331+
#gem 'rollbar', '= 3.1.2'
1332+
end
1333+
12621334
appraise 'contrib' do
12631335
gem 'actionpack'
12641336
gem 'actionview'

Rakefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ namespace :spec do
6868
t.rspec_opts = args.to_a.join(' ')
6969
end
7070

71+
RSpec::Core::RakeTask.new(:rollbar) do |t, args|
72+
t.pattern = 'spec/ddtrace/profiling/tasks/setup_spec.rb'
73+
t.rspec_opts = args.to_a.join(' ')
74+
end
75+
7176
RSpec::Core::RakeTask.new(:contrib) do |t, args|
7277
contrib_paths = [
7378
'analytics',
@@ -260,6 +265,10 @@ task :ci do
260265
declare 'bundle exec appraisal rails32-postgres rake spec:action_view'
261266
declare 'bundle exec appraisal rails32-mysql2 rake spec:active_record'
262267
declare 'bundle exec appraisal rails32-postgres rake spec:active_support'
268+
269+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
270+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
271+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
263272
end
264273
elsif Gem::Version.new('2.1.0') <= Gem::Version.new(RUBY_VERSION) \
265274
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0')
@@ -327,6 +336,10 @@ task :ci do
327336
declare 'bundle exec appraisal rails32-postgres rake spec:action_view'
328337
declare 'bundle exec appraisal rails32-mysql2 rake spec:active_record'
329338
declare 'bundle exec appraisal rails32-postgres rake spec:active_support'
339+
340+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
341+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
342+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
330343
end
331344
elsif Gem::Version.new('2.2.0') <= Gem::Version.new(RUBY_VERSION)\
332345
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')
@@ -410,6 +423,10 @@ task :ci do
410423
declare 'bundle exec appraisal rails4-postgres rake spec:rails'
411424
declare 'bundle exec appraisal rails5-mysql2 rake spec:rails'
412425
declare 'bundle exec appraisal rails5-postgres rake spec:rails'
426+
427+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
428+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
429+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
413430
end
414431
elsif Gem::Version.new('2.3.0') <= Gem::Version.new(RUBY_VERSION) \
415432
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4.0')
@@ -498,6 +515,10 @@ task :ci do
498515
# explicitly test resque-2x compatability
499516
declare 'bundle exec appraisal resque2-redis3 rake spec:resque'
500517
declare 'bundle exec appraisal resque2-redis4 rake spec:resque'
518+
519+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
520+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
521+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
501522
end
502523
elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) \
503524
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0')
@@ -573,6 +594,10 @@ task :ci do
573594
# explicitly test cucumber compatibility
574595
declare 'bundle exec appraisal cucumber3 rake spec:cucumber'
575596
declare 'bundle exec appraisal cucumber4 rake spec:cucumber'
597+
598+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
599+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
600+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
576601
end
577602
elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
578603
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6.0')
@@ -668,6 +693,10 @@ task :ci do
668693
declare 'bundle exec appraisal cucumber3 rake spec:cucumber'
669694
declare 'bundle exec appraisal cucumber4 rake spec:cucumber'
670695
declare 'bundle exec appraisal cucumber5 rake spec:cucumber'
696+
697+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
698+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
699+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
671700
elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION) \
672701
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0')
673702
# Main library
@@ -765,6 +794,10 @@ task :ci do
765794
declare 'bundle exec appraisal cucumber3 rake spec:cucumber'
766795
declare 'bundle exec appraisal cucumber4 rake spec:cucumber'
767796
declare 'bundle exec appraisal cucumber5 rake spec:cucumber'
797+
798+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
799+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
800+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
768801
end
769802
elsif Gem::Version.new('2.7.0') <= Gem::Version.new(RUBY_VERSION) \
770803
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
@@ -934,6 +967,10 @@ task :ci do
934967
declare 'bundle exec appraisal cucumber3 rake spec:cucumber'
935968
declare 'bundle exec appraisal cucumber4 rake spec:cucumber'
936969
declare 'bundle exec appraisal cucumber5 rake spec:cucumber'
970+
971+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
972+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
973+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
937974
end
938975
end
939976
end

lib/ddtrace/profiling/tasks/setup.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Tasks
99
# Sets up profiling for the application
1010
class Setup
1111
def run
12+
check_warnings!
1213
activate_main_extensions
1314
autostart_profiler
1415
end
@@ -79,6 +80,21 @@ def autostart_profiler
7980
log "[DDTRACE] Could not autostart profiling. Cause: #{e.message} Location: #{e.backtrace.first}"
8081
end
8182

83+
def check_warnings!
84+
warn_if_incompatible_rollbar_gem_detected
85+
end
86+
87+
def warn_if_incompatible_rollbar_gem_detected
88+
incompatible_rollbar_versions = Gem::Requirement.new('<= 3.1.1')
89+
90+
if Gem::Specification.find_all_by_name('rollbar', incompatible_rollbar_versions).any?
91+
log "[DDTRACE] Incompatible version of the rollbar gem is installed (#{incompatible_rollbar_versions}). " \
92+
'Loading this version of the rollbar gem will disable ddtrace\'s CPU profiling. ' \
93+
'Please upgrade to the latest rollbar version. ' \
94+
'See https://github.com/rollbar/rollbar-gem/pull/1018 for details.'
95+
end
96+
end
97+
8298
private
8399

84100
def log(message)

spec/ddtrace/profiling/tasks/setup_spec.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
subject(:run) { task.run }
1313

1414
it do
15+
expect(task).to receive(:check_warnings!).ordered
1516
expect(task).to receive(:activate_main_extensions).ordered
1617
expect(task).to receive(:autostart_profiler).ordered
1718
run
@@ -346,4 +347,85 @@
346347
end
347348
end
348349
end
350+
351+
describe '#check_warnings!' do
352+
subject(:check_warnings!) { task.check_warnings! }
353+
354+
it do
355+
expect(task).to receive(:warn_if_incompatible_rollbar_gem_detected)
356+
357+
check_warnings!
358+
end
359+
end
360+
361+
describe '#warn_if_incompatible_rollbar_gem_detected' do
362+
subject(:warn_if_incompatible_rollbar_gem_detected) { task.warn_if_incompatible_rollbar_gem_detected }
363+
364+
# Testing this code is slightly awkward for two reasons:
365+
# 1. We want to avoid using exactly the same code (gem apis) in the tests than we have for production.
366+
# 2. A given Ruby installation can only be in one of the possible states (no rollbar installed, old rollbar
367+
# installed, etc)
368+
#
369+
# To address this, we:
370+
# 1. Shell out to gem to detect if rollbar is installed or not (rather than using the same gem apis we want to test)
371+
# 2. Rely on the Appraisal gem test setup to be able to check the multiple cases in different runs
372+
373+
before(:context) do
374+
@rollbar_versions_installed =
375+
`gem list`.each_line.select { |it| it.start_with?('rollbar ') }.sort.map(&:strip)
376+
end
377+
378+
context 'when rollbar gem is not installed' do
379+
before do
380+
if @rollbar_versions_installed.any?
381+
skip "Current gem environment (#{@rollbar_versions_installed}) not setup for this test"
382+
end
383+
end
384+
385+
it 'does not display a warning to STDOUT' do
386+
expect(STDOUT).to_not receive(:puts)
387+
388+
warn_if_incompatible_rollbar_gem_detected
389+
end
390+
end
391+
392+
context 'when compatible version of rollbar gem is installed' do
393+
before do
394+
skip %q(FIXME NEW ROLLBAR NEEDED: This test cannot be enabled until a new version of rollbar (> 3.1.1) including
395+
"https://github.com/rollbar/rollbar-gem/pull/1018" is released.
396+
397+
Once this new version is released, we need to:
398+
1. Remove this skip
399+
2. Update the `Appraisals` file to enable the new version in the 'compatible-rollbar' appraisals~
400+
3. Enable the 'compatible-rollbar' validations in the `Rakefile`.)
401+
402+
if @rollbar_versions_installed != ['rollbar (3.1.2)']
403+
skip "Current gem environment (#{@rollbar_versions_installed}) not setup for this test"
404+
end
405+
end
406+
407+
it 'does not display a warning to STDOUT' do
408+
expect(STDOUT).to_not receive(:puts)
409+
410+
warn_if_incompatible_rollbar_gem_detected
411+
end
412+
end
413+
414+
context 'when incompatible version of rollbar gem is installed' do
415+
before do
416+
if @rollbar_versions_installed != ['rollbar (3.1.1)']
417+
skip "Current gem environment (#{@rollbar_versions_installed}) not setup for this test"
418+
end
419+
end
420+
421+
it 'displays a warning to STDOUT' do
422+
expect(STDOUT).to receive(:puts) do |message|
423+
STDERR.puts(message)
424+
expect(message).to include('Incompatible version of the rollbar')
425+
end
426+
427+
warn_if_incompatible_rollbar_gem_detected
428+
end
429+
end
430+
end
349431
end

0 commit comments

Comments
 (0)