From 3891b17e919f5de68906f8e28785d8780f9f3b7b Mon Sep 17 00:00:00 2001 From: Zaba505 Date: Sun, 17 Dec 2023 13:51:04 -0500 Subject: [PATCH] example(issue-35): register reflection service so grpc example works with insomnia etc. --- example/simple_grpc/Containerfile | 1 + example/simple_grpc/main.go | 9 ++++++++- example/simple_grpc/simple_grpc.proto | 5 +++++ example/simple_http/Containerfile | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/example/simple_grpc/Containerfile b/example/simple_grpc/Containerfile index 978ee21..489d3b0 100644 --- a/example/simple_grpc/Containerfile +++ b/example/simple_grpc/Containerfile @@ -4,5 +4,6 @@ # https://opensource.org/licenses/MIT FROM scratch +EXPOSE 9080 COPY simple_grpc / ENTRYPOINT ["/simple_grpc"] \ No newline at end of file diff --git a/example/simple_grpc/main.go b/example/simple_grpc/main.go index 6579ee4..2793a32 100644 --- a/example/simple_grpc/main.go +++ b/example/simple_grpc/main.go @@ -18,6 +18,7 @@ import ( "go.opentelemetry.io/otel" "google.golang.org/grpc" + "google.golang.org/grpc/reflection" ) type simpleService struct { @@ -25,7 +26,7 @@ type simpleService struct { } func (*simpleService) Echo(ctx context.Context, req *simple_grpc_pb.EchoRequest) (*simple_grpc_pb.EchoResponse, error) { - _, span := otel.Tracer("main").Start(ctx, "simpleServer.Echo") + _, span := otel.Tracer("main").Start(ctx, "simpleService.Echo") defer span.End() resp := &simple_grpc_pb.EchoResponse{ Message: req.Message, @@ -48,6 +49,12 @@ func initRuntime(bc bedrock.BuildContext) (bedrock.Runtime, error) { brgrpc.ServiceName("simple"), brgrpc.Readiness(&health.Readiness{}), ), + // register reflection service so you can test this example + // via Insomnia, Postman and any other API testing tool that + // understands gRPC reflection. + brgrpc.Service(func(s *grpc.Server) { + reflection.Register(s) + }), ) return rt, nil } diff --git a/example/simple_grpc/simple_grpc.proto b/example/simple_grpc/simple_grpc.proto index 09733d6..1713774 100644 --- a/example/simple_grpc/simple_grpc.proto +++ b/example/simple_grpc/simple_grpc.proto @@ -1,3 +1,8 @@ +// Copyright (c) 2023 Z5Labs and Contributors +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + syntax = "proto3"; package simple_grpc_pb; diff --git a/example/simple_http/Containerfile b/example/simple_http/Containerfile index 5c472d4..6054c4b 100644 --- a/example/simple_http/Containerfile +++ b/example/simple_http/Containerfile @@ -4,5 +4,6 @@ # https://opensource.org/licenses/MIT FROM scratch +EXPOSE 8080 COPY simple_http / ENTRYPOINT ["/simple_http"] \ No newline at end of file