Skip to content

Commit

Permalink
[CSM] Use xds-enabled server and xds credentials in examples (#11706)
Browse files Browse the repository at this point in the history
  • Loading branch information
yashykt authored Nov 26, 2024
1 parent 20d09ce commit a79982c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/example-gcp-csm-observability/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}"
implementation "io.grpc:grpc-gcp-csm-observability:${grpcVersion}"
implementation "io.grpc:grpc-xds:${grpcVersion}"
implementation "io.opentelemetry:opentelemetry-sdk:${openTelemetryVersion}"
implementation "io.opentelemetry:opentelemetry-sdk-metrics:${openTelemetryVersion}"
implementation "io.opentelemetry:opentelemetry-exporter-prometheus:${openTelemetryPrometheusVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.gcp.csm.observability.CsmObservability;
import io.grpc.xds.XdsChannelCredentials;
import io.opentelemetry.exporter.prometheus.PrometheusHttpServer;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
Expand Down Expand Up @@ -127,8 +128,10 @@ public void run() {
observability.registerGlobal();

// Create a communication channel to the server, known as a Channel.
ManagedChannel channel = Grpc.newChannelBuilder(target, InsecureChannelCredentials.create())
.build();
ManagedChannel channel =
Grpc.newChannelBuilder(
target, XdsChannelCredentials.create(InsecureChannelCredentials.create()))
.build();
CsmObservabilityClient client = new CsmObservabilityClient(channel);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.gcp.csm.observability.CsmObservability;
import io.grpc.stub.StreamObserver;
import io.grpc.xds.XdsServerBuilder;
import io.grpc.xds.XdsServerCredentials;
import io.opentelemetry.exporter.prometheus.PrometheusHttpServer;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
Expand All @@ -40,10 +42,12 @@ public class CsmObservabilityServer {

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

Expand Down

0 comments on commit a79982c

Please sign in to comment.