Skip to content

Commit 0e00ee8

Browse files
GitHKAndrei Neagu
andauthored
✨Ui will now receive logs from dynamic-services (ITISFoundation#2602)
* added rabbitmq * first draft for logs fetching * interface cahanged * refacted setup * changed entire interface and setup * added typing * fixing testsuite * reverting to older settings scheme * added rabbit env vars * first iteraction of log fecthing * new log format * refactor log format * fixing director-v2 tests * using proper log format * not sending twice * updated logging message * added rabbitmq tests * @pcrespov refactor logging module usage * added more tests * cleanup container after test * fixed test * removed dataclass * finished settings refactor * reverted back * fxied tests * removing test * better name for the channel * enabling logs only for flaky test * fixed test * removed traces of old impelemtation for settings * refacrtor rabbitmq to not be setup by the docker_logs module * refactor internals to make is simpler to use * using queues to dispatch messages at a interval * refactored test * refactor code * sending logs to the UI from dynamic-sidecar * fix pylint issues * refactored dy-sidecar env vars * fix test * fixing message * changed level of logs * no need to relog messages * rename * removed rabbit settings * renamed and removed thins which are not strictly required * fixing timeout and method * using fstrings * fixes after merge * refactor env vars assembly * fixing broken test * using monkeypatch * fix fixture definition * fixed test * replacing docker IP with get_ip * using get_ip * fix import order * swapped json serializer * no need for these * fix unit tests * downgrading to debug * fixed an issue when zipping * reducing log noise * putting [sidecar] in front of logs * fix test * update help * minor fixes * replacing mocking objects * refactor test * fix pylint * refactor no longer blocks * added registry availablity check * fix failing test, reduced timeout Co-authored-by: Andrei Neagu <[email protected]>
1 parent 21a15b3 commit 0e00ee8

33 files changed

+1018
-211
lines changed

ci/github/integration-testing/director-v2.bash

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ test() {
2323
echo "testing in services/director-v2/tests/integration/$1"
2424
pytest --cov=simcore_service_director_v2 --durations=10 --cov-append \
2525
--color=yes --cov-report=term-missing --cov-report=xml --cov-config=.coveragerc \
26-
-vvv \
27-
-v -m "not travis" "services/director-v2/tests/integration/$1"
26+
-v -m "not travis" "services/director-v2/tests/integration/$1" --log-level=DEBUG
2827
}
2928

3029
clean_up() {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
from .proxy import get_dynamic_proxy_spec
12
from .settings import (
23
MATCH_SERVICE_VERSION,
34
MATCH_SIMCORE_REGISTRY,
45
inject_settings_to_create_service_params,
56
merge_settings_before_use,
67
)
7-
from .spec_dynamic_sidecar import (
8+
from .sidecar import (
89
extract_service_port_from_compose_start_spec,
910
get_dynamic_sidecar_spec,
1011
)
11-
from .spec_proxy import get_dynamic_proxy_spec
Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import json
21
import logging
32
from pathlib import Path
43
from typing import Any, Dict
54

65
from models_library.service_settings_labels import SimcoreServiceSettingsLabel
7-
from settings_library.docker_registry import RegistrySettings
6+
from servicelib.json_serialization import json_dumps
87

98
from ....core.settings import AppSettings, DynamicSidecarSettings
109
from ....models.schemas.constants import DYNAMIC_SIDECAR_SERVICE_PREFIX
1110
from ....models.schemas.dynamic_services import SchedulerData, ServiceType
12-
from ....utils.registry import get_dynamic_sidecar_env_vars
1311
from ..volumes_resolver import DynamicSidecarVolumesPathsResolver
1412
from .settings import inject_settings_to_create_service_params
1513

@@ -22,13 +20,17 @@ def extract_service_port_from_compose_start_spec(
2220
return create_service_params["labels"]["service_port"]
2321

2422

25-
def _get_dy_sidecar_env_vars(
26-
scheduler_data: SchedulerData, app_settings: AppSettings
23+
def _get_environment_variables(
24+
compose_namespace: str, scheduler_data: SchedulerData, app_settings: AppSettings
2725
) -> Dict[str, str]:
26+
registry_settings = app_settings.DIRECTOR_V2_DOCKER_REGISTRY
27+
rabbit_settings = app_settings.CELERY.CELERY_RABBIT
2828
return {
29+
"SIMCORE_HOST_NAME": scheduler_data.service_name,
30+
"DYNAMIC_SIDECAR_COMPOSE_NAMESPACE": compose_namespace,
2931
"DY_SIDECAR_PATH_INPUTS": f"{scheduler_data.paths_mapping.inputs_path}",
3032
"DY_SIDECAR_PATH_OUTPUTS": f"{scheduler_data.paths_mapping.outputs_path}",
31-
"DY_SIDECAR_STATE_PATHS": json.dumps(
33+
"DY_SIDECAR_STATE_PATHS": json_dumps(
3234
[f"{x}" for x in scheduler_data.paths_mapping.state_paths]
3335
),
3436
"DY_SIDECAR_USER_ID": f"{scheduler_data.user_id}",
@@ -41,12 +43,22 @@ def _get_dy_sidecar_env_vars(
4143
"POSTGRES_USER": f"{app_settings.POSTGRES.POSTGRES_USER}",
4244
"POSTGRES_DB": f"{app_settings.POSTGRES.POSTGRES_DB}",
4345
"STORAGE_ENDPOINT": app_settings.STORAGE_ENDPOINT,
46+
"REGISTRY_AUTH": f"{registry_settings.REGISTRY_AUTH}",
47+
"REGISTRY_PATH": f"{registry_settings.REGISTRY_PATH}",
48+
"REGISTRY_URL": f"{registry_settings.REGISTRY_URL}",
49+
"REGISTRY_USER": f"{registry_settings.REGISTRY_USER}",
50+
"REGISTRY_PW": f"{registry_settings.REGISTRY_PW.get_secret_value()}",
51+
"REGISTRY_SSL": f"{registry_settings.REGISTRY_SSL}",
52+
"RABBIT_HOST": f"{rabbit_settings.RABBIT_HOST}",
53+
"RABBIT_PORT": f"{rabbit_settings.RABBIT_PORT}",
54+
"RABBIT_USER": f"{rabbit_settings.RABBIT_USER}",
55+
"RABBIT_PASSWORD": f"{rabbit_settings.RABBIT_PASSWORD.get_secret_value()}",
56+
"RABBIT_CHANNELS": json_dumps(rabbit_settings.RABBIT_CHANNELS),
4457
}
4558

4659

4760
async def get_dynamic_sidecar_spec(
4861
scheduler_data: SchedulerData,
49-
docker_registry_settings: RegistrySettings,
5062
dynamic_sidecar_settings: DynamicSidecarSettings,
5163
dynamic_sidecar_network_id: str,
5264
swarm_network_id: str,
@@ -156,19 +168,16 @@ async def get_dynamic_sidecar_spec(
156168
"service_key": scheduler_data.key,
157169
"service_tag": scheduler_data.version,
158170
"paths_mapping": scheduler_data.paths_mapping.json(),
159-
"compose_spec": json.dumps(scheduler_data.compose_spec),
171+
"compose_spec": json_dumps(scheduler_data.compose_spec),
160172
"container_http_entry": scheduler_data.container_http_entry,
161173
},
162174
"name": scheduler_data.service_name,
163175
"networks": [swarm_network_id, dynamic_sidecar_network_id],
164176
"task_template": {
165177
"ContainerSpec": {
166-
"Env": {
167-
"SIMCORE_HOST_NAME": scheduler_data.service_name,
168-
"DYNAMIC_SIDECAR_COMPOSE_NAMESPACE": compose_namespace,
169-
**get_dynamic_sidecar_env_vars(docker_registry_settings),
170-
**_get_dy_sidecar_env_vars(scheduler_data, app_settings),
171-
},
178+
"Env": _get_environment_variables(
179+
compose_namespace, scheduler_data, app_settings
180+
),
172181
"Hosts": [],
173182
"Image": dynamic_sidecar_settings.DYNAMIC_SIDECAR_IMAGE,
174183
"Init": True,

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/scheduler/events.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from tenacity.before_sleep import before_sleep_log
1212
from tenacity.stop import stop_after_delay
1313
from tenacity.wait import wait_exponential, wait_fixed
14-
from settings_library.docker_registry import RegistrySettings
1514

1615
from ....core.settings import DynamicSidecarSettings
1716
from ....models.schemas.dynamic_services import (
@@ -84,9 +83,6 @@ async def will_trigger(cls, app: FastAPI, scheduler_data: SchedulerData) -> bool
8483

8584
@classmethod
8685
async def action(cls, app: FastAPI, scheduler_data: SchedulerData) -> None:
87-
docker_registry_settings: RegistrySettings = (
88-
app.state.settings.DIRECTOR_V2_DOCKER_REGISTRY
89-
)
9086
dynamic_sidecar_settings: DynamicSidecarSettings = (
9187
app.state.settings.DYNAMIC_SERVICES.DYNAMIC_SIDECAR
9288
)
@@ -125,7 +121,6 @@ async def action(cls, app: FastAPI, scheduler_data: SchedulerData) -> None:
125121
# start dynamic-sidecar and run the proxy on the same node
126122
dynamic_sidecar_create_service_params = await get_dynamic_sidecar_spec(
127123
scheduler_data=scheduler_data,
128-
docker_registry_settings=docker_registry_settings,
129124
dynamic_sidecar_settings=dynamic_sidecar_settings,
130125
dynamic_sidecar_network_id=dynamic_sidecar_network_id,
131126
swarm_network_id=swarm_network_id,

services/director-v2/src/simcore_service_director_v2/utils/registry.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

services/director-v2/tests/integration/02/test__dynamic_sidecar_nodeports_integration.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import httpx
3131
import pytest
3232
import sqlalchemy as sa
33+
from _pytest.monkeypatch import MonkeyPatch
3334
from aiodocker.containers import DockerContainer
3435
from asgi_lifespan import LifespanManager
3536
from fastapi import FastAPI
@@ -40,6 +41,7 @@
4041
from models_library.settings.redis import RedisConfig
4142
from py._path.local import LocalPath
4243
from pytest_mock.plugin import MockerFixture
44+
from pytest_simcore.helpers.utils_docker import get_ip
4345
from shared_comp_utils import (
4446
assert_computation_task_out_obj,
4547
assert_pipeline_status,
@@ -237,7 +239,7 @@ async def db_manager(postgres_dsn: Dict[str, str]) -> AsyncIterable[DBManager]:
237239

238240
@pytest.fixture
239241
async def fast_api_app(
240-
minimal_configuration: None, network_name: str, monkeypatch
242+
minimal_configuration: None, network_name: str, monkeypatch: MonkeyPatch
241243
) -> FastAPI:
242244
# Works as below line in docker.compose.yml
243245
# ${DOCKER_REGISTRY:-itisfoundation}/dynamic-sidecar:${DOCKER_IMAGE_TAG:-latest}
@@ -261,6 +263,10 @@ async def fast_api_app(
261263
monkeypatch.setenv("DIRECTOR_V2_CELERY_SCHEDULER_ENABLED", "false")
262264
monkeypatch.setenv("DYNAMIC_SIDECAR_TRAEFIK_ACCESS_LOG", "true")
263265
monkeypatch.setenv("DYNAMIC_SIDECAR_TRAEFIK_LOGLEVEL", "debug")
266+
# patch host for dynamic-sidecar, not reachable via localhost
267+
# the dynamic-sidecar (running inside a container) will use
268+
# this address to reach the rabbit service
269+
monkeypatch.setenv("RABBIT_HOST", f"{get_ip()}")
264270

265271
settings = AppSettings.create_from_envs()
266272

services/director-v2/tests/integration/02/test_dynamic_services_routes.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33

44
import asyncio
55
import logging
6-
from typing import Any, Dict
6+
from typing import Any, AsyncIterable, Dict
77
from uuid import uuid4
88

99
import aiodocker
1010
import pytest
1111
from async_asgi_testclient import TestClient
1212
from async_asgi_testclient.response import Response
1313
from async_timeout import timeout
14+
from models_library.settings.rabbit import RabbitConfig
1415
from pydantic import PositiveInt
1516
from pytest_mock.plugin import MockerFixture
17+
from pytest_simcore.helpers.utils_docker import get_ip
1618
from simcore_service_director_v2.core.application import init_app
1719
from simcore_service_director_v2.core.settings import AppSettings
1820
from utils import ensure_network_cleanup, patch_dynamic_service_url
@@ -21,13 +23,17 @@
2123

2224
logger = logging.getLogger(__name__)
2325

24-
pytest_simcore_core_services_selection = ["director"]
26+
pytest_simcore_core_services_selection = [
27+
"director",
28+
"rabbit",
29+
]
2530

2631

2732
@pytest.fixture
2833
def minimal_configuration(
2934
dy_static_file_server_dynamic_sidecar_service: Dict,
3035
simcore_services_ready: None,
36+
rabbit_service: RabbitConfig,
3137
):
3238
pass
3339

@@ -76,7 +82,7 @@ async def test_client(
7682
mock_env: None,
7783
network_name: str,
7884
monkeypatch,
79-
) -> TestClient:
85+
) -> AsyncIterable[TestClient]:
8086
monkeypatch.setenv("SC_BOOT_MODE", "production")
8187
monkeypatch.setenv("DYNAMIC_SIDECAR_EXPOSE_PORT", "true")
8288
monkeypatch.setenv("SIMCORE_SERVICES_NETWORK_NAME", network_name)
@@ -92,6 +98,11 @@ async def test_client(
9298
monkeypatch.setenv("POSTGRES_DB", "mocked_db")
9399
monkeypatch.setenv("DIRECTOR_V2_POSTGRES_ENABLED", "false")
94100

101+
# patch host for dynamic-sidecar, not reachable via localhost
102+
# the dynamic-sidecar (running inside a container) will use
103+
# this address to reach the rabbit service
104+
monkeypatch.setenv("RABBIT_HOST", f"{get_ip()}")
105+
95106
settings = AppSettings.create_from_envs()
96107

97108
app = init_app(settings)

services/director-v2/tests/integration/02/test_mixed_dynamic_sidecar_and_legacy_project.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from models_library.projects import ProjectAtDB
1717
from models_library.settings.rabbit import RabbitConfig
1818
from models_library.settings.redis import RedisConfig
19+
from pytest_simcore.helpers.utils_docker import get_ip
1920
from simcore_sdk.node_ports_common import config as node_ports_config
2021
from simcore_service_director_v2.core.application import init_app
2122
from simcore_service_director_v2.core.settings import AppSettings
@@ -155,6 +156,10 @@ async def director_v2_client(
155156
monkeypatch.setenv("POSTGRES_PASSWORD", "mocked_password")
156157
monkeypatch.setenv("POSTGRES_DB", "mocked_db")
157158
monkeypatch.setenv("DIRECTOR_V2_POSTGRES_ENABLED", "false")
159+
# patch host for dynamic-sidecar, not reachable via localhost
160+
# the dynamic-sidecar (running inside a container) will use
161+
# this address to reach the rabbit service
162+
monkeypatch.setenv("RABBIT_HOST", f"{get_ip()}")
158163

159164
settings = AppSettings.create_from_envs()
160165

services/director-v2/tests/integration/02/utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from fastapi import FastAPI
1212
from models_library.projects import Node
1313
from pydantic import PositiveInt
14+
from pytest_simcore.helpers.utils_docker import get_ip
1415
from simcore_service_director_v2.models.schemas.constants import (
1516
DYNAMIC_PROXY_SERVICE_PREFIX,
1617
DYNAMIC_SIDECAR_SERVICE_PREFIX,
@@ -23,7 +24,7 @@
2324
from tenacity.wait import wait_fixed
2425

2526
SERVICE_WAS_CREATED_BY_DIRECTOR_V2 = 20
26-
SERVICES_ARE_READY_TIMEOUT = 10 * 60
27+
SERVICES_ARE_READY_TIMEOUT = 2 * 60
2728
SEPARATOR = "=" * 50
2829

2930

@@ -57,7 +58,7 @@ async def patch_dynamic_service_url(app: FastAPI, node_uuid: str) -> str:
5758
Normally director-v2 talks via docker-netwoks with the dynamic-sidecar.
5859
Since the director-v2 was started outside docker and is not
5960
running in a container, the service port needs to be exposed and the
60-
url needs to be changed to 172.17.0.1 (docker localhost)
61+
url needs to be changed to get_ip()
6162
6263
returns: the local endpoint
6364
"""
@@ -85,11 +86,11 @@ async def patch_dynamic_service_url(app: FastAPI, node_uuid: str) -> str:
8586
async with scheduler._lock: # pylint: disable=protected-access
8687
for entry in scheduler._to_observe.values(): # pylint: disable=protected-access
8788
if entry.scheduler_data.service_name == service_name:
88-
entry.scheduler_data.dynamic_sidecar.hostname = "172.17.0.1"
89+
entry.scheduler_data.dynamic_sidecar.hostname = f"{get_ip()}"
8990
entry.scheduler_data.dynamic_sidecar.port = port
9091

9192
endpoint = entry.scheduler_data.dynamic_sidecar.endpoint
92-
assert endpoint == f"http://172.17.0.1:{port}"
93+
assert endpoint == f"http://{get_ip()}:{port}"
9394
break
9495

9596
assert endpoint is not None
@@ -101,7 +102,7 @@ async def _get_proxy_port(node_uuid: str) -> PositiveInt:
101102
Normally director-v2 talks via docker-netwoks with the started proxy.
102103
Since the director-v2 was started outside docker and is not
103104
running in a container, the service port needs to be exposed and the
104-
url needs to be changed to 172.17.0.1 (docker localhost)
105+
url needs to be changed to get_ip()
105106
106107
returns: the local endpoint
107108
"""
@@ -328,9 +329,9 @@ async def assert_service_is_available( # pylint: disable=redefined-outer-name
328329
exposed_port: PositiveInt, is_legacy: bool, service_uuid: str
329330
) -> None:
330331
service_address = (
331-
f"http://172.17.0.1:{exposed_port}/x/{service_uuid}"
332+
f"http://{get_ip()}:{exposed_port}/x/{service_uuid}"
332333
if is_legacy
333-
else f"http://172.17.0.1:{exposed_port}"
334+
else f"http://{get_ip()}:{exposed_port}"
334335
)
335336
print(f"checking service @ {service_address}")
336337

0 commit comments

Comments
 (0)