Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config transport endpoint #2678

Merged
merged 6 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ DD_API_KEY=00000000000000000000000000000000
DD_METRIC_AGENT_PORT=8125
DD_TRACE_AGENT_PORT=8126
DD_INSTRUMENTATION_TELEMETRY_ENABLED=false
DD_REMOTE_CONFIGURATION_ENABLED=true
TEST_DDAGENT_VAR_RUN=/var/run/datadog
TEST_DDAGENT_UNIX_SOCKET=${TEST_DDAGENT_VAR_RUN}/apm.socket
TEST_DDAGENT_API_KEY=invalid_key_but_this_is_fine
Expand Down
2 changes: 2 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ target :ddtrace do
library 'json'
library 'ipaddr'
library 'net-http'
library 'securerandom'
library 'base64'

# TODO: gem 'libddwaf'

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ services:
- "DD_API_KEY=${DD_API_KEY}"
- DD_HOSTNAME=dd-trace-rb-ci
- DD_APM_RECEIVER_SOCKET=/var/run/datadog/apm.socket
- DD_REMOTE_CONFIGURATION_ENABLED=true
expose:
- "8125/udp"
- "8126"
Expand Down
54 changes: 54 additions & 0 deletions lib/datadog/core/transport/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require_relative '../../../ddtrace/transport/request'
require_relative '../../../ddtrace/transport/parcel'

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

def count
data.length
end
end

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

# Config response
module Response
attr_reader :roots, :targets, :target_files, :client_configs
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
29 changes: 29 additions & 0 deletions lib/datadog/core/transport/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,35 @@ def root(
end
end

# Builds a new Transport::HTTP::Client with default settings
# Pass a block to override any settings.
def v7(
agent_settings: DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS,
**options
)
new(Transport::Config::Transport) do |transport|
transport.adapter(agent_settings)
transport.headers default_headers

apis = API.defaults

transport.api API::V7, apis[API::V7]

# Apply any settings given by options
unless options.empty?
transport.default_api = options[:api_version] if options.key?(:api_version)
transport.headers options[:headers] if options.key?(:headers)
end

if agent_settings.deprecated_for_removal_transport_configuration_proc
agent_settings.deprecated_for_removal_transport_configuration_proc.call(transport)
end

# Call block to apply any customization, if provided
yield(transport) if block_given?
end
end

def default_headers
{
Datadog::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL => '1',
Expand Down
10 changes: 10 additions & 0 deletions lib/datadog/core/transport/http/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# TODO: only needed for Negotiation::API::Endpoint
require_relative 'negotiation'

# TODO: only needed for Config::API::Endpoint
require_relative 'config'

module Datadog
module Core
module Transport
Expand All @@ -28,6 +31,7 @@ module HTTP
module API
# Default API versions
ROOT = 'root'
V7 = 'v0.7'

module_function

Expand All @@ -38,6 +42,12 @@ def defaults
'/info',
)
end,
V7 => Spec.new do |s|
s.config = Config::API::Endpoint.new(
'/v0.7/config',
Core::Encoding::JSONEncoder,
)
end,
]
end
end
Expand Down
Loading