Skip to content

Commit 2f0e383

Browse files
Merge branch 'master' into fix-invitation-url
2 parents a870379 + f28db63 commit 2f0e383

File tree

21 files changed

+424
-345
lines changed

21 files changed

+424
-345
lines changed

packages/service-library/requirements/_base.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ repro-zipfile
3030
tenacity
3131
toolz
3232
tqdm
33+
yarl

packages/service-library/requirements/_base.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ wrapt==1.16.0
274274
# opentelemetry-instrumentation-redis
275275
yarl==1.12.1
276276
# via
277+
# -r requirements/_base.in
277278
# aio-pika
278279
# aiohttp
279280
# aiormq

packages/service-library/src/servicelib/aiohttp/tracing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from opentelemetry.sdk.trace.export import BatchSpanProcessor
2121
from servicelib.logging_utils import log_context
2222
from settings_library.tracing import TracingSettings
23+
from yarl import URL
2324

2425
_logger = logging.getLogger(__name__)
2526
try:
@@ -54,7 +55,7 @@ def setup_tracing(
5455
"""
5556
_ = app
5657
opentelemetry_collector_endpoint = (
57-
tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT
58+
f"{tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT}"
5859
)
5960
opentelemetry_collector_port = tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_PORT
6061
if not opentelemetry_collector_endpoint and not opentelemetry_collector_port:
@@ -72,9 +73,8 @@ def setup_tracing(
7273
resource = Resource(attributes={"service.name": service_name})
7374
trace.set_tracer_provider(TracerProvider(resource=resource))
7475
tracer_provider: trace.TracerProvider = trace.get_tracer_provider()
75-
tracing_destination: str = (
76-
f"{opentelemetry_collector_endpoint}:{opentelemetry_collector_port}/v1/traces"
77-
)
76+
77+
tracing_destination: str = f"{URL(opentelemetry_collector_endpoint).with_port(opentelemetry_collector_port).with_path('/v1/traces')}"
7878

7979
_logger.info(
8080
"Trying to connect service %s to tracing collector at %s.",

packages/service-library/src/servicelib/fastapi/tracing.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from opentelemetry.sdk.trace.export import BatchSpanProcessor
1818
from servicelib.logging_utils import log_context
1919
from settings_library.tracing import TracingSettings
20+
from yarl import URL
2021

2122
_logger = logging.getLogger(__name__)
2223

@@ -75,7 +76,13 @@ def setup_tracing(
7576
trace.set_tracer_provider(TracerProvider(resource=resource))
7677
global_tracer_provider = trace.get_tracer_provider()
7778
assert isinstance(global_tracer_provider, TracerProvider) # nosec
78-
tracing_destination: str = f"{tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT}:{tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_PORT}/v1/traces"
79+
80+
opentelemetry_collector_endpoint: str = (
81+
f"{tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT}"
82+
)
83+
84+
tracing_destination: str = f"{URL(opentelemetry_collector_endpoint).with_port(tracing_settings.TRACING_OPENTELEMETRY_COLLECTOR_PORT).with_path('/v1/traces')}"
85+
7986
_logger.info(
8087
"Trying to connect service %s to opentelemetry tracing collector at %s.",
8188
service_name,

packages/settings-library/src/settings_library/docker_registry.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
from functools import cached_property
2-
from typing import Any
2+
from typing import Any, Self
33

4-
from pydantic import Field, SecretStr, field_validator
4+
from pydantic import (
5+
AnyHttpUrl,
6+
Field,
7+
SecretStr,
8+
TypeAdapter,
9+
field_validator,
10+
model_validator,
11+
)
512
from pydantic_settings import SettingsConfigDict
613

714
from .base import BaseCustomSettings
@@ -12,31 +19,49 @@ class RegistrySettings(BaseCustomSettings):
1219
REGISTRY_PATH: str | None = Field(
1320
default=None,
1421
# This is useful in case of a local registry, where the registry url (path) is relative to the host docker engine"
15-
description="development mode only, in case a local registry is used",
22+
description="development mode only, in case a local registry is used - "
23+
"this is the hostname to the docker registry as seen from the host running the containers (e.g. 127.0.0.1:5000)",
1624
)
1725
# NOTE: name is missleading, http or https protocol are not included
18-
REGISTRY_URL: str = Field(default="", description="address to the docker registry")
26+
REGISTRY_URL: str = Field(
27+
...,
28+
description="hostname of docker registry (without protocol but with port if available)",
29+
min_length=1,
30+
)
1931

2032
REGISTRY_USER: str = Field(
2133
..., description="username to access the docker registry"
2234
)
2335
REGISTRY_PW: SecretStr = Field(
2436
..., description="password to access the docker registry"
2537
)
26-
REGISTRY_SSL: bool = Field(..., description="access to registry through ssl")
38+
REGISTRY_SSL: bool = Field(
39+
..., description="True if docker registry is using HTTPS protocol"
40+
)
2741

2842
@field_validator("REGISTRY_PATH", mode="before")
2943
@classmethod
3044
def _escape_none_string(cls, v) -> Any | None:
3145
return None if v == "None" else v
3246

47+
@model_validator(mode="after")
48+
def check_registry_authentication(self: Self) -> Self:
49+
if self.REGISTRY_AUTH and any(
50+
not v for v in (self.REGISTRY_USER, self.REGISTRY_PW)
51+
):
52+
msg = "If REGISTRY_AUTH is True, both REGISTRY_USER and REGISTRY_PW must be provided"
53+
raise ValueError(msg)
54+
return self
55+
3356
@cached_property
3457
def resolved_registry_url(self) -> str:
3558
return self.REGISTRY_PATH or self.REGISTRY_URL
3659

3760
@cached_property
38-
def api_url(self) -> str:
39-
return f"{self.REGISTRY_URL}/v2"
61+
def api_url(self) -> AnyHttpUrl:
62+
return TypeAdapter(AnyHttpUrl).validate_python(
63+
f"http{'s' if self.REGISTRY_SSL else ''}://{self.REGISTRY_URL}/v2"
64+
)
4065

4166
model_config = SettingsConfigDict(
4267
json_schema_extra={

packages/settings-library/tests/test_docker_registry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"REGISTRY_USER": "usr",
1212
"REGISTRY_PW": "pwd",
1313
"REGISTRY_SSL": "False",
14+
"REGISTRY_URL": "pytest.registry.com",
1415
}
1516

1617

services/director-v2/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def mock_env(
186186
"REGISTRY_PW": "test",
187187
"REGISTRY_SSL": "false",
188188
"REGISTRY_USER": "test",
189+
"REGISTRY_URL": faker.url(),
189190
"SC_BOOT_MODE": "production",
190191
"SIMCORE_SERVICES_NETWORK_NAME": "test_network_name",
191192
"SWARM_STACK_NAME": "pytest-simcore",

services/director/requirements/_base.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
aiocache
1616
aiodocker
1717
fastapi[all]
18-
httpx
18+
httpx[http2]
1919
prometheus-client
2020
pydantic
21+
tenacity

services/director/requirements/_base.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ h11==0.14.0
114114
# via
115115
# httpcore
116116
# uvicorn
117+
h2==4.1.0
118+
# via httpx
119+
hpack==4.0.0
120+
# via h2
117121
httpcore==1.0.6
118122
# via httpx
119123
httptools==0.6.4
@@ -135,6 +139,8 @@ httpx==0.27.2
135139
# -r requirements/../../../packages/service-library/requirements/_fastapi.in
136140
# -r requirements/_base.in
137141
# fastapi
142+
hyperframe==6.0.1
143+
# via h2
138144
idna==3.10
139145
# via
140146
# anyio
@@ -422,7 +428,9 @@ starlette==0.41.3
422428
# -c requirements/../../../requirements/constraints.txt
423429
# fastapi
424430
tenacity==9.0.0
425-
# via -r requirements/../../../packages/service-library/requirements/_base.in
431+
# via
432+
# -r requirements/../../../packages/service-library/requirements/_base.in
433+
# -r requirements/_base.in
426434
toolz==1.0.0
427435
# via -r requirements/../../../packages/service-library/requirements/_base.in
428436
tqdm==4.67.0

services/director/requirements/_test.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ faker
1616
jsonref
1717
pytest
1818
pytest-asyncio
19+
pytest-benchmark
1920
pytest-cov
2021
pytest-docker
2122
pytest-instafail

0 commit comments

Comments
 (0)