Skip to content

Commit

Permalink
Enable type checking for AgentSettingsResolver/AgentSettings
Browse files Browse the repository at this point in the history
Steep doesn't seem to be a big fan of Structs so I just went ahead
and turned the `AgentSettings` into a regular class that's equivalent
to the struct we had before.

(In particular, I decided to still keep every field as optional).

Ideally this would be a `Data` class, but we're far from dropping
support for Rubies that don't have it.
  • Loading branch information
ivoanjo authored and quinna-h committed Jan 8, 2025
1 parent d015ca2 commit c24490f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
1 change: 0 additions & 1 deletion Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ target :datadog do
ignore 'lib/datadog/core/buffer/thread_safe.rb'
ignore 'lib/datadog/core/chunker.rb'
ignore 'lib/datadog/core/configuration.rb'
ignore 'lib/datadog/core/configuration/agent_settings_resolver.rb'
ignore 'lib/datadog/core/configuration/base.rb'
ignore 'lib/datadog/core/configuration/components.rb'
ignore 'lib/datadog/core/configuration/dependency_resolver.rb'
Expand Down
22 changes: 11 additions & 11 deletions lib/datadog/core/configuration/agent_settings_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ module Configuration
# Whenever there is a conflict (different configurations are provided in different orders), it MUST warn the users
# about it and pick a value based on the following priority: code > environment variable > defaults.
class AgentSettingsResolver
AgentSettings = Struct.new(
:adapter,
:ssl,
:hostname,
:port,
:uds_path,
:timeout_seconds,
keyword_init: true
) do
def initialize(*)
super
# Immutable container for the resulting settings
class AgentSettings
attr_reader :adapter, :ssl, :hostname, :port, :uds_path, :timeout_seconds

def initialize(adapter: nil, ssl: nil, hostname: nil, port: nil, uds_path: nil, timeout_seconds: nil)
@adapter = adapter
@ssl = ssl
@hostname = hostname
@port = port
@uds_path = uds_path
@timeout_seconds = timeout_seconds
freeze
end
end
Expand Down
46 changes: 32 additions & 14 deletions sig/datadog/core/configuration/agent_settings_resolver.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ module Datadog
module Core
module Configuration
class AgentSettingsResolver
class AgentSettings < ::Struct[untyped]
class AgentSettings
def initialize: (adapter: untyped, ssl: untyped, hostname: untyped, port: untyped, uds_path: untyped, timeout_seconds: untyped) -> void
def merge: (**::Hash[untyped, untyped] member_values) -> AgentSettingsResolver

attr_reader adapter: untyped
attr_reader ssl: untyped
Expand All @@ -14,6 +13,17 @@ module Datadog
attr_reader timeout_seconds: untyped
end

@settings: untyped
@logger: untyped
@configured_hostname: untyped
@configured_port: untyped
@configured_ssl: untyped
@configured_timeout_seconds: untyped
@configured_uds_path: untyped
@uds_fallback: untyped
@mixed_http_and_uds: untyped
@parsed_url: untyped

def self.call: (untyped settings, ?logger: untyped) -> untyped

private
Expand All @@ -38,41 +48,49 @@ module Datadog

def configured_uds_path: () -> untyped

def try_parsing_as_integer: (value: untyped, friendly_name: untyped) -> untyped
def parsed_url_ssl?: () -> (nil | untyped)

def try_parsing_as_boolean: (value: untyped, friendly_name: untyped) -> untyped
def try_parsing_as_integer: (value: untyped, friendly_name: untyped) -> untyped

def ssl?: () -> bool
def ssl?: () -> (false | untyped)

def hostname: () -> untyped

def port: () -> untyped

def uds_path: () -> untyped

def timeout_seconds: () -> untyped

def uds_fallback: () -> untyped
def parsed_url_uds_path: () -> (nil | untyped)

def should_use_uds_fallback?: () -> untyped
def uds_path: () -> (nil | untyped)

def should_use_uds?: () -> bool
def uds_fallback: () -> untyped

def can_use_uds?: () -> bool
def should_use_uds?: () -> untyped

def parsed_url: () -> untyped
def mixed_http_and_uds: () -> untyped

def parsed_url_ssl?: () -> untyped
def can_use_uds?: () -> untyped

def parsed_url_uds_path: () -> untyped
def parsed_url: () -> untyped

def pick_from: (*untyped configurations_in_priority_order) -> untyped

def warn_if_configuration_mismatch: (untyped detected_configurations_in_priority_order) -> (nil | untyped)

def log_warning: (untyped message) -> (untyped | nil)

def http_scheme?: (untyped uri) -> untyped

def parsed_http_url: () -> (untyped | nil)

def unix_scheme?: (untyped uri) -> untyped

class DetectedConfiguration
@friendly_name: untyped

@value: untyped

attr_reader friendly_name: untyped

attr_reader value: untyped
Expand Down
1 change: 1 addition & 0 deletions sig/datadog/core/configuration/ext.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Datadog
end

module Agent
ENV_DEFAULT_HOST: 'DD_AGENT_HOST'
ENV_DEFAULT_PORT: 'DD_TRACE_AGENT_PORT'
ENV_DEFAULT_URL: 'DD_TRACE_AGENT_URL'
ENV_DEFAULT_TIMEOUT_SECONDS: 'DD_TRACE_AGENT_TIMEOUT_SECONDS'
Expand Down

0 comments on commit c24490f

Please sign in to comment.