From 8049266e642e3a6a0782ab9eee5fee439f0acfcc Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 2 Jun 2020 17:31:56 +0200 Subject: [PATCH] improvements --- examples/csharp/Xds/GreeterServer/Program.cs | 6 +- examples/csharp/Xds/README.md | 90 +++++++++++++++++--- 2 files changed, 83 insertions(+), 13 deletions(-) diff --git a/examples/csharp/Xds/GreeterServer/Program.cs b/examples/csharp/Xds/GreeterServer/Program.cs index 030dd61c8b2..e7a2965739f 100644 --- a/examples/csharp/Xds/GreeterServer/Program.cs +++ b/examples/csharp/Xds/GreeterServer/Program.cs @@ -30,14 +30,14 @@ namespace GreeterServer // Server side handler of the SayHello RPC public override Task SayHello(HelloRequest request, ServerCallContext context) { - String hostName = Dns.GetHostName(); + String hostName = Dns.GetHostName(); // TODO: make hostname configurable return Task.FromResult(new HelloReply { Message = $"Hello {request.Name} from {hostName}!"}); } } class Program { - const int Port = 50051; + const int Port = 50051; // TODO: make port configurable public static void Main(string[] args) { @@ -49,7 +49,7 @@ namespace GreeterServer Server server = new Server { Services = { Greeter.BindService(greeterImpl), Health.BindService(healthServiceImpl), ServerReflection.BindService(reflectionImpl) }, - Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } + Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } // TODO: don't listen on just localhost }; server.Start(); diff --git a/examples/csharp/Xds/README.md b/examples/csharp/Xds/README.md index 7c09f307896..9b3f939dcf0 100644 --- a/examples/csharp/Xds/README.md +++ b/examples/csharp/Xds/README.md @@ -3,7 +3,7 @@ gRPC Hostname example (C#) BACKGROUND ------------- -This is a version of the helloworld example with a server whose response includes its hostname. It also supports health and reflection services. This makes it a good server to test infrastructure, like load balancing. +This is a version of the helloworld example with a server whose response includes its hostname. It also supports health and reflection services. This makes it a good server to test infrastructure, such as XDS load balancing. PREREQUISITES ------------- @@ -13,17 +13,87 @@ PREREQUISITES You can also build the solution `Greeter.sln` using Visual Studio 2019, but it's not a requirement. -BUILD AND RUN +RUN THE EXAMPLE ------------- -- Build and run the server +First, build and run the server, then verify the server is running and +check the server is behaving as expected (more on that below). - ``` - > dotnet run -p GreeterServer - ``` +``` +cd GreeterServer +dotnet run +``` -- Build and run the client +After configuring your xDS server to track the gRPC server we just started, +create a bootstrap file as desribed in [gRFC A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md): - ``` - > dotnet run -p GreeterClient - ``` +``` +{ + xds_servers": [ + { + "server_uri": , + "channel_creds": [ + { + "type": , + "config": + } + ] + } + ], + "node": +} +``` + +Then point the `GRPC_XDS_BOOTSTRAP` environment variable at the bootstrap file: + +``` +export GRPC_XDS_BOOTSTRAP=/etc/xds-bootstrap.json +``` + +Finally, run your client: + +``` +cd GreeterClient +dotnet run -- xds-experimental:///my-backend +``` + +VERIFYING THE SERVER +------------- + +`grpcurl` can be used to test your server. If you don't have it, +install [`grpcurl`](https://github.com/fullstorydev/grpcurl/releases). This will allow +you to manually test the service. + +Exercise your server's application-layer service: + +```sh +> grpcurl --plaintext -d '{"name": "you"}' localhost:50051 +{ + "message": "Hello you from jtatt.muc.corp.google.com!" +} +``` + +Make sure that all of your server's services are available via reflection: + +```sh +> grpcurl --plaintext localhost:50051 list +grpc.health.v1.Health +grpc.reflection.v1alpha.ServerReflection +helloworld.Greeter +``` + +Make sure that your services are reporting healthy: + +```sh +> grpcurl --plaintext -d '{"service": "helloworld.Greeter"}' localhost:50051 +grpc.health.v1.Health/Check +{ + "status": "SERVING" +} + +> grpcurl --plaintext -d '{"service": ""}' localhost:50051 +grpc.health.v1.Health/Check +{ + "status": "SERVING" +} +```