Skip to content

Commit

Permalink
Merge pull request #3039 from DataDog/skip-non-monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc authored Aug 11, 2023
2 parents 42f82ae + 47bc81f commit cab2453
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 6 deletions.
27 changes: 25 additions & 2 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative 'base'
require_relative 'ext'
require_relative '../environment/execution'
require_relative '../environment/ext'
require_relative '../runtime/ext'
require_relative '../telemetry/ext'
Expand Down Expand Up @@ -559,10 +560,21 @@ def initialize(*_)
#
# @default `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment variable, otherwise `true`.
# Can be disabled as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection).
# By default, telemetry is disabled in development environments.
# @return [Boolean]
option :enabled do |o|
o.env Core::Telemetry::Ext::ENV_ENABLED
o.default true
o.default do
if Datadog::Core::Environment::Execution.development?
Datadog.logger.debug do
'Development environment detected, disabling Telemetry. ' \
'You can enable it with DD_INSTRUMENTATION_TELEMETRY_ENABLED=true.'
end
false
else
true
end
end
o.type :bool
end

Expand All @@ -586,10 +598,21 @@ def initialize(*_)
# Enable remote configuration. This allows fetching of remote configuration for live updates.
#
# @default `DD_REMOTE_CONFIGURATION_ENABLED` environment variable, otherwise `true`.
# By default, remote configuration is disabled in development environments.
# @return [Boolean]
option :enabled do |o|
o.env Core::Remote::Ext::ENV_ENABLED
o.default true
o.default do
if Datadog::Core::Environment::Execution.development?
Datadog.logger.debug do
'Development environment detected, disabling Remote Configuration. ' \
'You can enable it with DD_REMOTE_CONFIGURATION_ENABLED=true.'
end
false
else
true
end
end
o.type :bool
end

Expand Down
2 changes: 2 additions & 0 deletions spec/datadog/core/configuration/components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
let(:remote) { instance_double(Datadog::Core::Remote::Component, start: nil, shutdown!: nil) }
let(:telemetry) { instance_double(Datadog::Core::Telemetry::Client) }

include_context 'non-development execution environment'

before do
# Ensure the real task never gets run (so it doesn't apply our thread patches and other extensions to our test env)
if Datadog::Profiling.supported?
Expand Down
22 changes: 20 additions & 2 deletions spec/datadog/core/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,15 @@
context 'is not defined' do
let(:env_var_value) { nil }

it { is_expected.to be true }
context 'in a development environment' do
it { is_expected.to be false }
end

context 'not in a development environment' do
include_context 'non-development execution environment'

it { is_expected.to be true }
end
end

[true, false].each do |value|
Expand Down Expand Up @@ -1305,7 +1313,15 @@
context 'is not defined' do
let(:environment) { nil }

it { is_expected.to be true }
context 'in a development environment' do
it { is_expected.to be false }
end

context 'not in a development environment' do
include_context 'non-development execution environment'

it { is_expected.to be true }
end
end

context 'is defined' do
Expand All @@ -1317,6 +1333,8 @@
end

describe '#enabled=' do
include_context 'non-development execution environment'

it 'updates the #enabled setting' do
expect { settings.remote.enabled = false }
.to change { settings.remote.enabled }
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/core/remote/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'spec_helper'
require 'datadog/core/remote/component'

RSpec.describe Datadog::Core::Remote::Component do
RSpec.describe Datadog::Core::Remote::Component, :integration do
let(:settings) { Datadog::Core::Configuration::Settings.new }
let(:agent_settings) { Datadog::Core::Configuration::AgentSettingsResolver.call(settings, logger: nil) }
let(:capabilities) { Datadog::Core::Remote::Client::Capabilities.new(settings) }
Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/contrib/suite/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'rackup' if Rack::VERSION[0] >= 3
require 'webrick'

RSpec.describe 'contrib integration testing' do
RSpec.describe 'contrib integration testing', :integration do
around do |example|
ClimateControl.modify('DD_REMOTE_CONFIGURATION_ENABLED' => nil) { example.run }
end
Expand Down
4 changes: 4 additions & 0 deletions spec/support/core_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module CoreHelpers
RSpec.shared_context 'non-development execution environment' do
before { allow(Datadog::Core::Environment::Execution).to receive(:development?).and_return(false) }
end

# Asserts that a deprecated action is recorded by the `subject` execution.
RSpec.shared_examples 'records deprecated action' do |matcher = nil|
it 'records deprecated action in the deprecation log' do
Expand Down
2 changes: 2 additions & 0 deletions spec/support/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def self.included(base)
skip('Integration tests can be enabled by setting the environment variable `TEST_DATADOG_INTEGRATION=1`')
end
end

include_context 'non-development execution environment'
end
end
end
Expand Down

0 comments on commit cab2453

Please sign in to comment.