Skip to content

Commit

Permalink
Remove Bifurcation For GRPC Query Server
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
  • Loading branch information
mahadzaryab1 committed Oct 31, 2024
1 parent 4f5eca1 commit d144eeb
Showing 1 changed file with 2 additions and 47 deletions.
49 changes: 2 additions & 47 deletions cmd/query/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"go.opentelemetry.io/otel/metric/noop"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"
Expand Down Expand Up @@ -78,12 +77,7 @@ func NewServer(
return nil, errors.New("server with TLS enabled can not use same host ports for gRPC and HTTP. Use dedicated HTTP and gRPC host ports instead")
}

var grpcServer *grpc.Server
if !separatePorts {
grpcServer, err = createGRPCServerLegacy(ctx, options, tm)
} else {
grpcServer, err = createGRPCServerOTEL(ctx, options, tm, telset)
}
grpcServer, err := createGRPCServer(ctx, options, tm, telset)
if err != nil {
return nil, err
}
Expand All @@ -103,45 +97,6 @@ func NewServer(
}, nil
}

func createGRPCServerLegacy(
ctx context.Context,
options *QueryOptions,
tm *tenancy.Manager,
) (*grpc.Server, error) {
var grpcOpts []grpc.ServerOption

if options.GRPC.TLSSetting != nil {
tlsCfg, err := options.GRPC.TLSSetting.LoadTLSConfig(ctx)
if err != nil {
return nil, err
}

creds := credentials.NewTLS(tlsCfg)

grpcOpts = append(grpcOpts, grpc.Creds(creds))
}

unaryInterceptors := []grpc.UnaryServerInterceptor{
bearertoken.NewUnaryServerInterceptor(),
}
streamInterceptors := []grpc.StreamServerInterceptor{
bearertoken.NewStreamServerInterceptor(),
}
//nolint:contextcheck
if tm.Enabled {
unaryInterceptors = append(unaryInterceptors, tenancy.NewGuardingUnaryInterceptor(tm))
streamInterceptors = append(streamInterceptors, tenancy.NewGuardingStreamInterceptor(tm))
}

grpcOpts = append(grpcOpts,
grpc.ChainUnaryInterceptor(unaryInterceptors...),
grpc.ChainStreamInterceptor(streamInterceptors...),
)

server := grpc.NewServer(grpcOpts...)
return server, nil
}

func registerGRPCHandlers(
server *grpc.Server,
querySvc *querysvc.QueryService,
Expand All @@ -165,7 +120,7 @@ func registerGRPCHandlers(
grpc_health_v1.RegisterHealthServer(server, healthServer)
}

func createGRPCServerOTEL(
func createGRPCServer(
ctx context.Context,
options *QueryOptions,
tm *tenancy.Manager,
Expand Down

0 comments on commit d144eeb

Please sign in to comment.