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/csm_observability: add a flag to use XdsCredentials #7588

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 10 additions & 1 deletion examples/features/csm_observability/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/credentials/xds"
"google.golang.org/grpc/examples/features/proto/echo"
"google.golang.org/grpc/stats/opentelemetry"
"google.golang.org/grpc/stats/opentelemetry/csm"
Expand All @@ -40,6 +41,7 @@ import (
)

var (
useXdsCreds = flag.Bool("xds-creds", false, "use credentials provided by xDS. Defaults to insecure")
target = flag.String("target", "xds:///helloworld:50051", "the server address to connect to")
prometheusEndpoint = flag.String("prometheus_endpoint", ":9464", "the Prometheus exporter endpoint")
)
Expand All @@ -56,7 +58,14 @@ func main() {
cleanup := csm.EnableObservability(context.Background(), opentelemetry.Options{MetricsOptions: opentelemetry.MetricsOptions{MeterProvider: provider}})
defer cleanup()

cc, err := grpc.NewClient(*target, grpc.WithTransportCredentials(insecure.NewCredentials()))
credentials := insecure.NewCredentials()
if *useXdsCreds {
credentials, err = xds.NewClientCredentials(xds.ClientOptions{FallbackCreds: insecure.NewCredentials()})
if err != nil {
log.Fatalf("Failed to create xDS credentials: %v", err)
}
}
cc, err := grpc.NewClient(*target, grpc.WithTransportCredentials(credentials))
if err != nil {
log.Fatalf("Failed to start NewClient: %v", err)
}
Expand Down
Loading