Skip to content

Commit

Permalink
chore: back to ipch
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Phelps <[email protected]>
  • Loading branch information
markphelps committed Jan 30, 2025
1 parent e41c1a9 commit 2a6c714
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
13 changes: 2 additions & 11 deletions cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,16 @@ func run(ctx context.Context, logger *zap.Logger, cfg *config.Config) error {

// acts as a registry for all grpc services so they can be shared between
// the grpc server and the in-process client connection
var (
ipch = &inprocgrpc.Channel{}
handlers = &grpchan.HandlerMap{}
)
ipch := &inprocgrpc.Channel{}

grpcServer, err := cmd.NewGRPCServer(ctx, logger, cfg, handlers, info, forceMigrate)
grpcServer, err := cmd.NewGRPCServer(ctx, logger, cfg, ipch, info, forceMigrate)

Check warning on line 357 in cmd/flipt/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/flipt/main.go#L355-L357

Added lines #L355 - L357 were not covered by tests
if err != nil {
return err
}

// register all grpc services onto the grpc server
handlers.ForEach(grpcServer.RegisterService)

// starts grpc server
g.Go(grpcServer.Run)

// register all grpc services onto the in-process client connection
handlers.ForEach(ipch.RegisterService)

if cfg.Tracing.Enabled {
ipch = grpchan.InterceptClientConn(ipch, otelgrpc.UnaryClientInterceptor(), nil).(*inprocgrpc.Channel)

Check warning on line 366 in cmd/flipt/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/flipt/main.go#L365-L366

Added lines #L365 - L366 were not covered by tests
}
Expand Down
20 changes: 15 additions & 5 deletions internal/cmd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

sq "github.com/Masterminds/squirrel"
"github.com/fullstorydev/grpchan"
"github.com/fullstorydev/grpchan/inprocgrpc"
"go.flipt.io/flipt/internal/cache"
"go.flipt.io/flipt/internal/cache/memory"
"go.flipt.io/flipt/internal/cache/redis"
Expand Down Expand Up @@ -69,6 +70,7 @@ import (
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
Expand Down Expand Up @@ -98,7 +100,7 @@ func NewGRPCServer(
ctx context.Context,
logger *zap.Logger,
cfg *config.Config,
handlers *grpchan.HandlerMap,
ipch *inprocgrpc.Channel,
info info.Flipt,
forceMigrate bool,
) (*GRPCServer, error) {
Expand Down Expand Up @@ -287,6 +289,8 @@ func NewGRPCServer(
tokenDeletedEnabled = checker.Check("token:deleted")
}

handlers := &grpchan.HandlerMap{}

authInterceptors, authShutdown, err := authenticationGRPC(

Check warning on line 294 in internal/cmd/grpc.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L292-L294

Added lines #L292 - L294 were not covered by tests
ctx,
logger,
Expand Down Expand Up @@ -485,21 +489,27 @@ func NewGRPCServer(
grpcOpts = append(grpcOpts, grpc.Creds(creds))
}

ipch.WithServerUnaryInterceptor(grpc_middleware.ChainUnaryServer(interceptors...))

Check warning on line 493 in internal/cmd/grpc.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L492-L493

Added lines #L492 - L493 were not covered by tests
// initialize grpc server
server.Server = grpc.NewServer(grpcOpts...)
grpcServer := grpc.NewServer(grpcOpts...)
grpc_health.RegisterHealthServer(handlers, healthsrv)

handlers.ForEach(ipch.RegisterService)
handlers.ForEach(grpcServer.RegisterService)

Check warning on line 499 in internal/cmd/grpc.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L495-L499

Added lines #L495 - L499 were not covered by tests

// register grpcServer graceful stop on shutdown
server.onShutdown(func(context.Context) error {
healthsrv.Shutdown()
server.GracefulStop()
grpcServer.GracefulStop()

Check warning on line 504 in internal/cmd/grpc.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L504

Added line #L504 was not covered by tests
return nil
})

grpc_prometheus.EnableHandlingTimeHistogram()
grpc_prometheus.Register(server.Server)
reflection.Register(server.Server)
grpc_prometheus.Register(grpcServer)
reflection.Register(grpcServer)

Check warning on line 510 in internal/cmd/grpc.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L509-L510

Added lines #L509 - L510 were not covered by tests

server.Server = grpcServer

Check warning on line 512 in internal/cmd/grpc.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L512

Added line #L512 was not covered by tests
return server, nil
}

Expand Down

0 comments on commit 2a6c714

Please sign in to comment.