From 2b7997cfcb282de7b1b70627ab704deee92af875 Mon Sep 17 00:00:00 2001 From: vianney Date: Tue, 24 Feb 2026 17:30:09 +0100 Subject: [PATCH] support multiple ressources for stats --- manifests/python.yml | 8 -------- tests/stats/test_stats.py | 8 ++++++-- utils/interfaces/_agent.py | 5 +++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/manifests/python.yml b/manifests/python.yml index ddcdff86a70..a4141f2a66d 100644 --- a/manifests/python.yml +++ b/manifests/python.yml @@ -1726,17 +1726,9 @@ manifest: tests/stats/test_stats.py::Test_Client_Stats::test_client_stats: - weblog_declaration: "*": v2.8.0 - *django: bug (APMSP-1375) - - # Added by easy win activation script - weblog_declaration: - tornado: missing_feature tests/stats/test_stats.py::Test_Client_Stats::test_is_trace_root: - weblog_declaration: "*": v2.8.0 - *django: bug (APMSP-1375) - - # Added by easy win activation script - weblog_declaration: - tornado: missing_feature tests/stats/test_stats.py::Test_Time_Bucketing::test_client_side_stats_bucket_alignment: # Modified by easy win activation script - weblog_declaration: '*': missing_feature diff --git a/tests/stats/test_stats.py b/tests/stats/test_stats.py index ef14cee1eb7..83742ed2cd5 100644 --- a/tests/stats/test_stats.py +++ b/tests/stats/test_stats.py @@ -22,6 +22,10 @@ class Test_Client_Stats: """Test client-side stats are compatible with Agent implementation""" + # The resource for the /stats-unique route differ between weblogs. + # We use this list to match all requests to this route regardless of the weblog. + STATS_UNIQUE_RESOURCES = ["GET /stats-unique", "GET stats-unique", "__main__.StatsUniqueHandler"] + def setup_client_stats(self): for _ in range(5): weblog.get("/stats-unique") @@ -34,7 +38,7 @@ def test_client_stats(self): ok_top_hits = 0 no_content_hits = 0 no_content_top_hits = 0 - for s in interfaces.agent.get_stats(resource="GET /stats-unique"): + for s in interfaces.agent.get_stats(resource=self.STATS_UNIQUE_RESOURCES): stats_count += 1 logger.debug(f"asserting on {s}") if s["HTTPStatusCode"] == 200: @@ -85,7 +89,7 @@ def test_is_trace_root(self): assertions to `test_client_stats` method. """ root_found = False - for s in interfaces.agent.get_stats(resource="GET /stats-unique"): + for s in interfaces.agent.get_stats(resource=self.STATS_UNIQUE_RESOURCES): if s["SpanKind"] == "server": root_found |= s["IsTraceRoot"] == 1 assert root_found diff --git a/utils/interfaces/_agent.py b/utils/interfaces/_agent.py index 392f4b1b3b5..3c3adf6129c 100644 --- a/utils/interfaces/_agent.py +++ b/utils/interfaces/_agent.py @@ -252,12 +252,13 @@ def get_sketches(self): def get_dsm_data(self): return self.get_data(path_filters="/api/v0.1/pipeline_stats") - def get_stats(self, resource: str = ""): + def get_stats(self, resource: str | list[str] = ""): """Attempts to fetch the stats the agent will submit to the backend. When a valid request is given, then we filter the stats to the ones sampled during that request's execution, and only return those. """ + resources = [resource] if isinstance(resource, str) else resource for data in self.get_data(path_filters="/api/v0.2/stats"): client_stats_payloads = data["request"]["content"]["Stats"] @@ -265,7 +266,7 @@ def get_stats(self, resource: str = ""): for client_stats_payload in client_stats_payloads: for client_stats_buckets in client_stats_payload["Stats"]: for client_grouped_stat in client_stats_buckets["Stats"]: - if resource == "" or client_grouped_stat["Resource"] == resource: + if not resources or "" in resources or client_grouped_stat["Resource"] in resources: yield client_grouped_stat @staticmethod