Skip to content

Commit 1eec145

Browse files
authored
Remove unused imports from CSM Observability example (#11307)
1 parent 9e287f9 commit 1eec145

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

examples/example-gcp-csm-observability/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ dependencies {
3636
implementation "io.grpc:grpc-gcp-csm-observability:${grpcVersion}"
3737
implementation "io.opentelemetry:opentelemetry-sdk:${openTelemetryVersion}"
3838
implementation "io.opentelemetry:opentelemetry-sdk-metrics:${openTelemetryVersion}"
39-
implementation "io.opentelemetry:opentelemetry-exporter-logging:${openTelemetryVersion}"
4039
implementation "io.opentelemetry:opentelemetry-exporter-prometheus:${openTelemetryPrometheusVersion}"
4140
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
4241
runtimeOnly "io.grpc:grpc-xds:${grpcVersion}"

examples/example-gcp-csm-observability/src/main/java/io/grpc/examples/csmobservability/CsmObservabilityClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
import io.grpc.Grpc;
2121
import io.grpc.InsecureChannelCredentials;
2222
import io.grpc.ManagedChannel;
23-
import io.grpc.ManagedChannelBuilder;
2423
import io.grpc.StatusRuntimeException;
2524
import io.grpc.examples.helloworld.GreeterGrpc;
2625
import io.grpc.examples.helloworld.HelloReply;
2726
import io.grpc.examples.helloworld.HelloRequest;
2827
import io.grpc.gcp.csm.observability.CsmObservability;
29-
import io.opentelemetry.exporter.logging.LoggingMetricExporter;
3028
import io.opentelemetry.exporter.prometheus.PrometheusHttpServer;
3129
import io.opentelemetry.sdk.OpenTelemetrySdk;
3230
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
@@ -69,7 +67,9 @@ public void greet(String name) {
6967
*/
7068
public static void main(String[] args) throws Exception {
7169
String user = "world";
70+
// Use xDS to establish contact with the server "helloworld:50051".
7271
String target = "xds:///helloworld:50051";
72+
// The port on which prometheus metrics will be exposed.
7373
int prometheusPort = 9464;
7474
AtomicBoolean sendRpcs = new AtomicBoolean(true);
7575
if (args.length > 0) {

examples/example-gcp-csm-observability/src/main/java/io/grpc/examples/csmobservability/CsmObservabilityServer.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,37 @@
3838
public class CsmObservabilityServer {
3939
private static final Logger logger = Logger.getLogger(CsmObservabilityServer.class.getName());
4040

41-
private Server gRPCServer;
41+
private Server server;
4242
private void start(int port) throws IOException {
43-
gRPCServer = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
43+
server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
4444
.addService(new GreeterImpl())
4545
.build()
4646
.start();
4747
logger.info("Server started, listening on " + port);
4848
}
4949

5050
private void stop() throws InterruptedException {
51-
if (gRPCServer != null) {
52-
gRPCServer.shutdown().awaitTermination(30, TimeUnit.SECONDS);
51+
if (server != null) {
52+
server.shutdown().awaitTermination(30, TimeUnit.SECONDS);
5353
}
5454
}
5555

56+
/**
57+
* Await termination on the main thread since the grpc library uses daemon threads.
58+
*/
5659
private void blockUntilShutdown() throws InterruptedException {
57-
if (gRPCServer != null) {
58-
gRPCServer.awaitTermination();
60+
if (server != null) {
61+
server.awaitTermination();
5962
}
6063
}
6164

6265
/**
6366
* Main launches the server from the command line.
6467
*/
6568
public static void main(String[] args) throws IOException, InterruptedException {
66-
/* The port on which the server should run. */
69+
// The port on which the server should run.
6770
int port = 50051;
71+
// The port on which prometheus metrics will be exposed.
6872
int prometheusPort = 9464;
6973

7074
if (args.length > 0) {

0 commit comments

Comments
 (0)