Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tracer] Add support for RID v22a #123

Merged
merged 5 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions monitoring/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN rm -rf __pycache__
ADD ./interfaces /app/interfaces
ADD ./monitoring /app/monitoring
COPY ./monitoring/health_check.sh /app/health_check.sh
RUN chmod 766 /app/health_check.sh
barroco marked this conversation as resolved.
Show resolved Hide resolved
WORKDIR /app/monitoring

# Additional preparations for uss_qualifier/webapp
Expand Down
16 changes: 9 additions & 7 deletions monitoring/mock_uss/run_locally_tracer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,26 @@ POLL='--rid-isa-poll-interval=15 --scd-operation-poll-interval=15 --scd-constrai
TRACER_OPTIONS="$AREA $LOGS $MONITOR $POLL"


PORT=${PORT:-8078}
AUTH="DummyOAuth(http://host.docker.internal:8085/token,tracer)"
DSS="http://host.docker.internal:8082"
DSS=${MOCK_USS_DSS_URL:-"http://host.docker.internal:8082"}
PUBLIC_KEY="/var/test-certs/auth2.pem"
AUD=${MOCK_USS_TOKEN_AUDIENCE:-localhost,host.docker.internal}
container_name="mock_uss_tracer"
AUD=${MOCK_USS_TOKEN_AUDIENCE:-host.docker.internal:${PORT}}
mickmis marked this conversation as resolved.
Show resolved Hide resolved
RID_VERSION=${MOCK_USS_RID_VERSION:-"F3411-19"}
CONTAINER_NAME=${MOCK_CONTAINER_NAME:-"mock_uss_tracer"}

PORT=8078
BASE_URL="http://${MOCK_USS_TOKEN_AUDIENCE:-host.docker.internal}:${PORT}"
BASE_URL="http://${AUD:-host.docker.internal}"

if [ "$CI" == "true" ]; then
docker_args="--add-host host.docker.internal:host-gateway" # Required to reach other containers in Ubuntu (used for Github Actions)
else
docker_args="-it"
fi

docker container rm -f ${container_name} || echo "No pre-existing ${container_name} container to remove"
docker container rm -f "${CONTAINER_NAME}" || echo "No pre-existing ${CONTAINER_NAME} container to remove"

# shellcheck disable=SC2086
docker run ${docker_args} --name ${container_name} \
docker run ${docker_args} --name "${CONTAINER_NAME}" \
-u "$(id -u):$(id -g)" \
-e MOCK_USS_AUTH_SPEC="${AUTH}" \
-e MOCK_USS_DSS_URL="${DSS}" \
Expand All @@ -47,6 +48,7 @@ docker run ${docker_args} --name ${container_name} \
-e MOCK_USS_BASE_URL="${BASE_URL}" \
-e MOCK_USS_TRACER_OPTIONS="${TRACER_OPTIONS}" \
-e MOCK_USS_SERVICES="tracer" \
-e MOCK_USS_RID_VERSION="${RID_VERSION}" \
-p ${PORT}:5000 \
-v "${SCRIPT_DIR}/../../build/test-certs:/var/test-certs:ro" \
-v "$(pwd)/$OUTPUT_DIR:/app/monitoring/mock_uss/$OUTPUT_DIR" \
Expand Down
12 changes: 12 additions & 0 deletions monitoring/mock_uss/run_locally_tracer_v22a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then
"${SCRIPT_DIR}/../build.sh" || exit 1
fi

MOCK_CONTAINER_NAME="mock_uss_tracer_v22a" \
MOCK_USS_RID_VERSION="F3411-22a" \
MOCK_USS_DSS_URL="http://host.docker.internal:8082" \
PORT=8088 \
"${SCRIPT_DIR}/run_locally_tracer.sh" "$@"
2 changes: 1 addition & 1 deletion monitoring/mock_uss/templates/tracer/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div>
Tracer:
<a href="{{ url_for('tracer_list_logs') }}">Home</a>
<a href="{{ url_for('tracer_rid_v19_get_rid_poll') }}">RID v19 Flights</a>
<a href="{{ url_for('tracer_rid_get_poll') }}">RID {{ rid_version }} Flights</a>
</div>
<hr>
<div>
Expand Down
2 changes: 1 addition & 1 deletion monitoring/mock_uss/templates/tracer/rid_poll.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "tracer/base.html" %}

{% block content %}
<form action="{{ url_for('tracer_rid_v19_request_rid_poll') }}" method="POST">
<form action="{{ url_for('tracer_rid_request_poll') }}" method="POST">
<p>
<label for="area">Area (lat,lng,lat,lng):</label>
<input type="text" id="area" name="area" size="40">
Expand Down
7 changes: 7 additions & 0 deletions monitoring/mock_uss/tracer/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from monitoring.mock_uss import import_environment_variable, require_config_value
from monitoring.mock_uss.config import KEY_DSS_URL, KEY_BASE_URL
from monitoring.monitorlib.rid import RIDVersion


KEY_TRACER_OPTIONS = "MOCK_USS_TRACER_OPTIONS"
KEY_RID_VERSION = "MOCK_USS_RID_VERSION"

import_environment_variable(KEY_TRACER_OPTIONS)
require_config_value(KEY_DSS_URL)
require_config_value(KEY_BASE_URL)
import_environment_variable(
KEY_RID_VERSION,
default=RIDVersion.f3411_19,
mutator=RIDVersion,
)
35 changes: 24 additions & 11 deletions monitoring/mock_uss/tracer/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TASK_POLL_OPS,
TASK_POLL_CONSTRAINTS,
)
from monitoring.mock_uss.tracer.config import KEY_RID_VERSION
from monitoring.monitorlib import ids, versioning
from monitoring.monitorlib import fetch
import monitoring.monitorlib.fetch.rid
Expand All @@ -30,6 +31,8 @@
RID_SUBSCRIPTION_ID_CODE = "tracer RID Subscription"
SCD_SUBSCRIPTION_ID_CODE = "tracer SCD Subscription"

RID_VERSION = webapp.config[KEY_RID_VERSION]

resources: Optional[ResourceSet] = None


Expand Down Expand Up @@ -106,9 +109,17 @@ def _subscribe(
if base_url.endswith("/"):
base_url = base_url[0:-1]
if monitor_rid:
_subscribe_rid(resources, base_url + "/tracer/f3411v19")
if RID_VERSION == RIDVersion.f3411_19:
_subscribe_rid(resources, base_url + "/tracer/f3411v19")
elif RID_VERSION == RIDVersion.f3411_22a:
_subscribe_rid(resources, base_url + "/tracer/f3411v22a/v2")
else:
raise NotImplementedError(
f"Cannot subscribe to DSS using RID version {RID_VERSION}"
)

if monitor_scd:
_subscribe_scd(resources, base_url)
_subscribe_scd(resources, base_url + "/tracer/f3548v21")


def _unsubscribe(resources: ResourceSet, monitor_rid: bool, monitor_scd: bool) -> None:
Expand All @@ -135,8 +146,8 @@ def _subscribe_rid(resources: ResourceSet, uss_base_url: str) -> None:
end_time=resources.end_time,
uss_base_url=uss_base_url,
subscription_id=_rid_subscription_id(),
rid_version=RIDVersion.f3411_19,
utm_client=resources.dss_client,
rid_version=RID_VERSION,
utm_client=resources.dss_clients["rid"],
)
resources.logger.log_new(RID_SUBSCRIPTION_KEY, create_result)
if not create_result.success:
Expand All @@ -145,7 +156,7 @@ def _subscribe_rid(resources: ResourceSet, uss_base_url: str) -> None:

def _clear_existing_rid_subscription(resources: ResourceSet, suffix: str) -> None:
existing_result = fetch.rid.subscription(
_rid_subscription_id(), RIDVersion.f3411_19, resources.dss_client
_rid_subscription_id(), RID_VERSION, resources.dss_clients["rid"]
)
logfile = resources.logger.log_new(
"{}_{}_get".format(RID_SUBSCRIPTION_KEY, suffix), existing_result
Expand All @@ -159,8 +170,8 @@ def _clear_existing_rid_subscription(resources: ResourceSet, suffix: str) -> Non
del_result = mutate.rid.delete_subscription(
subscription_id=_rid_subscription_id(),
subscription_version=existing_result.subscription.version,
rid_version=RIDVersion.f3411_19,
utm_client=resources.dss_client,
rid_version=RID_VERSION,
utm_client=resources.dss_clients["rid"],
)
logfile = resources.logger.log_new(
"{}_{}_del".format(RID_SUBSCRIPTION_KEY, suffix), del_result
Expand All @@ -183,11 +194,11 @@ def _subscribe_scd(resources: ResourceSet, base_url: str) -> None:
_clear_existing_scd_subscription(resources, "old")

create_result = mutate.scd.put_subscription(
resources.dss_client,
resources.dss_clients["scd"],
resources.area,
resources.start_time,
resources.end_time,
base_url + "/tracer/f3548v21",
base_url,
_scd_subscription_id(),
)
logfile = resources.logger.log_new(SCD_SUBSCRIPTION_KEY, create_result)
Expand All @@ -198,7 +209,9 @@ def _subscribe_scd(resources: ResourceSet, base_url: str) -> None:


def _clear_existing_scd_subscription(resources: ResourceSet, suffix: str) -> None:
get_result = fetch.scd.subscription(resources.dss_client, _scd_subscription_id())
get_result = fetch.scd.subscription(
resources.dss_clients["scd"], _scd_subscription_id()
)
logfile = resources.logger.log_new(
"{}_{}_get".format(SCD_SUBSCRIPTION_KEY, suffix), get_result
)
Expand All @@ -209,7 +222,7 @@ def _clear_existing_scd_subscription(resources: ResourceSet, suffix: str) -> Non

if get_result.subscription is not None:
del_result = mutate.scd.delete_subscription(
resources.dss_client,
resources.dss_clients["scd"],
_scd_subscription_id(),
get_result.subscription.version,
)
Expand Down
12 changes: 7 additions & 5 deletions monitoring/mock_uss/tracer/polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ def indent(s: str, level: int) -> str:
return "\n".join(" " * level + line for line in s.split("\n"))


def poll_rid_isas(resources: ResourceSet, box: s2sphere.LatLngRect) -> Any:
def poll_rid_isas(
resources: ResourceSet, box: s2sphere.LatLngRect, rid_version: RIDVersion
) -> Any:
return fetch.rid.isas(
box,
resources.start_time,
resources.end_time,
RIDVersion.f3411_19,
resources.dss_client,
rid_version,
resources.dss_clients["rid"],
)


Expand All @@ -29,7 +31,7 @@ def poll_scd_operations(resources: ResourceSet) -> Any:
str, fetch.scd.FetchedEntity
] = {}
return fetch.scd.operations(
resources.dss_client,
resources.dss_clients["scd"],
resources.area,
resources.start_time,
resources.end_time,
Expand All @@ -41,7 +43,7 @@ def poll_scd_constraints(resources: ResourceSet) -> Any:
if "constraints" not in resources.scd_cache:
resources.scd_cache["constraints"]: Dict[str, fetch.scd.FetchedEntity] = {}
return fetch.scd.constraints(
resources.dss_client,
resources.dss_clients["scd"],
resources.area,
resources.start_time,
resources.end_time,
Expand Down
30 changes: 23 additions & 7 deletions monitoring/mock_uss/tracer/resources.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import argparse
import datetime
import shlex
from typing import List, Dict

import s2sphere

from monitoring import mock_uss
from monitoring.mock_uss.config import KEY_DSS_URL
from monitoring.mock_uss.tracer.config import KEY_RID_VERSION
from monitoring.monitorlib.rid import RIDVersion
from monitoring.monitorlib import auth, infrastructure, geo
from monitoring.mock_uss import webapp, tracer
import monitoring.mock_uss.tracer.config
from monitoring.mock_uss.tracer import tracerlog


Expand All @@ -25,13 +28,13 @@ class ResourceSet(object):

def __init__(
self,
dss_client: infrastructure.UTMClientSession,
dss_clients: Dict[str, infrastructure.UTMClientSession],
area: s2sphere.LatLngRect,
logger: tracerlog.Logger,
start_time: datetime.datetime,
end_time: datetime.datetime,
):
self.dss_client = dss_client
self.dss_clients = dss_clients
self.area = area
self.logger = logger
self.start_time = start_time
Expand Down Expand Up @@ -102,9 +105,22 @@ def from_arguments(cls, args: argparse.Namespace):
adapter: auth.AuthAdapter = auth.make_auth_adapter(
webapp.config[mock_uss.config.KEY_AUTH_SPEC]
)
dss_client = infrastructure.UTMClientSession(
webapp.config[mock_uss.config.KEY_DSS_URL], adapter
)

if webapp.config[KEY_RID_VERSION] == RIDVersion.f3411_19:
_dss_rid_base_url = webapp.config[KEY_DSS_URL]
elif webapp.config[KEY_RID_VERSION] == RIDVersion.f3411_22a:
_dss_rid_base_url = webapp.config[KEY_DSS_URL] + "/rid/v2"
else:
raise NotImplementedError(
f"Cannot construct DSS base URL using RID version {webapp.config[KEY_RID_VERSION]}"
)
_dss_scd_base_url = webapp.config[KEY_DSS_URL]

dss_clients = {
"rid": infrastructure.UTMClientSession(_dss_rid_base_url, adapter),
"scd": infrastructure.UTMClientSession(_dss_scd_base_url, adapter),
}
barroco marked this conversation as resolved.
Show resolved Hide resolved

area: s2sphere.LatLngRect = geo.make_latlng_rect(args.area)
start_time = datetime.datetime.fromisoformat(args.start_time)
end_time = start_time + datetime.timedelta(hours=args.trace_hours)
Expand All @@ -122,4 +138,4 @@ def from_arguments(cls, args: argparse.Namespace):
if args.output_folder
else None
)
return ResourceSet(dss_client, area, logger, start_time, end_time)
return ResourceSet(dss_clients, area, logger, start_time, end_time)
Loading