|
1 | 1 | import pytest |
2 | | -from utils import interfaces, weblog, features, scenarios, logger |
| 2 | +from utils import context, features, interfaces, logger, missing_feature, scenarios, weblog |
3 | 3 |
|
4 | 4 | """ |
5 | 5 | Test scenarios we want: |
@@ -99,6 +99,35 @@ def test_disable(self): |
99 | 99 | requests = list(interfaces.library.get_data("/v0.6/stats")) |
100 | 100 | assert len(requests) == 0, "Client-side stats should be disabled by default" |
101 | 101 |
|
| 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 | + |
102 | 131 |
|
103 | 132 | @features.client_side_stats_supported |
104 | 133 | @scenarios.trace_stats_computation |
|
0 commit comments