Skip to content

Commit 5e94312

Browse files
committed
chore: Client side stats aggregates on GRPC status code
* Adds a parameteric test for the grpc status code * Replace parametric test by regular for the grpc status code
1 parent ba1fd58 commit 5e94312

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

tests/stats/test_stats.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from utils import interfaces, weblog, features, scenarios, logger
2+
from utils import context, features, interfaces, logger, missing_feature, scenarios, weblog
33

44
"""
55
Test scenarios we want:
@@ -99,6 +99,35 @@ def test_disable(self):
9999
requests = list(interfaces.library.get_data("/v0.6/stats"))
100100
assert len(requests) == 0, "Client-side stats should be disabled by default"
101101

102+
def setup_grpc_status_code(self):
103+
self.grpc_request = weblog.grpc("grpc stats")
104+
105+
@missing_feature(
106+
context.library != "java" or context.library < "java@1.61.0-SNAPSHOT",
107+
reason="GRPCStatusCode stats payload field was added in java@1.61.0-SNAPSHOT",
108+
force_skip=True,
109+
)
110+
@missing_feature(
111+
context.weblog_variant != "spring-boot",
112+
reason="gRPC stats coverage requires a weblog variant with gRPC support",
113+
force_skip=True,
114+
)
115+
def test_grpc_status_code(self):
116+
grpc_stats = []
117+
118+
for data in interfaces.library.get_data("/v0.6/stats"):
119+
payload = data["request"]["content"]
120+
for bucket in payload.get("Stats", []):
121+
for stat in bucket.get("Stats", []):
122+
if stat.get("Type") == "rpc" and stat.get("SpanKind") == "server":
123+
grpc_stats.append(stat)
124+
125+
assert grpc_stats, "Expected at least one gRPC stats entry in the v0.6/stats payload"
126+
# 0 means OK in gRPC status codes
127+
assert any(stat.get("GRPCStatusCode") == "0" for stat in grpc_stats), (
128+
f"Expected a gRPC stats entry with GRPCStatusCode=0, got: {grpc_stats}"
129+
)
130+
102131

103132
@features.client_side_stats_supported
104133
@scenarios.trace_stats_computation

utils/docker_fixtures/spec/trace.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class V06StatsAggr(TypedDict):
7171
Type: str
7272
Service: str
7373
HTTPStatusCode: int
74+
GRPCStatusCode: str
7475
Synthetics: bool
7576
Hits: int
7677
TopLevelHits: int
@@ -131,6 +132,7 @@ def decode_v06_stats(data: bytes) -> V06StatsPayload:
131132
Service=raw_stats["Service"],
132133
Type=raw_stats.get("Type"),
133134
HTTPStatusCode=raw_stats.get("HTTPStatusCode"),
135+
GRPCStatusCode=raw_stats.get("GRPCStatusCode"),
134136
Synthetics=raw_stats["Synthetics"],
135137
Hits=raw_stats["Hits"],
136138
TopLevelHits=raw_stats["TopLevelHits"],

0 commit comments

Comments
 (0)