Skip to content

Commit 122f4a2

Browse files
mabdinuravara1986juanjuxP403n1x87christophe-papazian
authored
fix(rcm): validate remote config is enabled [backport #5241 to 1.9] (#5353)
Backports: https://github.com/DataDog/dd-trace-py/pull/5241/files Resolves: #5343 ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) are followed. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Author is aware of the performance implications of this PR as reported in the benchmarks PR comment. ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer is aware of, and discussed the performance implications of this PR as reported in the benchmarks PR comment. --------- Co-authored-by: Alberto Vara <[email protected]> Co-authored-by: Juanjo Alvarez Martinez <[email protected]> Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: Christophe Papazian <[email protected]>
1 parent 4a24318 commit 122f4a2

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed

ddtrace/debugging/_debugger.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import defaultdict
22
from itertools import chain
3+
import os
34
import sys
45
import threading
56
from types import FunctionType
@@ -57,6 +58,7 @@
5758
from ddtrace.internal.remoteconfig import RemoteConfig
5859
from ddtrace.internal.safety import _isinstance
5960
from ddtrace.internal.service import Service
61+
from ddtrace.internal.utils.formats import asbool
6062
from ddtrace.internal.wrapping import Wrapper
6163

6264

@@ -245,6 +247,12 @@ def __init__(self, tracer=None):
245247
raise_on_exceed=False,
246248
)
247249

250+
# TODO: this is only temporary and will be reverted once the DD_REMOTE_CONFIGURATION_ENABLED variable
251+
# has been removed
252+
if asbool(os.environ.get("DD_REMOTE_CONFIGURATION_ENABLED", True)) is False:
253+
os.environ["DD_REMOTE_CONFIGURATION_ENABLED"] = "true"
254+
log.info("Disabled Remote Configuration enabled by Dynamic Instrumentation.")
255+
248256
# Register the debugger with the RCM client.
249257
RemoteConfig.register("LIVE_DEBUGGING", self.__rc_adapter__(self._on_configuration))
250258

ddtrace/internal/remoteconfig/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def _check_remote_config_enable_in_agent(cls):
4646
@classmethod
4747
def enable(cls):
4848
# type: () -> bool
49-
if cls._check_remote_config_enable_in_agent():
49+
# TODO: this is only temporary. DD_REMOTE_CONFIGURATION_ENABLED variable will be deprecated
50+
rc_env_enabled = asbool(os.environ.get("DD_REMOTE_CONFIGURATION_ENABLED", "true"))
51+
if rc_env_enabled and cls._check_remote_config_enable_in_agent():
5052
with cls._worker_lock:
5153
if cls._worker is None:
5254
cls._worker = RemoteConfigWorker()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
remote config: Ensure DD_REMOTE_CONFIGURATION_ENABLED environment variable disables remote config if set to False

tests/contrib/gunicorn/test_gunicorn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def gunicorn_server(gunicorn_server_settings, tmp_path):
108108
cmd = ["ddtrace-run"]
109109
cmd += ["gunicorn", "--config", str(cfg_file), str(gunicorn_server_settings.app_path)]
110110
print("Running %r with configuration file %s" % (" ".join(cmd), cfg))
111-
111+
gunicorn_server_settings.env["DD_REMOTE_CONFIGURATION_ENABLED"] = "true"
112112
server_process = subprocess.Popen(
113113
cmd,
114114
env=gunicorn_server_settings.env,

tests/internal/remoteconfig/test_remoteconfig.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,58 @@ def get_mock_encoded_msg(msg):
9292
@mock.patch.object(RemoteConfig, "_check_remote_config_enable_in_agent")
9393
def test_remote_config_register_auto_enable(mock_check_remote_config_enable_in_agent):
9494
# ASM_FEATURES product is enabled by default, but LIVE_DEBUGGER isn't
95+
with override_env(dict(DD_REMOTE_CONFIGURATION_ENABLED="true")):
96+
assert RemoteConfig._worker is None
97+
98+
RemoteConfig.register("LIVE_DEBUGGER", lambda m, c: None)
99+
100+
assert RemoteConfig._worker._client._products["LIVE_DEBUGGER"] is not None
101+
102+
RemoteConfig.disable()
103+
104+
105+
def test_remote_config_register_validate_rc_disabled():
95106
assert RemoteConfig._worker is None
96107

97-
mock_check_remote_config_enable_in_agent.return_value = True
98-
RemoteConfig.register("LIVE_DEBUGGER", lambda m, c: None)
108+
with override_env(dict(DD_REMOTE_CONFIGURATION_ENABLED="false")):
109+
RemoteConfig.register("LIVE_DEBUGGER", lambda m, c: None)
99110

100-
assert RemoteConfig._worker._client._products["LIVE_DEBUGGER"] is not None
111+
assert RemoteConfig._worker is None
101112

102-
RemoteConfig.disable()
103113

114+
def test_remote_config_enable_validate_rc_disabled():
104115
assert RemoteConfig._worker is None
105116

117+
with override_env(dict(DD_REMOTE_CONFIGURATION_ENABLED="false")):
118+
RemoteConfig.enable()
119+
120+
assert RemoteConfig._worker is None
121+
106122

107123
@pytest.mark.subprocess
108124
def test_remote_config_forksafe():
109125
import mock
110126

111127
from ddtrace.internal.remoteconfig import RemoteConfig
128+
from tests.utils import override_env
112129

113-
with mock.patch.object(
114-
RemoteConfig, "_check_remote_config_enable_in_agent"
115-
) as mock_check_remote_config_enable_in_agent:
116-
mock_check_remote_config_enable_in_agent.return_value = True
130+
with override_env(dict(DD_REMOTE_CONFIGURATION_ENABLED="true")):
131+
with mock.patch.object(
132+
RemoteConfig, "_check_remote_config_enable_in_agent"
133+
) as mock_check_remote_config_enable_in_agent:
134+
mock_check_remote_config_enable_in_agent.return_value = True
117135

118-
import os
136+
import os
119137

120-
RemoteConfig.enable()
138+
RemoteConfig.enable()
121139

122-
parent_worker = RemoteConfig._worker
123-
assert parent_worker is not None
140+
parent_worker = RemoteConfig._worker
141+
assert parent_worker is not None
124142

125-
if os.fork() == 0:
126-
assert RemoteConfig._worker is not None
127-
assert RemoteConfig._worker is not parent_worker
128-
exit(0)
143+
if os.fork() == 0:
144+
assert RemoteConfig._worker is not None
145+
assert RemoteConfig._worker is not parent_worker
146+
exit(0)
129147

130148

131149
@mock.patch.object(RemoteConfigClient, "_send_request")
@@ -139,7 +157,7 @@ def _reload_features(self, metadata, features):
139157

140158
callback = Callback()
141159

142-
with override_env(dict(DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS="0.1")):
160+
with override_env(dict(DD_REMOTE_CONFIGURATION_ENABLED="true", DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS="0.1")):
143161
mock_check_remote_config_enable_in_agent.return_value = True
144162
mock_send_request.return_value = get_mock_encoded_msg(b'{"asm":{"enabled":true}}')
145163
rc = RemoteConfig()
@@ -183,7 +201,7 @@ def _reload_features(self, metadata, features):
183201

184202
callback = Callback()
185203

186-
with override_env(dict(DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS="0.1")):
204+
with override_env(dict(DD_REMOTE_CONFIGURATION_ENABLED="true", DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS="0.1")):
187205
mock_check_remote_config_enable_in_agent.return_value = True
188206
mock_send_request.return_value = get_mock_encoded_msg(
189207
b'{"rules_data": [{"data": [{"expiration": 1662804872, "value": "127.0.0.0"}, '

0 commit comments

Comments
 (0)