Skip to content

Commit

Permalink
Changed: Don't run profiling when google-protobuf isn't supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Sep 9, 2020
1 parent 3ac6fd7 commit ca48cf2
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ elsif Gem::Version.new('2.2.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'faraday'
gem 'grape'
gem 'graphql', '< 1.9.4'
gem 'grpc', '~> 1.21.0' # Last version to support Ruby < 2.3
gem 'grpc', '~> 1.19.0' # Last version to support Ruby < 2.3 & google-protobuf < 3.7
gem 'hiredis'
gem 'http'
gem 'mongo', '>= 2.8.0'
Expand Down
35 changes: 15 additions & 20 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,33 @@ source 'https://rubygems.org'

gemspec

# Add debugger for pry that's compatible with 0.10.4
gem 'pry-nav', git: 'https://github.com/nixme/pry-nav.git', branch: 'master'
# This file was generated by Appraisal

# Development dependencies
gem 'rake', '>= 10.5'
gem 'rubocop', '= 0.49.1' if RUBY_VERSION >= '2.1.0'
gem 'rspec', '~> 3.0'
gem 'rspec-collection_matchers', '~> 1.1'
gem 'minitest', '= 5.10.1'
gem 'minitest-around', '0.5.0'
gem 'minitest-stub_any_instance', '1.0.2'
gem 'addressable', '~> 2.4.0' # locking transitive dependency of webmock
gem 'appraisal', '~> 2.2'
gem 'yard', '~> 0.9'
gem 'webmock', '~> 2.0'
gem 'builder'

gem 'climate_control', '~> 0.2.0'

# locking transitive dependency of webmock
gem 'addressable', '~> 2.4.0'
gem 'benchmark-ips', '~> 2.8'
gem 'benchmark-memory', '~> 0.1'
gem 'builder'
gem 'climate_control', '~> 0.2.0'
gem 'memory_profiler', '~> 0.9'
gem 'minitest', '= 5.10.1'
gem 'minitest-around', '0.5.0'
gem 'minitest-stub_any_instance', '1.0.2'
gem 'pry', '~> 0.10.4'
# Add debugger for pry that's compatible with 0.10.4
gem 'pry-nav', git: 'https://github.com/nixme/pry-nav.git', branch: 'master'
gem 'pry-stack_explorer', '~> 0.4.9.2'
gem 'rake', '>= 10.5'
gem 'rspec', '~> 3.0'
gem 'rspec-collection_matchers', '~> 1.1'
gem 'rubocop', '= 0.49.1' if RUBY_VERSION >= '2.1.0'
gem 'simplecov', '~> 0.17'
gem 'warning', '~> 1' if RUBY_VERSION >= '2.5.0'
gem 'webmock', '~> 2.0'
gem 'yard', '~> 0.9'

if RUBY_PLATFORM != 'java'
gem 'sqlite3', '~> 1.3.6'
gem 'redcarpet', '~> 3.4'
gem 'sqlite3', '~> 1.3.6'
else
gem 'jdbc-sqlite3', '~> 3'
end
18 changes: 15 additions & 3 deletions ddtrace.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,23 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_runtime_dependency 'msgpack'
# NOTE: Exclude 3.7.x because the required_ruby_version mismatches
# actual Ruby support. It would break Ruby < 2.3.
spec.add_runtime_dependency 'google-protobuf', '~> 3.0', '!= 3.7.0', '!= 3.7.1'

# Optional extensions
spec.add_development_dependency 'dogstatsd-ruby', '>= 3.3.0'
spec.add_development_dependency 'opentracing', '>= 0.4.1'

if RUBY_PLATFORM != 'java'
# NOTE: Exclude 3.7.x because the required_ruby_version mismatches
# actual Ruby support. It would break Ruby < 2.3.
google_protobuf_versions = [
'~> 3.0',
'!= 3.7.0.rc.2',
'!= 3.7.0.rc.3',
'!= 3.7.0',
'!= 3.7.1',
'!= 3.8.0.rc.1'
]

spec.add_development_dependency 'google-protobuf', *google_protobuf_versions
end
end
1 change: 1 addition & 0 deletions lib/ddtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'ddtrace/patcher'
require 'ddtrace/augmentation'
require 'ddtrace/metrics'
require 'ddtrace/profiling'

# \Datadog global namespace that includes all tracing functionality for Tracer and Span classes.
module Datadog
Expand Down
30 changes: 30 additions & 0 deletions lib/ddtrace/profiling.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Datadog
# Contains profiler for generating stack profiles, etc.
module Profiling
module_function

GOOGLE_PROTOBUF_MINIMUM_VERSION = Gem::Version.new('3.0')

def supported?
google_protobuf_supported?
end

def google_protobuf_supported?
RUBY_PLATFORM != 'java' \
&& !Gem.loaded_specs['google-protobuf'].nil? \
&& Gem.loaded_specs['google-protobuf'].version >= GOOGLE_PROTOBUF_MINIMUM_VERSION
end

def load_profiling
require 'ddtrace/profiling/collectors/stack'
require 'ddtrace/profiling/exporter'
require 'ddtrace/profiling/recorder'
require 'ddtrace/profiling/scheduler'
require 'ddtrace/profiling/transport/io'

require 'ddtrace/profiling/pprof/pprof_pb' if google_protobuf_supported?
end

load_profiling if supported?
end
end
2 changes: 0 additions & 2 deletions lib/ddtrace/profiling/encoding/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module Encoding
module Profile
# Encodes events to pprof
module Protobuf
DEFAULT_ENCODING = 'UTF-8'.freeze

module_function

def encode(flushes)
Expand Down
2 changes: 0 additions & 2 deletions lib/ddtrace/profiling/pprof/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
require 'ddtrace/profiling/pprof/message_set'
require 'ddtrace/profiling/pprof/string_table'

require 'ddtrace/profiling/pprof/pprof_pb'

module Datadog
module Profiling
module Pprof
Expand Down
5 changes: 5 additions & 0 deletions spec/ddtrace/profiling/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'

require 'ddtrace'
require 'ddtrace/profiling'
require 'ddtrace/profiling/pprof/template'
require 'ddtrace/profiling/collectors/stack'
require 'ddtrace/profiling/recorder'
Expand All @@ -9,6 +10,10 @@
require 'ddtrace/profiling/encoding/profile'

RSpec.describe 'profiling integration test' do
before do
skip 'Profiling is not supported.' unless Datadog::Profiling.supported?
end

shared_context 'StackSample events' do
let(:stack_one) { Thread.current.backtrace_locations.first(3) }
let(:stack_two) { Thread.current.backtrace_locations.first(3) }
Expand Down
5 changes: 5 additions & 0 deletions spec/ddtrace/profiling/pprof/builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
require 'spec_helper'

require 'ddtrace/profiling'
require 'ddtrace/profiling/events/stack'
require 'ddtrace/profiling/pprof/builder'

RSpec.describe Datadog::Profiling::Pprof::Builder do
before do
skip 'Profiling is not supported.' unless Datadog::Profiling.supported?
end

subject(:builder) { described_class.new }

let(:id_sequence) { Datadog::Utils::Sequence.new(1) }
Expand Down
5 changes: 5 additions & 0 deletions spec/ddtrace/profiling/pprof/stack_sample_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
require 'spec_helper'

require 'ddtrace/profiling'
require 'ddtrace/profiling/events/stack'
require 'ddtrace/profiling/pprof/stack_sample'

RSpec.describe Datadog::Profiling::Pprof::StackSample do
before do
skip 'Profiling is not supported.' unless Datadog::Profiling.supported?
end

subject(:converter) { described_class.new(builder, sample_type_mappings) }
let(:builder) { Datadog::Profiling::Pprof::Builder.new }
let(:sample_type_mappings) do
Expand Down
5 changes: 5 additions & 0 deletions spec/ddtrace/profiling/pprof/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
require 'spec_helper'

require 'ddtrace/profiling'
require 'ddtrace/profiling/pprof/template'

RSpec.describe Datadog::Profiling::Pprof::Template do
before do
skip 'Profiling is not supported.' unless Datadog::Profiling.supported?
end

subject(:template) { described_class.new(mappings) }
let(:mappings) { described_class::DEFAULT_MAPPINGS }

Expand Down

0 comments on commit ca48cf2

Please sign in to comment.