Skip to content

Commit

Permalink
automate-gateway: cleanup GRPC/HTTP multiplexing cruft
Browse files Browse the repository at this point in the history
This was carried over from some ancient grpc-gateway example code[1]; and
we're not exposing the GRPC API that way right now.

Using (*grpc.Server).ServeHTTP has some issues:

1. it's known to be slow, very slow[2]
2. it's seems to be not working with go-grpc >= 1.19 [3]

Furthermore, we're exposing the proper GRPC server (the native go-grpc
one) on a different port. If decide to (finally!) expose our GRPC API,
that's the thing we should expose.

So, since we don't need this multiplexing business, we shouldn't keep
the code around. This is the cleanup.

[1]: https://github.com/philips/grpc-gateway-example/
[2]: grpc/grpc-go#586
[3]: soheilhy/cmux#64 (comment)

Signed-off-by: Stephan Renatus <srenatus@chef.io>
  • Loading branch information
srenatus committed May 22, 2019
1 parent 468a0e1 commit 9263d22
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions components/automate-gateway/gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"net/http"
"net/url"
"strings"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
Expand Down Expand Up @@ -254,19 +253,6 @@ func WithRouteFeatureToggles(c *Config) Opts {
}
}

// handle GRPC returns
func (s *Server) grpcHandlerFunc(grpcServer *grpc.Server, muxHandler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// partial check of https://github.com/grpc/grpc-go/blob/master/transport/handler_server.go#L50
if r.ProtoMajor >= 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
// TODO: proxy to s.grpcURI instead
grpcServer.ServeHTTP(w, r)
} else {
muxHandler.ServeHTTP(w, r)
}
})
}

// NewGRPCServer returns a *grpc.Server instance
func (s *Server) NewGRPCServer() (*grpc.Server, error) {
authClient, err := s.clientsFactory.AuthenticationClient()
Expand Down Expand Up @@ -452,13 +438,11 @@ func (s *Server) Serve() error {
// Register Prometheus metrics handler.
mux.Handle("/metrics", promhttp.Handler())

handler := s.grpcHandlerFunc(grpcServer, mux)

// start server
uri := fmt.Sprintf("%s:%d", s.httpListenHost, s.httpListenPort)
srv := &http.Server{
Addr: uri,
Handler: handler,
Handler: mux,
TLSConfig: &tls.Config{
Certificates: []tls.Certificate{*s.serviceKeyPair},
NextProtos: []string{"h2"},
Expand Down

0 comments on commit 9263d22

Please sign in to comment.