Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: Remove unused imports from CSM Observability example #11307

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading