From 9bc2c9f865a862fc22118251995b740dd2cd45cf Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Tue, 23 Jun 2020 17:53:12 -0700 Subject: [PATCH] Update gateway to avoid an extra gRPC call Signed-off-by: Bogdan Drutu --- receiver/otlpreceiver/otlp.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index d6174430345..62c92297bf2 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -224,24 +224,16 @@ func (r *Receiver) startServer(host component.Host) error { err := componenterror.ErrAlreadyStarted r.startServerOnce.Do(func() { err = nil - // Register the grpc-gateway on the HTTP server mux - c := context.Background() - opts := []grpc.DialOption{grpc.WithInsecure()} - endpoint := r.ln.Addr().String() - - _, ok := r.ln.(*net.UnixListener) - if ok { - endpoint = "unix:" + endpoint - } - err = collectortrace.RegisterTraceServiceHandlerFromEndpoint(c, r.gatewayMux, endpoint, opts) - if err != nil { - return + // Register the grpc-gateway on the HTTP server mux + if r.traceReceiver != nil { + // Cannot return error, impossible to test + _ = collectortrace.RegisterTraceServiceHandlerServer(context.Background(), r.gatewayMux, r.traceReceiver) } - err = collectormetrics.RegisterMetricsServiceHandlerFromEndpoint(c, r.gatewayMux, endpoint, opts) - if err != nil { - return + if r.metricsReceiver != nil { + // Cannot return error, impossible to test + _ = collectormetrics.RegisterMetricsServiceHandlerServer(context.Background(), r.gatewayMux, r.metricsReceiver) } // Start the gRPC and HTTP/JSON (grpc-gateway) servers on the same port.