-
Notifications
You must be signed in to change notification settings - Fork 15
[parametric] reuse the test-agent per xdist worker to cut container churn #7235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ce3f55a
docs(parametric): add test-agent reuse POC plan
bm1549 a8c2b82
feat(parametric): add WorkerAgentPool for test-agent reuse
bm1549 d63db0e
refactor(parametric): extract start_agent/stop_agent + rebind_request
bm1549 d4680a1
fix(_test_agent): address review findings on start_agent/get_test_age…
bm1549 d329b36
feat(parametric): pooled-agent creator (worker-scoped network + agent)
bm1549 f3cf962
fix(parametric-agent-pool): guard _pool_seed_request None, type annot…
bm1549 7ca986d
docs(parametric): scope plan to default-env pooling (Option B) + chur…
bm1549 185319c
feat(parametric): use WorkerAgentPool in test_agent fixture
bm1549 08ff3a8
refactor(parametric): thread request through pool creator, remove _po…
bm1549 902231d
fix(parametric): restore early return in pooled test_agent branch (pr…
bm1549 84c8485
test(parametric): log agent container creations for reuse verification
bm1549 e690585
docs(parametric): test-agent reuse POC handoff note
bm1549 fb0d34d
fix(parametric): give pooled agents distinct host-port band to avoid …
bm1549 d9b4b48
chore(parametric): drop internal SDD scratch + plan doc from POC branch
bm1549 cf8b4fb
fix(parametric-pool): apply pre-push review fixes for agent pool corr…
bm1549 4318912
fix(parametric): keep OTLP session-clear best-effort (it returns 400 …
bm1549 6d50787
style(parametric): ruff format _test_agent.py (collapse wrapped log_p…
bm1549 2d8cb67
fix(parametric): satisfy ruff check (annotations, drop unused noqa, l…
bm1549 f4f2c34
fix(parametric): use Any+noqa for duck-typed pool acquire (fixes mypy…
bm1549 3163895
fix(parametric): don't pool agents for custom-OTLP-port tests
bm1549 4f2e50a
fix(test_the_test): gate docker smoke test at runtime, not via skipif…
bm1549 1957508
fix(parametric): reset remote-config in pooled agent clear()
bm1549 73e0de7
docs: move parametric agent-reuse POC writeup off the PR
bm1549 d50bfd7
fix(parametric): reset remote-config on pool reuse, not in clear()
bm1549 b2a0045
Merge origin/main into brian.marks/parametric-agent-reuse
bm1549 7a1752f
fix(parametric): pre-push review — pooled port band off FFE + pool ev…
bm1549 62eda0e
fix(test_the_test): update smoke test for start_agent context manager
bm1549 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| from utils._context._scenarios import scenarios | ||
| from utils.docker_fixtures._core import get_docker_client | ||
| from utils.docker_fixtures._test_agent import DEFAULT_OTLP_HTTP_PORT, DEFAULT_OTLP_GRPC_PORT | ||
|
|
||
|
|
||
| def test_start_agent_then_stop(request: pytest.FixtureRequest): | ||
| # Docker-backed smoke test. Gate at runtime rather than with a module-level | ||
| # pytest.mark.skipif: the root conftest's _item_must_pass iterates skipif | ||
| # marker.args[0] (all(marker.args[0])), which raises on a bool condition and | ||
| # crashes collection for every session that collects this file. | ||
| if os.getenv("DOCKER_SMOKE") != "1": | ||
| pytest.skip("Docker-backed; run with DOCKER_SMOKE=1") | ||
|
|
||
| factory = scenarios.parametric._test_agent_factory # noqa: SLF001 | ||
| factory.configure("logs_parametric") | ||
| factory.pull() | ||
|
|
||
| client = get_docker_client().networks.create(name="reuse_smoke_net", driver="bridge") | ||
| try: | ||
| with factory.start_agent( | ||
| request=request, | ||
| worker_id="gw0", | ||
| container_name="ddapm-test-agent-reuse-smoke", | ||
| docker_network=client.name, | ||
| agent_env={}, | ||
| container_otlp_http_port=DEFAULT_OTLP_HTTP_PORT, | ||
| container_otlp_grpc_port=DEFAULT_OTLP_GRPC_PORT, | ||
| ) as api: | ||
| assert api.info()["version"] == "test" # agent answered → it is ready | ||
| finally: | ||
| client.remove() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import contextlib | ||
| from collections.abc import Iterator | ||
|
|
||
| from utils.docker_fixtures._test_agent_pool import WorkerAgentPool, agent_env_key | ||
|
|
||
|
|
||
| class _FakeApi: | ||
| def __init__(self) -> None: | ||
| self.clear_calls = 0 | ||
| self.reset_rc_calls = 0 | ||
| self.rebind_calls: list[object] = [] | ||
|
|
||
| def clear(self) -> None: | ||
| self.clear_calls += 1 | ||
|
|
||
| def reset_remote_config(self) -> None: | ||
| self.reset_rc_calls += 1 | ||
|
|
||
| def rebind_request(self, request: object) -> None: | ||
| self.rebind_calls.append(request) | ||
|
|
||
|
|
||
| class _FakeCreator: | ||
| """Context-manager creator: yields a _FakeApi and counts teardowns on exit.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| self.created_envs: list[dict] = [] | ||
| self.stopped = 0 | ||
|
|
||
| @contextlib.contextmanager | ||
| def __call__(self, request: object, agent_env: dict[str, str]) -> Iterator[_FakeApi]: # noqa: ARG002 | ||
| self.created_envs.append(dict(agent_env)) | ||
| try: | ||
| yield _FakeApi() | ||
| finally: | ||
| self.stopped += 1 | ||
|
|
||
|
|
||
| def test_env_key_is_order_independent(): | ||
| assert agent_env_key({"A": "1", "B": "2"}) == agent_env_key({"B": "2", "A": "1"}) | ||
|
|
||
|
|
||
| def test_same_env_reuses_and_clears(): | ||
| creator = _FakeCreator() | ||
| with WorkerAgentPool(creator) as pool: | ||
| api1 = pool.acquire(request="req1", agent_env={}) | ||
| api2 = pool.acquire(request="req2", agent_env={}) | ||
|
|
||
| assert api1 is api2 # reused, not recreated | ||
| assert len(creator.created_envs) == 1 # created exactly once | ||
| assert api1.clear_calls == 2 # cleared on both acquires (first + reuse) | ||
| assert api1.reset_rc_calls == 2 # remote-config reset on both acquires too | ||
| assert api1.rebind_calls == ["req2"] # rebound only on reuse, not on first acquire | ||
|
|
||
|
|
||
| def test_distinct_env_creates_separate_agents(): | ||
| creator = _FakeCreator() | ||
| with WorkerAgentPool(creator) as pool: | ||
| a = pool.acquire(request="r", agent_env={}) | ||
| b = pool.acquire(request="r", agent_env={"DD_ENV": "prod"}) | ||
|
|
||
| assert a is not b | ||
| assert len(creator.created_envs) == 2 | ||
|
|
||
|
|
||
| def test_exit_tears_down_every_agent(): | ||
| creator = _FakeCreator() | ||
| with WorkerAgentPool(creator) as pool: | ||
| pool.acquire(request="r", agent_env={}) | ||
| pool.acquire(request="r", agent_env={"DD_ENV": "prod"}) | ||
| assert creator.stopped == 0 # still open inside the context | ||
|
|
||
| assert creator.stopped == 2 # both agents torn down on exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.