Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][query] Remove bifurcation for grpc query server #6145

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading