From cd8f7aba74a892e39e35905e4a3d9c5c6c64be54 Mon Sep 17 00:00:00 2001 From: Roch Devost Date: Fri, 24 Apr 2026 16:43:20 -0400 Subject: [PATCH 1/2] remove the need to sleep in remote config --- utils/_remote_config.py | 62 ++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/utils/_remote_config.py b/utils/_remote_config.py index c8dd28f7976..974dd6c1403 100644 --- a/utils/_remote_config.py +++ b/utils/_remote_config.py @@ -6,7 +6,6 @@ import hashlib import json import re -import time import uuid from typing import Any, Literal from collections.abc import Mapping @@ -82,6 +81,14 @@ def send_state( assert api_enabled, f"Remote config API is not enabled on {context.scenario}" + # Collect runtime_ids of all processes currently polling RC so we can wait for each one to acknowledge. + known_runtime_ids: set[str] = set() + for _d in library.get_data(path_filters="/v0.7/config"): + try: + known_runtime_ids.add(_d["request"]["content"]["client"]["client_tracer"]["runtime_id"]) + except (KeyError, TypeError): + pass + if target == "backend": assert backend_enabled, f"Remote config backend is not enabled on {context.scenario}" # Build protobuf on test runner side, send bytes to proxy @@ -107,41 +114,56 @@ def send_state( "apply_error": "", } - state = {} + acknowledged_runtime_ids: set[str] = set() + + def _all_processes_acknowledged() -> bool: + return not known_runtime_ids or acknowledged_runtime_ids >= known_runtime_ids def remote_config_applied(data: dict) -> bool: - nonlocal state if data["path"] != "/v0.7/config": return False - state = data.get("request", {}).get("content", {}).get("client", {}).get("state", {}) + client_state = data.get("request", {}).get("content", {}).get("client", {}).get("state", {}) + + try: + rid = data["request"]["content"]["client"]["client_tracer"]["runtime_id"] + except (KeyError, TypeError): + rid = None + if len(client_configs) == 0: - found = state["targets_version"] == state_version and state.get("config_states", []) == [] + found = client_state.get("targets_version") == state_version and client_state.get("config_states", []) == [] if found: - current_states.state = ApplyState.ACKNOWLEDGED - return found + if rid: + acknowledged_runtime_ids.add(rid) + if _all_processes_acknowledged(): + current_states.state = ApplyState.ACKNOWLEDGED + return True + return False - if state["targets_version"] != version: + if client_state.get("targets_version") != version: return False - config_states = state.get("config_states", []) - for state in config_states: - config_state = current_states.configs.get(state["id"]) - if config_state and state["product"] == config_state["product"]: - logger.debug(f"Remote config state: {state}") - config_state.update(state) + for cs in client_state.get("config_states", []): + config_state = current_states.configs.get(cs["id"]) + if config_state and cs["product"] == config_state["product"]: + logger.debug(f"Remote config state: {cs}") + config_state.update(cs) if wait_for_acknowledged_status: - for state in current_states.configs.values(): - if state["apply_state"] == ApplyState.UNKNOWN: + for config_state in current_states.configs.values(): + if config_state["apply_state"] == ApplyState.UNKNOWN: return False - current_states.state = ApplyState.ACKNOWLEDGED - return True + if rid: + acknowledged_runtime_ids.add(rid) + + if _all_processes_acknowledged(): + current_states.state = ApplyState.ACKNOWLEDGED + return True + + return False library.wait_for(remote_config_applied, timeout=30) - # ensure the library has enough time to apply the config to all subprocesses - time.sleep(2) return current_states From 9db3e947eb230bba4bf7911bbbd5f12768c20bc2 Mon Sep 17 00:00:00 2001 From: Roch Devost Date: Fri, 24 Apr 2026 17:38:39 -0400 Subject: [PATCH 2/2] fix lint --- utils/_remote_config.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utils/_remote_config.py b/utils/_remote_config.py index 974dd6c1403..18d5efc040f 100644 --- a/utils/_remote_config.py +++ b/utils/_remote_config.py @@ -3,6 +3,7 @@ # Copyright 2021 Datadog, Inc. import base64 +import contextlib import hashlib import json import re @@ -84,10 +85,8 @@ def send_state( # Collect runtime_ids of all processes currently polling RC so we can wait for each one to acknowledge. known_runtime_ids: set[str] = set() for _d in library.get_data(path_filters="/v0.7/config"): - try: + with contextlib.suppress(KeyError, TypeError): known_runtime_ids.add(_d["request"]["content"]["client"]["client_tracer"]["runtime_id"]) - except (KeyError, TypeError): - pass if target == "backend": assert backend_enabled, f"Remote config backend is not enabled on {context.scenario}"