Skip to content

Commit 2db0747

Browse files
github-actions[bot]Kyle-Verhoogmabdinur
authored
fix(tracer): handle deleted remote configurations [backport 2.4] (#7940)
Backport 26ede5c from #7933 to 2.4. The data format changed with the recent refactor the the remoteconfig client. A `None` value used to be passed to the handling method when a configuration was deleted. A test case is added to cover the regression. No release note is required because the feature isn't released yet. Co-authored-by: Kyle Verhoog <[email protected]> Co-authored-by: Munir Abdinur <[email protected]>
1 parent f7ed8d1 commit 2db0747

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

ddtrace/settings/config.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -690,27 +690,24 @@ def __init__(self, callback):
690690

691691
def _handle_remoteconfig(self, data, test_tracer=None):
692692
# type: (Any, Any) -> None
693-
694-
# If no data is submitted then the RC config has been deleted. Revert the settings.
695-
if not data:
696-
for item in self._config.values():
697-
item.unset_rc()
693+
if not isinstance(data, dict) or (isinstance(data, dict) and "config" not in data):
694+
log.warning("unexpected RC payload %r", data)
698695
return
699-
700696
if len(data["config"]) == 0:
701697
log.warning("unexpected number of RC payloads %r", data)
702698
return
703699

700+
# If no data is submitted then the RC config has been deleted. Revert the settings.
704701
config = data["config"][0]
705-
if "lib_config" not in config:
706-
log.warning("unexpected RC payload %r", config)
707-
return
708-
709-
lib_config = config["lib_config"]
710702
updated_items = [] # type: List[Tuple[str, Any]]
711703

712-
if "tracing_sampling_rate" in lib_config:
713-
updated_items.append(("_trace_sample_rate", lib_config["tracing_sampling_rate"]))
704+
if not config:
705+
for item in self._config:
706+
updated_items.append((item, None))
707+
else:
708+
lib_config = config["lib_config"]
709+
if "tracing_sampling_rate" in lib_config:
710+
updated_items.append(("_trace_sample_rate", lib_config["tracing_sampling_rate"]))
714711

715712
self._set_config_items([(k, v, "remote_config") for k, v in updated_items])
716713

tests/internal/test_settings.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ def _base_rc_config(cfg):
3232
}
3333

3434

35+
def _deleted_rc_config():
36+
return {
37+
"metadata": [],
38+
"config": [False],
39+
}
40+
41+
3542
@pytest.mark.parametrize(
3643
"testcase",
3744
[
@@ -125,7 +132,7 @@ def test_remoteconfig_sampling_rate_user(run_python_code_in_subprocess):
125132
"""
126133
from ddtrace import config, tracer
127134
from ddtrace.sampler import DatadogSampler
128-
from tests.internal.test_settings import _base_rc_config
135+
from tests.internal.test_settings import _base_rc_config, _deleted_rc_config
129136
130137
with tracer.trace("test") as span:
131138
pass
@@ -153,6 +160,16 @@ def test_remoteconfig_sampling_rate_user(run_python_code_in_subprocess):
153160
assert span.get_metric("_dd.rule_psr") == 0.4
154161
155162
config._handle_remoteconfig(_base_rc_config({"tracing_sampling_rate": None}))
163+
with tracer.trace("test") as span:
164+
pass
165+
assert span.get_metric("_dd.rule_psr") == 0.3
166+
167+
config._handle_remoteconfig(_base_rc_config({"tracing_sampling_rate": 0.4}))
168+
with tracer.trace("test") as span:
169+
pass
170+
assert span.get_metric("_dd.rule_psr") == 0.4
171+
172+
config._handle_remoteconfig(_deleted_rc_config())
156173
with tracer.trace("test") as span:
157174
pass
158175
assert span.get_metric("_dd.rule_psr") == 0.3

0 commit comments

Comments
 (0)