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

[uss_qualifier] Identify duplicate record_query calls #429

Merged
merged 2 commits into from
Dec 21, 2023
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
8 changes: 8 additions & 0 deletions monitoring/monitorlib/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@
def stacktrace_string(e: Exception) -> str:
"""Return a multi-line string containing a stacktrace for the specified exception."""
return "".join(traceback.format_exception(e))


def current_stack_string(exclude_levels: int = 1) -> str:
"""Return a multi-line string containing a trace of the current execution state."""
stack = traceback.extract_stack()
if exclude_levels > 0:
stack = stack[0:-exclude_levels]
return "".join(traceback.format_list(stack))
7 changes: 7 additions & 0 deletions monitoring/uss_qualifier/scenarios/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from monitoring import uss_qualifier as uss_qualifier_module
from monitoring.monitorlib import fetch, inspection
from monitoring.monitorlib.errors import current_stack_string
from monitoring.monitorlib.inspection import fullname
from monitoring.uss_qualifier import scenarios as scenarios_module
from monitoring.uss_qualifier.common_data_definitions import Severity
Expand Down Expand Up @@ -363,6 +364,12 @@ def record_query(self, query: fetch.Query) -> None:
self._expect_phase({ScenarioPhase.RunningTestStep, ScenarioPhase.CleaningUp})
if "queries" not in self._step_report:
self._step_report.queries = []
for existing_query in self._step_report.queries:
if query.request.timestamp == existing_query.request.timestamp:
logger.error(
f"The same query ({query.query_type} to {query.participant_id} at {query.request.timestamp}) was recorded multiple times. This is likely a bug in uss_qualifier at:\n{current_stack_string(2)}"
)
return
self._step_report.queries.append(query)
participant = (
"UNKNOWN"
Expand Down
Loading