Skip to content

Commit

Permalink
Merge pull request #2498 from DataDog/refactor/move_metrics_env_to_co…
Browse files Browse the repository at this point in the history
…nfiguration

Move Metrics ENV constants to Core::Configuration::Ext
  • Loading branch information
delner authored Dec 21, 2022
2 parents feb1109 + 1c22b53 commit 0145b16
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/UpgradeGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ end
| `Datadog::Ext::Sampling` | `Datadog::Tracing::Metadata::Ext::Sampling` |
| `Datadog::Ext::SQL` | `Datadog::Tracing::Metadata::Ext::SQL` |
| `Datadog::Ext::Test` | `Datadog::Tracing::Configuration::Ext::Test` |
| `Datadog::Ext::Transport::HTTP::ENV_DEFAULT_HOST` | `Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_HOST` |
| `Datadog::Ext::Transport::HTTP::ENV_DEFAULT_HOST` | `Datadog::Core::Configuration::Ext::Transport::ENV_DEFAULT_HOST` |
| `Datadog::Ext::Transport::HTTP::ENV_DEFAULT_PORT` | `Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_PORT` |
| `Datadog::Ext::Transport::HTTP::ENV_DEFAULT_URL` | `Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_URL` |
| `Datadog::Ext::Transport` | `Datadog::Transport::Ext` |
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/core/configuration/agent_settings_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def configured_hostname
value: parsed_url && parsed_url.hostname
),
DetectedConfiguration.new(
friendly_name: "#{Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_HOST} environment variable",
value: ENV[Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_HOST]
friendly_name: "#{Datadog::Core::Configuration::Ext::Transport::ENV_DEFAULT_HOST} environment variable",
value: ENV[Datadog::Core::Configuration::Ext::Transport::ENV_DEFAULT_HOST]
)
)
end
Expand Down
8 changes: 8 additions & 0 deletions lib/datadog/core/configuration/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module Diagnostics
ENV_HEALTH_METRICS_ENABLED = 'DD_HEALTH_METRICS_ENABLED'.freeze
ENV_STARTUP_LOGS_ENABLED = 'DD_TRACE_STARTUP_LOGS'.freeze
end

module Metrics
ENV_DEFAULT_PORT = 'DD_METRIC_AGENT_PORT'.freeze
end

module Transport
ENV_DEFAULT_HOST = 'DD_AGENT_HOST'.freeze
end
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/datadog/core/metrics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative '../utils/time'
require_relative '../utils/only_once'
require_relative '../configuration/ext'

require_relative 'ext'
require_relative 'options'
Expand Down Expand Up @@ -50,11 +51,11 @@ def enabled=(enabled)
end

def default_hostname
ENV.fetch(Ext::ENV_DEFAULT_HOST, Ext::DEFAULT_HOST)
ENV.fetch(Configuration::Ext::Transport::ENV_DEFAULT_HOST, Ext::DEFAULT_HOST)
end

def default_port
ENV.fetch(Ext::ENV_DEFAULT_PORT, Ext::DEFAULT_PORT).to_i
ENV.fetch(Configuration::Ext::Metrics::ENV_DEFAULT_PORT, Ext::DEFAULT_PORT).to_i
end

def default_statsd_client
Expand Down
2 changes: 0 additions & 2 deletions lib/datadog/core/metrics/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Metrics
module Ext
DEFAULT_HOST = '127.0.0.1'.freeze
DEFAULT_PORT = 8125
ENV_DEFAULT_HOST = 'DD_AGENT_HOST'.freeze
ENV_DEFAULT_PORT = 'DD_METRIC_AGENT_PORT'.freeze

TAG_LANG = 'language'.freeze
TAG_LANG_INTERPRETER = 'language-interpreter'.freeze
Expand Down
1 change: 0 additions & 1 deletion lib/datadog/tracing/configuration/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ module Test

# @public_api
module Transport
ENV_DEFAULT_HOST = 'DD_AGENT_HOST'.freeze
ENV_DEFAULT_PORT = 'DD_TRACE_AGENT_PORT'.freeze
ENV_DEFAULT_URL = 'DD_TRACE_AGENT_URL'.freeze
end
Expand Down
8 changes: 4 additions & 4 deletions spec/datadog/core/metrics/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
let(:value) { 'my-hostname' }

around do |example|
ClimateControl.modify(Datadog::Core::Metrics::Ext::ENV_DEFAULT_HOST => value) do
ClimateControl.modify(Datadog::Core::Configuration::Ext::Transport::ENV_DEFAULT_HOST => value) do
example.run
end
end
Expand All @@ -229,7 +229,7 @@

context 'not set' do
around do |example|
ClimateControl.modify(Datadog::Core::Metrics::Ext::ENV_DEFAULT_HOST => nil) do
ClimateControl.modify(Datadog::Core::Configuration::Ext::Transport::ENV_DEFAULT_HOST => nil) do
example.run
end
end
Expand All @@ -247,7 +247,7 @@
let(:value) { '1234' }

around do |example|
ClimateControl.modify(Datadog::Core::Metrics::Ext::ENV_DEFAULT_PORT => value) do
ClimateControl.modify(Datadog::Core::Configuration::Ext::Metrics::ENV_DEFAULT_PORT => value) do
example.run
end
end
Expand All @@ -257,7 +257,7 @@

context 'not set' do
around do |example|
ClimateControl.modify(Datadog::Core::Metrics::Ext::ENV_DEFAULT_PORT => nil) do
ClimateControl.modify(Datadog::Core::Configuration::Ext::Metrics::ENV_DEFAULT_PORT => nil) do
example.run
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/benchmark/support/benchmark_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def report_results(result, step)
# agent process in the system.
#
# It finds a locally available port to listen on, and updates the value of
# {Datadog::Ext::Transport::HTTP::ENV_DEFAULT_PORT} accordingly.
# {Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_PORT} accordingly.
RSpec.shared_context 'minimal agent' do
let(:agent_server) { TCPServer.new '127.0.0.1', agent_port }
let(:agent_port) { ENV[Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_PORT].to_i }
Expand Down

0 comments on commit 0145b16

Please sign in to comment.