Skip to content

Commit bfa5a26

Browse files
committed
Fix: bazel tests
1 parent b8bd9f1 commit bfa5a26

2 files changed

Lines changed: 121 additions & 55 deletions

File tree

xds/src/test/java/io/grpc/xds/FakeControlPlaneXdsIntegrationTest.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,9 @@
6767
import io.grpc.MethodDescriptor;
6868
import io.grpc.NoopMetricSink;
6969
import io.grpc.Server;
70-
import io.grpc.opentelemetry.GrpcOpenTelemetry;
7170
import io.grpc.testing.protobuf.SimpleRequest;
7271
import io.grpc.testing.protobuf.SimpleResponse;
7372
import io.grpc.testing.protobuf.SimpleServiceGrpc;
74-
import io.opentelemetry.api.OpenTelemetry;
75-
import io.opentelemetry.sdk.OpenTelemetrySdk;
76-
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
77-
import io.opentelemetry.sdk.metrics.data.MetricData;
78-
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
7973
import java.net.InetSocketAddress;
8074
import java.util.Arrays;
8175
import java.util.List;
@@ -406,55 +400,6 @@ public void configureChannelBuilder(ManagedChannelBuilder<?> builder) {
406400
}
407401
}
408402

409-
@Test
410-
public void childChannelConfigurator_passesOtelSdkToChannel_E2E() throws Exception {
411-
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
412-
SdkMeterProvider meterProvider = SdkMeterProvider.builder()
413-
.registerMetricReader(metricReader)
414-
.build();
415-
OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
416-
.setMeterProvider(meterProvider)
417-
.build();
418-
GrpcOpenTelemetry grpcOtel = GrpcOpenTelemetry.newBuilder()
419-
.sdk(openTelemetry)
420-
.build();
421-
422-
ChannelConfigurator configurator = new ChannelConfigurator() {
423-
@Override
424-
public void configureChannelBuilder(ManagedChannelBuilder<?> builder) {
425-
grpcOtel.configureChannelBuilder(builder);
426-
}
427-
};
428-
429-
ManagedChannel channel = Grpc.newChannelBuilder("test-xds:///test-server",
430-
InsecureChannelCredentials.create())
431-
.childChannelConfigurator(configurator)
432-
.build();
433-
434-
try {
435-
SimpleServiceGrpc.SimpleServiceBlockingStub blockingStub = SimpleServiceGrpc.newBlockingStub(
436-
channel);
437-
blockingStub.unaryRpc(SimpleRequest.getDefaultInstance());
438-
439-
boolean hasMetrics = false;
440-
for (int i = 0; i < 20; i++) {
441-
for (MetricData metric : metricReader.collectAllMetrics()) {
442-
if (metric.getName().startsWith("grpc.client.")) {
443-
hasMetrics = true;
444-
break;
445-
}
446-
}
447-
if (hasMetrics) {
448-
break;
449-
}
450-
Thread.sleep(100);
451-
}
452-
assertThat(hasMetrics).isTrue();
453-
} finally {
454-
channel.shutdownNow();
455-
}
456-
}
457-
458403
@Test
459404
public void childChannelConfigurator_passesMetricSinkToServer_E2E() throws Exception {
460405
CountingMetricSink sink = new CountingMetricSink();
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright 2026 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.xds;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import io.grpc.ChannelConfigurator;
22+
import io.grpc.FlagResetRule;
23+
import io.grpc.Grpc;
24+
import io.grpc.InsecureChannelCredentials;
25+
import io.grpc.InternalFeatureFlags;
26+
import io.grpc.ManagedChannel;
27+
import io.grpc.ManagedChannelBuilder;
28+
import io.grpc.opentelemetry.GrpcOpenTelemetry;
29+
import io.grpc.testing.protobuf.SimpleRequest;
30+
import io.grpc.testing.protobuf.SimpleServiceGrpc;
31+
import io.opentelemetry.api.OpenTelemetry;
32+
import io.opentelemetry.sdk.OpenTelemetrySdk;
33+
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
34+
import io.opentelemetry.sdk.metrics.data.MetricData;
35+
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
36+
import java.util.Arrays;
37+
import org.junit.Before;
38+
import org.junit.Rule;
39+
import org.junit.Test;
40+
import org.junit.runner.RunWith;
41+
import org.junit.runners.Parameterized;
42+
import org.junit.runners.Parameterized.Parameter;
43+
import org.junit.runners.Parameterized.Parameters;
44+
45+
/**
46+
* xDS + OpenTelemetry E2E integration test using a fake control plane.
47+
* This class is skipped from Bazel builds because Bazel doesn't compile the
48+
* grpc-opentelemetry module.
49+
*/
50+
@RunWith(Parameterized.class)
51+
public class FakeControlPlaneXdsOtelIntegrationTest {
52+
53+
@Rule(order = 0)
54+
public ControlPlaneRule controlPlane = new ControlPlaneRule();
55+
@Rule(order = 1)
56+
public DataPlaneRule dataPlane = new DataPlaneRule(controlPlane);
57+
@Rule(order = 2)
58+
public final FlagResetRule flagResetRule = new FlagResetRule();
59+
60+
@Parameters(name = "enableRfc3986UrisParam={0}")
61+
public static Iterable<Object[]> data() {
62+
return Arrays.asList(new Object[][] {{true}, {false}});
63+
}
64+
65+
@Parameter public boolean enableRfc3986UrisParam;
66+
67+
@Before
68+
public void setupRfc3986UrisFeatureFlag() throws Exception {
69+
flagResetRule.setFlagForTest(
70+
InternalFeatureFlags::setRfc3986UrisEnabled, enableRfc3986UrisParam);
71+
}
72+
73+
@Test
74+
public void childChannelConfigurator_passesOtelSdkToChannel_E2E() throws Exception {
75+
InMemoryMetricReader metricReader = InMemoryMetricReader.create();
76+
SdkMeterProvider meterProvider = SdkMeterProvider.builder()
77+
.registerMetricReader(metricReader)
78+
.build();
79+
OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
80+
.setMeterProvider(meterProvider)
81+
.build();
82+
GrpcOpenTelemetry grpcOtel = GrpcOpenTelemetry.newBuilder()
83+
.sdk(openTelemetry)
84+
.build();
85+
86+
ChannelConfigurator configurator = new ChannelConfigurator() {
87+
@Override
88+
public void configureChannelBuilder(ManagedChannelBuilder<?> builder) {
89+
grpcOtel.configureChannelBuilder(builder);
90+
}
91+
};
92+
93+
ManagedChannel channel = Grpc.newChannelBuilder("test-xds:///test-server",
94+
InsecureChannelCredentials.create())
95+
.childChannelConfigurator(configurator)
96+
.build();
97+
98+
try {
99+
SimpleServiceGrpc.SimpleServiceBlockingStub blockingStub = SimpleServiceGrpc.newBlockingStub(
100+
channel);
101+
blockingStub.unaryRpc(SimpleRequest.getDefaultInstance());
102+
103+
boolean hasMetrics = false;
104+
for (int i = 0; i < 20; i++) {
105+
for (MetricData metric : metricReader.collectAllMetrics()) {
106+
if (metric.getName().startsWith("grpc.client.")) {
107+
hasMetrics = true;
108+
break;
109+
}
110+
}
111+
if (hasMetrics) {
112+
break;
113+
}
114+
Thread.sleep(100);
115+
}
116+
assertThat(hasMetrics).isTrue();
117+
} finally {
118+
channel.shutdownNow();
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)