|
35 | 35 | import io.opentelemetry.sdk.metrics.data.MetricData; |
36 | 36 | import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; |
37 | 37 | import java.util.Arrays; |
| 38 | +import java.util.concurrent.TimeUnit; |
38 | 39 | import org.junit.Before; |
39 | 40 | import org.junit.Rule; |
40 | 41 | import org.junit.Test; |
@@ -118,22 +119,22 @@ public void configureChannelBuilder(ManagedChannelBuilder<?> builder) { |
118 | 119 | SimpleServiceGrpc.newBlockingStub(channel); |
119 | 120 | blockingStub.unaryRpc(SimpleRequest.getDefaultInstance()); |
120 | 121 |
|
| 122 | + // Shut down the channel to complete the RPC cycle. |
| 123 | + channel.shutdownNow(); |
| 124 | + channel.awaitTermination(5, TimeUnit.SECONDS); |
| 125 | + |
121 | 126 | // Verify that OpenTelemetry metrics specifically from the xDS Control Plane ADS stream |
122 | | - // successfully propagated, method name is recorded as 'other' because dynamic descriptors |
123 | | - // are not sampled to local tracing by default. |
124 | | - boolean foundXdsMetrics = false; |
125 | | - for (int i = 0; i < 50; i++) { |
126 | | - for (MetricData metric : metricReader.collectAllMetrics()) { |
127 | | - if (metric.toString().contains("grpc.client.") && metric.toString().contains("other")) { |
128 | | - foundXdsMetrics = true; |
| 127 | + // successfully propagated, with the exact stream method name preserved. |
| 128 | + boolean foundTargetMethod = false; |
| 129 | + for (MetricData metric : metricReader.collectAllMetrics()) { |
| 130 | + String name = metric.getName(); |
| 131 | + if ("grpc.client.attempt.started".equals(name) || "grpc.client.call.duration".equals(name)) { |
| 132 | + if (metric.toString().contains("envoy.service.discovery.v3.AggregatedDiscoveryService")) { |
| 133 | + foundTargetMethod = true; |
129 | 134 | break; |
130 | 135 | } |
131 | 136 | } |
132 | | - if (foundXdsMetrics) { |
133 | | - break; |
134 | | - } |
135 | | - Thread.sleep(100); |
136 | 137 | } |
137 | | - assertThat(foundXdsMetrics).isTrue(); |
| 138 | + assertThat(foundTargetMethod).isTrue(); |
138 | 139 | } |
139 | 140 | } |
0 commit comments