Skip to content

Commit

Permalink
Remove the lazy option from core configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Jun 26, 2023
1 parent 0e396e9 commit 35ddd1c
Show file tree
Hide file tree
Showing 58 changed files with 8 additions and 283 deletions.
3 changes: 0 additions & 3 deletions lib/datadog/ci/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def self.add_settings!(base)
settings :ci do
option :enabled do |o|
o.default { env_to_bool(CI::Ext::Settings::ENV_MODE_ENABLED, false) }
o.lazy
end

# DEV: Alias to Datadog::Tracing::Contrib::Extensions::Configuration::Settings#instrument.
Expand All @@ -37,12 +36,10 @@ def self.add_settings!(base)

option :trace_flush do |o|
o.default { nil }
o.lazy
end

option :writer_options do |o|
o.default { {} }
o.lazy
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions lib/datadog/ci/contrib/cucumber/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ module Configuration
class Settings < Datadog::Tracing::Contrib::Configuration::Settings
option :enabled do |o|
o.default { env_to_bool(Ext::ENV_ENABLED, true) }
o.lazy
end

option :service_name do |o|
o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
o.lazy
end

option :operation_name do |o|
o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME }
o.lazy
o.default { ENV.fetch(Ext::ENV_OPERATION_NAME, Ext::OPERATION_NAME) }
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions lib/datadog/ci/contrib/rspec/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ module Configuration
class Settings < Datadog::Tracing::Contrib::Configuration::Settings
option :enabled do |o|
o.default { env_to_bool(Ext::ENV_ENABLED, true) }
o.lazy
end

option :service_name do |o|
o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
o.lazy
end

option :operation_name do |o|
o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME }
o.lazy
o.default { ENV.fetch(Ext::ENV_OPERATION_NAME, Ext::OPERATION_NAME) }
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/datadog/core/configuration/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def settings(name, &block)

option(name) do |o|
o.default { settings_class.new }
o.lazy

o.resetter do |value|
value.reset! if value.respond_to?(:reset!)
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/core/configuration/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def reset
end

def default_value
if definition.lazy
if definition.default.instance_of?(Proc)
context_eval(&definition.default)
else
definition.default
Expand Down
9 changes: 0 additions & 9 deletions lib/datadog/core/configuration/option_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class OptionDefinition
:default,
:delegate_to,
:depends_on,
:lazy,
:name,
:on_set,
:resetter,
Expand All @@ -24,7 +23,6 @@ def initialize(name, meta = {}, &block)
@default = meta[:default]
@delegate_to = meta[:delegate_to]
@depends_on = meta[:depends_on] || []
@lazy = meta[:lazy] || false
@name = name.to_sym
@on_set = meta[:on_set]
@resetter = meta[:resetter]
Expand All @@ -48,7 +46,6 @@ def initialize(name, options = {})
@delegate_to = nil
@depends_on = []
@helpers = {}
@lazy = false
@name = name.to_sym
@on_set = nil
@resetter = nil
Expand Down Expand Up @@ -78,10 +75,6 @@ def helper(name, *_args, &block)
@helpers[name] = block
end

def lazy(value = true)
@lazy = value
end

def on_set(&block)
@on_set = block
end
Expand All @@ -105,7 +98,6 @@ def apply_options!(options = {})
default(options[:default]) if options.key?(:default)
delegate_to(&options[:delegate_to]) if options.key?(:delegate_to)
depends_on(*options[:depends_on]) if options.key?(:depends_on)
lazy(options[:lazy]) if options.key?(:lazy)
on_set(&options[:on_set]) if options.key?(:on_set)
resetter(&options[:resetter]) if options.key?(:resetter)
setter(&options[:setter]) if options.key?(:setter)
Expand All @@ -121,7 +113,6 @@ def meta
default: @default,
delegate_to: @delegate_to,
depends_on: @depends_on,
lazy: @lazy,
on_set: @on_set,
resetter: @resetter,
setter: @setter,
Expand Down
24 changes: 1 addition & 23 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def initialize(*_)
# @return [String,nil]
option :api_key do |o|
o.default { ENV.fetch(Core::Environment::Ext::ENV_API_KEY, nil) }
o.lazy
end

# Datadog diagnostic settings.
Expand All @@ -100,7 +99,6 @@ def initialize(*_)
# @return [Boolean]
option :debug do |o|
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED, false) }
o.lazy
o.on_set do |enabled|
# Enable rich debug print statements.
# We do not need to unnecessarily load 'pp' unless in debugging mode.
Expand All @@ -118,7 +116,6 @@ def initialize(*_)
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_HEALTH_METRICS_ENABLED, false) }
o.lazy
end

# {Datadog::Statsd} instance to collect health metrics.
Expand All @@ -144,7 +141,6 @@ def initialize(*_)
option :enabled do |o|
# Defaults to nil as we want to know when the default value is being used
o.default { env_to_bool(Datadog::Core::Configuration::Ext::Diagnostics::ENV_STARTUP_LOGS_ENABLED, nil) }
o.lazy
end
end
end
Expand All @@ -159,7 +155,6 @@ def initialize(*_)

# NOTE: env also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details.
o.default { ENV.fetch(Core::Environment::Ext::ENV_ENVIRONMENT, nil) }
o.lazy
end

# Internal `Datadog.logger` configuration.
Expand Down Expand Up @@ -195,7 +190,6 @@ def initialize(*_)
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Profiling::Ext::ENV_ENABLED, false) }
o.lazy
end

# @public_api
Expand Down Expand Up @@ -229,7 +223,6 @@ def initialize(*_)
# @default `DD_PROFILING_MAX_FRAMES` environment variable, otherwise 400
option :max_frames do |o|
o.default { env_to_int(Profiling::Ext::ENV_MAX_FRAMES, 400) }
o.lazy
end

# @public_api
Expand All @@ -242,7 +235,6 @@ def initialize(*_)
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Profiling::Ext::ENV_ENDPOINT_COLLECTION_ENABLED, true) }
o.lazy
end
end
end
Expand Down Expand Up @@ -285,7 +277,6 @@ def initialize(*_)
# @default `DD_PROFILING_FORCE_ENABLE_LEGACY` environment variable, otherwise `false`
option :force_enable_legacy_profiler do |o|
o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_LEGACY', false) }
o.lazy
o.on_set do |value|
if value
Datadog.logger.warn(
Expand Down Expand Up @@ -318,7 +309,6 @@ def initialize(*_)
# @default `DD_PROFILING_FORCE_ENABLE_GC` environment variable, otherwise `false`
option :force_enable_gc_profiling do |o|
o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_GC', false) }
o.lazy
end

# Can be used to enable/disable the Datadog::Profiling.allocation_count feature.
Expand All @@ -340,7 +330,6 @@ def initialize(*_)
# @default `DD_PROFILING_SKIP_MYSQL2_CHECK` environment variable, otherwise `false`
option :skip_mysql2_check do |o|
o.default { env_to_bool('DD_PROFILING_SKIP_MYSQL2_CHECK', false) }
o.lazy
end

# The profiler gathers data by sending `SIGPROF` unix signals to Ruby application threads.
Expand All @@ -364,7 +353,6 @@ def initialize(*_)
# @default `DD_PROFILING_NO_SIGNALS_WORKAROUND_ENABLED` environment variable as a boolean, otherwise `:auto`
option :no_signals_workaround_enabled do |o|
o.default { env_to_bool('DD_PROFILING_NO_SIGNALS_WORKAROUND_ENABLED', :auto) }
o.lazy
end
end

Expand All @@ -376,7 +364,6 @@ def initialize(*_)
option :timeout_seconds do |o|
o.setter { |value| value.nil? ? 30.0 : value.to_f }
o.default { env_to_float(Profiling::Ext::ENV_UPLOAD_TIMEOUT, 30.0) }
o.lazy
end
end
end
Expand All @@ -390,7 +377,6 @@ def initialize(*_)
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Core::Runtime::Ext::Metrics::ENV_ENABLED, false) }
o.lazy
end

option :opts, default: ->(_i) { {} }, lazy: true
Expand All @@ -407,7 +393,6 @@ def initialize(*_)

# NOTE: service also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details.
o.default { ENV.fetch(Core::Environment::Ext::ENV_SERVICE, Core::Environment::Ext::FALLBACK_SERVICE_NAME) }
o.lazy

# There's a few cases where we don't want to use the fallback service name, so this helper allows us to get a
# nil instead so that one can do
Expand All @@ -430,7 +415,6 @@ def initialize(*_)
# @return [String,nil]
option :site do |o|
o.default { ENV.fetch(Core::Environment::Ext::ENV_SITE, nil) }
o.lazy
end

# Default tags
Expand Down Expand Up @@ -476,8 +460,6 @@ def initialize(*_)
# Merge with previous tags
(old_value || {}).merge(string_tags)
end

o.lazy
end

# The time provider used by Datadog. It must respect the interface of [Time](https://ruby-doc.org/core-3.0.1/Time.html).
Expand All @@ -490,7 +472,7 @@ def initialize(*_)
# @default `->{ Time.now }`
# @return [Proc<Time>]
option :time_now_provider do |o|
o.default { ::Time.now }
o.default { -> { ::Time.now } }

o.on_set do |time_provider|
Core::Utils::Time.now_provider = time_provider
Expand All @@ -512,7 +494,6 @@ def initialize(*_)
option :version do |o|
# NOTE: version also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details.
o.default { ENV.fetch(Core::Environment::Ext::ENV_VERSION, nil) }
o.lazy
end

# Client-side telemetry configuration
Expand All @@ -525,7 +506,6 @@ def initialize(*_)
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Core::Telemetry::Ext::ENV_ENABLED, true) }
o.lazy
end
end

Expand All @@ -538,7 +518,6 @@ def initialize(*_)
# @return [Boolean]
option :enabled do |o|
o.default { env_to_bool(Core::Remote::Ext::ENV_ENABLED, true) }
o.lazy
end

# Tune remote configuration polling interval.
Expand All @@ -547,7 +526,6 @@ def initialize(*_)
# @return [Float]
option :poll_interval_seconds do |o|
o.default { env_to_float(Core::Remote::Ext::ENV_POLL_INTERVAL_SECONDS, 5.0) }
o.lazy
end

# Declare service name to bind to remote configuration. Use when
Expand Down
Loading

0 comments on commit 35ddd1c

Please sign in to comment.