Skip to content
Open
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: 0 additions & 8 deletions manifests/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tests/stats/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions utils/interfaces/_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,21 @@ 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"]

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
Expand Down
Loading