Skip to content

Commit 8cbe750

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 e2893cb commit 8cbe750

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'
@@ -197,6 +206,15 @@ elsif Gem::Version.new('2.1.0') <= Gem::Version.new(RUBY_VERSION) \
197206
gem 'lograge'
198207
end
199208

209+
appraise 'rollbar-incompatible' do
210+
gem 'rollbar', '= 3.1.1'
211+
end
212+
213+
appraise 'rollbar-compatible' do
214+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
215+
#gem 'rollbar', '= 3.1.2'
216+
end
217+
200218
appraise 'contrib-old' do
201219
gem 'active_model_serializers', '~> 0.9.0'
202220
gem 'activerecord', '3.2.22.5'
@@ -373,6 +391,15 @@ elsif Gem::Version.new('2.2.0') <= Gem::Version.new(RUBY_VERSION) \
373391
gem 'lograge'
374392
end
375393

394+
appraise 'rollbar-incompatible' do
395+
gem 'rollbar', '= 3.1.1'
396+
end
397+
398+
appraise 'rollbar-compatible' do
399+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
400+
#gem 'rollbar', '= 3.1.2'
401+
end
402+
376403
appraise 'contrib' do
377404
gem 'actionpack'
378405
gem 'actionview'
@@ -568,6 +595,15 @@ elsif Gem::Version.new('2.3.0') <= Gem::Version.new(RUBY_VERSION) \
568595

569596
(3..4).each { |v| gem_cucumber(v) }
570597

598+
appraise 'rollbar-incompatible' do
599+
gem 'rollbar', '= 3.1.1'
600+
end
601+
602+
appraise 'rollbar-compatible' do
603+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
604+
#gem 'rollbar', '= 3.1.2'
605+
end
606+
571607
appraise 'contrib' do
572608
gem 'actionpack'
573609
gem 'actionview'
@@ -672,6 +708,15 @@ elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) \
672708

673709
(3..4).each { |v| gem_cucumber(v) }
674710

711+
appraise 'rollbar-incompatible' do
712+
gem 'rollbar', '= 3.1.1'
713+
end
714+
715+
appraise 'rollbar-compatible' do
716+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
717+
#gem 'rollbar', '= 3.1.2'
718+
end
719+
675720
appraise 'contrib' do
676721
gem 'actionpack'
677722
gem 'actionview'
@@ -873,6 +918,15 @@ elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
873918

874919
(3..5).each { |v| gem_cucumber(v) }
875920

921+
appraise 'rollbar-incompatible' do
922+
gem 'rollbar', '= 3.1.1'
923+
end
924+
925+
appraise 'rollbar-compatible' do
926+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
927+
#gem 'rollbar', '= 3.1.2'
928+
end
929+
876930
appraise 'contrib' do
877931
gem 'actionpack'
878932
gem 'actionview'
@@ -1049,6 +1103,15 @@ elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION) \
10491103

10501104
(3..5).each { |v| gem_cucumber(v) }
10511105

1106+
appraise 'rollbar-incompatible' do
1107+
gem 'rollbar', '= 3.1.1'
1108+
end
1109+
1110+
appraise 'rollbar-compatible' do
1111+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
1112+
#gem 'rollbar', '= 3.1.2'
1113+
end
1114+
10521115
appraise 'contrib' do
10531116
gem 'actionpack'
10541117
gem 'actionview'
@@ -1226,6 +1289,15 @@ elsif Gem::Version.new('2.7.0') <= Gem::Version.new(RUBY_VERSION) \
12261289

12271290
(3..5).each { |v| gem_cucumber(v) }
12281291

1292+
appraise 'rollbar-incompatible' do
1293+
gem 'rollbar', '= 3.1.1'
1294+
end
1295+
1296+
appraise 'rollbar-compatible' do
1297+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
1298+
#gem 'rollbar', '= 3.1.2'
1299+
end
1300+
12291301
appraise 'contrib' do
12301302
gem 'actionpack'
12311303
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',
@@ -259,6 +264,10 @@ task :ci do
259264
declare 'bundle exec appraisal rails32-postgres rake spec:action_view'
260265
declare 'bundle exec appraisal rails32-mysql2 rake spec:active_record'
261266
declare 'bundle exec appraisal rails32-postgres rake spec:active_support'
267+
268+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
269+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
270+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
262271
end
263272
elsif Gem::Version.new('2.1.0') <= Gem::Version.new(RUBY_VERSION) \
264273
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0')
@@ -325,6 +334,10 @@ task :ci do
325334
declare 'bundle exec appraisal rails32-postgres rake spec:action_view'
326335
declare 'bundle exec appraisal rails32-mysql2 rake spec:active_record'
327336
declare 'bundle exec appraisal rails32-postgres rake spec:active_support'
337+
338+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
339+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
340+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
328341
end
329342
elsif Gem::Version.new('2.2.0') <= Gem::Version.new(RUBY_VERSION)\
330343
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3.0')
@@ -407,6 +420,10 @@ task :ci do
407420
declare 'bundle exec appraisal rails4-postgres rake spec:rails'
408421
declare 'bundle exec appraisal rails5-mysql2 rake spec:rails'
409422
declare 'bundle exec appraisal rails5-postgres rake spec:rails'
423+
424+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
425+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
426+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
410427
end
411428
elsif Gem::Version.new('2.3.0') <= Gem::Version.new(RUBY_VERSION) \
412429
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4.0')
@@ -494,6 +511,10 @@ task :ci do
494511
# explicitly test resque-2x compatability
495512
declare 'bundle exec appraisal resque2-redis3 rake spec:resque'
496513
declare 'bundle exec appraisal resque2-redis4 rake spec:resque'
514+
515+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
516+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
517+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
497518
end
498519
elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) \
499520
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0')
@@ -568,6 +589,10 @@ task :ci do
568589
# explicitly test cucumber compatibility
569590
declare 'bundle exec appraisal cucumber3 rake spec:cucumber'
570591
declare 'bundle exec appraisal cucumber4 rake spec:cucumber'
592+
593+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
594+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
595+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
571596
end
572597
elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
573598
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6.0')
@@ -662,6 +687,10 @@ task :ci do
662687
declare 'bundle exec appraisal cucumber3 rake spec:cucumber'
663688
declare 'bundle exec appraisal cucumber4 rake spec:cucumber'
664689
declare 'bundle exec appraisal cucumber5 rake spec:cucumber'
690+
691+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
692+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
693+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
665694
elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION) \
666695
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0')
667696
# Main library
@@ -758,6 +787,10 @@ task :ci do
758787
declare 'bundle exec appraisal cucumber3 rake spec:cucumber'
759788
declare 'bundle exec appraisal cucumber4 rake spec:cucumber'
760789
declare 'bundle exec appraisal cucumber5 rake spec:cucumber'
790+
791+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
792+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
793+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
761794
end
762795
elsif Gem::Version.new('2.7.0') <= Gem::Version.new(RUBY_VERSION) \
763796
&& Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0')
@@ -925,6 +958,10 @@ task :ci do
925958
declare 'bundle exec appraisal cucumber3 rake spec:cucumber'
926959
declare 'bundle exec appraisal cucumber4 rake spec:cucumber'
927960
declare 'bundle exec appraisal cucumber5 rake spec:cucumber'
961+
962+
declare 'bundle exec appraisal rollbar-incompatible rake spec:rollbar'
963+
# FIXME: See note under "FIXME NEW ROLLBAR NEEDED" in setup_spec.rb for details
964+
# declare 'bundle exec appraisal rollbar-compatible rake spec:rollbar'
928965
end
929966
end
930967
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)