Skip to content

Commit

Permalink
ekump/decouple core transport (#3150)
Browse files Browse the repository at this point in the history
* Move ddtrace/transport to datadog/tracing/transport as it is tracing specific.

* Update Datadog::Transport namespace to Datadog::Tracing::Transport

* Move datadog/core/transport to datadog/remote/transport

* Update Datadog::Core::Transport to Datadog::Core::Remote::Transport

* Move commonly used files between Remote and Transport to Datadog::Core::Transport

* Create Datadog::Core::Transport::Ext that Datadog::Transport::Ext (ddtrace) references. The file in ddtrace should be replaced in 2.0.

* cleanup rubocop TODOs and Steepfile ignores for refactor
  • Loading branch information
ekump authored Sep 25, 2023
1 parent 20c8800 commit 9810fe0
Show file tree
Hide file tree
Showing 212 changed files with 4,693 additions and 4,447 deletions.
25 changes: 0 additions & 25 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ Lint/MissingSuper:
- 'lib/datadog/profiling/pprof/converter.rb'
- 'lib/datadog/profiling/pprof/template.rb'
- 'lib/datadog/profiling/scheduler.rb'
- 'lib/ddtrace/transport/http/adapters/net.rb'
- 'lib/ddtrace/transport/http/adapters/unix_socket.rb'
- 'lib/ddtrace/transport/http/builder.rb'
- 'lib/ddtrace/transport/http/env.rb'
- 'lib/ddtrace/transport/http/traces.rb'
- 'lib/ddtrace/transport/traces.rb'
- 'spec/support/faux_transport.rb'
- 'spec/support/spy_transport.rb'

Expand Down Expand Up @@ -71,12 +65,6 @@ RSpec/LeakyConstantDeclaration:
- 'spec/datadog/tracing/benchmark/support/benchmark_helper.rb'
- 'spec/datadog/tracing/contrib/rails/rack_spec.rb'

# Offense count: 32
RSpec/MissingExampleGroupArgument:
Exclude:
- 'spec/ddtrace/transport/http/adapters/net_spec.rb'
- 'spec/ddtrace/transport/http/adapters/test_spec.rb'

# Offense count: 71
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Expand All @@ -96,7 +84,6 @@ RSpec/NamedSubject:
- 'spec/datadog/tracing/contrib/patcher_spec.rb'
- 'spec/datadog/tracing/contrib/rails/cache_spec.rb'
- 'spec/datadog/tracing/contrib/rails/database_spec.rb'
- 'spec/ddtrace/transport/traces_spec.rb'

# Offense count: 8
RSpec/RepeatedDescription:
Expand Down Expand Up @@ -391,18 +378,6 @@ Style/FrozenStringLiteralComment:
- 'lib/datadog/tracing/workers/trace_writer.rb'
- 'lib/datadog/tracing/writer.rb'
- 'lib/ddtrace/profiling/preload.rb'
- 'lib/ddtrace/transport/http/adapters/net.rb'
- 'lib/ddtrace/transport/http/adapters/test.rb'
- 'lib/ddtrace/transport/http/adapters/unix_socket.rb'
- 'lib/ddtrace/transport/http/api.rb'
- 'lib/ddtrace/transport/http/builder.rb'
- 'lib/ddtrace/transport/http/client.rb'
- 'lib/ddtrace/transport/http/statistics.rb'
- 'lib/ddtrace/transport/http/traces.rb'
- 'lib/ddtrace/transport/io/client.rb'
- 'lib/ddtrace/transport/response.rb'
- 'lib/ddtrace/transport/serializable_trace.rb'
- 'lib/ddtrace/transport/traces.rb'

Metrics/BlockNesting:
Exclude:
Expand Down
55 changes: 23 additions & 32 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ target :ddtrace do

check 'lib/'

ignore 'lib/datadog/appsec/contrib/'
ignore 'lib/datadog/ci/contrib/'
ignore 'lib/datadog/tracing/contrib/'

ignore 'lib/datadog/appsec.rb'
ignore 'lib/datadog/appsec/component.rb'
ignore 'lib/datadog/appsec/contrib/'
ignore 'lib/datadog/appsec/contrib/auto_instrument.rb'
ignore 'lib/datadog/appsec/contrib/integration.rb'
ignore 'lib/datadog/appsec/contrib/rack/gateway/request.rb'
Expand Down Expand Up @@ -38,6 +35,7 @@ target :ddtrace do
ignore 'lib/datadog/ci.rb'
ignore 'lib/datadog/ci/configuration/components.rb'
ignore 'lib/datadog/ci/configuration/settings.rb'
ignore 'lib/datadog/ci/contrib/'
ignore 'lib/datadog/ci/contrib/cucumber/configuration/settings.rb'
ignore 'lib/datadog/ci/contrib/cucumber/ext.rb'
ignore 'lib/datadog/ci/contrib/cucumber/formatter.rb'
Expand Down Expand Up @@ -115,6 +113,14 @@ target :ddtrace do
ignore 'lib/datadog/core/telemetry/v1/integration.rb'
ignore 'lib/datadog/core/telemetry/v1/product.rb'
ignore 'lib/datadog/core/telemetry/v1/telemetry_request.rb'
ignore 'lib/datadog/core/transport/ext.rb'
ignore 'lib/datadog/core/transport/http/adapters/net.rb'
ignore 'lib/datadog/core/transport/http/adapters/registry.rb'
ignore 'lib/datadog/core/transport/http/adapters/test.rb'
ignore 'lib/datadog/core/transport/http/adapters/unix_socket.rb'
ignore 'lib/datadog/core/transport/http/api/fallbacks.rb'
ignore 'lib/datadog/core/transport/http/env.rb'
ignore 'lib/datadog/core/transport/http/response.rb'
ignore 'lib/datadog/core/utils.rb'
ignore 'lib/datadog/core/utils/compression.rb'
ignore 'lib/datadog/core/utils/forking.rb'
Expand Down Expand Up @@ -201,6 +207,7 @@ target :ddtrace do
ignore 'lib/datadog/tracing/context.rb'
ignore 'lib/datadog/tracing/context_provider.rb'
ignore 'lib/datadog/tracing/contrib.rb'
ignore 'lib/datadog/tracing/contrib/'
ignore 'lib/datadog/tracing/contrib/action_cable/configuration/settings.rb'
ignore 'lib/datadog/tracing/contrib/action_cable/event.rb'
ignore 'lib/datadog/tracing/contrib/action_cable/events.rb'
Expand Down Expand Up @@ -601,41 +608,25 @@ target :ddtrace do
ignore 'lib/datadog/tracing/trace_operation.rb'
ignore 'lib/datadog/tracing/trace_segment.rb'
ignore 'lib/datadog/tracing/tracer.rb'
ignore 'lib/datadog/tracing/transport/http.rb'
ignore 'lib/datadog/tracing/transport/http/api.rb'
ignore 'lib/datadog/tracing/transport/http/builder.rb'
ignore 'lib/datadog/tracing/transport/http/client.rb'
ignore 'lib/datadog/tracing/transport/http/statistics.rb'
ignore 'lib/datadog/tracing/transport/http/traces.rb'
ignore 'lib/datadog/tracing/transport/io/client.rb'
ignore 'lib/datadog/tracing/transport/io/traces.rb'
ignore 'lib/datadog/tracing/transport/serializable_trace.rb'
ignore 'lib/datadog/tracing/transport/statistics.rb'
ignore 'lib/datadog/tracing/transport/trace_formatter.rb'
ignore 'lib/datadog/tracing/transport/traces.rb'
ignore 'lib/datadog/tracing/utils.rb'
ignore 'lib/datadog/tracing/workers.rb'
ignore 'lib/datadog/tracing/workers/trace_writer.rb'
ignore 'lib/datadog/tracing/writer.rb'
ignore 'lib/ddtrace/auto_instrument.rb'
ignore 'lib/ddtrace/auto_instrument_base.rb'
ignore 'lib/ddtrace/transport/ext.rb'
ignore 'lib/ddtrace/transport/http.rb'
ignore 'lib/ddtrace/transport/http/adapters/net.rb'
ignore 'lib/ddtrace/transport/http/adapters/registry.rb'
ignore 'lib/ddtrace/transport/http/adapters/test.rb'
ignore 'lib/ddtrace/transport/http/adapters/unix_socket.rb'
ignore 'lib/ddtrace/transport/http/api.rb'
ignore 'lib/ddtrace/transport/http/api/endpoint.rb'
ignore 'lib/ddtrace/transport/http/api/fallbacks.rb'
ignore 'lib/ddtrace/transport/http/api/instance.rb'
ignore 'lib/ddtrace/transport/http/api/map.rb'
ignore 'lib/ddtrace/transport/http/api/spec.rb'
ignore 'lib/ddtrace/transport/http/builder.rb'
ignore 'lib/ddtrace/transport/http/client.rb'
ignore 'lib/ddtrace/transport/http/env.rb'
ignore 'lib/ddtrace/transport/http/response.rb'
ignore 'lib/ddtrace/transport/http/statistics.rb'
ignore 'lib/ddtrace/transport/http/traces.rb'
ignore 'lib/ddtrace/transport/io.rb'
ignore 'lib/ddtrace/transport/io/client.rb'
ignore 'lib/ddtrace/transport/io/response.rb'
ignore 'lib/ddtrace/transport/io/traces.rb'
ignore 'lib/ddtrace/transport/parcel.rb'
ignore 'lib/ddtrace/transport/request.rb'
ignore 'lib/ddtrace/transport/response.rb'
ignore 'lib/ddtrace/transport/serializable_trace.rb'
ignore 'lib/ddtrace/transport/statistics.rb'
ignore 'lib/ddtrace/transport/trace_formatter.rb'
ignore 'lib/ddtrace/transport/traces.rb'
ignore 'lib/ddtrace/version.rb'

# References `RubyVM::YJIT`, which does not have type information.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/profiler_http_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize

@transport = Datadog::Profiling::HttpTransport.new(
agent_settings: Datadog::Core::Configuration::AgentSettingsResolver::AgentSettings.new(
adapter: Datadog::Transport::Ext::HTTP::ADAPTER,
adapter: Datadog::Core::Transport::Ext::HTTP::ADAPTER,
uds_path: nil,
ssl: false,
hostname: '127.0.0.1',
Expand Down
9 changes: 5 additions & 4 deletions lib/datadog/core/configuration/agent_settings_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative 'settings'
require_relative 'ext'
require_relative '../transport/ext'

module Datadog
module Core
Expand Down Expand Up @@ -66,9 +67,9 @@ def initialize(settings, logger: Datadog.logger)

def call
# A transport_options proc configured for unix domain socket overrides most of the logic on this file
if transport_options.adapter == Datadog::Transport::Ext::UnixSocket::ADAPTER
if transport_options.adapter == Datadog::Core::Transport::Ext::UnixSocket::ADAPTER
return AgentSettings.new(
adapter: Datadog::Transport::Ext::UnixSocket::ADAPTER,
adapter: Datadog::Core::Transport::Ext::UnixSocket::ADAPTER,
ssl: false,
hostname: nil,
port: nil,
Expand Down Expand Up @@ -96,9 +97,9 @@ def call

def adapter
if should_use_uds?
Datadog::Transport::Ext::UnixSocket::ADAPTER
Datadog::Core::Transport::Ext::UnixSocket::ADAPTER
else
Datadog::Transport::Ext::HTTP::ADAPTER
Datadog::Core::Transport::Ext::HTTP::ADAPTER
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/core/remote/client/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Datadog
module Core
module Remote
class Client
# Capbailities
# Capabilities
class Capabilities
attr_reader :products, :capabilities, :receivers, :base64_capabilities

Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/core/remote/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative 'worker'
require_relative 'client/capabilities'
require_relative 'client'
require_relative '../transport/http'
require_relative 'transport/http'
require_relative '../remote'
require_relative 'negotiation'

Expand All @@ -22,7 +22,7 @@ def initialize(settings, capabilities, agent_settings)
transport_options[:agent_settings] = agent_settings if agent_settings

negotiation = Negotiation.new(settings, agent_settings)
transport_v7 = Datadog::Core::Transport::HTTP.v7(**transport_options.dup)
transport_v7 = Datadog::Core::Remote::Transport::HTTP.v7(**transport_options.dup)

@barrier = Barrier.new(BARRIER_TIMEOUT)

Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/core/remote/negotiation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative '../transport/http'
require_relative 'transport/http'

module Datadog
module Core
Expand All @@ -11,7 +11,7 @@ def initialize(_settings, agent_settings)
transport_options = {}
transport_options[:agent_settings] = agent_settings if agent_settings

@transport_root = Datadog::Core::Transport::HTTP.root(**transport_options.dup)
@transport_root = Datadog::Core::Remote::Transport::HTTP.root(**transport_options.dup)
@logged = {}
end

Expand Down
60 changes: 60 additions & 0 deletions lib/datadog/core/remote/transport/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require_relative '../../../core/transport/request'
require_relative '../../../core/transport/parcel'

module Datadog
module Core
module Remote
module Transport
module Config
# Data transfer object for encoded traces
class EncodedParcel
include Datadog::Core::Transport::Parcel

def count
data.length
end
end

# Config request
class Request < Datadog::Core::Transport::Request
end

# Config response
module Response
attr_reader :roots, :targets, :target_files, :client_configs

def empty?
@empty
end
end

# Config transport
class Transport
attr_reader :client, :apis, :default_api, :current_api_id

def initialize(apis, default_api)
@apis = apis

@client = HTTP::Client.new(current_api)
end

##### there is only one transport! it's negotiation!
def send_config(payload)
json = JSON.dump(payload)
parcel = EncodedParcel.new(json)
request = Request.new(parcel)

@client.send_config_payload(request)
end

def current_api
@apis[HTTP::API::V7]
end
end
end
end
end
end
end
Loading

0 comments on commit 9810fe0

Please sign in to comment.