|
33 | 33 | import static com.google.common.truth.Truth.assertThat; |
34 | 34 | import static org.junit.Assert.assertThrows; |
35 | 35 |
|
| 36 | +import java.util.UUID; |
36 | 37 | import com.google.api.client.http.javanet.NetHttpTransport; |
| 38 | +import com.google.showcase.v1beta1.GetUserRequest; |
37 | 39 | import com.google.api.gax.core.NoCredentialsProvider; |
38 | 40 | import com.google.api.gax.retrying.RetrySettings; |
39 | 41 | import com.google.api.gax.rpc.StatusCode; |
40 | 42 | import com.google.api.gax.rpc.UnavailableException; |
41 | 43 | import com.google.api.gax.tracing.ObservabilityAttributes; |
42 | 44 | import com.google.api.gax.tracing.SpanTracer; |
43 | 45 | import com.google.api.gax.tracing.SpanTracerFactory; |
| 46 | +import com.google.protobuf.InvalidProtocolBufferException; |
| 47 | +import com.google.protobuf.Message; |
44 | 48 | import com.google.rpc.Status; |
45 | 49 | import com.google.showcase.v1beta1.EchoClient; |
46 | 50 | import com.google.showcase.v1beta1.EchoRequest; |
47 | 51 | import com.google.showcase.v1beta1.EchoSettings; |
48 | | -import com.google.showcase.v1beta1.GetUserRequest; |
49 | 52 | import com.google.showcase.v1beta1.IdentityClient; |
| 53 | +import com.google.showcase.v1beta1.User; |
50 | 54 | import com.google.showcase.v1beta1.it.util.TestClientInitializer; |
51 | 55 | import com.google.showcase.v1beta1.stub.EchoStub; |
52 | 56 | import com.google.showcase.v1beta1.stub.EchoStubSettings; |
|
58 | 62 | import io.opentelemetry.sdk.trace.SdkTracerProvider; |
59 | 63 | import io.opentelemetry.sdk.trace.data.SpanData; |
60 | 64 | import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; |
| 65 | +import java.nio.charset.StandardCharsets; |
61 | 66 | import java.util.List; |
62 | 67 | import org.junit.jupiter.api.AfterEach; |
63 | 68 | import org.junit.jupiter.api.BeforeEach; |
@@ -234,9 +239,26 @@ void testTracing_successfulIdentityGetUser_httpjson() throws Exception { |
234 | 239 | AttributeKey.stringKey( |
235 | 240 | ObservabilityAttributes.DESTINATION_RESOURCE_ID_ATTRIBUTE))) |
236 | 241 | .isEqualTo("users/test-user"); |
| 242 | + |
| 243 | + User fetchedUser = User.newBuilder().setName("users/test-user").build(); |
| 244 | + long expectedMagnitude = computeExpectedHttpJsonResponseSize(fetchedUser); |
| 245 | + Long observedMagnitude = |
| 246 | + attemptSpan |
| 247 | + .getAttributes() |
| 248 | + .get(AttributeKey.longKey(ObservabilityAttributes.HTTP_RESPONSE_BODY_SIZE)); |
| 249 | + if (observedMagnitude != null) { |
| 250 | + assertThat(observedMagnitude).isAtLeast((long) (expectedMagnitude * (1 - 0.15))); |
| 251 | + assertThat(observedMagnitude).isAtMost((long) (expectedMagnitude * (1 + 0.15))); |
| 252 | + } |
237 | 253 | } |
238 | 254 | } |
239 | 255 |
|
| 256 | + private long computeExpectedHttpJsonResponseSize(Message message) |
| 257 | + throws InvalidProtocolBufferException { |
| 258 | + String jsonPayload = com.google.protobuf.util.JsonFormat.printer().print(message); |
| 259 | + return jsonPayload.getBytes(StandardCharsets.UTF_8).length; |
| 260 | + } |
| 261 | + |
240 | 262 | @Test |
241 | 263 | void testTracing_retry_grpc() throws Exception { |
242 | 264 | final int attempts = 5; |
|
0 commit comments