Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/apm_tracing_e2e/test_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setup_datadog_otel_span(self):
# - duration of one second
# - span kind of SpanKind - Internal
def test_datadog_otel_span(self):
spans = interfaces.backend_v2.get_spans_list(self.req)
spans = interfaces.mocked_backend.get_spans_list(self.req)
assert len(spans) >= 2, "Agent did not submit the spans we want!"

# Assert the parent span sent by the agent.
Expand Down Expand Up @@ -50,7 +50,7 @@ def setup_distributed_otel_trace(self):
)

def test_distributed_otel_trace(self):
spans = interfaces.backend_v2.get_spans_list(self.req)
spans = interfaces.mocked_backend.get_spans_list(self.req)
assert len(spans) >= 3, "Agent did not submit the spans we want!"

# Assert the parent span sent by the agent.
Expand Down
4 changes: 2 additions & 2 deletions tests/apm_tracing_e2e/test_single_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setup_parent_span_is_single_span(self):

def test_parent_span_is_single_span(self):
# Only the parent span should be submitted to the backend!
spans = interfaces.backend_v2.get_spans_list(self.req)
spans = interfaces.mocked_backend.get_spans_list(self.req)
assert len(spans) == 1, "Agent did not submit the spans we want!"

# Assert the spans sent by the agent.
Expand All @@ -47,7 +47,7 @@ def setup_child_span_is_single_span(self):

def test_child_span_is_single_span(self):
# Only the child should be submitted to the backend!
spans = interfaces.backend_v2.get_spans_list(self.req)
spans = interfaces.mocked_backend.get_spans_list(self.req)
assert len(spans) == 1, "Agent did not submit the spans we want!"

# Assert the spans sent by the agent.
Expand Down
8 changes: 4 additions & 4 deletions tests/ffe/utils/evp.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def excluded_data(self, path_filters: str | None = None) -> list[dict[str, Any]]
return [
data
for api_key in self.excluded_api_keys
for data in interfaces.backend_v2.get_data(path_filters=path_filters, with_api_key=api_key)
for data in interfaces.mocked_backend.get_data(path_filters=path_filters, with_api_key=api_key)
]


Expand All @@ -125,15 +125,15 @@ def feature_flagging_evp_egress() -> FeatureFlaggingEVPEgress:
assert "serverless-init" in scenario.components
# serverless-init relays the events: the SDK must not send them straight to the intake
return FeatureFlaggingEVPEgress(
interfaces.backend_v2,
interfaces.mocked_backend,
"sidecar",
excluded_api_keys=(scenario.weblog_api_key,),
expected_api_key=scenario.sidecar_api_key,
)

assert scenario.exposure_egress == "direct"
assert "serverless-init" not in scenario.components
return FeatureFlaggingEVPEgress(interfaces.backend_v2, "direct", expected_api_key=scenario.weblog_api_key)
return FeatureFlaggingEVPEgress(interfaces.mocked_backend, "direct", expected_api_key=scenario.weblog_api_key)


def register_expected_evp_capture(path: str) -> None:
Expand Down Expand Up @@ -468,7 +468,7 @@ def assert_agentless_evp_topology(egress: FeatureFlaggingEVPEgress) -> None:
assert name not in environment
assert "serverless-init" not in scenario.components
assert scenario.serverless_init_container is None
assert_no_evp_proxy_requests(interfaces.backend_v2.get_data(with_api_key=scenario.weblog_api_key))
assert_no_evp_proxy_requests(interfaces.mocked_backend.get_data(with_api_key=scenario.weblog_api_key))
return

assert egress.route == "sidecar"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_otlp_runtime_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def get_runtime_metrics_by_name() -> dict[str, list[dict[str, str]]]:
Tags are parsed from "key:value" strings in the series the agent sent to the mocked backend.
"""
result: dict[str, list[dict[str, str]]] = {}
for _, metric in interfaces.backend_v2.get_metrics():
for _, metric in interfaces.mocked_backend.get_metrics():
name: str = metric["metric"]
tags: dict[str, str] = dict(tag.split(":", 1) for tag in metric.get("tags", []) if ":" in tag)
result.setdefault(name, []).append(tags)
Expand All @@ -268,7 +268,7 @@ def wait_for_runtime_metrics(library: str) -> None:
if not expected:
return

interfaces.backend_v2.wait_for(
interfaces.mocked_backend.wait_for(
lambda _: expected.keys() <= get_runtime_metrics_by_name().keys(),
timeout=RUNTIME_METRICS_WAIT_TIMEOUT,
)
Expand Down
8 changes: 3 additions & 5 deletions tests/test_the_test/test_docker_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,8 @@ def test_end_to_end_scenario_only_flushes_agent_backed_non_empty_test_runs(


@scenarios.test_the_test
def test_mocked_backend_v2_agent_sends_to_the_mocked_backend_container(monkeypatch: pytest.MonkeyPatch) -> None:
scenario = DdTraceEndToEndScenario(
"FAKE_MOCKED_BACKEND_V2", doc="", mocked_backend_v2=True, use_proxy_for_agent=False
)
def test_mocked_backend_agent_sends_to_the_mocked_backend_container(monkeypatch: pytest.MonkeyPatch) -> None:
scenario = DdTraceEndToEndScenario("FAKE_MOCKED_BACKEND_V2", doc="", mocked_backend=True, use_proxy_for_agent=False)
mocked_backend = scenario.mocked_backend_container
assert mocked_backend in scenario._containers # noqa: SLF001

Expand All @@ -161,7 +159,7 @@ def test_mocked_backend_v2_agent_sends_to_the_mocked_backend_container(monkeypat


@scenarios.test_the_test
def test_no_mocked_backend_container_without_mocked_backend_v2() -> None:
def test_no_mocked_backend_container_without_mocked_backend() -> None:
scenario = DdTraceEndToEndScenario("FAKE_NO_MOCKED_BACKEND_V2", doc="", use_proxy_for_agent=False)
assert scenario.mocked_backend_container not in scenario._containers # noqa: SLF001
assert "DD_DD_URL" not in scenario.agent_container.environment
Expand Down
6 changes: 3 additions & 3 deletions tests/test_the_test/test_ffe_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ def test_feature_flagging_agentless_evp_topology_supports_both_routes(
scenario.weblog_infra.http_container._library = ComponentVersion("java", "0.66.0") # noqa: SLF001
scenario._last_direct_evp_runtime_evidence = _direct_runtime_evidence("java") # noqa: SLF001
monkeypatch.setattr(context, "scenario", scenario)
monkeypatch.setattr(interfaces.backend_v2, "get_data", lambda **_: [])
monkeypatch.setattr(interfaces.mocked_backend, "get_data", lambda **_: [])

assert_agentless_evp_topology(FeatureFlaggingEVPEgress(interfaces.backend_v2, route))
assert_agentless_evp_topology(FeatureFlaggingEVPEgress(interfaces.mocked_backend, route))

environment = scenario.weblog_infra.library_container.environment
for runtime_trust_variable in ("REQUESTS_CA_BUNDLE", "SSL_CERT_FILE"):
Expand All @@ -407,7 +407,7 @@ def test_feature_flagging_agentless_evp_topology_supports_both_routes(
library_container._fix_host_pwd_in_volumes() # noqa: SLF001 - reproduce container start normalization
normalized_source = f"{library_container.host_project_dir}{DIRECT_EVP_CA_BUNDLE_SOURCE[1:]}"
assert library_container.volumes[normalized_source] == expected_mount
assert_agentless_evp_topology(FeatureFlaggingEVPEgress(interfaces.backend_v2, route))
assert_agentless_evp_topology(FeatureFlaggingEVPEgress(interfaces.mocked_backend, route))


@scenarios.test_the_test
Expand Down
20 changes: 11 additions & 9 deletions tests/test_the_test/test_mock_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from cryptography.hazmat.primitives.serialization import pkcs12

from utils import scenarios
from utils.interfaces._backend_v2 import _BackendV2InterfaceValidator
from utils.interfaces._mocked_backend import _MockedBackendInterfaceValidator
from utils._context.containers import MockedBackendContainer, TestedContainer
from utils._context._scenarios.agentless_endtoend import JAVA_TRUSTSTORE_SOURCE
from utils.mocked_backend import MockedBackendClient, MockedBackendServer
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_runs_without_the_rest_of_utils(tmp_path: Path):
@scenarios.test_the_test
def test_entry_point_serves_until_sigterm(tmp_path: Path):
"""`python -m utils.mocked_backend` is how the mocked backend will run in its own container."""
log_folder = tmp_path / "backend_v2" # created by the entry point
log_folder = tmp_path / "mocked_backend" # created by the entry point
process = subprocess.Popen(
[sys.executable, "-m", "utils.mocked_backend", "--port", "0", "--log-folder", str(log_folder)],
cwd=Path(__file__).parents[2],
Expand Down Expand Up @@ -369,9 +369,11 @@ def test_health_endpoint(server: MockedBackendServer, tmp_path: Path):
assert list(tmp_path.glob("*.json")) == []


def _backend_v2_with_requests(tmp_path: Path, requests_: list[tuple[str, str | None]]) -> _BackendV2InterfaceValidator:
"""A backend_v2 interface that received a series request per (filename, api_key)"""
interface = _BackendV2InterfaceValidator()
def _mocked_backend_with_requests(
tmp_path: Path, requests_: list[tuple[str, str | None]]
) -> _MockedBackendInterfaceValidator:
"""A mocked backend interface that received a series request per (filename, api_key)"""
interface = _MockedBackendInterfaceValidator()
interface.configure(str(tmp_path), replay=False)
for filename, api_key in requests_:
headers = [["Content-Type", "application/json"]] + ([["DD-API-KEY", api_key]] if api_key else [])
Expand All @@ -388,8 +390,8 @@ def _backend_v2_with_requests(tmp_path: Path, requests_: list[tuple[str, str | N


@scenarios.test_the_test
def test_backend_v2_with_api_key_only_returns_requests_sent_with_this_key(tmp_path: Path):
interface = _backend_v2_with_requests(
def test_mocked_backend_with_api_key_only_returns_requests_sent_with_this_key(tmp_path: Path):
interface = _mocked_backend_with_requests(
tmp_path, [("000__agent.json", "agent-key"), ("001__sidecar.json", "sidecar-key"), ("002__nokey.json", None)]
)

Expand All @@ -403,8 +405,8 @@ def test_backend_v2_with_api_key_only_returns_requests_sent_with_this_key(tmp_pa


@scenarios.test_the_test
def test_backend_v2_with_api_key_ignores_the_header_name_case(tmp_path: Path):
interface = _backend_v2_with_requests(tmp_path, [("000__agent.json", "agent-key")])
def test_mocked_backend_with_api_key_ignores_the_header_name_case(tmp_path: Path):
interface = _mocked_backend_with_requests(tmp_path, [("000__agent.json", "agent-key")])
data = next(interface.get_data())
data["request"]["headers"] = [["dd-api-key", "agent-key"]]

Expand Down
14 changes: 7 additions & 7 deletions tests/test_the_test/test_mock_ffe_agentless_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ def wait_for(matcher: Callable[[dict[str, Any]], bool], *, timeout: int) -> bool
return matcher(next(captures))

wait = MagicMock()
monkeypatch.setattr(interfaces.backend_v2, "wait_for", wait_for)
monkeypatch.setattr(interfaces.backend_v2, "wait", wait)
monkeypatch.setattr(interfaces.mocked_backend, "wait_for", wait_for)
monkeypatch.setattr(interfaces.mocked_backend, "wait", wait)

scenario._wait_for_expected_evp_captures(is_empty_test_run=False) # noqa: SLF001

Expand Down Expand Up @@ -485,9 +485,9 @@ def wait_for(matcher: Callable[[dict[str, Any]], bool], *, timeout: int) -> bool
return any(matcher(candidate) for candidate in (priming_capture, capture))

settle = MagicMock(side_effect=lambda _: lifecycle.append("settle"))
monkeypatch.setattr(interfaces.backend_v2, "get_data", get_data)
monkeypatch.setattr(interfaces.backend_v2, "wait_for", wait_for)
monkeypatch.setattr(interfaces.backend_v2, "wait", settle)
monkeypatch.setattr(interfaces.mocked_backend, "get_data", get_data)
monkeypatch.setattr(interfaces.mocked_backend, "wait_for", wait_for)
monkeypatch.setattr(interfaces.mocked_backend, "wait", settle)

runtime_container = MagicMock()
runtime_container.status = "exited"
Expand Down Expand Up @@ -552,7 +552,7 @@ def test_agentless_end_to_end_scenario_stops_backend_when_status_fails(
monkeypatch.setattr(scenario, "mocked_backend_container", container)

with pytest.raises(RuntimeError, match="status failed"):
scenario._stop_mocked_backend_v2() # noqa: SLF001 - focused lifecycle test
scenario._stop_mocked_backend() # noqa: SLF001 - focused lifecycle test

container.stop.assert_called_once_with()

Expand Down Expand Up @@ -580,7 +580,7 @@ def test_agentless_end_to_end_scenario_persists_backend_status_for_replay(
container.client.ffe_get_status.return_value = expected_status
monkeypatch.setattr(recording_scenario, "mocked_backend_container", container)

recording_scenario._stop_mocked_backend_v2() # noqa: SLF001 - focused lifecycle test
recording_scenario._stop_mocked_backend() # noqa: SLF001 - focused lifecycle test

container.stop.assert_called_once_with()
assert recording_scenario.mock_backend_status() == expected_status
Expand Down
2 changes: 1 addition & 1 deletion tests/test_v1_payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setup_field_changes(self):

def test_field_changes(self):
library_traces = list(interfaces.library.get_traces(self.r))
agent_traces = list(interfaces.backend_v2.get_traces(self.r))
agent_traces = list(interfaces.mocked_backend.get_traces(self.r))
assert len(library_traces) == 1
_, trace = library_traces[0]
assert isinstance(trace.raw_trace, dict)
Expand Down
42 changes: 20 additions & 22 deletions utils/_context/_scenarios/_core/endtoend.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(
scenario_groups: list[ScenarioGroup] | None = None,
enable_ipv6: bool = False,
use_proxy: bool = True,
mocked_backend: bool = True,
rc_api_enabled: bool = False,
rc_backend_enabled: bool = False,
meta_structs_disabled: bool = False,
Expand Down Expand Up @@ -91,7 +90,6 @@ def __init__(
client_drop_p0s=client_drop_p0s,
obfuscation_version=obfuscation_version,
enable_ipv6=enable_ipv6,
mocked_backend=mocked_backend,
)

self._containers.append(self.proxy_container)
Expand Down Expand Up @@ -240,7 +238,7 @@ def __init__(
include_agent: bool = True,
include_opentelemetry: bool = False,
require_api_key: bool = False,
mocked_backend_v2: bool = False,
mocked_backend: bool = False,
other_weblog_containers: tuple[type[TestedContainer], ...] = (),
) -> None:
scenario_groups = [*self._default_scenario_groups, *(scenario_groups or [])]
Expand Down Expand Up @@ -268,22 +266,22 @@ def __init__(
self._use_proxy_for_agent = include_agent and use_proxy_for_agent
self._use_proxy_for_weblog = use_proxy_for_weblog
self._require_api_key = require_api_key
self._mocked_backend_v2 = mocked_backend_v2
self._mocked_backend = mocked_backend

if mocked_backend_v2 and self._use_proxy_for_agent:
if mocked_backend and self._use_proxy_for_agent:
raise ValueError(
"mocked_backend_v2 is not compatible with use_proxy_for_agent: the agent can't send its "
"mocked_backend is not compatible with use_proxy_for_agent: the agent can't send its "
"traffic to both the proxy and the mocked backend. Set use_proxy_for_agent=False."
)

self.dd_api_key = (
FakeDatadogKey.DEFAULT if mocked_backend_v2 else os.environ.get("DD_API_KEY", FakeDatadogKey.DEFAULT)
FakeDatadogKey.DEFAULT if mocked_backend else os.environ.get("DD_API_KEY", FakeDatadogKey.DEFAULT)
)
"""The API key used by the agent to send data to the backend"""

# it serves HTTPS on its domain, and on the intake hostnames derived from it (see MOCKED_BACKEND_DOMAIN)
self.mocked_backend_container = MockedBackendContainer(tls=True)
if mocked_backend_v2:
if mocked_backend:
self._containers.append(self.mocked_backend_container)
if include_agent:
agent_env = dict(agent_env) if agent_env else {}
Expand Down Expand Up @@ -367,8 +365,8 @@ def configure(self, config: pytest.Config):
interfaces.library.configure(self.host_log_folder, replay=self.replay)
if self._require_api_key: # only used by scenarios querying the real Datadog backend
interfaces.backend_legacy.configure(self.host_log_folder, replay=self.replay)
if self._mocked_backend_v2:
interfaces.backend_v2.configure(self.host_log_folder, replay=self.replay)
if self._mocked_backend:
interfaces.mocked_backend.configure(self.host_log_folder, replay=self.replay)
interfaces.library_dotnet_managed.configure(self.host_log_folder, replay=self.replay)
interfaces.library_stdout.configure(self.host_log_folder, replay=self.replay)
if self.include_agent:
Expand Down Expand Up @@ -412,7 +410,7 @@ def configure(self, config: pytest.Config):
self.warmups.append(self._set_weblog_domain)
self.warmups.append(self._set_components)

def _stop_mocked_backend_v2(self) -> None:
def _stop_mocked_backend(self) -> None:
"""Called once the agent and the weblog are stopped. Subclasses can extend it to read the mocked backend
state before it stops.
"""
Expand All @@ -429,7 +427,7 @@ def _set_containers_dependancies(self) -> None:
for buddy in self.buddies:
buddy.depends_on.append(self.agent_container)

if self._mocked_backend_v2:
if self._mocked_backend:
if self.include_agent:
self.agent_container.depends_on.append(self.mocked_backend_container)
# e.g. agentless libraries may reach it as soon as they start
Expand All @@ -442,7 +440,7 @@ def _start_interfaces_watchdog(self):
)
agent_interfaces: list[ProxyBasedInterfaceValidator] = [interfaces.agent] if self.include_agent else []
backend_interfaces: list[ProxyBasedInterfaceValidator] = (
[interfaces.backend_v2] if self._mocked_backend_v2 else []
[interfaces.mocked_backend] if self._mocked_backend else []
)
super().start_interfaces_watchdog(
[interfaces.library]
Expand Down Expand Up @@ -512,9 +510,9 @@ def _wait_and_stop_containers(self, *, is_empty_test_run: bool):
if self._require_api_key:
interfaces.backend_legacy.load_data_from_logs()

if self._mocked_backend_v2:
interfaces.backend_v2.load_data_from_logs()
interfaces.backend_v2.check_deserialization_errors()
if self._mocked_backend:
interfaces.mocked_backend.load_data_from_logs()
interfaces.mocked_backend.check_deserialization_errors()

if self.include_opentelemetry:
interfaces.open_telemetry.load_data_from_logs()
Expand Down Expand Up @@ -545,13 +543,13 @@ def _wait_and_stop_containers(self, *, is_empty_test_run: bool):
self._wait_interface(
interfaces.open_telemetry, 0 if is_empty_test_run else self.backend_interface_timeout
)
if self._mocked_backend_v2:
if self._mocked_backend:
# stopped last: it receives what the agent and the weblog send until they stop
self._stop_mocked_backend_v2()
self._stop_mocked_backend()
# the watchdog polls files about once per second: the last ones may not be ingested yet. Nothing else
# can arrive now, so ingest them all instead of waiting an arbitrary time
interfaces.backend_v2.ingest_all_files()
interfaces.backend_v2.check_deserialization_errors()
interfaces.mocked_backend.ingest_all_files()
interfaces.mocked_backend.check_deserialization_errors()

def _stop_weblog(self, *, is_empty_test_run: bool) -> None:
"""Stop the weblog after setup traffic has been generated."""
Expand Down Expand Up @@ -634,7 +632,7 @@ def __init__(
include_opentelemetry: bool = False,
library_interface_timeout: int | None = None,
meta_structs_disabled: bool = False,
mocked_backend_v2: bool = False,
mocked_backend: bool = False,
obfuscation_version: int | None | Literal["MISSING"] = None,
other_weblog_containers: tuple[type[TestedContainer], ...] = (),
rc_api_enabled: bool = False,
Expand Down Expand Up @@ -663,7 +661,7 @@ def __init__(
include_opentelemetry=include_opentelemetry,
library_interface_timeout=library_interface_timeout,
meta_structs_disabled=meta_structs_disabled,
mocked_backend_v2=mocked_backend_v2,
mocked_backend=mocked_backend,
obfuscation_version=obfuscation_version,
other_weblog_containers=other_weblog_containers,
rc_api_enabled=rc_api_enabled,
Expand Down
Loading
Loading