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: 4 additions & 0 deletions monitoring/monitorlib/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class UTMClientSession(requests.Session):
If the URL starts with '/', then automatically prefix the URL with the
`prefix_url` specified on construction (this is usually the base URL of the
DSS).

When possible, a UTMClientSession should be reused rather than creating a
new one because an excessive number of UTMClientSessions can exhaust the
number of connections allowed by the system (see #1407).
"""

def __init__(
Expand Down
9 changes: 6 additions & 3 deletions monitoring/uss_qualifier/resources/astm/f3411/dss.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from implicitdict import ImplicitDict

from monitoring.monitorlib import infrastructure
from monitoring.monitorlib.infrastructure import UTMClientSession
from monitoring.monitorlib.rid import RIDVersion
from monitoring.uss_qualifier.reports.report import ParticipantID
from monitoring.uss_qualifier.resources.communications import AuthAdapterResource
Expand Down Expand Up @@ -40,12 +41,12 @@ def __init__(
participant_id: ParticipantID,
base_url: str,
rid_version: RIDVersion,
auth_adapter: infrastructure.AuthAdapter,
client: UTMClientSession,
):
self.participant_id = participant_id
self.base_url = base_url
self.rid_version = rid_version
self.client = infrastructure.UTMClientSession(base_url, auth_adapter)
self.client = client

def is_same_as(self, other: DSSInstance) -> bool:
return (
Expand Down Expand Up @@ -81,7 +82,9 @@ def __init__(
specification.participant_id,
specification.base_url,
specification.rid_version,
auth_adapter.adapter,
infrastructure.UTMClientSession(
specification.base_url, auth_adapter.adapter
),
)

@classmethod
Expand Down
28 changes: 22 additions & 6 deletions monitoring/uss_qualifier/resources/astm/f3548/v21/dss.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
)
from uas_standards.astm.f3548.v21.constants import Scope

from monitoring.monitorlib import infrastructure
from monitoring.monitorlib.fetch import Query, QueryError, QueryType, query_and_describe
from monitoring.monitorlib.fetch import scd as fetch
from monitoring.monitorlib.fetch.scd import FetchedSubscription, FetchedSubscriptions
from monitoring.monitorlib.infrastructure import UTMClientSession
from monitoring.monitorlib.inspection import calling_function_name, fullname
from monitoring.monitorlib.mutate import scd as mutate
from monitoring.monitorlib.mutate.scd import MutatedSubscription
Expand All @@ -65,6 +65,9 @@ class DSSInstanceSpecification(ImplicitDict):
supports_ovn_request: Optional[bool]
"""Whether this DSS instance supports the optional extension not part of the original F3548 standard API allowing a USS to request a specific OVN when creating or updating an operational intent."""

timeout_seconds: Optional[float]
"""If specified, number of seconds to allow before timing out requests to this DSS instance."""

def __init__(self, *args, **kwargs):
super().__init__(**kwargs)
try:
Expand All @@ -77,21 +80,21 @@ class DSSInstance:
participant_id: str
user_participant_ids: list[str]
base_url: str
client: infrastructure.UTMClientSession
client: UTMClientSession
_scopes_authorized: set[str]

def __init__(
self,
participant_id: str,
user_participant_ids: list[str],
base_url: str,
auth_adapter: infrastructure.AuthAdapter,
client: UTMClientSession,
scopes_authorized: list[str],
):
self.participant_id = participant_id
self.user_participant_ids = user_participant_ids
self.base_url = base_url
self.client = infrastructure.UTMClientSession(base_url, auth_adapter)
self.client = client
self._scopes_authorized = set(
s.value if isinstance(s, Enum) else s for s in scopes_authorized
)
Expand Down Expand Up @@ -126,7 +129,11 @@ def with_different_auth(
participant_id=self.participant_id,
user_participant_ids=self.user_participant_ids,
base_url=self.base_url,
auth_adapter=auth_adapter.adapter,
client=UTMClientSession(
self.base_url,
auth_adapter=auth_adapter.adapter,
timeout_seconds=self.client.timeout_seconds,
),
scopes_authorized=list(scopes_required),
)

Expand Down Expand Up @@ -694,6 +701,7 @@ def delete_subscription(self, sub_id: str, sub_version: str) -> MutatedSubscript
class DSSInstanceResource(Resource[DSSInstanceSpecification]):
_specification: DSSInstanceSpecification
_auth_adapter: AuthAdapterResource
_client: UTMClientSession

def __init__(
self,
Expand All @@ -704,6 +712,14 @@ def __init__(
super().__init__(specification, resource_origin)
self._specification = specification
self._auth_adapter = auth_adapter
timeout_seconds = (
specification.timeout_seconds
if "timeout_seconds" in specification
else None
)
self._client = UTMClientSession(
self._specification.base_url, auth_adapter.adapter, timeout_seconds
)

def can_use_scope(self, scope: str) -> bool:
return scope in self._auth_adapter.scopes
Expand Down Expand Up @@ -777,7 +793,7 @@ def get_instance(self, scopes_required: dict[str, str]) -> DSSInstance:
else []
),
self._specification.base_url,
self._auth_adapter.adapter,
self._client,
list(scopes_required),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
"null"
]
},
"timeout_seconds": {
"description": "If specified, number of seconds to allow before timing out requests to this DSS instance.",
"type": [
"number",
"null"
]
},
"user_participant_ids": {
"description": "IDs of any participants using this DSS instance, apart from the USS responsible for this DSS instance.",
"items": {
Expand Down
Loading