Skip to content

Commit

Permalink
Merge remote-tracking branch 'interuss/main' into scd0100
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmis committed Dec 25, 2023
2 parents 8dcd4dc + 4ace256 commit 20f8dbc
Show file tree
Hide file tree
Showing 33 changed files with 235 additions and 210 deletions.
5 changes: 2 additions & 3 deletions monitoring/deployment_manager/actions/test/hello_world.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import time

from monitoring.deployment_manager import deploylib
import monitoring.deployment_manager.deploylib.namespaces
import monitoring.deployment_manager.deploylib.systems
from monitoring.deployment_manager.infrastructure import deployment_action, Context
from monitoring.deployment_manager.systems.test import hello_world
from monitoring.monitorlib.delay import sleep


@deployment_action("test/hello_world/deploy")
Expand Down Expand Up @@ -52,7 +51,7 @@ def destroy(context: Context) -> None:
namespace.metadata.name, context.spec.cluster.name
)
)
time.sleep(15)
sleep(15, "destruction of hello_world system may take a few seconds")

deploylib.systems.delete_resources(
existing_resources, namespace, context.clients, context.log
Expand Down
8 changes: 6 additions & 2 deletions monitoring/mock_uss/flights/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Callable, Optional

from monitoring.mock_uss.flights.database import FlightRecord, db, DEADLOCK_TIMEOUT
from monitoring.monitorlib.delay import sleep


def lock_flight(flight_id: str, log: Callable[[str], None]) -> FlightRecord:
Expand All @@ -25,7 +26,7 @@ def lock_flight(flight_id: str, log: Callable[[str], None]) -> FlightRecord:
break
# We found an existing flight but it was locked; wait for it to become
# available
time.sleep(0.5)
sleep(0.5, f"flight {flight_id} is currently already locked")

if datetime.utcnow() > deadline:
raise RuntimeError(
Expand Down Expand Up @@ -61,7 +62,10 @@ def delete_flight_record(flight_id: str) -> Optional[FlightRecord]:
# No FlightRecord found
return None
# There is a race condition with another handler to create or modify the requested flight; wait for that to resolve
time.sleep(0.5)
sleep(
0.5,
f"flight {flight_id} is currently already locked while we are trying to delete it",
)
if datetime.utcnow() > deadline:
raise RuntimeError(
f"Deadlock in delete_flight while attempting to gain access to flight {flight_id} (now: {datetime.utcnow()}, deadline: {deadline})"
Expand Down
7 changes: 5 additions & 2 deletions monitoring/mock_uss/ridsp/behavior.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from time import sleep
from typing import Optional

from monitoring.monitorlib.delay import sleep
from monitoring.monitorlib.rid_automated_testing.injection_api import TestFlight
from implicitdict import ImplicitDict
from uas_standards.astm.f3411.v19.api import RIDFlight
Expand Down Expand Up @@ -56,6 +56,9 @@ def adjust_reported_flight(
p.position.alt *= FEET_PER_METER

if behavior.delay_flight_report_s > 0:
sleep(behavior.delay_flight_report_s)
sleep(
behavior.delay_flight_report_s,
"specified Service Provider behavior is to delay before reporting flight",
)

return adjusted
27 changes: 27 additions & 0 deletions monitoring/monitorlib/delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from datetime import timedelta
import time
from typing import Union

from loguru import logger


MAX_SILENT_DELAY_S = 0.4
"""Number of seconds to delay above which a reasoning message should be displayed."""


def sleep(duration: Union[float, timedelta], reason: str) -> None:
"""Sleep for the specified amount of time, logging the fact that the delay is occurring (when appropriate).
Args:
duration: Amount of time to sleep for; interpreted as seconds if float.
reason: Reason the delay is happening (to be printed to console/log if appropriate).
"""
if isinstance(duration, timedelta):
duration = duration.total_seconds()
if duration <= 0:
# No need to delay
return

if duration > MAX_SILENT_DELAY_S:
logger.debug(f"Delaying {duration:.1f} seconds because {reason}")
time.sleep(duration)
3 changes: 3 additions & 0 deletions monitoring/monitorlib/fetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ class QueryType(str, Enum):
"interuss.automated_testing.flight_planning.v1.DeleteFlightPlan"
)

def __str__(self):
return self.value

@staticmethod
def flight_details(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
Expand Down
4 changes: 2 additions & 2 deletions monitoring/prober/rid/v1/test_isa_expiry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test ISAs aren't returned after they expire."""

import datetime
import time

from monitoring.monitorlib.delay import sleep
from monitoring.monitorlib.infrastructure import default_scope
from monitoring.monitorlib import rid_v1
from monitoring.prober.infrastructure import register_resource_type
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_valid_immediately(ids, session_ridv1):

def test_sleep_5_seconds():
# But if we wait 5 seconds it will expire...
time.sleep(5)
sleep(5, "if we wait 5 seconds, the ISA of interest will expire")


@default_scope(Scope.Read)
Expand Down
4 changes: 2 additions & 2 deletions monitoring/prober/rid/v2/test_isa_expiry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test ISAs aren't returned after they expire."""

import datetime
import time

from monitoring.monitorlib.delay import sleep
from uas_standards.astm.f3411.v22a.api import OPERATIONS, OperationID
from uas_standards.astm.f3411.v22a.constants import Scope

Expand Down Expand Up @@ -68,7 +68,7 @@ def test_valid_immediately(ids, session_ridv2):

def test_sleep_5_seconds():
# But if we wait 5 seconds it will expire...
time.sleep(5)
sleep(5, "if we wait 5 seconds, the ISA of interest will expire")


@default_scope(Scope.DisplayProvider)
Expand Down
9 changes: 8 additions & 1 deletion monitoring/uss_qualifier/reports/sequence_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
TestScenarioReport,
PassedCheck,
FailedCheck,
Severity,
SkippedActionReport,
ErrorReport,
)
Expand Down Expand Up @@ -150,6 +151,7 @@ def rows(self) -> int:
@dataclass
class TestedParticipant(object):
has_failures: bool = False
has_infos: bool = False
has_successes: bool = False
has_queries: bool = False

Expand Down Expand Up @@ -337,7 +339,10 @@ def append_notes(new_notes):
)
for pid in participants:
p = scenario_participants.get(pid, TestedParticipant())
p.has_failures = True
if failed_check.severity == Severity.Low:
p.has_infos = True
else:
p.has_failures = True
scenario_participants[pid] = p
if "notes" in report and report.notes:
for key, note in report.notes.items():
Expand Down Expand Up @@ -618,6 +623,7 @@ def _generate_scenario_pages(
UNATTRIBUTED_PARTICIPANT=UNATTRIBUTED_PARTICIPANT,
len=len,
str=str,
Severity=Severity,
)
)
else:
Expand Down Expand Up @@ -654,5 +660,6 @@ def generate_sequence_view(
ActionNodeType=ActionNodeType,
UNATTRIBUTED_PARTICIPANT=UNATTRIBUTED_PARTICIPANT,
len=len,
Severity=Severity,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,7 @@
<html lang="en">
<head>
<title>TR-{{ test_run.test_run_id[0:7] }} sequence view</title>
<style>
body {
margin: 0;
color: #24292f;
background-color: #ffffff;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
font-size: 16px;
line-height: 1.5;
word-wrap: break-word;
}
table {
border-spacing: 0;
border-collapse: collapse;
width: max-content;
max-width: 100%;
overflow: auto;
}
tr {
border-top: 1px solid hsla(210,18%,87%,1);
}
table tr:nth-child(2n) {
background-color: #f6f8fa;
}
td {
padding: 6px 6px;
vertical-align: top;
border: 1px solid #d0d7de;
}
th {
padding: 6px 6px;
text-align: left;
background-color: rgb(230, 230, 230);
border: 1px solid #d0d7de;
height: 40px;
}
a {
background-color: transparent;
color: #0969da;
text-decoration: none;
}
h2 {
margin-block-end: 0.1em;
}
p {
margin-top: 0.1em;
margin-bottom: 0.1em;
}
.sticky_cell_value {
position: sticky;
top: 40px;
z-index: 0;
}
.pass_result {
background-color: rgb(192, 255, 192);
}
.fail_result {
background-color: rgb(255, 192, 192);
}
.not_tested {
background-color: rgb(192, 192, 192);
}
.skipped_explanation {
font-style: italic;
}
</style>
{% include "sequence_view/style.html" %}
{{ explorer_header() }}
</head>
<body>
Expand Down Expand Up @@ -200,6 +136,8 @@ <h2>Scenarios executed</h2>
{% if row.scenario_node and participant_id in row.scenario_node.scenario.participants %}
{% if row.scenario_node.scenario.participants[participant_id].has_failures %}
<td class="fail_result">&#x274C;</td>
{% elif row.scenario_node.scenario.participants[participant_id].has_infos %}
<td class="info_result">&#8505;&#65039;</td>
{% elif row.scenario_node.scenario.participants[participant_id].has_successes %}
<td class="pass_result">&#x2705;</td>
{% elif row.scenario_node.scenario.participants[participant_id].has_queries %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,11 @@
<!DOCTYPE html>
{% from "explorer.html" import explorer_header, explorer_content, explorer_footer %}
{% from "sequence_view/severity.html" import severity_symbol, severity_class with context %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>s{{ test_scenario.scenario_index }} - {{ test_scenario.name }}</title>
<style>
body {
margin: 0;
color: #24292f;
background-color: #ffffff;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
font-size: 16px;
line-height: 1.5;
word-wrap: break-word;
}
table {
border-spacing: 0;
border-collapse: collapse;
width: max-content;
max-width: 100%;
overflow: auto;
}
tr {
border-top: 1px solid hsla(210,18%,87%,1);
}
table tr:nth-child(2n) {
background-color: #f6f8fa;
}
td {
padding: 6px 6px;
vertical-align: top;
border: 1px solid #d0d7de;
}
th {
padding: 6px 6px;
text-align: left;
background-color: rgb(230, 230, 230);
border: 1px solid #d0d7de;
}
a {
background-color: transparent;
color: #0969da;
text-decoration: none;
}
h2 {
margin-block-end: 0.1em;
}
.sticky_cell_value {
position: sticky;
top: 0px;
z-index: 0;
}
.pass_result {
background-color: rgb(192, 255, 192);
}
.fail_result {
background-color: rgb(255, 192, 192);
}
.not_tested {
background-color: rgb(192, 192, 192);
}
.failed_check_summary {
font-style: italic;
}
</style>
{% include "sequence_view/style.html" %}
{{ explorer_header() }}
</head>
<body>
Expand Down Expand Up @@ -131,8 +73,8 @@ <h3>{{ test_scenario.type }}</h3>
{% endif %}
{% endfor %}
{% elif event.type == EventType.FailedCheck %}
<td>&#x274C;</td>
<td class="fail_result">
<td>{{ severity_symbol(event.failed_check.severity) }}</td>
<td class="{{ severity_class(event.failed_check.severity) }}">
{% if event.failed_check.documentation_url %}
<a href="{{ event.failed_check.documentation_url }}">{{ event.failed_check.name }}</a>
{% else %}
Expand All @@ -152,17 +94,19 @@ <h3>{{ test_scenario.type }}</h3>
</td>
{% for participant_id in all_participants %}
{% if (participant_id != UNATTRIBUTED_PARTICIPANT and participant_id in event.failed_check.participants) or (participant_id == UNATTRIBUTED_PARTICIPANT and not event.failed_check.participants) %}
<td class="fail_result">&#x274C;</td>
<td class="{{ severity_class(event.failed_check.severity) }}">
{{ severity_symbol(event.failed_check.severity) }}
</td>
{% else %}
<td></td>
{% endif %}
{% endfor %}
{% elif event.type == EventType.Query %}
<td>&#x1F310;</td>
<td>
{{ event.query.request.method }} {{ event.query.request.url_hostname }}
{% set query_dict = {event.query.request.method + " " + event.query.request.url_hostname + " " + str(event.query.response.status_code): event.query} %}
{% set query_id = "e" + str(event.event_index) + "query" %}
{{ explorer_content(query_id, event.query) }}
{{ explorer_content(query_id, query_dict) }}
{% set collapsible.queries = collapsible.queries + [query_id] %}
</td>
{% for participant_id in all_participants %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% macro severity_symbol(s) %}
{% if s == Severity.Low %}
&#8505;&#65039;
{% elif s == Severity.Medium %}
&#9888;&#65039;
{% elif s == Severity.High %}
&#x1F6D1;
{% elif s == Severity.Critical %}
&#9762;&#65039;
{% else %}
?
{% endif %}
{% endmacro %}

{% macro severity_class(s) %}
{% if s == Severity.Low %}
info_result
{% else %}
fail_result
{% endif %}
{% endmacro %}
Loading

0 comments on commit 20f8dbc

Please sign in to comment.