From 20531458d1c22f9a054f01d11c74ef28ce0d896b Mon Sep 17 00:00:00 2001 From: Florian David Date: Fri, 4 Sep 2020 12:17:16 +0200 Subject: [PATCH 1/5] Changed: Profiling HTTP request 'type' field to 'auto' --- lib/ddtrace/ext/profiling.rb | 2 +- lib/ddtrace/profiling/transport/http/api/endpoint.rb | 11 +---------- .../transport/http/adapters/net_integration_spec.rb | 2 +- .../profiling/transport/http/api/endpoint_spec.rb | 2 +- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/ddtrace/ext/profiling.rb b/lib/ddtrace/ext/profiling.rb index ab0bdbe5268..e60ebaf2681 100644 --- a/lib/ddtrace/ext/profiling.rb +++ b/lib/ddtrace/ext/profiling.rb @@ -33,7 +33,7 @@ module HTTP FORM_FIELD_TAG_VERSION = 'version'.freeze FORM_FIELD_TAGS = 'tags'.freeze FORM_FIELD_TYPES = 'types'.freeze - FORM_FIELD_TYPE_CPU_TIME = 'cpu_time'.freeze + FORM_FIELD_TYPES_AUTO = 'auto'.freeze HEADER_CONTENT_TYPE = 'Content-Type'.freeze HEADER_CONTENT_TYPE_OCTET_STREAM = 'application/octet-stream'.freeze diff --git a/lib/ddtrace/profiling/transport/http/api/endpoint.rb b/lib/ddtrace/profiling/transport/http/api/endpoint.rb index 2bd34414f7a..94f3731bf8f 100644 --- a/lib/ddtrace/profiling/transport/http/api/endpoint.rb +++ b/lib/ddtrace/profiling/transport/http/api/endpoint.rb @@ -14,10 +14,6 @@ module API class Endpoint < Datadog::Transport::HTTP::API::Endpoint include Datadog::Ext::Profiling::Transport::HTTP - TYPE_MAPPINGS = { - cpu_time_ns: 'ruby-cpu'.freeze - }.freeze - attr_reader \ :encoder @@ -71,11 +67,6 @@ def build_form(env) def build_pprof(flush) pprof = encoder.encode(flush) - # Convert types - types = pprof.types.map do |type| - TYPE_MAPPINGS.key?(type) ? TYPE_MAPPINGS[type] : type.to_s - end - # Wrap pprof as a gzipped file gzipped_data = Datadog::Utils::Compression.gzip(pprof.data) pprof_file = Datadog::Vendor::Multipart::Post::UploadIO.new( @@ -84,7 +75,7 @@ def build_pprof(flush) PPROF_DEFAULT_FILENAME ) - [pprof_file, types] + [pprof_file, [FORM_FIELD_TYPES_AUTO]] end end end diff --git a/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb b/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb index 55702bf7277..edab57948da 100644 --- a/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb +++ b/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb @@ -87,7 +87,7 @@ 'recording-start' => kind_of(String), 'recording-end' => kind_of(String), 'data[0]' => kind_of(String), - 'types[0]' => /ruby-cpu(,wall_time_ns)?/, # TODO: Replace + 'types[0]' => /auto/, 'runtime' => Datadog::Ext::Runtime::LANG_INTERPRETER, 'format' => Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_FORMAT_PPROF ) diff --git a/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb b/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb index 2a10e6a7397..822e9bf3c3a 100644 --- a/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb +++ b/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb @@ -111,7 +111,7 @@ it 'includes env tags' do call expect(env.form).to include( - 'types[0]' => 'wall_time_ns,ruby-cpu' + 'types[0]' => 'auto' ) end end From 818296e5f0230e5eec0fb96819cf02b562a7845d Mon Sep 17 00:00:00 2001 From: David Elner Date: Tue, 8 Sep 2020 14:41:37 -0400 Subject: [PATCH 2/5] Added: #lang_engine and #lang_platform to Identity. --- lib/ddtrace/ext/runtime.rb | 2 ++ lib/ddtrace/runtime/identity.rb | 8 +++++++ spec/ddtrace/runtime/identity_spec.rb | 30 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/lib/ddtrace/ext/runtime.rb b/lib/ddtrace/ext/runtime.rb index f5f7230aa9d..f348ac98a1b 100644 --- a/lib/ddtrace/ext/runtime.rb +++ b/lib/ddtrace/ext/runtime.rb @@ -5,7 +5,9 @@ module Ext module Runtime # Identity LANG = 'ruby'.freeze + LANG_ENGINE = RUBY_ENGINE LANG_INTERPRETER = (RUBY_ENGINE + '-' + RUBY_PLATFORM).freeze + LANG_PLATFORM = RUBY_PLATFORM LANG_VERSION = RUBY_VERSION TRACER_VERSION = Datadog::VERSION::STRING diff --git a/lib/ddtrace/runtime/identity.rb b/lib/ddtrace/runtime/identity.rb index 5ea524d6ff2..e84cfc7ec5b 100644 --- a/lib/ddtrace/runtime/identity.rb +++ b/lib/ddtrace/runtime/identity.rb @@ -25,10 +25,18 @@ def lang Ext::Runtime::LANG end + def lang_engine + Ext::Runtime::LANG_ENGINE + end + def lang_interpreter Ext::Runtime::LANG_INTERPRETER end + def lang_platform + Ext::Runtime::LANG_PLATFORM + end + def lang_version Ext::Runtime::LANG_VERSION end diff --git a/spec/ddtrace/runtime/identity_spec.rb b/spec/ddtrace/runtime/identity_spec.rb index 2b25309f2cd..6e55aa15402 100644 --- a/spec/ddtrace/runtime/identity_spec.rb +++ b/spec/ddtrace/runtime/identity_spec.rb @@ -38,4 +38,34 @@ end end end + + describe '::lang' do + subject(:lang) { described_class.lang } + it { is_expected.to eq(Datadog::Ext::Runtime::LANG) } + end + + describe '::lang_engine' do + subject(:lang_engine) { described_class.lang_engine } + it { is_expected.to eq(Datadog::Ext::Runtime::LANG_ENGINE) } + end + + describe '::lang_interpreter' do + subject(:lang_interpreter) { described_class.lang_interpreter } + it { is_expected.to eq(Datadog::Ext::Runtime::LANG_INTERPRETER) } + end + + describe '::lang_platform' do + subject(:lang_platform) { described_class.lang_platform } + it { is_expected.to eq(Datadog::Ext::Runtime::LANG_PLATFORM) } + end + + describe '::lang_version' do + subject(:lang_version) { described_class.lang_version } + it { is_expected.to eq(Datadog::Ext::Runtime::LANG_VERSION) } + end + + describe '::tracer_version' do + subject(:tracer_version) { described_class.tracer_version } + it { is_expected.to eq(Datadog::Ext::Runtime::TRACER_VERSION) } + end end From 183d2ebdcec21ea27e65b071df973e7d903fae09 Mon Sep 17 00:00:00 2001 From: David Elner Date: Tue, 8 Sep 2020 14:42:08 -0400 Subject: [PATCH 3/5] Added: #runtime_engine and #runtime_platform to Flush. --- lib/ddtrace/profiling/flush.rb | 6 ++- spec/ddtrace/profiling/flush_spec.rb | 81 ++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 spec/ddtrace/profiling/flush_spec.rb diff --git a/lib/ddtrace/profiling/flush.rb b/lib/ddtrace/profiling/flush.rb index 3b709ec4a08..585b0fc290a 100644 --- a/lib/ddtrace/profiling/flush.rb +++ b/lib/ddtrace/profiling/flush.rb @@ -15,7 +15,8 @@ module Profiling :version, :host, :language, - :runtime, + :runtime_engine, + :runtime_platform, :runtime_version, :profiler_version ) do @@ -27,7 +28,8 @@ def initialize(*args) self.version = version || Datadog.configuration.version self.host = host || Datadog::Runtime::Socket.hostname self.language = language || Datadog::Runtime::Identity.lang - self.runtime = runtime || Datadog::Runtime::Identity.lang_interpreter + self.runtime_engine = runtime_engine || Datadog::Runtime::Identity.lang_engine + self.runtime_platform = runtime_platform || Datadog::Runtime::Identity.lang_platform self.runtime_version = runtime_version || Datadog::Runtime::Identity.lang_version self.profiler_version = profiler_version || Datadog::Runtime::Identity.tracer_version end diff --git a/spec/ddtrace/profiling/flush_spec.rb b/spec/ddtrace/profiling/flush_spec.rb new file mode 100644 index 00000000000..ac375fe1bd7 --- /dev/null +++ b/spec/ddtrace/profiling/flush_spec.rb @@ -0,0 +1,81 @@ +RSpec.describe Datadog::Profiling::Flush do + describe '#new' do + context 'given no arguments' do + subject(:identifier) { described_class.new } + + it do + is_expected.to have_attributes( + start: nil, + finish: nil, + event_groups: nil, + event_count: nil, + runtime_id: Datadog::Runtime::Identity.id, + service: Datadog.configuration.service, + env: Datadog.configuration.env, + version: Datadog.configuration.version, + host: Datadog::Runtime::Socket.hostname, + language: Datadog::Runtime::Identity.lang, + runtime_engine: Datadog::Runtime::Identity.lang_engine, + runtime_platform: Datadog::Runtime::Identity.lang_platform, + runtime_version: Datadog::Runtime::Identity.lang_version, + profiler_version: Datadog::Runtime::Identity.tracer_version + ) + end + end + + context 'given full arguments' do + subject(:identifier) do + described_class.new( + start, + finish, + event_groups, + event_count, + runtime_id, + service, + env, + version, + host, + language, + runtime_engine, + runtime_platform, + runtime_version, + profiler_version + ) + end + + let(:start) { double('start') } + let(:finish) { double('finish') } + let(:event_groups) { double('event_groups') } + let(:event_count) { double('event_count') } + let(:runtime_id) { double('runtime_id') } + let(:service) { double('service') } + let(:env) { double('env') } + let(:version) { double('version') } + let(:host) { double('host') } + let(:language) { double('language') } + let(:runtime_engine) { double('runtime_engine') } + let(:runtime_platform) { double('runtime_platform') } + let(:runtime_version) { double('runtime_version') } + let(:profiler_version) { double('profiler_version') } + + it do + is_expected.to have_attributes( + start: start, + finish: finish, + event_groups: event_groups, + event_count: event_count, + runtime_id: runtime_id, + service: service, + env: env, + version: version, + host: host, + language: language, + runtime_engine: runtime_engine, + runtime_platform: runtime_platform, + runtime_version: runtime_version, + profiler_version: profiler_version + ) + end + end + end +end From 28893ef3b02b19ce3068766f3132ebb98c35ec55 Mon Sep 17 00:00:00 2001 From: David Elner Date: Tue, 8 Sep 2020 14:43:29 -0400 Subject: [PATCH 4/5] Changed: Move profiling types field to constant. --- lib/ddtrace/ext/profiling.rb | 2 +- lib/ddtrace/profiling/transport/http/api/endpoint.rb | 2 +- spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ddtrace/ext/profiling.rb b/lib/ddtrace/ext/profiling.rb index e60ebaf2681..7b1bb5c176e 100644 --- a/lib/ddtrace/ext/profiling.rb +++ b/lib/ddtrace/ext/profiling.rb @@ -32,7 +32,7 @@ module HTTP FORM_FIELD_TAG_SERVICE = 'service'.freeze FORM_FIELD_TAG_VERSION = 'version'.freeze FORM_FIELD_TAGS = 'tags'.freeze - FORM_FIELD_TYPES = 'types'.freeze + FORM_FIELD_TYPES = 'types[0]'.freeze FORM_FIELD_TYPES_AUTO = 'auto'.freeze HEADER_CONTENT_TYPE = 'Content-Type'.freeze diff --git a/lib/ddtrace/profiling/transport/http/api/endpoint.rb b/lib/ddtrace/profiling/transport/http/api/endpoint.rb index 94f3731bf8f..aa78c8f850f 100644 --- a/lib/ddtrace/profiling/transport/http/api/endpoint.rb +++ b/lib/ddtrace/profiling/transport/http/api/endpoint.rb @@ -54,7 +54,7 @@ def build_form(env) } # Add types - form['types[0]'] = types.join(',') + form[FORM_FIELD_TYPES] = types.join(',') # Optional fields form[FORM_FIELD_TAGS] << "#{FORM_FIELD_TAG_SERVICE}:#{flush.service}" unless flush.service.nil? diff --git a/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb b/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb index 822e9bf3c3a..c3a842fae0f 100644 --- a/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb +++ b/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb @@ -111,7 +111,7 @@ it 'includes env tags' do call expect(env.form).to include( - 'types[0]' => 'auto' + Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TYPES => Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TYPES_AUTO ) end end From be71575c183f96b412fa466878c086b891ec967a Mon Sep 17 00:00:00 2001 From: David Elner Date: Tue, 8 Sep 2020 15:59:04 -0400 Subject: [PATCH 5/5] Added: runtime_engine and runtime_platform tags to profiling HTTP request. --- lib/ddtrace/ext/profiling.rb | 2 ++ lib/ddtrace/profiling/transport/http/api/endpoint.rb | 7 +++++-- .../transport/http/adapters/net_integration_spec.rb | 6 ++++-- spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb | 6 ++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/ddtrace/ext/profiling.rb b/lib/ddtrace/ext/profiling.rb index 7b1bb5c176e..bfa734e912d 100644 --- a/lib/ddtrace/ext/profiling.rb +++ b/lib/ddtrace/ext/profiling.rb @@ -28,6 +28,8 @@ module HTTP FORM_FIELD_TAG_LANGUAGE = 'language'.freeze FORM_FIELD_TAG_PROFILER_VERSION = 'profiler_version'.freeze FORM_FIELD_TAG_RUNTIME = 'runtime'.freeze + FORM_FIELD_TAG_RUNTIME_ENGINE = 'runtime_engine'.freeze + FORM_FIELD_TAG_RUNTIME_PLATFORM = 'runtime_platform'.freeze FORM_FIELD_TAG_RUNTIME_VERSION = 'runtime_version'.freeze FORM_FIELD_TAG_SERVICE = 'service'.freeze FORM_FIELD_TAG_VERSION = 'version'.freeze diff --git a/lib/ddtrace/profiling/transport/http/api/endpoint.rb b/lib/ddtrace/profiling/transport/http/api/endpoint.rb index aa78c8f850f..28def19103f 100644 --- a/lib/ddtrace/profiling/transport/http/api/endpoint.rb +++ b/lib/ddtrace/profiling/transport/http/api/endpoint.rb @@ -42,14 +42,17 @@ def build_form(env) FORM_FIELD_RECORDING_START => flush.start.utc.iso8601, FORM_FIELD_RECORDING_END => flush.finish.utc.iso8601, FORM_FIELD_TAGS => [ - "#{FORM_FIELD_TAG_RUNTIME}:#{flush.runtime}", + "#{FORM_FIELD_TAG_RUNTIME}:#{flush.language}", + "#{FORM_FIELD_TAG_RUNTIME_ENGINE}:#{flush.runtime_engine}", + "#{FORM_FIELD_TAG_RUNTIME_PLATFORM}:#{flush.runtime_platform}", "#{FORM_FIELD_TAG_RUNTIME_VERSION}:#{flush.runtime_version}", "#{FORM_FIELD_TAG_PROFILER_VERSION}:#{flush.profiler_version}", + # NOTE: Redundant w/ 'runtime'; may want to remove this later. "#{FORM_FIELD_TAG_LANGUAGE}:#{flush.language}", "#{FORM_FIELD_TAG_HOST}:#{flush.host}" ], FORM_FIELD_DATA => pprof_file, - FORM_FIELD_RUNTIME => flush.runtime, + FORM_FIELD_RUNTIME => flush.language, FORM_FIELD_FORMAT => FORM_FIELD_FORMAT_PPROF } diff --git a/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb b/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb index edab57948da..f54ecd5c939 100644 --- a/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb +++ b/spec/ddtrace/profiling/transport/http/adapters/net_integration_spec.rb @@ -88,7 +88,7 @@ 'recording-end' => kind_of(String), 'data[0]' => kind_of(String), 'types[0]' => /auto/, - 'runtime' => Datadog::Ext::Runtime::LANG_INTERPRETER, + 'runtime' => Datadog::Ext::Runtime::LANG, 'format' => Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_FORMAT_PPROF ) @@ -96,7 +96,9 @@ tags = body["#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAGS}[]"].list expect(tags).to be_a_kind_of(Array) expect(tags).to include( - /#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME}:#{Datadog::Ext::Runtime::LANG_INTERPRETER}/, + /#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME}:#{Datadog::Ext::Runtime::LANG}/, + /#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME_ENGINE}:#{Datadog::Ext::Runtime::LANG_ENGINE}/, + /#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME_PLATFORM}:#{Datadog::Ext::Runtime::LANG_PLATFORM}/, /#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME_VERSION}:#{Datadog::Ext::Runtime::LANG_VERSION}/, /#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_PROFILER_VERSION}:#{Datadog::Ext::Runtime::TRACER_VERSION}/, /#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_LANGUAGE}:#{Datadog::Ext::Runtime::LANG}/ diff --git a/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb b/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb index c3a842fae0f..772d07bf73d 100644 --- a/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb +++ b/spec/ddtrace/profiling/transport/http/api/endpoint_spec.rb @@ -62,10 +62,12 @@ Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_FORMAT => Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_FORMAT_PPROF, Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_RECORDING_START => flush.start.utc.iso8601, Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_RECORDING_END => flush.finish.utc.iso8601, - Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_RUNTIME => flush.runtime, + Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_RUNTIME => flush.language, Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_RUNTIME_ID => flush.runtime_id, Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAGS => array_including( - "#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME}:#{flush.runtime}", + "#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME}:#{flush.language}", + "#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME_ENGINE}:#{flush.runtime_engine}", + "#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME_PLATFORM}:#{flush.runtime_platform}", "#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_RUNTIME_VERSION}:#{flush.runtime_version}", "#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_PROFILER_VERSION}:#{flush.profiler_version}", "#{Datadog::Ext::Profiling::Transport::HTTP::FORM_FIELD_TAG_LANGUAGE}:#{flush.language}",