Skip to content

Commit e2025d0

Browse files
committed
cleanup
1 parent f67776a commit e2025d0

9 files changed

Lines changed: 79 additions & 65 deletions

File tree

datadog_checks_dev/datadog_checks/dev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
from .__about__ import __version__
55
from .conditions import WaitFor
6-
from .docker import docker_run, get_docker_hostname, get_e2e_discovery_metadata, get_e2e_process_discovery_metadata
6+
from .docker import docker_run, get_docker_hostname, get_e2e_discovery_metadata, get_e2e_process_discovery_metadata, process_e2e_docker_run
77
from .env import environment_run
88
from .errors import RetryError
99
from .fs import chdir, get_here, temp_chdir, temp_dir

datadog_checks_dev/datadog_checks/dev/docker.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,33 @@ def get_e2e_process_discovery_metadata(
287287
}
288288

289289

290+
def process_e2e_docker_run(
291+
compose_file: str | os.PathLike[str],
292+
env_vars: Mapping[str, str] | None = None,
293+
conditions: Sequence | None = None,
294+
service_name: str | None = None,
295+
check_root: str | os.PathLike[str] | None = None,
296+
):
297+
"""Generator for process-autodiscovery e2e environments.
298+
299+
Yields the ``(config, metadata)`` tuple expected by ``dd_environment``, where
300+
``config`` is ``None`` (process autodiscovery must find and configure the check)
301+
and ``metadata`` comes from :func:`get_e2e_process_discovery_metadata`.
302+
303+
Use with ``yield from`` in a ``dd_environment`` fixture::
304+
305+
elif is_process_e2e:
306+
yield from process_e2e_docker_run(COMPOSE_FILE_PROCESS, env_vars=env_vars, conditions=conditions)
307+
"""
308+
with docker_run(
309+
compose_file=str(compose_file),
310+
env_vars=env_vars,
311+
conditions=list(conditions) if conditions is not None else None,
312+
service_name=service_name,
313+
):
314+
yield (None, get_e2e_process_discovery_metadata(check_root=check_root))
315+
316+
290317
def compose_file_active(compose_file):
291318
"""
292319
Returns a `bool` indicating whether or not a compose file has any active services.

datadog_checks_dev/datadog_checks/dev/plugin/pytest.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,21 @@ def enum_object_items(data_source, machine_name, object_name, detail_level):
483483
)
484484

485485

486+
PROCESS_E2E_ENV_NAME = 'e2e-process'
487+
488+
489+
@pytest.fixture(scope='session')
490+
def is_process_e2e() -> bool:
491+
return os.getenv('DDEV_E2E_ENV_NAME') == PROCESS_E2E_ENV_NAME
492+
493+
486494
def pytest_configure(config):
487495
# pytest will emit warnings if these aren't registered ahead of time
488496
for ttype in TEST_TYPES:
489497
config.addinivalue_line('markers', '{}: {}'.format(ttype.name, ttype.description))
490498

491499
config.addinivalue_line("markers", "latest_metrics: marker for verifying support of new metrics")
500+
config.addinivalue_line("markers", "not_process_e2e: skip this test in the process autodiscovery e2e environment")
492501

493502

494503
def pytest_addoption(parser):
@@ -498,16 +507,24 @@ def pytest_addoption(parser):
498507
def pytest_collection_modifyitems(config, items):
499508
# at test collection time, this function gets called by pytest, see:
500509
# https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option
501-
# if the particular option is not present, it will skip all tests marked `latest_metrics`
502-
if config.getoption("--run-latest-metrics"):
503-
# --run-check-metrics given in cli: do not skip slow tests
504-
return
510+
skip_latest_metrics = (
511+
None
512+
if config.getoption("--run-latest-metrics")
513+
else pytest.mark.skip(reason="need --run-latest-metrics option to run")
514+
)
515+
skip_not_process_e2e = (
516+
pytest.mark.skip(reason="not applicable in the process autodiscovery e2e environment")
517+
if os.getenv('DDEV_E2E_ENV_NAME') == PROCESS_E2E_ENV_NAME
518+
else None
519+
)
505520

506-
skip_latest_metrics = pytest.mark.skip(reason="need --run-latest-metrics option to run")
507521
for item in items:
508-
if "latest_metrics" in item.keywords:
522+
if skip_latest_metrics and "latest_metrics" in item.keywords:
509523
item.add_marker(skip_latest_metrics)
510524

525+
if skip_not_process_e2e and "not_process_e2e" in item.keywords:
526+
item.add_marker(skip_not_process_e2e)
527+
511528
item_path = item.path
512529
if item_path is None:
513530
continue

ddev/src/ddev/e2e/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class E2EEnvVars:
1616
RESULT_FILE = 'DDEV_E2E_RESULT_FILE'
1717
LOGS_DIR_PREFIX = 'DDEV_E2E_ENV_TEMP_DIR_DD_LOG_'
1818
DOCKER_VOLUMES = 'DDEV_E2E_ENV_docker_volumes'
19+
ENV_NAME = 'DDEV_E2E_ENV_NAME'
1920

2021

2122
class E2EMetadata:

ddev/src/ddev/e2e/run.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ def __init__(self, env: str, verbosity: int):
1919

2020
@contextmanager
2121
def start(self) -> Generator[list[str], None, None]:
22-
with EnvVars({E2EEnvVars.TEAR_DOWN: 'false', **get_hatch_env_vars(verbosity=self.__verbosity)}):
22+
with EnvVars(
23+
{
24+
E2EEnvVars.TEAR_DOWN: 'false',
25+
E2EEnvVars.ENV_NAME: self.__env,
26+
**get_hatch_env_vars(verbosity=self.__verbosity),
27+
}
28+
):
2329
yield self._base_command()
2430

2531
@contextmanager
2632
def stop(self) -> Generator[list[str], None, None]:
27-
with EnvVars({E2EEnvVars.SET_UP: 'false', **get_hatch_env_vars(verbosity=self.__verbosity)}):
33+
with EnvVars(
34+
{
35+
E2EEnvVars.SET_UP: 'false',
36+
E2EEnvVars.ENV_NAME: self.__env,
37+
**get_hatch_env_vars(verbosity=self.__verbosity),
38+
}
39+
):
2840
yield self._base_command()
2941

3042
def _base_command(self) -> list[str]:

krakend/hatch.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ KRAKEND_IS_LAB = "true"
2424
e2e-env = true
2525
dependencies = ["httpx"]
2626

27-
[envs.e2e-process.env-vars]
28-
KRAKEND_IS_PROCESS_E2E = "true"
29-
3027
[envs.e2e-process.overrides]
3128
matrix.krakend.env-vars = "KRAKEND_VERSION"
3229
matrix.krakend.dependencies = ["httpx"]

krakend/tests/conftest.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
from datadog_checks.dev import docker_run, get_e2e_discovery_metadata, get_e2e_process_discovery_metadata
11+
from datadog_checks.dev import docker_run, get_e2e_discovery_metadata, process_e2e_docker_run
1212
from datadog_checks.dev.conditions import CheckEndpoints
1313
from datadog_checks.dev.structures import LazyFunction
1414
from datadog_checks.krakend import KrakendCheck
@@ -17,19 +17,14 @@
1717

1818
COMPOSE_FILE_E2E = Path(__file__).parent / "docker" / "docker-compose.yml"
1919
COMPOSE_FILE_LAB = Path(__file__).parent / "lab" / "docker-compose.yml"
20-
COMPOSE_FILE_PROCESS_E2E = Path(__file__).parent / "docker-process" / "docker-compose.yml"
20+
COMPOSE_FILE_PROCESS_E2E = Path(__file__).parent / "docker" / "docker-compose.process.yml"
2121

2222

2323
@pytest.fixture(scope="session")
2424
def is_lab() -> bool:
2525
return os.environ.get("KRAKEND_IS_LAB", "false") == "true"
2626

2727

28-
@pytest.fixture(scope="session")
29-
def is_process_e2e() -> bool:
30-
return os.environ.get("KRAKEND_IS_PROCESS_E2E", "false") == "true"
31-
32-
3328
def run_docker_lab(env_vars: dict[str, str], conditions: list[LazyFunction]):
3429
with docker_run(
3530
compose_file=str(COMPOSE_FILE_LAB),
@@ -66,18 +61,6 @@ def run_docker_e2e(env_vars: dict[str, str], conditions: list[LazyFunction]):
6661
)
6762

6863

69-
def run_docker_process_e2e(env_vars: dict[str, str], conditions: list[LazyFunction]):
70-
with docker_run(
71-
compose_file=str(COMPOSE_FILE_PROCESS_E2E),
72-
env_vars=env_vars,
73-
conditions=conditions,
74-
):
75-
yield (
76-
None, # No static config — process autodiscovery must find and configure the check.
77-
get_e2e_process_discovery_metadata(),
78-
)
79-
80-
8164
@pytest.fixture(scope="session")
8265
def dd_environment(dd_save_state, is_lab, is_process_e2e):
8366
"""
@@ -102,7 +85,7 @@ def dd_environment(dd_save_state, is_lab, is_process_e2e):
10285
conditions = [
10386
CheckEndpoints(OPEN_METRICS_ENDPOINT, attempts=120, wait=2),
10487
]
105-
yield from run_docker_process_e2e(env_vars, conditions)
88+
yield from process_e2e_docker_run(COMPOSE_FILE_PROCESS_E2E, env_vars=env_vars, conditions=conditions)
10689
else:
10790
conditions = [
10891
CheckEndpoints(f"{GATEWAY_ENDPOINT}/__health", attempts=120, wait=2),

krakend/tests/docker-process/docker-compose.yml renamed to krakend/tests/docker/docker-compose.process.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ services:
33
image: krakend:${KRAKEND_VERSION}
44
network_mode: host
55
volumes:
6-
- ../docker/krakend.json:/etc/krakend/krakend.json:ro
6+
- ./krakend.json:/etc/krakend/krakend.json:ro
77
command: ["run", "-d", "-c", "/etc/krakend/krakend.json"]

krakend/tests/test_e2e.py

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@
1010

1111

1212
@pytest.mark.e2e
13-
def test_e2e(dd_agent_check, instance: InstanceBuilder, is_process_e2e):
14-
if is_process_e2e:
15-
pytest.skip('direct-config test does not apply to the process autodiscovery environment')
16-
13+
@pytest.mark.not_process_e2e
14+
def test_e2e(dd_agent_check, instance: InstanceBuilder):
1715
config = {"init_config": {}, "instances": [instance(True, True, get_docker_hostname(), 9090)]}
1816

1917
aggregator = dd_agent_check(config, check_rate=True)
2018

21-
metadata_metrics = get_metrics_from_metadata()
22-
2319
aggregator.assert_metrics_using_metadata(
24-
metadata_metrics,
20+
get_metrics_from_metadata(),
2521
check_submission_type=True,
2622
check_symmetric_inclusion=True,
2723
)
@@ -34,37 +30,18 @@ def test_e2e_discovery(dd_agent_check_discovery, is_lab, is_process_e2e):
3430
# config discovery.
3531
if is_lab:
3632
pytest.skip('lab does not currently support configuration discovery')
37-
if is_process_e2e:
38-
pytest.skip('container discovery test does not apply to the process autodiscovery environment')
3933

40-
aggregator = dd_agent_check_discovery(check_rate=True)
41-
42-
metadata_metrics = get_metrics_from_metadata()
34+
timeout = 90 if is_process_e2e else 30
35+
aggregator = dd_agent_check_discovery(check_rate=True, discovery_timeout=timeout)
4336

4437
aggregator.assert_metrics_using_metadata(
45-
metadata_metrics,
38+
get_metrics_from_metadata(),
4639
check_submission_type=True,
47-
check_symmetric_inclusion=True,
40+
check_symmetric_inclusion=not is_process_e2e,
4841
)
4942

5043

5144
@pytest.mark.e2e
52-
def test_e2e_discovery_all_candidates(dd_agent_check, is_process_e2e):
53-
if is_process_e2e:
54-
pytest.skip('all-candidates test requires Docker network metadata unavailable with host networking')
45+
@pytest.mark.not_process_e2e
46+
def test_e2e_discovery_all_candidates(dd_agent_check):
5547
assert_all_discovery_candidates_stable(dd_agent_check, KrakendCheck)
56-
57-
58-
@pytest.mark.e2e
59-
def test_e2e_process_discovery(dd_agent_check_discovery, is_process_e2e):
60-
if not is_process_e2e:
61-
pytest.skip('process discovery test only runs in the e2e-process environment')
62-
63-
aggregator = dd_agent_check_discovery(check_rate=True, discovery_timeout=90)
64-
65-
metadata_metrics = get_metrics_from_metadata()
66-
67-
aggregator.assert_metrics_using_metadata(
68-
metadata_metrics,
69-
check_submission_type=True,
70-
)

0 commit comments

Comments
 (0)