Skip to content

Commit

Permalink
NET0220
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Sep 8, 2023
1 parent c8a1a79 commit 437e27f
Show file tree
Hide file tree
Showing 21 changed files with 375 additions and 44 deletions.
15 changes: 10 additions & 5 deletions monitoring/monitorlib/fetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ def describe_query(
resp: requests.Response,
initiated_at: datetime.datetime,
query_type: Optional[QueryType] = None,
server_id: Optional[str] = None,
) -> Query:
result = Query(
return Query(
request=describe_request(resp.request, initiated_at),
response=describe_response(resp),
server_id=server_id,
query_type=query_type,
)
if query_type is not None:
result.query_type = query_type
return result


def query_and_describe(
Expand Down Expand Up @@ -296,6 +296,7 @@ def query_and_describe(
else:
utm_session = True
req_kwargs = kwargs.copy()
req_kwargs.pop("server_id", None)
if "timeout" not in req_kwargs:
req_kwargs["timeout"] = TIMEOUTS

Expand All @@ -307,7 +308,10 @@ def query_and_describe(
t0 = datetime.datetime.utcnow()
try:
return describe_query(
client.request(verb, url, **req_kwargs), t0, query_type
client.request(verb, url, **req_kwargs),
t0,
query_type=query_type,
server_id=kwargs.get("server_id", None),
)
except (requests.Timeout, urllib3.exceptions.ReadTimeoutError) as e:
failure_message = f"query_and_describe attempt {attempt + 1} from PID {os.getpid()} to {verb} {url} failed with timeout {type(e).__name__}: {str(e)}"
Expand Down Expand Up @@ -337,6 +341,7 @@ def query_and_describe(
elapsed_s=(t1 - t0).total_seconds(),
reported=StringBasedDateTime(t1),
),
server_id=kwargs.get("server_id", None),
)
if query_type is not None:
result.query_type = query_type
Expand Down
89 changes: 75 additions & 14 deletions monitoring/monitorlib/fetch/rid.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ def query_flights(
session: UTMClientSession,
area: s2sphere.LatLngRect,
include_recent_positions: bool = True,
server_id: Optional[str] = None,
) -> FetchedUSSFlights:
return uss_flights(
self.flights_url, area, include_recent_positions, self.rid_version, session
self.flights_url,
area,
include_recent_positions,
self.rid_version,
session,
server_id=server_id,
)


Expand Down Expand Up @@ -534,21 +540,30 @@ def isa(
rid_version: RIDVersion,
session: UTMClientSession,
dss_base_url: str = "",
server_id: Optional[str] = None,
) -> FetchedISA:
if rid_version == RIDVersion.f3411_19:
op = v19.api.OPERATIONS[v19.api.OperationID.GetIdentificationServiceArea]
url = f"{dss_base_url}{op.path}".replace("{id}", isa_id)
return FetchedISA(
v19_query=fetch.query_and_describe(
session, op.verb, url, scope=v19.constants.Scope.Read
session,
op.verb,
url,
scope=v19.constants.Scope.Read,
server_id=server_id,
)
)
elif rid_version == RIDVersion.f3411_22a:
op = v22a.api.OPERATIONS[v22a.api.OperationID.GetIdentificationServiceArea]
url = f"{dss_base_url}{op.path}".replace("{id}", isa_id)
return FetchedISA(
v22a_query=fetch.query_and_describe(
session, op.verb, url, scope=v22a.constants.Scope.DisplayProvider
session,
op.verb,
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
)
)
else:
Expand Down Expand Up @@ -660,6 +675,7 @@ def isas(
rid_version: RIDVersion,
session: UTMClientSession,
dss_base_url: str = "",
server_id: Optional[str] = None,
) -> FetchedISAs:
t0 = rid_version.format_time(start_time)
t1 = rid_version.format_time(end_time)
Expand All @@ -669,7 +685,11 @@ def isas(
url = f"{dss_base_url}{op.path}?area={area}&earliest_time={t0}&latest_time={t1}"
return FetchedISAs(
v19_query=fetch.query_and_describe(
session, op.verb, url, scope=v19.constants.Scope.Read
session,
op.verb,
url,
scope=v19.constants.Scope.Read,
server_id=server_id,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -678,7 +698,11 @@ def isas(
url = f"{dss_base_url}{op.path}?area={area}&earliest_time={t0}&latest_time={t1}"
return FetchedISAs(
v22a_query=fetch.query_and_describe(
session, op.verb, url, scope=v22a.constants.Scope.DisplayProvider
session,
op.verb,
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
)
)
else:
Expand Down Expand Up @@ -755,6 +779,7 @@ def uss_flights(
include_recent_positions: bool,
rid_version: RIDVersion,
session: UTMClientSession,
server_id: Optional[str] = None,
) -> FetchedUSSFlights:
if rid_version == RIDVersion.f3411_19:
query = fetch.query_and_describe(
Expand All @@ -773,6 +798,7 @@ def uss_flights(
else "false",
},
scope=v19.constants.Scope.Read,
server_id=server_id,
)
query.query_type = QueryType.F3411v19Flights
return FetchedUSSFlights(v19_query=query)
Expand All @@ -793,6 +819,7 @@ def uss_flights(
flights_url,
params=params,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
)
query.query_type = QueryType.F3411v22aFlights
return FetchedUSSFlights(v22a_query=query)
Expand Down Expand Up @@ -879,10 +906,11 @@ def flight_details(
enhanced_details: bool,
rid_version: RIDVersion,
session: UTMClientSession,
server_id: Optional[str] = None,
) -> FetchedUSSFlightDetails:
url = f"{flights_url}/{flight_id}/details"
if rid_version == RIDVersion.f3411_19:
kwargs = {}
kwargs = {"server_id": server_id}
if enhanced_details:
kwargs["params"] = {"enhanced": "true"}
kwargs["scope"] = (
Expand All @@ -894,7 +922,11 @@ def flight_details(
return FetchedUSSFlightDetails(v19_query=query)
elif rid_version == RIDVersion.f3411_22a:
query = fetch.query_and_describe(
session, "GET", url, scope=v22a.constants.Scope.DisplayProvider
session,
"GET",
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
)
return FetchedUSSFlightDetails(v22a_query=query)
else:
Expand Down Expand Up @@ -946,22 +978,33 @@ def all_flights(
session: UTMClientSession,
dss_base_url: str = "",
enhanced_details: bool = False,
server_id: Optional[str] = None,
) -> FetchedFlights:
t = datetime.datetime.utcnow()
isa_list = isas(area, t, t, rid_version, session, dss_base_url)
isa_list = isas(area, t, t, rid_version, session, dss_base_url, server_id=server_id)

uss_flight_queries: Dict[str, FetchedUSSFlights] = {}
uss_flight_details_queries: Dict[str, FetchedUSSFlightDetails] = {}
for flights_url in isa_list.flights_urls:
flights_for_url = uss_flights(
flights_url, area, include_recent_positions, rid_version, session
flights_url,
area,
include_recent_positions,
rid_version,
session,
server_id=server_id,
)
uss_flight_queries[flights_url] = flights_for_url

if get_details and flights_for_url.success:
for flight in flights_for_url.flights:
details = flight_details(
flights_url, flight.id, enhanced_details, rid_version, session
flights_url,
flight.id,
enhanced_details,
rid_version,
session,
server_id=server_id,
)
uss_flight_details_queries[flight.id] = details

Expand Down Expand Up @@ -1039,21 +1082,30 @@ def subscription(
rid_version: RIDVersion,
session: UTMClientSession,
dss_base_url: str = "",
server_id: Optional[str] = None,
) -> FetchedSubscription:
if rid_version == RIDVersion.f3411_19:
op = v19.api.OPERATIONS[v19.api.OperationID.GetSubscription]
url = f"{dss_base_url}{op.path}".replace("{id}", subscription_id)
return FetchedSubscription(
v19_query=fetch.query_and_describe(
session, op.verb, url, scope=v19.constants.Scope.Read
session,
op.verb,
url,
scope=v19.constants.Scope.Read,
server_id=server_id,
)
)
elif rid_version == RIDVersion.f3411_22a:
op = v22a.api.OPERATIONS[v22a.api.OperationID.GetSubscription]
url = f"{dss_base_url}{op.path}".replace("{id}", subscription_id)
return FetchedSubscription(
v22a_query=fetch.query_and_describe(
session, op.verb, url, scope=v22a.constants.Scope.DisplayProvider
session,
op.verb,
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
)
)
else:
Expand Down Expand Up @@ -1137,21 +1189,30 @@ def subscriptions(
rid_version: RIDVersion,
session: UTMClientSession,
dss_base_url: str = "",
server_id: Optional[str] = None,
) -> FetchedSubscriptions:
if rid_version == RIDVersion.f3411_19:
op = v19.api.OPERATIONS[v19.api.OperationID.SearchSubscriptions]
url = f"{dss_base_url}{op.path}?area={rid_v1.geo_polygon_string_from_s2(area)}"
return FetchedSubscriptions(
v19_query=fetch.query_and_describe(
session, op.verb, url, scope=v19.constants.Scope.Read
session,
op.verb,
url,
scope=v19.constants.Scope.Read,
server_id=server_id,
)
)
elif rid_version == RIDVersion.f3411_22a:
op = v22a.api.OPERATIONS[v22a.api.OperationID.SearchSubscriptions]
url = f"{dss_base_url}{op.path}?area={rid_v2.geo_polygon_string_from_s2(area)}"
return FetchedSubscriptions(
v22a_query=fetch.query_and_describe(
session, op.verb, url, scope=v22a.constants.Scope.DisplayProvider
session,
op.verb,
url,
scope=v22a.constants.Scope.DisplayProvider,
server_id=server_id,
)
)
else:
Expand Down
Loading

0 comments on commit 437e27f

Please sign in to comment.