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

GCP CSM Observability Java client use XdsCredentials #11505

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion examples/example-gcp-csm-observability/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ 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}"
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
runtimeOnly "io.grpc:grpc-xds:${grpcVersion}"
runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.grpc.examples.csmobservability;

import io.grpc.Channel;
import io.grpc.ChannelCredentials;
import io.grpc.Grpc;
import io.grpc.InsecureChannelCredentials;
import io.grpc.ManagedChannel;
Expand All @@ -25,9 +26,11 @@
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;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
Expand Down Expand Up @@ -72,14 +75,22 @@ public static void main(String[] args) throws Exception {
// The port on which prometheus metrics will be exposed.
int prometheusPort = 9464;
AtomicBoolean sendRpcs = new AtomicBoolean(true);
ChannelCredentials credentials = InsecureChannelCredentials.create();
if (args.length > 0) {
if ("--help".equals(args[0])) {
System.err.println("Usage: [name [target [prometheusPort]]]");
System.err.println("Usage: [--xds-creds] [name [target [prometheusPort]]]");
System.err.println("");
System.err.println(" --xds-creds Use credentials provided by xDS. Defaults to insecure");
System.err.println(" name The name you wish to be greeted by. Defaults to " + user);
System.err.println(" target The server to connect to. Defaults to " + target);
System.err.println(" prometheusPort The port to expose prometheus metrics. Defaults to " + prometheusPort);
System.exit(1);
} else if ("--xds-creds".equals(args[0])) {
// The xDS credentials use the security configured by the xDS server when available. When
// xDS is not used or when xDS does not provide security configuration, the xDS credentials
// fall back to other credentials (in this case, InsecureChannelCredentials).
credentials = XdsChannelCredentials.create(InsecureChannelCredentials.create());
args = Arrays.copyOfRange(args, 1, args.length);
}
user = args[0];
}
Expand Down Expand Up @@ -127,7 +138,7 @@ public void run() {
observability.registerGlobal();

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

Expand Down