Skip to content

Commit

Permalink
chore: try to wire things up again
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 7a1d53e commit 5cf000f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build/testing/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

var (
fliptAddr = flag.String("flipt-addr", "grpc://localhost:9000", "Address for running Flipt instance (gRPC only)")
fliptAddr = flag.String("flipt-addr", "grpc://localhost:9000", "Address for running Flipt instance")
fliptToken = flag.String("flipt-token", "", "Full-Access authentication token to be used during test suite")
fliptReferences = flag.Bool("flipt-supports-references", false, "Identifies the backend as supporting references")
)
Expand Down
11 changes: 9 additions & 2 deletions cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,20 @@ 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
ipch := &inprocgrpc.Channel{}
var (
ipch = &inprocgrpc.Channel{}
handlers = &grpchan.HandlerMap{}
)

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

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

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

View check run for this annotation

Codecov / codecov/patch

cmd/flipt/main.go#L355-L362

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

handlers.ForEach(grpcServer.RegisterService)

// register all grpc services onto the grpc server

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

View check run for this annotation

Codecov / codecov/patch

cmd/flipt/main.go#L367-L369

Added lines #L367 - L369 were not covered by tests
// starts grpc server
g.Go(grpcServer.Run)
Expand Down
20 changes: 10 additions & 10 deletions internal/cmd/authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"strings"

"github.com/fullstorydev/grpchan/inprocgrpc"
"github.com/fullstorydev/grpchan"
"github.com/go-chi/chi/v5"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/selector"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
Expand Down Expand Up @@ -91,7 +91,7 @@ func authenticationGRPC(
ctx context.Context,
logger *zap.Logger,
cfg *config.Config,
ipch *inprocgrpc.Channel,
handlers *grpchan.HandlerMap,
forceMigrate bool,
tokenDeletedEnabled bool,
authOpts ...containers.Option[authmiddlewaregrpc.InterceptorOptions],
Expand All @@ -108,8 +108,8 @@ func authenticationGRPC(
// All that is required to establish a connection for authentication is to either make auth required
// or configure at-least one authentication method (e.g. enable token method).
if !authCfg.Enabled() && (cfg.Storage.Type != config.DatabaseStorageType) {
rpcauth.RegisterPublicAuthenticationServiceServer(ipch, public.NewServer(logger, authCfg))
rpcauth.RegisterAuthenticationServiceServer(ipch, authn.NewServer(logger, storageauthmemory.NewStore()))
rpcauth.RegisterPublicAuthenticationServiceServer(handlers, public.NewServer(logger, authCfg))
rpcauth.RegisterAuthenticationServiceServer(handlers, authn.NewServer(logger, storageauthmemory.NewStore()))
return nil, shutdown, nil

Check warning on line 113 in internal/cmd/authn.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/authn.go#L111-L113

Added lines #L111 - L113 were not covered by tests
}

Expand All @@ -128,8 +128,8 @@ func authenticationGRPC(

var interceptors []grpc.UnaryServerInterceptor

Check warning on line 129 in internal/cmd/authn.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/authn.go#L129

Added line #L129 was not covered by tests

rpcauth.RegisterPublicAuthenticationServiceServer(ipch, public.NewServer(logger, authCfg))
rpcauth.RegisterAuthenticationServiceServer(ipch, authn.NewServer(logger, store, authn.WithAuditLoggingEnabled(tokenDeletedEnabled)))
rpcauth.RegisterPublicAuthenticationServiceServer(handlers, public.NewServer(logger, authCfg))
rpcauth.RegisterAuthenticationServiceServer(handlers, authn.NewServer(logger, store, authn.WithAuditLoggingEnabled(tokenDeletedEnabled)))

Check warning on line 132 in internal/cmd/authn.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/authn.go#L131-L132

Added lines #L131 - L132 were not covered by tests

// register auth method token service
if authCfg.Methods.Token.Enabled {
Expand Down Expand Up @@ -160,20 +160,20 @@ func authenticationGRPC(
logger.Info("access token created", zap.String("client_token", clientToken))
}

rpcauth.RegisterAuthenticationMethodTokenServiceServer(ipch, authtoken.NewServer(logger, store))
rpcauth.RegisterAuthenticationMethodTokenServiceServer(handlers, authtoken.NewServer(logger, store))

Check warning on line 163 in internal/cmd/authn.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/authn.go#L163

Added line #L163 was not covered by tests

logger.Debug("authentication method \"token\" server registered")
}

// register auth method oidc service
if authCfg.Methods.OIDC.Enabled {
rpcauth.RegisterAuthenticationMethodOIDCServiceServer(ipch, authoidc.NewServer(logger, store, authCfg))
rpcauth.RegisterAuthenticationMethodOIDCServiceServer(handlers, authoidc.NewServer(logger, store, authCfg))

Check warning on line 170 in internal/cmd/authn.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/authn.go#L170

Added line #L170 was not covered by tests

logger.Debug("authentication method \"oidc\" server registered")
}

if authCfg.Methods.Github.Enabled {
rpcauth.RegisterAuthenticationMethodGithubServiceServer(ipch, authgithub.NewServer(logger, store, authCfg))
rpcauth.RegisterAuthenticationMethodGithubServiceServer(handlers, authgithub.NewServer(logger, store, authCfg))

Check warning on line 176 in internal/cmd/authn.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/authn.go#L176

Added line #L176 was not covered by tests

logger.Debug("authentication method \"github\" registered")
}
Expand All @@ -183,7 +183,7 @@ func authenticationGRPC(
if err != nil {
return nil, nil, fmt.Errorf("configuring kubernetes authentication: %w", err)

Check warning on line 184 in internal/cmd/authn.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/authn.go#L184

Added line #L184 was not covered by tests
}
rpcauth.RegisterAuthenticationMethodKubernetesServiceServer(ipch, kubernetesServer)
rpcauth.RegisterAuthenticationMethodKubernetesServiceServer(handlers, kubernetesServer)

Check warning on line 186 in internal/cmd/authn.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/authn.go#L186

Added line #L186 was not covered by tests

logger.Debug("authentication method \"kubernetes\" server registered")
}
Expand Down
24 changes: 11 additions & 13 deletions internal/cmd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"go.opentelemetry.io/contrib/propagators/autoprop"

sq "github.com/Masterminds/squirrel"
"github.com/fullstorydev/grpchan/inprocgrpc"
"github.com/fullstorydev/grpchan"
"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,7 +69,6 @@ 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 @@ -99,7 +98,7 @@ func NewGRPCServer(
ctx context.Context,
logger *zap.Logger,
cfg *config.Config,
ipch *inprocgrpc.Channel,
handlers *grpchan.HandlerMap,
info info.Flipt,
forceMigrate bool,
) (*GRPCServer, error) {
Expand Down Expand Up @@ -292,7 +291,7 @@ func NewGRPCServer(
ctx,
logger,
cfg,
ipch,
handlers,

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

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L294

Added line #L294 was not covered by tests
forceMigrate,
tokenDeletedEnabled,
authnOpts...,
Expand All @@ -318,24 +317,24 @@ func NewGRPCServer(
server.onShutdown(func(ctx context.Context) error {
return analyticsExporter.Shutdown(ctx)
})
rpcanalytics.RegisterAnalyticsServiceServer(ipch, analytics.New(logger, client))
rpcanalytics.RegisterAnalyticsServiceServer(handlers, analytics.New(logger, client))

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

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L320

Added line #L320 was not covered by tests
logger.Debug("analytics enabled", zap.String("database", client.String()), zap.String("flush_period", cfg.Analytics.Buffer.FlushPeriod.String()))
} else if cfg.Analytics.Storage.Prometheus.Enabled {
client, err := prometheus.New(logger, cfg)
if err != nil {
return nil, err
}
rpcanalytics.RegisterAnalyticsServiceServer(ipch, analytics.New(logger, client))
rpcanalytics.RegisterAnalyticsServiceServer(handlers, analytics.New(logger, client))

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

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L327

Added line #L327 was not covered by tests
logger.Debug("analytics enabled", zap.String("database", client.String()))
}
}

// register servers
rpcflipt.RegisterFliptServer(ipch, fliptsrv)
rpcmeta.RegisterMetadataServiceServer(ipch, metasrv)
rpcevaluation.RegisterEvaluationServiceServer(ipch, evalsrv)
rpcevaluation.RegisterDataServiceServer(ipch, evaldatasrv)
rpcoffrep.RegisterOFREPServiceServer(ipch, ofrepsrv)
rpcflipt.RegisterFliptServer(handlers, fliptsrv)
rpcmeta.RegisterMetadataServiceServer(handlers, metasrv)
rpcevaluation.RegisterEvaluationServiceServer(handlers, evalsrv)
rpcevaluation.RegisterDataServiceServer(handlers, evaldatasrv)
rpcoffrep.RegisterOFREPServiceServer(handlers, ofrepsrv)

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

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L333-L337

Added lines #L333 - L337 were not covered by tests

// forward internal gRPC logging to zap
grpcLogLevel, err := zapcore.ParseLevel(cfg.Log.GRPCLevel)
Expand Down Expand Up @@ -488,8 +487,7 @@ func NewGRPCServer(

// initialize grpc server
server.Server = grpc.NewServer(grpcOpts...)
grpc_health.RegisterHealthServer(ipch, healthsrv)
ipch.WithServerUnaryInterceptor(grpc_middleware.ChainUnaryServer(interceptors...))
grpc_health.RegisterHealthServer(handlers, healthsrv)

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

View check run for this annotation

Codecov / codecov/patch

internal/cmd/grpc.go#L490

Added line #L490 was not covered by tests

// register grpcServer graceful stop on shutdown
server.onShutdown(func(context.Context) error {
Expand Down
4 changes: 1 addition & 3 deletions internal/cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ func NewHTTPServer(

// mount the metadata service to the chi router under /meta.
r.Mount("/meta", runtime.NewServeMux(
func(mux *runtime.ServeMux) {
meta.RegisterMetadataServiceHandlerClient(ctx, mux, meta.NewMetadataServiceClient(conn))
},
register(ctx, meta.NewMetadataServiceClient(conn), meta.RegisterMetadataServiceHandlerClient),

Check warning on line 188 in internal/cmd/http.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/http.go#L188

Added line #L188 was not covered by tests
runtime.WithMetadata(method.ForwardPrefix),
))
})
Expand Down

0 comments on commit 5cf000f

Please sign in to comment.