Skip to content

Commit

Permalink
Remove unused imports from CSM Observability example (#11307) (#11310)
Browse files Browse the repository at this point in the history
  • Loading branch information
DNVindhya authored Jun 23, 2024
1 parent 4824eaf commit c11b560
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion examples/example-gcp-csm-observability/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ dependencies {
implementation "io.grpc:grpc-gcp-csm-observability:${grpcVersion}"
implementation "io.opentelemetry:opentelemetry-sdk:${openTelemetryVersion}"
implementation "io.opentelemetry:opentelemetry-sdk-metrics:${openTelemetryVersion}"
implementation "io.opentelemetry:opentelemetry-exporter-logging:${openTelemetryVersion}"
implementation "io.opentelemetry:opentelemetry-exporter-prometheus:${openTelemetryPrometheusVersion}"
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
runtimeOnly "io.grpc:grpc-xds:${grpcVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import io.grpc.Grpc;
import io.grpc.InsecureChannelCredentials;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.gcp.csm.observability.CsmObservability;
import io.opentelemetry.exporter.logging.LoggingMetricExporter;
import io.opentelemetry.exporter.prometheus.PrometheusHttpServer;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
Expand Down Expand Up @@ -69,7 +67,9 @@ public void greet(String name) {
*/
public static void main(String[] args) throws Exception {
String user = "world";
// Use xDS to establish contact with the server "helloworld:50051".
String target = "xds:///helloworld:50051";
// The port on which prometheus metrics will be exposed.
int prometheusPort = 9464;
AtomicBoolean sendRpcs = new AtomicBoolean(true);
if (args.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,37 @@
public class CsmObservabilityServer {
private static final Logger logger = Logger.getLogger(CsmObservabilityServer.class.getName());

private Server gRPCServer;
private Server server;
private void start(int port) throws IOException {
gRPCServer = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
.addService(new GreeterImpl())
.build()
.start();
logger.info("Server started, listening on " + port);
}

private void stop() throws InterruptedException {
if (gRPCServer != null) {
gRPCServer.shutdown().awaitTermination(30, TimeUnit.SECONDS);
if (server != null) {
server.shutdown().awaitTermination(30, TimeUnit.SECONDS);
}
}

/**
* Await termination on the main thread since the grpc library uses daemon threads.
*/
private void blockUntilShutdown() throws InterruptedException {
if (gRPCServer != null) {
gRPCServer.awaitTermination();
if (server != null) {
server.awaitTermination();
}
}

/**
* Main launches the server from the command line.
*/
public static void main(String[] args) throws IOException, InterruptedException {
/* The port on which the server should run. */
// The port on which the server should run.
int port = 50051;
// The port on which prometheus metrics will be exposed.
int prometheusPort = 9464;

if (args.length > 0) {
Expand Down

0 comments on commit c11b560

Please sign in to comment.