From 71724a4d232d1a1ef87e60bc9b38960a3aced444 Mon Sep 17 00:00:00 2001 From: Julien Perrochet Date: Wed, 15 Nov 2023 10:36:18 +0100 Subject: [PATCH] [uss_qualifier] debug aggregate queries stats for #343 --- .../monitorlib/fetch/evaluation_test.py | 37 +++++++++++++++++++ .../astm/netrid/common/aggregate_checks.py | 13 +++++-- 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 monitoring/monitorlib/fetch/evaluation_test.py diff --git a/monitoring/monitorlib/fetch/evaluation_test.py b/monitoring/monitorlib/fetch/evaluation_test.py new file mode 100644 index 0000000000..5ed048628a --- /dev/null +++ b/monitoring/monitorlib/fetch/evaluation_test.py @@ -0,0 +1,37 @@ +from datetime import datetime + +from implicitdict import StringBasedDateTime + +from monitoring.monitorlib.fetch import ( + Query, + RequestDescription, + ResponseDescription, + evaluation, +) + + +def _fq(ts: int, elapsed: float): + """returns a fake query with the specified epoch timestamp as 'initiated_at'""" + return Query( + request=RequestDescription( + method=None, + url=None, + initiated_at=StringBasedDateTime(datetime.fromtimestamp(ts)), + ), + response=ResponseDescription(elapsed_s=elapsed, reported=None), + ) + + +def test_get_init_subsequent_queries_durations(): + dummy_queries = [_fq(10, 2), _fq(12, 1), _fq(13, 0.9), _fq(14, 0.8)] + query_dict = {"some-url": dummy_queries} + (init_d, subseq_d) = evaluation.get_init_subsequent_queries_durations(5, query_dict) + + assert init_d == [2] + assert subseq_d == [1, 0.9, 0.8] + + query_dict = {"some-url": dummy_queries, "another-url": dummy_queries} + + (init_d, subseq_d) = evaluation.get_init_subsequent_queries_durations(5, query_dict) + assert init_d == [2, 2] + assert subseq_d == [1, 0.9, 0.8, 1, 0.9, 0.8] diff --git a/monitoring/uss_qualifier/scenarios/astm/netrid/common/aggregate_checks.py b/monitoring/uss_qualifier/scenarios/astm/netrid/common/aggregate_checks.py index 4e4f15fe3d..754ed328ba 100644 --- a/monitoring/uss_qualifier/scenarios/astm/netrid/common/aggregate_checks.py +++ b/monitoring/uss_qualifier/scenarios/astm/netrid/common/aggregate_checks.py @@ -79,10 +79,10 @@ def _init_queries(self, context: ExecutionContext): for query in self._queries: for base_url, participant in self._participants_by_base_url.items(): - if query.request.url.startswith(base_url): - self._queries_by_participant[participant].append(query) - # TODO opportunity here to set the participant_id on the query if it's not already there - # maybe do so after most/all queries have been tagged at the call site where possible + if query.request.url.startswith( + base_url + ) and not query.has_field_with_value("participant_id"): + query.participant_id = participant break # Only consider queries with the participant/server explicitly identified @@ -372,3 +372,8 @@ def _dp_display_data_times_step(self): f"{participant}/display_data", f"percentiles on {len(relevant_queries)} relevant queries ({len(relevant_queries_by_url)} different URLs, {len(init_durations)} initial queries, {len(subsequent_durations)} subsequent queries): init 95th: {init_95th}; init 99th: {init_99th}; subsequent 95th: {subsequent_95th}; subsequent 99th: {subsequent_99th}", ) + + self.record_note( + f"{participant}/display_data details", + f"Initial durations: {init_durations} subsequent durations: {subsequent_durations}", + )